ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
WebProcessor.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\Processor;
13
20{
24 protected $serverData;
25
29 protected $extraFields = array(
30 'url' => 'REQUEST_URI',
31 'ip' => 'REMOTE_ADDR',
32 'http_method' => 'REQUEST_METHOD',
33 'server' => 'SERVER_NAME',
34 'referrer' => 'HTTP_REFERER',
35 );
36
41 public function __construct($serverData = null, array $extraFields = null)
42 {
43 if (null === $serverData) {
44 $this->serverData = &$_SERVER;
45 } elseif (is_array($serverData) || $serverData instanceof \ArrayAccess) {
46 $this->serverData = $serverData;
47 } else {
48 throw new \UnexpectedValueException('$serverData must be an array or object implementing ArrayAccess.');
49 }
50
51 if (null !== $extraFields) {
52 foreach (array_keys($this->extraFields) as $fieldName) {
53 if (!in_array($fieldName, $extraFields)) {
54 unset($this->extraFields[$fieldName]);
55 }
56 }
57 }
58 }
59
64 public function __invoke(array $record)
65 {
66 // skip processing if for some reason request data
67 // is not present (CLI or wonky SAPIs)
68 if (!isset($this->serverData['REQUEST_URI'])) {
69 return $record;
70 }
71
72 $record['extra'] = $this->appendExtraFields($record['extra']);
73
74 return $record;
75 }
76
82 public function addExtraField($extraName, $serverName)
83 {
84 $this->extraFields[$extraName] = $serverName;
85
86 return $this;
87 }
88
93 private function appendExtraFields(array $extra)
94 {
95 foreach ($this->extraFields as $extraName => $serverName) {
96 $extra[$extraName] = isset($this->serverData[$serverName]) ? $this->serverData[$serverName] : null;
97 }
98
99 if (isset($this->serverData['UNIQUE_ID'])) {
100 $extra['unique_id'] = $this->serverData['UNIQUE_ID'];
101 }
102
103 return $extra;
104 }
105}
Injects url/method and remote IP of the current web request in all records.
addExtraField($extraName, $serverName)
__construct($serverData=null, array $extraFields=null)
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']