浏览代码

Updated position of iconEmoji variable to prevent BC breaks

Derek Clapham 11 年之前
父节点
当前提交
ff6c458260
共有 2 个文件被更改,包括 8 次插入5 次删除
  1. 6 3
      src/Monolog/Handler/SlackHandler.php
  2. 2 2
      tests/Monolog/Handler/SlackHandlerTest.php

+ 6 - 3
src/Monolog/Handler/SlackHandler.php

@@ -59,7 +59,7 @@ class SlackHandler extends SocketHandler
      * @param int    $level         The minimum logging level at which this handler will be triggered
      * @param int    $level         The minimum logging level at which this handler will be triggered
      * @param bool   $bubble        Whether the messages that are handled can bubble up the stack or not
      * @param bool   $bubble        Whether the messages that are handled can bubble up the stack or not
      */
      */
-    public function __construct($token, $channel, $username = 'Monolog', $iconEmoji = 'alien', $useAttachment = true, $level = Logger::CRITICAL, $bubble = true)
+    public function __construct($token, $channel, $username = 'Monolog', $useAttachment = true, $level = Logger::CRITICAL, $bubble = true, $iconEmoji = null)
     {
     {
         if (!extension_loaded('openssl')) {
         if (!extension_loaded('openssl')) {
             throw new MissingExtensionException('The OpenSSL PHP extension is required to use the SlackHandler');
             throw new MissingExtensionException('The OpenSSL PHP extension is required to use the SlackHandler');
@@ -99,7 +99,6 @@ class SlackHandler extends SocketHandler
             'token' => $this->token,
             'token' => $this->token,
             'channel' => $this->channel,
             'channel' => $this->channel,
             'username' => $this->username,
             'username' => $this->username,
-            'icon_emoji' => ":{$this->iconEmoji}:",
             'text' => '',
             'text' => '',
             'attachments' => array()
             'attachments' => array()
         );
         );
@@ -128,7 +127,11 @@ class SlackHandler extends SocketHandler
         } else {
         } else {
             $dataArray['text'] = $record['message'];
             $dataArray['text'] = $record['message'];
         }
         }
-
+        
+        if ($this->iconEmoji !== null) {
+            $dataArray['icon_emoji'] = ":{$this->iconEmoji}:";
+        }
+        
         return http_build_query($dataArray);
         return http_build_query($dataArray);
     }
     }
 
 

+ 2 - 2
tests/Monolog/Handler/SlackHandlerTest.php

@@ -54,7 +54,7 @@ class SlackHandlerTest extends TestCase
         fseek($this->res, 0);
         fseek($this->res, 0);
         $content = fread($this->res, 1024);
         $content = fread($this->res, 1024);
 
 
-        $this->assertRegexp('/token=myToken&channel=channel1&username=Monolog&icon_emoji=%3Aalien%3A&text=&attachments=.*$/', $content);
+        $this->assertRegexp('/token=myToken&channel=channel1&username=Monolog&text=&attachments=.*&icon_emoji=%3Aalien%3A$/', $content);
     }
     }
 
 
     /**
     /**
@@ -96,7 +96,7 @@ class SlackHandlerTest extends TestCase
 
 
     private function createHandler($token = 'myToken', $channel = 'channel1', $username = 'Monolog', $iconEmoji = 'alien', $useAttachment = true)
     private function createHandler($token = 'myToken', $channel = 'channel1', $username = 'Monolog', $iconEmoji = 'alien', $useAttachment = true)
     {
     {
-        $constructorArgs = array($token, $channel, $username, $iconEmoji, $useAttachment, Logger::DEBUG, true);
+        $constructorArgs = array($token, $channel, $username, $useAttachment, Logger::DEBUG, true, $iconEmoji);
         $this->res = fopen('php://memory', 'a');
         $this->res = fopen('php://memory', 'a');
         $this->handler = $this->getMock(
         $this->handler = $this->getMock(
             '\Monolog\Handler\SlackHandler',
             '\Monolog\Handler\SlackHandler',