Quellcode durchsuchen

Merge pull request #535 from dec5e/slack_extandable

Making SlackHandler more extendable
Jordi Boggiano vor 10 Jahren
Ursprung
Commit
e064827e23
1 geänderte Dateien mit 21 neuen und 9 gelöschten Zeilen
  1. 21 9
      src/Monolog/Handler/SlackHandler.php

+ 21 - 9
src/Monolog/Handler/SlackHandler.php

@@ -120,19 +120,32 @@ class SlackHandler extends SocketHandler
      * @return string
      */
     private function buildContent($record)
+    {
+        $dataArray = $this->prepareContentData($record);
+
+        return http_build_query($dataArray);
+    }
+
+    /**
+     * Prepares content data
+     *
+     * @param  array $record
+     * @return array
+     */
+    protected function prepareContentData($record)
     {
         $dataArray = array(
-            'token' => $this->token,
-            'channel' => $this->channel,
-            'username' => $this->username,
-            'text' => '',
+            'token'       => $this->token,
+            'channel'     => $this->channel,
+            'username'    => $this->username,
+            'text'        => '',
             'attachments' => array()
         );
 
         if ($this->useAttachment) {
             $attachment = array(
                 'fallback' => $record['message'],
-                'color' => $this->getAttachmentColor($record['level'])
+                'color'    => $this->getAttachmentColor($record['level'])
             );
 
             if ($this->useShortAttachment) {
@@ -173,7 +186,7 @@ class SlackHandler extends SocketHandler
                                 'title' => $var,
                                 'value' => $val,
                                 'short' => $this->useShortAttachment
-                           );
+                            );
                         }
                     }
                 }
@@ -192,7 +205,7 @@ class SlackHandler extends SocketHandler
                                 'title' => $var,
                                 'value' => $val,
                                 'short' => $this->useShortAttachment
-                           );
+                            );
                         }
                     }
                 }
@@ -206,8 +219,7 @@ class SlackHandler extends SocketHandler
         if ($this->iconEmoji) {
             $dataArray['icon_emoji'] = ":{$this->iconEmoji}:";
         }
-
-        return http_build_query($dataArray);
+        return $dataArray;
     }
 
     /**