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

AnnotationFileLoader.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 4.59 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\Routing\Loader;
013   
014  use Symfony\Component\Config\FileLocatorInterface;
015  use Symfony\Component\Config\Loader\FileLoader;
016  use Symfony\Component\Config\Resource\FileResource;
017  use Symfony\Component\Routing\RouteCollection;
018   
019  /**
020   * AnnotationFileLoader loads routing information from annotations set
021   * on a PHP class and its methods.
022   *
023   * @author Fabien Potencier <fabien@symfony.com>
024   */
025  class AnnotationFileLoader extends FileLoader
026  {
027      protected $loader;
028   
029      /**
030       * @throws \RuntimeException
031       */
032      public function __construct(FileLocatorInterface $locator, AnnotationClassLoader $loader)
033      {
034          if (!\function_exists('token_get_all')) {
035              throw new \RuntimeException('The Tokenizer extension is required for the routing annotation loaders.');
036          }
037   
038          parent::__construct($locator);
039   
040          $this->loader = $loader;
041      }
042   
043      /**
044       * Loads from annotations from a file.
045       *
046       * @param string      $file A PHP file path
047       * @param string|null $type The resource type
048       *
049       * @return RouteCollection|null A RouteCollection instance
050       *
051       * @throws \InvalidArgumentException When the file does not exist or its routes cannot be parsed
052       */
053      public function load($file, $type = null)
054      {
055          $path = $this->locator->locate($file);
056   
057          $collection = new RouteCollection();
058          if ($class = $this->findClass($path)) {
059              $refl = new \ReflectionClass($class);
060              if ($refl->isAbstract()) {
061                  return null;
062              }
063   
064              $collection->addResource(new FileResource($path));
065              $collection->addCollection($this->loader->load($class, $type));
066          }
067          if (\PHP_VERSION_ID >= 70000) {
068              // PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
069              gc_mem_caches();
070          }
071   
072          return $collection;
073      }
074   
075      /**
076       * {@inheritdoc}
077       */
078      public function supports($resource, $type = null)
079      {
080          return \is_string($resource) && 'php' === pathinfo($resource, \PATHINFO_EXTENSION) && (!$type || 'annotation' === $type);
081      }
082   
083      /**
084       * Returns the full class name for the first class in the file.
085       *
086       * @param string $file A PHP file path
087       *
088       * @return string|false Full class name if found, false otherwise
089       */
090      protected function findClass($file)
091      {
092          $class = false;
093          $namespace = false;
094          $tokens = token_get_all(file_get_contents($file));
095   
096          if (1 === \count($tokens) && \T_INLINE_HTML === $tokens[0][0]) {
097              throw new \InvalidArgumentException(sprintf('The file "%s" does not contain PHP code. Did you forgot to add the "<?php" start tag at the beginning of the file?', $file));
098          }
099   
100          $nsTokens = [\T_NS_SEPARATOR => true, \T_STRING => true];
101          if (\defined('T_NAME_QUALIFIED')) {
102              $nsTokens[T_NAME_QUALIFIED] = true;
103          }
104   
105          for ($i = 0; isset($tokens[$i]); ++$i) {
106              $token = $tokens[$i];
107   
108              if (!isset($token[1])) {
109                  continue;
110              }
111   
112              if (true === $class && \T_STRING === $token[0]) {
113                  return $namespace.'\\'.$token[1];
114              }
115   
116              if (true === $namespace && isset($nsTokens[$token[0]])) {
117                  $namespace = $token[1];
118                  while (isset($tokens[++$i][1], $nsTokens[$tokens[$i][0]])) {
119                      $namespace .= $tokens[$i][1];
120                  }
121                  $token = $tokens[$i];
122              }
123   
124              if (\T_CLASS === $token[0]) {
125                  // Skip usage of ::class constant and anonymous classes
126                  $skipClassToken = false;
127                  for ($j = $i - 1; $j > 0; --$j) {
128                      if (!isset($tokens[$j][1])) {
129                          break;
130                      }
131   
132                      if (\T_DOUBLE_COLON === $tokens[$j][0] || \T_NEW === $tokens[$j][0]) {
133                          $skipClassToken = true;
134                          break;
135                      } elseif (!\in_array($tokens[$j][0], [\T_WHITESPACE, \T_DOC_COMMENT, \T_COMMENT])) {
136                          break;
137                      }
138                  }
139   
140                  if (!$skipClassToken) {
141                      $class = true;
142                  }
143              }
144   
145              if (\T_NAMESPACE === $token[0]) {
146                  $namespace = true;
147              }
148          }
149   
150          return false;
151      }
152  }
153