Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

LoggerDataCollector.php

Zuletzt modifiziert: 01.05.2026, 11:26 - Dateigröße: 8.33 KiB


 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\Debug\Exception\SilencedErrorContext;
 015  use Symfony\Component\HttpFoundation\Request;
 016  use Symfony\Component\HttpFoundation\Response;
 017  use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
 018   
 019  /**
 020   * LogDataCollector.
 021   *
 022   * @author Fabien Potencier <fabien@symfony.com>
 023   */
 024  class LoggerDataCollector extends DataCollector implements LateDataCollectorInterface
 025  {
 026      private $logger;
 027      private $containerPathPrefix;
 028   
 029      public function __construct($logger = null, $containerPathPrefix = null)
 030      {
 031          if (null !== $logger && $logger instanceof DebugLoggerInterface) {
 032              if (!method_exists($logger, 'clear')) {
 033                  @trigger_error(sprintf('Implementing "%s" without the "clear()" method is deprecated since Symfony 3.4 and will be unsupported in 4.0 for class "%s".', DebugLoggerInterface::class, \get_class($logger)), \E_USER_DEPRECATED);
 034              }
 035   
 036              $this->logger = $logger;
 037          }
 038   
 039          $this->containerPathPrefix = $containerPathPrefix;
 040      }
 041   
 042      /**
 043       * {@inheritdoc}
 044       */
 045      public function collect(Request $request, Response $response, \Exception $exception = null)
 046      {
 047          // everything is done as late as possible
 048      }
 049   
 050      /**
 051       * {@inheritdoc}
 052       */
 053      public function reset()
 054      {
 055          if ($this->logger && method_exists($this->logger, 'clear')) {
 056              $this->logger->clear();
 057          }
 058          $this->data = [];
 059      }
 060   
 061      /**
 062       * {@inheritdoc}
 063       */
 064      public function lateCollect()
 065      {
 066          if (null !== $this->logger) {
 067              $containerDeprecationLogs = $this->getContainerDeprecationLogs();
 068              $this->data = $this->computeErrorsCount($containerDeprecationLogs);
 069              $this->data['compiler_logs'] = $this->getContainerCompilerLogs();
 070              $this->data['logs'] = $this->sanitizeLogs(array_merge($this->logger->getLogs(), $containerDeprecationLogs));
 071              $this->data = $this->cloneVar($this->data);
 072          }
 073      }
 074   
 075      public function getLogs()
 076      {
 077          return isset($this->data['logs']) ? $this->data['logs'] : [];
 078      }
 079   
 080      public function getPriorities()
 081      {
 082          return isset($this->data['priorities']) ? $this->data['priorities'] : [];
 083      }
 084   
 085      public function countErrors()
 086      {
 087          return isset($this->data['error_count']) ? $this->data['error_count'] : 0;
 088      }
 089   
 090      public function countDeprecations()
 091      {
 092          return isset($this->data['deprecation_count']) ? $this->data['deprecation_count'] : 0;
 093      }
 094   
 095      public function countWarnings()
 096      {
 097          return isset($this->data['warning_count']) ? $this->data['warning_count'] : 0;
 098      }
 099   
 100      public function countScreams()
 101      {
 102          return isset($this->data['scream_count']) ? $this->data['scream_count'] : 0;
 103      }
 104   
 105      public function getCompilerLogs()
 106      {
 107          return isset($this->data['compiler_logs']) ? $this->data['compiler_logs'] : [];
 108      }
 109   
 110      /**
 111       * {@inheritdoc}
 112       */
 113      public function getName()
 114      {
 115          return 'logger';
 116      }
 117   
 118      private function getContainerDeprecationLogs()
 119      {
 120          if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Deprecations.log')) {
 121              return [];
 122          }
 123   
 124          if ('' === $logContent = trim(file_get_contents($file))) {
 125              return [];
 126          }
 127   
 128          $bootTime = filemtime($file);
 129          $logs = [];
 130          foreach (unserialize($logContent) as $log) {
 131              $log['context'] = ['exception' => new SilencedErrorContext($log['type'], $log['file'], $log['line'], $log['trace'], $log['count'])];
 132              $log['timestamp'] = $bootTime;
 133              $log['priority'] = 100;
 134              $log['priorityName'] = 'DEBUG';
 135              $log['channel'] = '-';
 136              $log['scream'] = false;
 137              unset($log['type'], $log['file'], $log['line'], $log['trace'], $log['trace'], $log['count']);
 138              $logs[] = $log;
 139          }
 140   
 141          return $logs;
 142      }
 143   
 144      private function getContainerCompilerLogs()
 145      {
 146          if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Compiler.log')) {
 147              return [];
 148          }
 149   
 150          $logs = [];
 151          foreach (file($file, \FILE_IGNORE_NEW_LINES) as $log) {
 152              $log = explode(': ', $log, 2);
 153              if (!isset($log[1]) || !preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $log[0])) {
 154                  $log = ['Unknown Compiler Pass', implode(': ', $log)];
 155              }
 156   
 157              $logs[$log[0]][] = ['message' => $log[1]];
 158          }
 159   
 160          return $logs;
 161      }
 162   
 163      private function sanitizeLogs($logs)
 164      {
 165          $sanitizedLogs = [];
 166          $silencedLogs = [];
 167   
 168          foreach ($logs as $log) {
 169              if (!$this->isSilencedOrDeprecationErrorLog($log)) {
 170                  $sanitizedLogs[] = $log;
 171   
 172                  continue;
 173              }
 174   
 175              $message = '_'.$log['message'];
 176              $exception = $log['context']['exception'];
 177   
 178              if ($exception instanceof SilencedErrorContext) {
 179                  if (isset($silencedLogs[$h = spl_object_hash($exception)])) {
 180                      continue;
 181                  }
 182                  $silencedLogs[$h] = true;
 183   
 184                  if (!isset($sanitizedLogs[$message])) {
 185                      $sanitizedLogs[$message] = $log + [
 186                          'errorCount' => 0,
 187                          'scream' => true,
 188                      ];
 189                  }
 190                  $sanitizedLogs[$message]['errorCount'] += $exception->count;
 191   
 192                  continue;
 193              }
 194   
 195              $errorId = md5("{$exception->getSeverity()}/{$exception->getLine()}/{$exception->getFile()}\0{$message}", true);
 196   
 197              if (isset($sanitizedLogs[$errorId])) {
 198                  ++$sanitizedLogs[$errorId]['errorCount'];
 199              } else {
 200                  $log += [
 201                      'errorCount' => 1,
 202                      'scream' => false,
 203                  ];
 204   
 205                  $sanitizedLogs[$errorId] = $log;
 206              }
 207          }
 208   
 209          return array_values($sanitizedLogs);
 210      }
 211   
 212      private function isSilencedOrDeprecationErrorLog(array $log)
 213      {
 214          if (!isset($log['context']['exception'])) {
 215              return false;
 216          }
 217   
 218          $exception = $log['context']['exception'];
 219   
 220          if ($exception instanceof SilencedErrorContext) {
 221              return true;
 222          }
 223   
 224          if ($exception instanceof \ErrorException && \in_array($exception->getSeverity(), [\E_DEPRECATED, \E_USER_DEPRECATED], true)) {
 225              return true;
 226          }
 227   
 228          return false;
 229      }
 230   
 231      private function computeErrorsCount(array $containerDeprecationLogs)
 232      {
 233          $silencedLogs = [];
 234          $count = [
 235              'error_count' => $this->logger->countErrors(),
 236              'deprecation_count' => 0,
 237              'warning_count' => 0,
 238              'scream_count' => 0,
 239              'priorities' => [],
 240          ];
 241   
 242          foreach ($this->logger->getLogs() as $log) {
 243              if (isset($count['priorities'][$log['priority']])) {
 244                  ++$count['priorities'][$log['priority']]['count'];
 245              } else {
 246                  $count['priorities'][$log['priority']] = [
 247                      'count' => 1,
 248                      'name' => $log['priorityName'],
 249                  ];
 250              }
 251              if ('WARNING' === $log['priorityName']) {
 252                  ++$count['warning_count'];
 253              }
 254   
 255              if ($this->isSilencedOrDeprecationErrorLog($log)) {
 256                  $exception = $log['context']['exception'];
 257                  if ($exception instanceof SilencedErrorContext) {
 258                      if (isset($silencedLogs[$h = spl_object_hash($exception)])) {
 259                          continue;
 260                      }
 261                      $silencedLogs[$h] = true;
 262                      $count['scream_count'] += $exception->count;
 263                  } else {
 264                      ++$count['deprecation_count'];
 265                  }
 266              }
 267          }
 268   
 269          foreach ($containerDeprecationLogs as $deprecationLog) {
 270              $count['deprecation_count'] += $deprecationLog['context']['exception']->count;
 271          }
 272   
 273          ksort($count['priorities']);
 274   
 275          return $count;
 276      }
 277  }
 278