ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
FlowdockHandler.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Monolog\Handler;
13
17
30{
34 protected $apiToken;
35
43 public function __construct($apiToken, $level = Logger::DEBUG, $bubble = true)
44 {
45 if (!extension_loaded('openssl')) {
46 throw new MissingExtensionException('The OpenSSL PHP extension is required to use the FlowdockHandler');
47 }
48
49 parent::__construct('ssl://api.flowdock.com:443', $level, $bubble);
50 $this->apiToken = $apiToken;
51 }
52
57 {
58 if (!$formatter instanceof FlowdockFormatter) {
59 throw new \InvalidArgumentException('The FlowdockHandler requires an instance of Monolog\Formatter\FlowdockFormatter to function correctly');
60 }
61
62 return parent::setFormatter($formatter);
63 }
64
70 protected function getDefaultFormatter()
71 {
72 throw new \InvalidArgumentException('The FlowdockHandler must be configured (via setFormatter) with an instance of Monolog\Formatter\FlowdockFormatter to function correctly');
73 }
74
80 protected function write(array $record)
81 {
82 parent::write($record);
83
84 $this->closeSocket();
85 }
86
93 protected function generateDataStream($record)
94 {
95 $content = $this->buildContent($record);
96
97 return $this->buildHeader($content) . $content;
98 }
99
106 private function buildContent($record)
107 {
108 return json_encode($record['formatted']['flowdock']);
109 }
110
117 private function buildHeader($content)
118 {
119 $header = "POST /v1/messages/team_inbox/" . $this->apiToken . " HTTP/1.1\r\n";
120 $header .= "Host: api.flowdock.com\r\n";
121 $header .= "Content-Type: application/json\r\n";
122 $header .= "Content-Length: " . strlen($content) . "\r\n";
123 $header .= "\r\n";
124
125 return $header;
126 }
127}
formats the record to be used in the FlowdockHandler
Sends notifications through the Flowdock push API.
buildHeader($content)
Builds the header of the API Call.
getDefaultFormatter()
Gets the default formatter.
__construct($apiToken, $level=Logger::DEBUG, $bubble=true)
setFormatter(FormatterInterface $formatter)
{{Sets the formatter.self}}
buildContent($record)
Builds the body of API call.
write(array $record)
{Connect (if necessary) and write to the socket.UnexpectedValueException RuntimeException}
Exception can be thrown if an extension for an handler is missing.
Stores to any socket - uses fsockopen() or pfsockopen().
closeSocket()
Close socket, if open.
Monolog log channel.
Definition: Logger.php:28
const DEBUG
Detailed debug information.
Definition: Logger.php:32
$header