ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
33 protected $extraFields = array(
34 'url' => 'REQUEST_URI',
35 'ip' => 'REMOTE_ADDR',
36 'http_method' => 'REQUEST_METHOD',
37 'server' => 'SERVER_NAME',
38 'referrer' => 'HTTP_REFERER',
39 );
40
45 public function __construct($serverData = null, array $extraFields = null)
46 {
47 if (null === $serverData) {
48 $this->serverData = &$_SERVER;
49 } elseif (is_array($serverData) || $serverData instanceof \ArrayAccess) {
50 $this->serverData = $serverData;
51 } else {
52 throw new \UnexpectedValueException('$serverData must be an array or object implementing ArrayAccess.');
53 }
54
55 if (null !== $extraFields) {
56 if (isset($extraFields[0])) {
57 foreach (array_keys($this->extraFields) as $fieldName) {
58 if (!in_array($fieldName, $extraFields)) {
59 unset($this->extraFields[$fieldName]);
60 }
61 }
62 } else {
63 $this->extraFields = $extraFields;
64 }
65 }
66 }
67
72 public function __invoke(array $record)
73 {
74 // skip processing if for some reason request data
75 // is not present (CLI or wonky SAPIs)
76 if (!isset($this->serverData['REQUEST_URI'])) {
77 return $record;
78 }
79
80 $record['extra'] = $this->appendExtraFields($record['extra']);
81
82 return $record;
83 }
84
90 public function addExtraField($extraName, $serverName)
91 {
92 $this->extraFields[$extraName] = $serverName;
93
94 return $this;
95 }
96
101 private function appendExtraFields(array $extra)
102 {
103 foreach ($this->extraFields as $extraName => $serverName) {
104 $extra[$extraName] = isset($this->serverData[$serverName]) ? $this->serverData[$serverName] : null;
105 }
106
107 if (isset($this->serverData['UNIQUE_ID'])) {
108 $extra['unique_id'] = $this->serverData['UNIQUE_ID'];
109 }
110
111 return $extra;
112 }
113}
An exception for terminatinating execution or to throw for unit testing.
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']