Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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: 09.10.2024, 12:58 - Dateigröße: 3.41 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\Routing\RouteCollection;
015  use Symfony\Component\Config\Resource\FileResource;
016  use Symfony\Component\Config\Loader\FileLoader;
017  use Symfony\Component\Config\FileLocatorInterface;
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       * Constructor.
031       *
032       * @param FileLocatorInterface  $locator A FileLocator instance
033       * @param AnnotationClassLoader $loader  An AnnotationClassLoader instance
034       *
035       * @throws \RuntimeException
036       */
037      public function __construct(FileLocatorInterface $locator, AnnotationClassLoader $loader)
038      {
039          if (!function_exists('token_get_all')) {
040              throw new \RuntimeException('The Tokenizer extension is required for the routing annotation loaders.');
041          }
042   
043          parent::__construct($locator);
044   
045          $this->loader = $loader;
046      }
047   
048      /**
049       * Loads from annotations from a file.
050       *
051       * @param string      $file A PHP file path
052       * @param string|null $type The resource type
053       *
054       * @return RouteCollection A RouteCollection instance
055       *
056       * @throws \InvalidArgumentException When the file does not exist or its routes cannot be parsed
057       */
058      public function load($file, $type = null)
059      {
060          $path = $this->locator->locate($file);
061   
062          $collection = new RouteCollection();
063          if ($class = $this->findClass($path)) {
064              $collection->addResource(new FileResource($path));
065              $collection->addCollection($this->loader->load($class, $type));
066          }
067   
068          return $collection;
069      }
070   
071      /**
072       * {@inheritdoc}
073       */
074      public function supports($resource, $type = null)
075      {
076          return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'annotation' === $type);
077      }
078   
079      /**
080       * Returns the full class name for the first class in the file.
081       *
082       * @param string $file A PHP file path
083       *
084       * @return string|false Full class name if found, false otherwise
085       */
086      protected function findClass($file)
087      {
088          $class = false;
089          $namespace = false;
090          $tokens = token_get_all(file_get_contents($file));
091          for ($i = 0, $count = count($tokens); $i < $count; $i++) {
092              $token = $tokens[$i];
093   
094              if (!is_array($token)) {
095                  continue;
096              }
097   
098              if (true === $class && T_STRING === $token[0]) {
099                  return $namespace.'\\'.$token[1];
100              }
101   
102              if (true === $namespace && T_STRING === $token[0]) {
103                  $namespace = '';
104                  do {
105                      $namespace .= $token[1];
106                      $token = $tokens[++$i];
107                  } while ($i < $count && is_array($token) && in_array($token[0], array(T_NS_SEPARATOR, T_STRING)));
108              }
109   
110              if (T_CLASS === $token[0]) {
111                  $class = true;
112              }
113   
114              if (T_NAMESPACE === $token[0]) {
115                  $namespace = true;
116              }
117          }
118   
119          return false;
120      }
121  }
122