[Routing] added new schemes and methods options to the annotation loader
This commit is contained in:
parent
508299400d
commit
65eca8a3d9
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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')
|
||||
);
|
||||
}
|
||||
|
@ -93,6 +93,8 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||
'requirements' => array(),
|
||||
'options' => array(),
|
||||
'defaults' => array(),
|
||||
'schemes' => array(),
|
||||
'methods' => array(),
|
||||
), $routeDatas);
|
||||
|
||||
$this->reader
|
||||
|
Reference in New Issue
Block a user