Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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

AddAnnotatedClassesToCachePass.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 4.45 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\DependencyInjection;
013   
014  use Composer\Autoload\ClassLoader;
015  use Symfony\Component\Debug\DebugClassLoader;
016  use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
017  use Symfony\Component\DependencyInjection\ContainerBuilder;
018  use Symfony\Component\HttpKernel\Kernel;
019   
020  /**
021   * Sets the classes to compile in the cache for the container.
022   *
023   * @author Fabien Potencier <fabien@symfony.com>
024   */
025  class AddAnnotatedClassesToCachePass implements CompilerPassInterface
026  {
027      private $kernel;
028   
029      public function __construct(Kernel $kernel)
030      {
031          $this->kernel = $kernel;
032      }
033   
034      /**
035       * {@inheritdoc}
036       */
037      public function process(ContainerBuilder $container)
038      {
039          $classes = [];
040          $annotatedClasses = [];
041          foreach ($container->getExtensions() as $extension) {
042              if ($extension instanceof Extension) {
043                  if (\PHP_VERSION_ID < 70000) {
044                      $classes = array_merge($classes, $extension->getClassesToCompile());
045                  }
046                  $annotatedClasses = array_merge($annotatedClasses, $extension->getAnnotatedClassesToCompile());
047              }
048          }
049   
050          $existingClasses = $this->getClassesInComposerClassMaps();
051   
052          if (\PHP_VERSION_ID < 70000) {
053              $classes = $container->getParameterBag()->resolveValue($classes);
054              $this->kernel->setClassCache($this->expandClasses($classes, $existingClasses));
055          }
056          $annotatedClasses = $container->getParameterBag()->resolveValue($annotatedClasses);
057          $this->kernel->setAnnotatedClassCache($this->expandClasses($annotatedClasses, $existingClasses));
058      }
059   
060      /**
061       * Expands the given class patterns using a list of existing classes.
062       *
063       * @param array $patterns The class patterns to expand
064       * @param array $classes  The existing classes to match against the patterns
065       *
066       * @return array A list of classes derived from the patterns
067       */
068      private function expandClasses(array $patterns, array $classes)
069      {
070          $expanded = [];
071   
072          // Explicit classes declared in the patterns are returned directly
073          foreach ($patterns as $key => $pattern) {
074              if ('\\' !== substr($pattern, -1) && false === strpos($pattern, '*')) {
075                  unset($patterns[$key]);
076                  $expanded[] = ltrim($pattern, '\\');
077              }
078          }
079   
080          // Match patterns with the classes list
081          $regexps = $this->patternsToRegexps($patterns);
082   
083          foreach ($classes as $class) {
084              $class = ltrim($class, '\\');
085   
086              if ($this->matchAnyRegexps($class, $regexps)) {
087                  $expanded[] = $class;
088              }
089          }
090   
091          return array_unique($expanded);
092      }
093   
094      private function getClassesInComposerClassMaps()
095      {
096          $classes = [];
097   
098          foreach (spl_autoload_functions() as $function) {
099              if (!\is_array($function)) {
100                  continue;
101              }
102   
103              if ($function[0] instanceof DebugClassLoader) {
104                  $function = $function[0]->getClassLoader();
105              }
106   
107              if (\is_array($function) && $function[0] instanceof ClassLoader) {
108                  $classes += array_filter($function[0]->getClassMap());
109              }
110          }
111   
112          return array_keys($classes);
113      }
114   
115      private function patternsToRegexps($patterns)
116      {
117          $regexps = [];
118   
119          foreach ($patterns as $pattern) {
120              // Escape user input
121              $regex = preg_quote(ltrim($pattern, '\\'));
122   
123              // Wildcards * and **
124              $regex = strtr($regex, ['\\*\\*' => '.*?', '\\*' => '[^\\\\]*?']);
125   
126              // If this class does not end by a slash, anchor the end
127              if ('\\' !== substr($regex, -1)) {
128                  $regex .= '$';
129              }
130   
131              $regexps[] = '{^\\\\'.$regex.'}';
132          }
133   
134          return $regexps;
135      }
136   
137      private function matchAnyRegexps($class, $regexps)
138      {
139          $isTest = false !== strpos($class, 'Test');
140   
141          foreach ($regexps as $regex) {
142              if ($isTest && false === strpos($regex, 'Test')) {
143                  continue;
144              }
145   
146              if (preg_match($regex, '\\'.$class)) {
147                  return true;
148              }
149          }
150   
151          return false;
152      }
153  }
154