Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a207006

Browse filesBrowse files
committed
minor #9996 [Routing] Added an extension point for globals in AnnotationClassLoader (lyrixx)
This PR was merged into the 2.5-dev branch. Discussion ---------- [Routing] Added an extension point for globals in AnnotationClassLoader | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - We need to add a new extension point for global to be able to support `@Method` on class: ``` php /** * @route("/api") * @method("GET") */ class FooBarController { /** * @route("/") */ public function listAction() { } /** * @route("/new") * @method("POST") */ public function newAction() { } } ``` Commits ------- 8f7524e [Routing] Added an extension point for globals in AnnotationClassLoader
2 parents e1b85db + 8f7524e commit a207006
Copy full SHA for a207006

File tree

Expand file treeCollapse file tree

1 file changed

+54
-47
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+54
-47
lines changed

‎src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php
+54-47Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -108,58 +108,12 @@ public function load($class, $type = null)
108108
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
109109
}
110110

111-
$globals = array(
112-
'path' => '',
113-
'requirements' => array(),
114-
'options' => array(),
115-
'defaults' => array(),
116-
'schemes' => array(),
117-
'methods' => array(),
118-
'host' => '',
119-
'condition' => '',
120-
);
121-
122111
$class = new \ReflectionClass($class);
123112
if ($class->isAbstract()) {
124113
throw new \InvalidArgumentException(sprintf('Annotations from class "%s" cannot be read as it is abstract.', $class));
125114
}
126115

127-
if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
128-
// for BC reasons
129-
if (null !== $annot->getPath()) {
130-
$globals['path'] = $annot->getPath();
131-
} elseif (null !== $annot->getPattern()) {
132-
$globals['path'] = $annot->getPattern();
133-
}
134-
135-
if (null !== $annot->getRequirements()) {
136-
$globals['requirements'] = $annot->getRequirements();
137-
}
138-
139-
if (null !== $annot->getOptions()) {
140-
$globals['options'] = $annot->getOptions();
141-
}
142-
143-
if (null !== $annot->getDefaults()) {
144-
$globals['defaults'] = $annot->getDefaults();
145-
}
146-
147-
if (null !== $annot->getSchemes()) {
148-
$globals['schemes'] = $annot->getSchemes();
149-
}
150-
151-
if (null !== $annot->getMethods()) {
152-
$globals['methods'] = $annot->getMethods();
153-
}
154-
155-
if (null !== $annot->getHost()) {
156-
$globals['host'] = $annot->getHost();
157-
}
158-
159-
if (null !== $annot->getCondition()) {
160-
$globals['condition'] = $annot->getCondition();
161-
}
162-
}
116+
$globals = $this->getGlobals($class);
163117

164118
$collection = new RouteCollection();
165119
$collection->addResource(new FileResource($class->getFileName()));
@@ -252,5 +206,58 @@ protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMetho
252206
return $name;
253207
}
254208

209+
protected function getGlobals(\ReflectionClass $class)
210+
{
211+
$globals = array(
212+
'path' => '',
213+
'requirements' => array(),
214+
'options' => array(),
215+
'defaults' => array(),
216+
'schemes' => array(),
217+
'methods' => array(),
218+
'host' => '',
219+
'condition' => '',
220+
);
221+
222+
if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
223+
// for BC reasons
224+
if (null !== $annot->getPath()) {
225+
$globals['path'] = $annot->getPath();
226+
} elseif (null !== $annot->getPattern()) {
227+
$globals['path'] = $annot->getPattern();
228+
}
229+
230+
if (null !== $annot->getRequirements()) {
231+
$globals['requirements'] = $annot->getRequirements();
232+
}
233+
234+
if (null !== $annot->getOptions()) {
235+
$globals['options'] = $annot->getOptions();
236+
}
237+
238+
if (null !== $annot->getDefaults()) {
239+
$globals['defaults'] = $annot->getDefaults();
240+
}
241+
242+
if (null !== $annot->getSchemes()) {
243+
$globals['schemes'] = $annot->getSchemes();
244+
}
245+
246+
if (null !== $annot->getMethods()) {
247+
$globals['methods'] = $annot->getMethods();
248+
}
249+
250+
if (null !== $annot->getHost()) {
251+
$globals['host'] = $annot->getHost();
252+
}
253+
254+
if (null !== $annot->getCondition()) {
255+
$globals['condition'] = $annot->getCondition();
256+
}
257+
}
258+
259+
return $globals;
260+
}
261+
255262
abstract protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot);
256263
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.