comparison vendor/symfony/routing/Loader/AnnotationFileLoader.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
9 * file that was distributed with this source code. 9 * file that was distributed with this source code.
10 */ 10 */
11 11
12 namespace Symfony\Component\Routing\Loader; 12 namespace Symfony\Component\Routing\Loader;
13 13
14 use Symfony\Component\Config\FileLocatorInterface;
15 use Symfony\Component\Config\Loader\FileLoader;
16 use Symfony\Component\Config\Resource\FileResource;
14 use Symfony\Component\Routing\RouteCollection; 17 use Symfony\Component\Routing\RouteCollection;
15 use Symfony\Component\Config\Resource\FileResource;
16 use Symfony\Component\Config\Loader\FileLoader;
17 use Symfony\Component\Config\FileLocatorInterface;
18 18
19 /** 19 /**
20 * AnnotationFileLoader loads routing information from annotations set 20 * AnnotationFileLoader loads routing information from annotations set
21 * on a PHP class and its methods. 21 * on a PHP class and its methods.
22 * 22 *
29 /** 29 /**
30 * @throws \RuntimeException 30 * @throws \RuntimeException
31 */ 31 */
32 public function __construct(FileLocatorInterface $locator, AnnotationClassLoader $loader) 32 public function __construct(FileLocatorInterface $locator, AnnotationClassLoader $loader)
33 { 33 {
34 if (!function_exists('token_get_all')) { 34 if (!\function_exists('token_get_all')) {
35 throw new \RuntimeException('The Tokenizer extension is required for the routing annotation loaders.'); 35 throw new \RuntimeException('The Tokenizer extension is required for the routing annotation loaders.');
36 } 36 }
37 37
38 parent::__construct($locator); 38 parent::__construct($locator);
39 39
70 /** 70 /**
71 * {@inheritdoc} 71 * {@inheritdoc}
72 */ 72 */
73 public function supports($resource, $type = null) 73 public function supports($resource, $type = null)
74 { 74 {
75 return is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'annotation' === $type); 75 return \is_string($resource) && 'php' === pathinfo($resource, PATHINFO_EXTENSION) && (!$type || 'annotation' === $type);
76 } 76 }
77 77
78 /** 78 /**
79 * Returns the full class name for the first class in the file. 79 * Returns the full class name for the first class in the file.
80 * 80 *
86 { 86 {
87 $class = false; 87 $class = false;
88 $namespace = false; 88 $namespace = false;
89 $tokens = token_get_all(file_get_contents($file)); 89 $tokens = token_get_all(file_get_contents($file));
90 90
91 if (1 === count($tokens) && T_INLINE_HTML === $tokens[0][0]) { 91 if (1 === \count($tokens) && T_INLINE_HTML === $tokens[0][0]) {
92 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)); 92 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));
93 } 93 }
94 94
95 for ($i = 0; isset($tokens[$i]); ++$i) { 95 for ($i = 0; isset($tokens[$i]); ++$i) {
96 $token = $tokens[$i]; 96 $token = $tokens[$i];
103 return $namespace.'\\'.$token[1]; 103 return $namespace.'\\'.$token[1];
104 } 104 }
105 105
106 if (true === $namespace && T_STRING === $token[0]) { 106 if (true === $namespace && T_STRING === $token[0]) {
107 $namespace = $token[1]; 107 $namespace = $token[1];
108 while (isset($tokens[++$i][1]) && in_array($tokens[$i][0], array(T_NS_SEPARATOR, T_STRING))) { 108 while (isset($tokens[++$i][1]) && \in_array($tokens[$i][0], [T_NS_SEPARATOR, T_STRING])) {
109 $namespace .= $tokens[$i][1]; 109 $namespace .= $tokens[$i][1];
110 } 110 }
111 $token = $tokens[$i]; 111 $token = $tokens[$i];
112 } 112 }
113 113
120 } 120 }
121 121
122 if (T_DOUBLE_COLON === $tokens[$j][0] || T_NEW === $tokens[$j][0]) { 122 if (T_DOUBLE_COLON === $tokens[$j][0] || T_NEW === $tokens[$j][0]) {
123 $skipClassToken = true; 123 $skipClassToken = true;
124 break; 124 break;
125 } elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) { 125 } elseif (!\in_array($tokens[$j][0], [T_WHITESPACE, T_DOC_COMMENT, T_COMMENT])) {
126 break; 126 break;
127 } 127 }
128 } 128 }
129 129
130 if (!$skipClassToken) { 130 if (!$skipClassToken) {