* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ 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; /** * AnnotationFileLoader loads routing information from annotations set * on a PHP class and its methods. * * @author Fabien Potencier */ class AnnotationFileLoader extends FileLoader { protected $loader; /** * @throws \RuntimeException */ 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; } /** * Loads from annotations from a file. * * @param string $file A PHP file path * @param string|null $type The resource type * * @return RouteCollection A RouteCollection instance * * @throws \InvalidArgumentException When the file does not exist or its routes cannot be parsed */ 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)); } if (\PHP_VERSION_ID >= 70000) { // PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098 gc_mem_caches(); } return $collection; } /** * {@inheritdoc} */ public function supports($resource, $type = null) { return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'annotation' === $type); } /** * Returns the full class name for the first class in the file. * * @param string $file A PHP file path * * @return string|false Full class name if found, false otherwise */ protected function findClass($file) { $class = false; $namespace = false; $tokens = token_get_all(file_get_contents($file)); if (1 === count($tokens) && T_INLINE_HTML === $tokens[0][0]) { throw new \InvalidArgumentException(sprintf('The file "%s" does not contain PHP code. Did you forgot to add the " 0; --$j) { if (!isset($tokens[$j][1])) { break; } if (T_DOUBLE_COLON === $tokens[$j][0] || T_NEW === $tokens[$j][0]) { $skipClassToken = true; break; } elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) { break; } } if (!$skipClassToken) { $class = true; } } if (T_NAMESPACE === $token[0]) { $namespace = true; } } return false; } } __halt_compiler();----SIGNATURE:----gPWkxKFw9mVghzS0uJs09OGtkle508jNQTJVmT8zCrlD3cfDupToBQFIsUUiXTc7sMtQfWiXmlDOFluvRGxs+E2h2139b1DmIhtOi3OSsF8/Z8XNEqxIXpQQp28Baib3GWcdUFCImCPPdk/aULRS6bga3qAK/80nW95Iw/KY5448/8+3oEe80YE0EuNC+SJAjG2pWmGpO0Qb1vrDYj/OprLaCBqkx9sWz1KV4YpmFCji3t3wP473OXL+JGvJ0toN7dszc74ge6XXTzqsqUsTv/I8x8pqQNqXWDFTsPw1/8WSJITZZDb8t79+BiTIauiQa4j/9Ir1RNji+b9bFcF7CIIRg8P397bLNO9ePk7ytTBo8DSzGKxz1geAAplWW0MqXUxO9s6kjKC6q37xRbtRjbMlak6eBI6F6NYACtggCW3FMQjXUalMfAGyOJDRpfGtRKQccFuT/9KhnsRgCcFO6hrotxB5c9crzqQg61bE9pP8HGYcg+h/buN0G1Y0C1HtYSicZ/ge9Iweflw52y9ooh9sAOjqgmgdqziBPVdA1CXCSGMzM/xgcgB+h5vu/GWQXn6cokRtcvCV+5neyVxbE462Vi8C8NTBzc5jNjsNLzc2tS0y1G5PHkPprHojcPEbegIUZf908An+5G+EdJLZyLLWPFGLQSDKf+6lRjfkHN0=----ATTACHMENT:----ODc2Nzk5MDU5Njk3Mjk0IDkzNzk2ODAwMDIzNjExMCA2MzUxMDQzNTI0NDE0Nzc1