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

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents c2387f117808
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
10 */ 10 */
11 11
12 namespace Symfony\Component\Routing\Loader; 12 namespace Symfony\Component\Routing\Loader;
13 13
14 use Doctrine\Common\Annotations\Reader; 14 use Doctrine\Common\Annotations\Reader;
15 use Symfony\Component\Config\Loader\LoaderInterface;
16 use Symfony\Component\Config\Loader\LoaderResolverInterface;
15 use Symfony\Component\Config\Resource\FileResource; 17 use Symfony\Component\Config\Resource\FileResource;
16 use Symfony\Component\Routing\Route; 18 use Symfony\Component\Routing\Route;
17 use Symfony\Component\Routing\RouteCollection; 19 use Symfony\Component\Routing\RouteCollection;
18 use Symfony\Component\Config\Loader\LoaderInterface;
19 use Symfony\Component\Config\Loader\LoaderResolverInterface;
20 20
21 /** 21 /**
22 * AnnotationClassLoader loads routing information from a PHP class and its methods. 22 * AnnotationClassLoader loads routing information from a PHP class and its methods.
23 * 23 *
24 * You need to define an implementation for the getRouteDefaults() method. Most of the 24 * You need to define an implementation for the getRouteDefaults() method. Most of the
118 } 118 }
119 } 119 }
120 } 120 }
121 121
122 if (0 === $collection->count() && $class->hasMethod('__invoke')) { 122 if (0 === $collection->count() && $class->hasMethod('__invoke')) {
123 $globals = $this->resetGlobals();
123 foreach ($this->reader->getClassAnnotations($class) as $annot) { 124 foreach ($this->reader->getClassAnnotations($class) as $annot) {
124 if ($annot instanceof $this->routeAnnotationClass) { 125 if ($annot instanceof $this->routeAnnotationClass) {
125 $globals['path'] = '';
126 $globals['name'] = '';
127
128 $this->addRoute($collection, $annot, $globals, $class, $class->getMethod('__invoke')); 126 $this->addRoute($collection, $annot, $globals, $class, $class->getMethod('__invoke'));
129 } 127 }
130 } 128 }
131 } 129 }
132 130
172 /** 170 /**
173 * {@inheritdoc} 171 * {@inheritdoc}
174 */ 172 */
175 public function supports($resource, $type = null) 173 public function supports($resource, $type = null)
176 { 174 {
177 return is_string($resource) && preg_match('/^(?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+$/', $resource) && (!$type || 'annotation' === $type); 175 return \is_string($resource) && preg_match('/^(?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+$/', $resource) && (!$type || 'annotation' === $type);
178 } 176 }
179 177
180 /** 178 /**
181 * {@inheritdoc} 179 * {@inheritdoc}
182 */ 180 */
210 return $name; 208 return $name;
211 } 209 }
212 210
213 protected function getGlobals(\ReflectionClass $class) 211 protected function getGlobals(\ReflectionClass $class)
214 { 212 {
215 $globals = array( 213 $globals = $this->resetGlobals();
214
215 if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
216 if (null !== $annot->getName()) {
217 $globals['name'] = $annot->getName();
218 }
219
220 if (null !== $annot->getPath()) {
221 $globals['path'] = $annot->getPath();
222 }
223
224 if (null !== $annot->getRequirements()) {
225 $globals['requirements'] = $annot->getRequirements();
226 }
227
228 if (null !== $annot->getOptions()) {
229 $globals['options'] = $annot->getOptions();
230 }
231
232 if (null !== $annot->getDefaults()) {
233 $globals['defaults'] = $annot->getDefaults();
234 }
235
236 if (null !== $annot->getSchemes()) {
237 $globals['schemes'] = $annot->getSchemes();
238 }
239
240 if (null !== $annot->getMethods()) {
241 $globals['methods'] = $annot->getMethods();
242 }
243
244 if (null !== $annot->getHost()) {
245 $globals['host'] = $annot->getHost();
246 }
247
248 if (null !== $annot->getCondition()) {
249 $globals['condition'] = $annot->getCondition();
250 }
251 }
252
253 return $globals;
254 }
255
256 private function resetGlobals()
257 {
258 return [
216 'path' => '', 259 'path' => '',
217 'requirements' => array(), 260 'requirements' => [],
218 'options' => array(), 261 'options' => [],
219 'defaults' => array(), 262 'defaults' => [],
220 'schemes' => array(), 263 'schemes' => [],
221 'methods' => array(), 264 'methods' => [],
222 'host' => '', 265 'host' => '',
223 'condition' => '', 266 'condition' => '',
224 'name' => '', 267 'name' => '',
225 ); 268 ];
226
227 if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
228 if (null !== $annot->getName()) {
229 $globals['name'] = $annot->getName();
230 }
231
232 if (null !== $annot->getPath()) {
233 $globals['path'] = $annot->getPath();
234 }
235
236 if (null !== $annot->getRequirements()) {
237 $globals['requirements'] = $annot->getRequirements();
238 }
239
240 if (null !== $annot->getOptions()) {
241 $globals['options'] = $annot->getOptions();
242 }
243
244 if (null !== $annot->getDefaults()) {
245 $globals['defaults'] = $annot->getDefaults();
246 }
247
248 if (null !== $annot->getSchemes()) {
249 $globals['schemes'] = $annot->getSchemes();
250 }
251
252 if (null !== $annot->getMethods()) {
253 $globals['methods'] = $annot->getMethods();
254 }
255
256 if (null !== $annot->getHost()) {
257 $globals['host'] = $annot->getHost();
258 }
259
260 if (null !== $annot->getCondition()) {
261 $globals['condition'] = $annot->getCondition();
262 }
263 }
264
265 return $globals;
266 } 269 }
267 270
268 protected function createRoute($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition) 271 protected function createRoute($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition)
269 { 272 {
270 return new Route($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition); 273 return new Route($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition);