ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
12 namespace Monolog\Handler;
13 
14 use Monolog\Logger;
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 }
const DEBUG
Detailed debug information.
Definition: Logger.php:32
Stores to any socket - uses fsockopen() or pfsockopen().
getDefaultFormatter()
Gets the default formatter.
buildContent($record)
Builds the body of API call.
__construct($apiToken, $level=Logger::DEBUG, $bubble=true)
formats the record to be used in the FlowdockHandler
Exception can be thrown if an extension for an handler is missing.
Sends notifications through the Flowdock push API.
Create styles array
The data for the language used.
buildHeader($content)
Builds the header of the API Call.
setFormatter(FormatterInterface $formatter)
{Sets the formatter.self}
closeSocket()
Close socket, if open.