Symfony\Component\Routing\Loader\AnnotationDirectoryLoader::load PHP Méthode

load() public méthode

Loads from annotations from a directory.
public load ( string $resource ) : RouteCollection
$resource string A directory prefixed with annotations:
Résultat Symfony\Component\Routing\RouteCollection A RouteCollection instance
    public function load($resource)
    {
        $dir = $this->getAbsolutePath(substr($resource, 12));
        if (!file_exists($dir)) {
            throw new \InvalidArgumentException(sprintf('The directory "%s" does not exist (in: %s).', $dir, implode(', ', $this->paths)));
        }

        $collection = new RouteCollection();
        foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
            if (!$file->isFile() || '.php' !== substr($file->getFilename(), -4)) {
                continue;
            }

            if ($class = $this->findClass($file)) {
                $collection->addCollection($this->loader->load($class));
            }
        }

        return $collection;
    }

Usage Example

Exemple #1
0
 private static function createMatcher($sourceFolder, $reader, $context)
 {
     $matcher = null;
     $routeCacheFile = self::$CACHE_FOLDER . "/" . self::ROUTE_CACHE_FILE;
     if (!self::$DEBUG) {
         if (!file_exists($routeCacheFile)) {
             $routeLoader = new RouteAnnotationClassLoader($reader);
             $loader = new AnnotationDirectoryLoader(new FileLocator([$sourceFolder]), $routeLoader);
             $routes = $loader->load($sourceFolder);
             $dumper = new PhpMatcherDumper($routes);
             file_put_contents($routeCacheFile, $dumper->dump(["class" => self::ROUTE_CACHE_CLASS]));
             $matcher = new UrlMatcher($routes, $context);
         } else {
             $routes = (include self::$CACHE_FOLDER . "/" . self::ROUTE_CACHE_FILE);
             $className = self::ROUTE_CACHE_CLASS;
             $matcher = new $className($context);
         }
     } else {
         $routeLoader = new RouteAnnotationClassLoader($reader);
         $loader = new AnnotationDirectoryLoader(new FileLocator([$sourceFolder]), $routeLoader);
         $routes = $loader->load($sourceFolder);
         $matcher = new UrlMatcher($routes, $context);
     }
     return $matcher;
 }
All Usage Examples Of Symfony\Component\Routing\Loader\AnnotationDirectoryLoader::load
AnnotationDirectoryLoader