Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
LoggerDataCollector.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\HttpKernel\DataCollector;
013
014 use Symfony\Component\HttpFoundation\Request;
015 use Symfony\Component\HttpFoundation\Response;
016 use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
017
018 /**
019 * LogDataCollector.
020 *
021 * @author Fabien Potencier <fabien@symfony.com>
022 */
023 class LoggerDataCollector extends DataCollector implements LateDataCollectorInterface
024 {
025 private $errorNames = array(
026 E_DEPRECATED => 'E_DEPRECATED',
027 E_USER_DEPRECATED => 'E_USER_DEPRECATED',
028 E_NOTICE => 'E_NOTICE',
029 E_USER_NOTICE => 'E_USER_NOTICE',
030 E_STRICT => 'E_STRICT',
031 E_WARNING => 'E_WARNING',
032 E_USER_WARNING => 'E_USER_WARNING',
033 E_COMPILE_WARNING => 'E_COMPILE_WARNING',
034 E_CORE_WARNING => 'E_CORE_WARNING',
035 E_USER_ERROR => 'E_USER_ERROR',
036 E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
037 E_COMPILE_ERROR => 'E_COMPILE_ERROR',
038 E_PARSE => 'E_PARSE',
039 E_ERROR => 'E_ERROR',
040 E_CORE_ERROR => 'E_CORE_ERROR',
041 );
042
043 private $logger;
044
045 public function __construct($logger = null)
046 {
047 if (null !== $logger && $logger instanceof DebugLoggerInterface) {
048 $this->logger = $logger;
049 }
050 }
051
052 /**
053 * {@inheritdoc}
054 */
055 public function collect(Request $request, Response $response, \Exception $exception = null)
056 {
057 // everything is done as late as possible
058 }
059
060 /**
061 * {@inheritdoc}
062 */
063 public function lateCollect()
064 {
065 if (null !== $this->logger) {
066 $this->data = $this->computeErrorsCount();
067 $this->data['logs'] = $this->sanitizeLogs($this->logger->getLogs());
068 }
069 }
070
071 /**
072 * Gets the logs.
073 *
074 * @return array An array of logs
075 */
076 public function getLogs()
077 {
078 return isset($this->data['logs']) ? $this->data['logs'] : array();
079 }
080
081 public function getPriorities()
082 {
083 return isset($this->data['priorities']) ? $this->data['priorities'] : array();
084 }
085
086 public function countErrors()
087 {
088 return isset($this->data['error_count']) ? $this->data['error_count'] : 0;
089 }
090
091 public function countDeprecations()
092 {
093 return isset($this->data['deprecation_count']) ? $this->data['deprecation_count'] : 0;
094 }
095
096 public function countScreams()
097 {
098 return isset($this->data['scream_count']) ? $this->data['scream_count'] : 0;
099 }
100
101 /**
102 * {@inheritdoc}
103 */
104 public function getName()
105 {
106 return 'logger';
107 }
108
109 private function sanitizeLogs($logs)
110 {
111 $errorContextById = array();
112 $sanitizedLogs = array();
113
114 foreach ($logs as $log) {
115 $context = $this->sanitizeContext($log['context']);
116
117 if (isset($context['type'], $context['file'], $context['line'], $context['level'])) {
118 $errorId = md5("{$context['type']}/{$context['line']}/{$context['file']}\x00{$log['message']}", true);
119 $silenced = !($context['type'] & $context['level']);
120 if (isset($this->errorNames[$context['type']])) {
121 $context = array_merge(array('name' => $this->errorNames[$context['type']]), $context);
122 }
123
124 if (isset($errorContextById[$errorId])) {
125 if (isset($errorContextById[$errorId]['errorCount'])) {
126 ++$errorContextById[$errorId]['errorCount'];
127 } else {
128 $errorContextById[$errorId]['errorCount'] = 2;
129 }
130
131 if (!$silenced && isset($errorContextById[$errorId]['scream'])) {
132 unset($errorContextById[$errorId]['scream']);
133 $errorContextById[$errorId]['level'] = $context['level'];
134 }
135
136 continue;
137 }
138
139 $errorContextById[$errorId] = &$context;
140 if ($silenced) {
141 $context['scream'] = true;
142 }
143
144 $log['context'] = &$context;
145 unset($context);
146 } else {
147 $log['context'] = $context;
148 }
149
150 $sanitizedLogs[] = $log;
151 }
152
153 return $sanitizedLogs;
154 }
155
156 private function sanitizeContext($context)
157 {
158 if (is_array($context)) {
159 foreach ($context as $key => $value) {
160 $context[$key] = $this->sanitizeContext($value);
161 }
162
163 return $context;
164 }
165
166 if (is_resource($context)) {
167 return sprintf('Resource(%s)', get_resource_type($context));
168 }
169
170 if (is_object($context)) {
171 if ($context instanceof \Exception) {
172 return sprintf('Exception(%s): %s', get_class($context), $context->getMessage());
173 }
174
175 return sprintf('Object(%s)', get_class($context));
176 }
177
178 return $context;
179 }
180
181 private function computeErrorsCount()
182 {
183 $count = array(
184 'error_count' => $this->logger->countErrors(),
185 'deprecation_count' => 0,
186 'scream_count' => 0,
187 'priorities' => array(),
188 );
189
190 foreach ($this->logger->getLogs() as $log) {
191 if (isset($count['priorities'][$log['priority']])) {
192 ++$count['priorities'][$log['priority']]['count'];
193 } else {
194 $count['priorities'][$log['priority']] = array(
195 'count' => 1,
196 'name' => $log['priorityName'],
197 );
198 }
199
200 if (isset($log['context']['type'], $log['context']['level'])) {
201 if (E_DEPRECATED === $log['context']['type'] || E_USER_DEPRECATED === $log['context']['type']) {
202 ++$count['deprecation_count'];
203 } elseif (!($log['context']['type'] & $log['context']['level'])) {
204 ++$count['scream_count'];
205 }
206 }
207 }
208
209 ksort($count['priorities']);
210
211 return $count;
212 }
213 }
214