AnnotationFileLoader.php in Zircon Profile 8
File
vendor/symfony/routing/Loader/AnnotationFileLoader.php
View source
<?php
namespace Symfony\Component\Routing\Loader;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Loader\FileLoader;
use Symfony\Component\Config\FileLocatorInterface;
class AnnotationFileLoader extends FileLoader {
protected $loader;
public function __construct(FileLocatorInterface $locator, AnnotationClassLoader $loader) {
if (!function_exists('token_get_all')) {
throw new \RuntimeException('The Tokenizer extension is required for the routing annotation loaders.');
}
parent::__construct($locator);
$this->loader = $loader;
}
public function load($file, $type = null) {
$path = $this->locator
->locate($file);
$collection = new RouteCollection();
if ($class = $this
->findClass($path)) {
$collection
->addResource(new FileResource($path));
$collection
->addCollection($this->loader
->load($class, $type));
}
return $collection;
}
public function supports($resource, $type = null) {
return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'annotation' === $type);
}
protected function findClass($file) {
$class = false;
$namespace = false;
$tokens = token_get_all(file_get_contents($file));
for ($i = 0, $count = count($tokens); $i < $count; ++$i) {
$token = $tokens[$i];
if (!is_array($token)) {
continue;
}
if (true === $class && T_STRING === $token[0]) {
return $namespace . '\\' . $token[1];
}
if (true === $namespace && T_STRING === $token[0]) {
$namespace = '';
do {
$namespace .= $token[1];
$token = $tokens[++$i];
} while ($i < $count && is_array($token) && in_array($token[0], array(
T_NS_SEPARATOR,
T_STRING,
)));
}
if (T_CLASS === $token[0]) {
$class = true;
}
if (T_NAMESPACE === $token[0]) {
$namespace = true;
}
}
return false;
}
}
Classes
Name |
Description |
AnnotationFileLoader |
AnnotationFileLoader loads routing information from annotations set
on a PHP class and its methods. |