diff --git a/src/Symfony/Component/Routing/Annotation/Route.php b/src/Symfony/Component/Routing/Annotation/Route.php index 7c8a772218..1d40f6c6a9 100644 --- a/src/Symfony/Component/Routing/Annotation/Route.php +++ b/src/Symfony/Component/Routing/Annotation/Route.php @@ -26,6 +26,8 @@ class Route private $options; private $defaults; private $hostname; + private $methods; + private $schemes; /** * Constructor. @@ -37,6 +39,8 @@ class Route $this->requirements = array(); $this->options = array(); $this->defaults = array(); + $this->methods = array(); + $this->schemes = array(); if (isset($data['value'])) { $data['path'] = $data['value']; @@ -127,4 +131,24 @@ class Route { return $this->defaults; } + + public function setSchemes($schemes) + { + $this->schemes = is_array($schemes) ? $schemes : array($schemes); + } + + public function getSchemes() + { + return $this->schemes; + } + + public function setMethods($methods) + { + $this->methods = is_array($methods) ? $methods : array($methods); + } + + public function getMethods() + { + return $this->methods; + } } diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index a9e216dc52..66ce367617 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -29,8 +29,9 @@ use Symfony\Component\Config\Loader\LoaderResolverInterface; * and on each method. * * The @Route annotation main value is the route path. The annotation also - * recognizes three parameters: requirements, options, and name. The name parameter - * is mandatory. Here is an example of how you should be able to use it: + * recognizes several parameters: requirements, options, defaults, schemes, + * methods, hostname, and name. The name parameter is mandatory. + * Here is an example of how you should be able to use it: * * /** * * @Route("/Blog") @@ -112,6 +113,8 @@ abstract class AnnotationClassLoader implements LoaderInterface 'requirements' => array(), 'options' => array(), 'defaults' => array(), + 'schemes' => array(), + 'methods' => array(), 'hostname' => '', ); @@ -140,6 +143,14 @@ abstract class AnnotationClassLoader implements LoaderInterface $globals['defaults'] = $annot->getDefaults(); } + if (null !== $annot->getSchemes()) { + $globals['schemes'] = $annot->getSchemes(); + } + + if (null !== $annot->getMethods()) { + $globals['methods'] = $annot->getMethods(); + } + if (null !== $annot->getHostname()) { $globals['hostname'] = $annot->getHostname(); } @@ -175,13 +186,15 @@ abstract class AnnotationClassLoader implements LoaderInterface } $requirements = array_replace($globals['requirements'], $annot->getRequirements()); $options = array_replace($globals['options'], $annot->getOptions()); + $schemes = array_replace($globals['schemes'], $annot->getSchemes()); + $methods = array_replace($globals['methods'], $annot->getMethods()); $hostname = $annot->getHostname(); if (null === $hostname) { $hostname = $globals['hostname']; } - $route = new Route($globals['path'].$annot->getPath(), $defaults, $requirements, $options, $hostname); + $route = new Route($globals['path'].$annot->getPath(), $defaults, $requirements, $options, $hostname, $schemes, $methods); $this->configureRoute($route, $class, $method, $annot); diff --git a/src/Symfony/Component/Routing/Tests/Annotation/RouteTest.php b/src/Symfony/Component/Routing/Tests/Annotation/RouteTest.php index a037d98272..53183e9581 100644 --- a/src/Symfony/Component/Routing/Tests/Annotation/RouteTest.php +++ b/src/Symfony/Component/Routing/Tests/Annotation/RouteTest.php @@ -41,6 +41,8 @@ class RouteTest extends \PHPUnit_Framework_TestCase array('options', array('compiler_class' => 'RouteCompiler'), 'getOptions'), array('name', 'blog_index', 'getName'), array('defaults', array('_controller' => 'MyBlogBundle:Blog:index'), 'getDefaults'), + array('schemes', array('https'), 'getSchemes'), + array('methods', array('GET', 'POST'), 'getMethods'), array('hostname', array('{locale}.example.com'), 'getHostname') ); } diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php index c8dfb0046c..95b0cf4573 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php @@ -93,6 +93,8 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest 'requirements' => array(), 'options' => array(), 'defaults' => array(), + 'schemes' => array(), + 'methods' => array(), ), $routeDatas); $this->reader