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.
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: 09.10.2024, 12:56 - Dateigröße: 3.87 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\HttpKernel\DataCollector\DataCollector;
015  use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
016  use Symfony\Component\HttpFoundation\Request;
017  use Symfony\Component\HttpFoundation\Response;
018   
019  /**
020   * TwigDataCollector.
021   *
022   * @author Fabien Potencier <fabien@symfony.com>
023   */
024  class TwigDataCollector extends DataCollector implements LateDataCollectorInterface
025  {
026      private $profile;
027      private $computed;
028   
029      public function __construct(\Twig_Profiler_Profile $profile)
030      {
031          $this->profile = $profile;
032      }
033   
034      /**
035       * {@inheritdoc}
036       */
037      public function collect(Request $request, Response $response, \Exception $exception = null)
038      {
039      }
040   
041      /**
042       * {@inheritdoc}
043       */
044      public function lateCollect()
045      {
046          $this->data['profile'] = serialize($this->profile);
047      }
048   
049      public function getTime()
050      {
051          return $this->getProfile()->getDuration() * 1000;
052      }
053   
054      public function getTemplateCount()
055      {
056          return $this->getComputedData('template_count');
057      }
058   
059      public function getTemplates()
060      {
061          return $this->getComputedData('templates');
062      }
063   
064      public function getBlockCount()
065      {
066          return $this->getComputedData('block_count');
067      }
068   
069      public function getMacroCount()
070      {
071          return $this->getComputedData('macro_count');
072      }
073   
074      public function getHtmlCallGraph()
075      {
076          $dumper = new \Twig_Profiler_Dumper_Html();
077          $dump = $dumper->dump($this->getProfile());
078   
079          // needed to remove the hardcoded CSS styles
080          $dump = str_replace(array(
081              '<span style="background-color: #ffd">',
082              '<span style="color: #d44">',
083              '<span style="background-color: #dfd">',
084          ), array(
085              '<span class="status-warning">',
086              '<span class="status-error">',
087              '<span class="status-success">',
088          ), $dump);
089   
090          return new \Twig_Markup($dump, 'UTF-8');
091      }
092   
093      public function getProfile()
094      {
095          if (null === $this->profile) {
096              $this->profile = unserialize($this->data['profile']);
097          }
098   
099          return $this->profile;
100      }
101   
102      private function getComputedData($index)
103      {
104          if (null === $this->computed) {
105              $this->computed = $this->computeData($this->getProfile());
106          }
107   
108          return $this->computed[$index];
109      }
110   
111      private function computeData(\Twig_Profiler_Profile $profile)
112      {
113          $data = array(
114              'template_count' => 0,
115              'block_count' => 0,
116              'macro_count' => 0,
117          );
118   
119          $templates = array();
120          foreach ($profile as $p) {
121              $d = $this->computeData($p);
122   
123              $data['template_count'] += ($p->isTemplate() ? 1 : 0) + $d['template_count'];
124              $data['block_count'] += ($p->isBlock() ? 1 : 0) + $d['block_count'];
125              $data['macro_count'] += ($p->isMacro() ? 1 : 0) + $d['macro_count'];
126   
127              if ($p->isTemplate()) {
128                  if (!isset($templates[$p->getTemplate()])) {
129                      $templates[$p->getTemplate()] = 1;
130                  } else {
131                      ++$templates[$p->getTemplate()];
132                  }
133              }
134   
135              foreach ($d['templates'] as $template => $count) {
136                  if (!isset($templates[$template])) {
137                      $templates[$template] = $count;
138                  } else {
139                      $templates[$template] += $count;
140                  }
141              }
142          }
143          $data['templates'] = $templates;
144   
145          return $data;
146      }
147   
148      /**
149       * {@inheritdoc}
150       */
151      public function getName()
152      {
153          return 'twig';
154      }
155  }
156