ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
FirePHPHandler.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
15
22{
26 const PROTOCOL_URI = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
27
31 const STRUCTURE_URI = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
32
36 const PLUGIN_URI = 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3';
37
41 const HEADER_PREFIX = 'X-Wf';
42
46 protected static $initialized = false;
47
52 protected static $messageIndex = 1;
53
54 protected static $sendHeaders = true;
55
63 protected function createHeader(array $meta, $message)
64 {
65 $header = sprintf('%s-%s', self::HEADER_PREFIX, join('-', $meta));
66
67 return array($header => $message);
68 }
69
77 protected function createRecordHeader(array $record)
78 {
79 // Wildfire is extensible to support multiple protocols & plugins in a single request,
80 // but we're not taking advantage of that (yet), so we're using "1" for simplicity's sake.
81 return $this->createHeader(
82 array(1, 1, 1, self::$messageIndex++),
83 $record['formatted']
84 );
85 }
86
90 protected function getDefaultFormatter()
91 {
92 return new WildfireFormatter();
93 }
94
102 protected function getInitHeaders()
103 {
104 // Initial payload consists of required headers for Wildfire
105 return array_merge(
106 $this->createHeader(array('Protocol', 1), self::PROTOCOL_URI),
107 $this->createHeader(array(1, 'Structure', 1), self::STRUCTURE_URI),
108 $this->createHeader(array(1, 'Plugin', 1), self::PLUGIN_URI)
109 );
110 }
111
118 protected function sendHeader($header, $content)
119 {
120 if (!headers_sent() && self::$sendHeaders) {
121 header(sprintf('%s: %s', $header, $content));
122 }
123 }
124
132 protected function write(array $record)
133 {
134 if (!self::$sendHeaders) {
135 return;
136 }
137
138 // WildFire-specific headers must be sent prior to any messages
139 if (!self::$initialized) {
140 self::$initialized = true;
141
142 self::$sendHeaders = $this->headersAccepted();
143 if (!self::$sendHeaders) {
144 return;
145 }
146
147 foreach ($this->getInitHeaders() as $header => $content) {
148 $this->sendHeader($header, $content);
149 }
150 }
151
152 $header = $this->createRecordHeader($record);
153 if (trim(current($header)) !== '') {
154 $this->sendHeader(key($header), current($header));
155 }
156 }
157
163 protected function headersAccepted()
164 {
165 if (!empty($_SERVER['HTTP_USER_AGENT']) && preg_match('{\bFirePHP/\d+\.\d+\b}', $_SERVER['HTTP_USER_AGENT'])) {
166 return true;
167 }
168
169 return isset($_SERVER['HTTP_X_FIREPHP_VERSION']);
170 }
171
175 public function __get($property)
176 {
177 if ('sendHeaders' !== $property) {
178 throw new \InvalidArgumentException('Undefined property '.$property);
179 }
180
181 return static::$sendHeaders;
182 }
183
187 public function __set($property, $value)
188 {
189 if ('sendHeaders' !== $property) {
190 throw new \InvalidArgumentException('Undefined property '.$property);
191 }
192
193 static::$sendHeaders = $value;
194 }
195}
Serializes a log message according to Wildfire's header requirements.
Base Handler class providing the Handler structure.
Simple FirePHP Handler (http://www.firephp.org/), which uses the Wildfire protocol.
createHeader(array $meta, $message)
Base header creation function used by init headers & record headers.
const STRUCTURE_URI
FirePHP structure for parsing messages & their presentation.
const PROTOCOL_URI
WildFire JSON header message format.
const HEADER_PREFIX
Header prefix for Wildfire to recognize & parse headers.
static $initialized
Whether or not Wildfire vendor-specific headers have been generated & sent yet.
headersAccepted()
Verifies if the headers are accepted by the current user agent.
createRecordHeader(array $record)
Creates message header from record.
sendHeader($header, $content)
Send header string to the client.
getInitHeaders()
Wildfire initialization headers to enable message parsing.
__get($property)
BC getter for the sendHeaders property that has been made static.
const PLUGIN_URI
Must reference a "known" plugin, otherwise headers won't display in FirePHP.
__set($property, $value)
BC setter for the sendHeaders property that has been made static.
getDefaultFormatter()
Gets the default formatter.FormatterInterface
write(array $record)
Creates & sends header for a record, ensuring init headers have been sent prior.
$header
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']