Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 65eca8a

Browse files
committed
[Routing] added new schemes and methods options to the annotation loader
1 parent 5082994 commit 65eca8a

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

src/Symfony/Component/Routing/Annotation/Route.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class Route
2626
private $options;
2727
private $defaults;
2828
private $hostname;
29+
private $methods;
30+
private $schemes;
2931

3032
/**
3133
* Constructor.
@@ -37,6 +39,8 @@ public function __construct(array $data)
3739
$this->requirements = array();
3840
$this->options = array();
3941
$this->defaults = array();
42+
$this->methods = array();
43+
$this->schemes = array();
4044

4145
if (isset($data['value'])) {
4246
$data['path'] = $data['value'];
@@ -127,4 +131,24 @@ public function getDefaults()
127131
{
128132
return $this->defaults;
129133
}
134+
135+
public function setSchemes($schemes)
136+
{
137+
$this->schemes = is_array($schemes) ? $schemes : array($schemes);
138+
}
139+
140+
public function getSchemes()
141+
{
142+
return $this->schemes;
143+
}
144+
145+
public function setMethods($methods)
146+
{
147+
$this->methods = is_array($methods) ? $methods : array($methods);
148+
}
149+
150+
public function getMethods()
151+
{
152+
return $this->methods;
153+
}
130154
}

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
* and on each method.
3030
*
3131
* The @Route annotation main value is the route path. The annotation also
32-
* recognizes three parameters: requirements, options, and name. The name parameter
33-
* is mandatory. Here is an example of how you should be able to use it:
32+
* recognizes several parameters: requirements, options, defaults, schemes,
33+
* methods, hostname, and name. The name parameter is mandatory.
34+
* Here is an example of how you should be able to use it:
3435
*
3536
* /**
3637
* * @Route("/Blog")
@@ -112,6 +113,8 @@ public function load($class, $type = null)
112113
'requirements' => array(),
113114
'options' => array(),
114115
'defaults' => array(),
116+
'schemes' => array(),
117+
'methods' => array(),
115118
'hostname' => '',
116119
);
117120

@@ -140,6 +143,14 @@ public function load($class, $type = null)
140143
$globals['defaults'] = $annot->getDefaults();
141144
}
142145

146+
if (null !== $annot->getSchemes()) {
147+
$globals['schemes'] = $annot->getSchemes();
148+
}
149+
150+
if (null !== $annot->getMethods()) {
151+
$globals['methods'] = $annot->getMethods();
152+
}
153+
143154
if (null !== $annot->getHostname()) {
144155
$globals['hostname'] = $annot->getHostname();
145156
}
@@ -175,13 +186,15 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl
175186
}
176187
$requirements = array_replace($globals['requirements'], $annot->getRequirements());
177188
$options = array_replace($globals['options'], $annot->getOptions());
189+
$schemes = array_replace($globals['schemes'], $annot->getSchemes());
190+
$methods = array_replace($globals['methods'], $annot->getMethods());
178191

179192
$hostname = $annot->getHostname();
180193
if (null === $hostname) {
181194
$hostname = $globals['hostname'];
182195
}
183196

184-
$route = new Route($globals['path'].$annot->getPath(), $defaults, $requirements, $options, $hostname);
197+
$route = new Route($globals['path'].$annot->getPath(), $defaults, $requirements, $options, $hostname, $schemes, $methods);
185198

186199
$this->configureRoute($route, $class, $method, $annot);
187200

src/Symfony/Component/Routing/Tests/Annotation/RouteTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public function getValidParameters()
4141
array('options', array('compiler_class' => 'RouteCompiler'), 'getOptions'),
4242
array('name', 'blog_index', 'getName'),
4343
array('defaults', array('_controller' => 'MyBlogBundle:Blog:index'), 'getDefaults'),
44+
array('schemes', array('https'), 'getSchemes'),
45+
array('methods', array('GET', 'POST'), 'getMethods'),
4446
array('hostname', array('{locale}.example.com'), 'getHostname')
4547
);
4648
}

src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public function testLoad($className, $routeDatas = array(), $methodArgs = array(
9393
'requirements' => array(),
9494
'options' => array(),
9595
'defaults' => array(),
96+
'schemes' => array(),
97+
'methods' => array(),
9698
), $routeDatas);
9799

98100
$this->reader

0 commit comments

Comments
 (0)