From 5526c24375dcbf739d01a8b6736b867c991dd4d7 Mon Sep 17 00:00:00 2001 From: bsitu Date: Wed, 6 Mar 2013 19:08:12 -0800 Subject: [PATCH] extract payload from generic format method This will allow 3rd parties to define their own payload for notification Change-Id: If3a7c1d7d51beb96379af46617e15f76a32e6c05 --- formatters/BasicFormatter.php | 52 +++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/formatters/BasicFormatter.php b/formatters/BasicFormatter.php index e55fd13f8..1ec081536 100644 --- a/formatters/BasicFormatter.php +++ b/formatters/BasicFormatter.php @@ -1,5 +1,10 @@ payload as $payloadComponent ) { - if ( in_array( $payloadComponent, $this->validPayloadComponents ) ) { - switch ( $payloadComponent ) { - case 'summary': - $payload .= $this->formatSummary( $event, $user ); - break; - case 'snippet': - // TODO: build this - break; - case 'welcome': - $details = array( - 'message' => 'notification-new-user-content', - 'params' => array( 'agent' ) - ); - $payload .= $this->formatFragment( $details, $event, $user )->parse(); - break; - } - } else { - throw new MWException( "Unrecognised payload component $payloadComponent" ); - } + $payload .= $this->formatPayload( $payloadComponent, $event, $user ); } if ( $payload !== '' ) { @@ -247,6 +233,32 @@ class EchoBasicFormatter extends EchoNotificationFormatter { return $message; } + /** + * Formats the payload of a notification, child method overwriting this method should + * always call this method in default case so they can use the payload defined in this + * function as well + * @param $payload string + * @param $event EchoEvent + * @param $user User + * @return string + */ + protected function formatPayload( $payload, $event, $user ) { + switch ( $payload ) { + case 'summary': + return $this->formatSummary( $event, $user ); + break; + case 'welcome': + $details = array( + 'message' => 'notification-new-user-content', + 'params' => array( 'agent' ) + ); + return $this->formatFragment( $details, $event, $user )->parse(); + break; + default: + return ''; + } + } + /** * Generate links based on output format and passed properties * $event EchoEvent