1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-06 13:16:39 +02:00

Move iconEmoji param upfront since Slack was never in a stable release

This commit is contained in:
Jordi Boggiano
2014-09-30 14:24:56 +01:00
parent 31358c858f
commit d2ec7648d0
2 changed files with 11 additions and 10 deletions

View File

@@ -52,14 +52,15 @@ class SlackHandler extends SocketHandler
private $useAttachment; private $useAttachment;
/** /**
* @param string $token Slack API token * @param string $token Slack API token
* @param string $channel Slack channel (encoded ID or name) * @param string $channel Slack channel (encoded ID or name)
* @param string $username Name of a bot * @param string $username Name of a bot
* @param bool $useAttachment Whether the message should be added to Slack as attachment (plain text otherwise) * @param bool $useAttachment Whether the message should be added to Slack as attachment (plain text otherwise)
* @param int $level The minimum logging level at which this handler will be triggered * @param string|null $iconEmoji The emoji name to use (or null)
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not * @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
*/ */
public function __construct($token, $channel, $username = 'Monolog', $useAttachment = true, $level = Logger::CRITICAL, $bubble = true, $iconEmoji = null) public function __construct($token, $channel, $username = 'Monolog', $useAttachment = true, $iconEmoji = null, $level = Logger::CRITICAL, $bubble = true)
{ {
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');
@@ -70,7 +71,7 @@ class SlackHandler extends SocketHandler
$this->token = $token; $this->token = $token;
$this->channel = $channel; $this->channel = $channel;
$this->username = $username; $this->username = $username;
$this->iconEmoji = $iconEmoji; $this->iconEmoji = trim($iconEmoji, ':');
$this->useAttachment = $useAttachment; $this->useAttachment = $useAttachment;
} }
@@ -128,7 +129,7 @@ class SlackHandler extends SocketHandler
$dataArray['text'] = $record['message']; $dataArray['text'] = $record['message'];
} }
if ($this->iconEmoji !== null) { if ($this->iconEmoji) {
$dataArray['icon_emoji'] = ":{$this->iconEmoji}:"; $dataArray['icon_emoji'] = ":{$this->iconEmoji}:";
} }

View File

@@ -106,7 +106,7 @@ class SlackHandlerTest extends TestCase
private function createHandler($token = 'myToken', $channel = 'channel1', $username = 'Monolog', $useAttachment = true, $iconEmoji = null) private function createHandler($token = 'myToken', $channel = 'channel1', $username = 'Monolog', $useAttachment = true, $iconEmoji = null)
{ {
$constructorArgs = array($token, $channel, $username, $useAttachment, Logger::DEBUG, true, $iconEmoji); $constructorArgs = array($token, $channel, $username, $useAttachment, $iconEmoji, Logger::DEBUG, true);
$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',