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

TwigDataCollector.php

Zuletzt modifiziert: 01.05.2026, 11:27 - Dateigröße: 5.25 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\Bridge\Twig\DataCollector;
 013   
 014  use Symfony\Component\HttpFoundation\Request;
 015  use Symfony\Component\HttpFoundation\Response;
 016  use Symfony\Component\HttpKernel\DataCollector\DataCollector;
 017  use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
 018  use Twig\Environment;
 019  use Twig\Error\LoaderError;
 020  use Twig\Markup;
 021  use Twig\Profiler\Dumper\HtmlDumper;
 022  use Twig\Profiler\Profile;
 023   
 024  /**
 025   * TwigDataCollector.
 026   *
 027   * @author Fabien Potencier <fabien@symfony.com>
 028   */
 029  class TwigDataCollector extends DataCollector implements LateDataCollectorInterface
 030  {
 031      private $profile;
 032      private $twig;
 033      private $computed;
 034   
 035      public function __construct(Profile $profile, Environment $twig = null)
 036      {
 037          $this->profile = $profile;
 038          $this->twig = $twig;
 039      }
 040   
 041      /**
 042       * {@inheritdoc}
 043       */
 044      public function collect(Request $request, Response $response, \Exception $exception = null)
 045      {
 046      }
 047   
 048      /**
 049       * {@inheritdoc}
 050       */
 051      public function reset()
 052      {
 053          $this->profile->reset();
 054          $this->computed = null;
 055          $this->data = [];
 056      }
 057   
 058      /**
 059       * {@inheritdoc}
 060       */
 061      public function lateCollect()
 062      {
 063          $this->data['profile'] = serialize($this->profile);
 064          $this->data['template_paths'] = [];
 065   
 066          if (null === $this->twig) {
 067              return;
 068          }
 069   
 070          $templateFinder = function (Profile $profile) use (&$templateFinder) {
 071              if ($profile->isTemplate()) {
 072                  try {
 073                      $template = $this->twig->load($name = $profile->getName());
 074                  } catch (LoaderError $e) {
 075                      $template = null;
 076                  }
 077   
 078                  if (null !== $template && '' !== $path = $template->getSourceContext()->getPath()) {
 079                      $this->data['template_paths'][$name] = $path;
 080                  }
 081              }
 082   
 083              foreach ($profile as $p) {
 084                  $templateFinder($p);
 085              }
 086          };
 087          $templateFinder($this->profile);
 088      }
 089   
 090      public function getTime()
 091      {
 092          return $this->getProfile()->getDuration() * 1000;
 093      }
 094   
 095      public function getTemplateCount()
 096      {
 097          return $this->getComputedData('template_count');
 098      }
 099   
 100      public function getTemplatePaths()
 101      {
 102          return $this->data['template_paths'];
 103      }
 104   
 105      public function getTemplates()
 106      {
 107          return $this->getComputedData('templates');
 108      }
 109   
 110      public function getBlockCount()
 111      {
 112          return $this->getComputedData('block_count');
 113      }
 114   
 115      public function getMacroCount()
 116      {
 117          return $this->getComputedData('macro_count');
 118      }
 119   
 120      public function getHtmlCallGraph()
 121      {
 122          $dumper = new HtmlDumper();
 123          $dump = $dumper->dump($this->getProfile());
 124   
 125          // needed to remove the hardcoded CSS styles
 126          $dump = str_replace([
 127              '<span style="background-color: #ffd">',
 128              '<span style="color: #d44">',
 129              '<span style="background-color: #dfd">',
 130          ], [
 131              '<span class="status-warning">',
 132              '<span class="status-error">',
 133              '<span class="status-success">',
 134          ], $dump);
 135   
 136          return new Markup($dump, 'UTF-8');
 137      }
 138   
 139      public function getProfile()
 140      {
 141          if (null === $this->profile) {
 142              if (\PHP_VERSION_ID >= 70000) {
 143                  $this->profile = unserialize($this->data['profile'], ['allowed_classes' => ['Twig_Profiler_Profile', 'Twig\Profiler\Profile']]);
 144              } else {
 145                  $this->profile = unserialize($this->data['profile']);
 146              }
 147          }
 148   
 149          return $this->profile;
 150      }
 151   
 152      private function getComputedData($index)
 153      {
 154          if (null === $this->computed) {
 155              $this->computed = $this->computeData($this->getProfile());
 156          }
 157   
 158          return $this->computed[$index];
 159      }
 160   
 161      private function computeData(Profile $profile)
 162      {
 163          $data = [
 164              'template_count' => 0,
 165              'block_count' => 0,
 166              'macro_count' => 0,
 167          ];
 168   
 169          $templates = [];
 170          foreach ($profile as $p) {
 171              $d = $this->computeData($p);
 172   
 173              $data['template_count'] += ($p->isTemplate() ? 1 : 0) + $d['template_count'];
 174              $data['block_count'] += ($p->isBlock() ? 1 : 0) + $d['block_count'];
 175              $data['macro_count'] += ($p->isMacro() ? 1 : 0) + $d['macro_count'];
 176   
 177              if ($p->isTemplate()) {
 178                  if (!isset($templates[$p->getTemplate()])) {
 179                      $templates[$p->getTemplate()] = 1;
 180                  } else {
 181                      ++$templates[$p->getTemplate()];
 182                  }
 183              }
 184   
 185              foreach ($d['templates'] as $template => $count) {
 186                  if (!isset($templates[$template])) {
 187                      $templates[$template] = $count;
 188                  } else {
 189                      $templates[$template] += $count;
 190                  }
 191              }
 192          }
 193          $data['templates'] = $templates;
 194   
 195          return $data;
 196      }
 197   
 198      /**
 199       * {@inheritdoc}
 200       */
 201      public function getName()
 202      {
 203          return 'twig';
 204      }
 205  }
 206