comparison vendor/symfony/routing/Loader/AnnotationClassLoader.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children c2387f117808
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
55 * 55 *
56 * @author Fabien Potencier <fabien@symfony.com> 56 * @author Fabien Potencier <fabien@symfony.com>
57 */ 57 */
58 abstract class AnnotationClassLoader implements LoaderInterface 58 abstract class AnnotationClassLoader implements LoaderInterface
59 { 59 {
60 /**
61 * @var Reader
62 */
63 protected $reader; 60 protected $reader;
64 61
65 /** 62 /**
66 * @var string 63 * @var string
67 */ 64 */
70 /** 67 /**
71 * @var int 68 * @var int
72 */ 69 */
73 protected $defaultRouteIndex = 0; 70 protected $defaultRouteIndex = 0;
74 71
75 /**
76 * Constructor.
77 *
78 * @param Reader $reader
79 */
80 public function __construct(Reader $reader) 72 public function __construct(Reader $reader)
81 { 73 {
82 $this->reader = $reader; 74 $this->reader = $reader;
83 } 75 }
84 76
125 $this->addRoute($collection, $annot, $globals, $class, $method); 117 $this->addRoute($collection, $annot, $globals, $class, $method);
126 } 118 }
127 } 119 }
128 } 120 }
129 121
122 if (0 === $collection->count() && $class->hasMethod('__invoke') && $annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
123 $globals['path'] = '';
124 $globals['name'] = '';
125 $this->addRoute($collection, $annot, $globals, $class, $class->getMethod('__invoke'));
126 }
127
130 return $collection; 128 return $collection;
131 } 129 }
132 130
133 protected function addRoute(RouteCollection $collection, $annot, $globals, \ReflectionClass $class, \ReflectionMethod $method) 131 protected function addRoute(RouteCollection $collection, $annot, $globals, \ReflectionClass $class, \ReflectionMethod $method)
134 { 132 {
135 $name = $annot->getName(); 133 $name = $annot->getName();
136 if (null === $name) { 134 if (null === $name) {
137 $name = $this->getDefaultRouteName($class, $method); 135 $name = $this->getDefaultRouteName($class, $method);
138 } 136 }
137 $name = $globals['name'].$name;
139 138
140 $defaults = array_replace($globals['defaults'], $annot->getDefaults()); 139 $defaults = array_replace($globals['defaults'], $annot->getDefaults());
141 foreach ($method->getParameters() as $param) { 140 foreach ($method->getParameters() as $param) {
142 if (false !== strpos($globals['path'].$annot->getPath(), sprintf('{%s}', $param->getName())) && !isset($defaults[$param->getName()]) && $param->isDefaultValueAvailable()) { 141 if (false !== strpos($globals['path'].$annot->getPath(), sprintf('{%s}', $param->getName())) && !isset($defaults[$param->getName()]) && $param->isDefaultValueAvailable()) {
143 $defaults[$param->getName()] = $param->getDefaultValue(); 142 $defaults[$param->getName()] = $param->getDefaultValue();
215 'defaults' => array(), 214 'defaults' => array(),
216 'schemes' => array(), 215 'schemes' => array(),
217 'methods' => array(), 216 'methods' => array(),
218 'host' => '', 217 'host' => '',
219 'condition' => '', 218 'condition' => '',
219 'name' => '',
220 ); 220 );
221 221
222 if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) { 222 if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
223 if (null !== $annot->getName()) {
224 $globals['name'] = $annot->getName();
225 }
226
223 if (null !== $annot->getPath()) { 227 if (null !== $annot->getPath()) {
224 $globals['path'] = $annot->getPath(); 228 $globals['path'] = $annot->getPath();
225 } 229 }
226 230
227 if (null !== $annot->getRequirements()) { 231 if (null !== $annot->getRequirements()) {