[Routing] added hostname matching support to AnnotationClassLoader

This commit is contained in:
Arnaud Le Blanc 2012-04-14 19:20:04 +02:00
parent cab450c94e
commit 7a15e006e6
2 changed files with 26 additions and 5 deletions

View File

@ -25,6 +25,7 @@ class Route
private $requirements; private $requirements;
private $options; private $options;
private $defaults; private $defaults;
private $hostnamePattern;
/** /**
* Constructor. * Constructor.
@ -61,6 +62,16 @@ class Route
return $this->pattern; return $this->pattern;
} }
public function setHostnamePattern($pattern)
{
$this->hostnamePattern = $pattern;
}
public function getHostnamePattern()
{
return $this->hostnamePattern;
}
public function setName($name) public function setName($name)
{ {
$this->name = $name; $this->name = $name;

View File

@ -97,10 +97,11 @@ abstract class AnnotationClassLoader implements LoaderInterface
} }
$globals = array( $globals = array(
'pattern' => '', 'pattern' => '',
'requirements' => array(), 'requirements' => array(),
'options' => array(), 'options' => array(),
'defaults' => array(), 'defaults' => array(),
'hostname_pattern' => null,
); );
$class = new \ReflectionClass($class); $class = new \ReflectionClass($class);
@ -124,6 +125,10 @@ abstract class AnnotationClassLoader implements LoaderInterface
if (null !== $annot->getDefaults()) { if (null !== $annot->getDefaults()) {
$globals['defaults'] = $annot->getDefaults(); $globals['defaults'] = $annot->getDefaults();
} }
if (null !== $annot->getHostnamePattern()) {
$globals['hostname_pattern'] = $annot->getHostnamePattern();
}
} }
$collection = new RouteCollection(); $collection = new RouteCollection();
@ -157,7 +162,12 @@ abstract class AnnotationClassLoader implements LoaderInterface
$requirements = array_merge($globals['requirements'], $annot->getRequirements()); $requirements = array_merge($globals['requirements'], $annot->getRequirements());
$options = array_merge($globals['options'], $annot->getOptions()); $options = array_merge($globals['options'], $annot->getOptions());
$route = new Route($globals['pattern'].$annot->getPattern(), $defaults, $requirements, $options); $hostnamePattern = $annot->getHostnamePattern();
if (null === $hostnamePattern) {
$hostnamePattern = $globals['hostname_pattern'];
}
$route = new Route($globals['pattern'].$annot->getPattern(), $defaults, $requirements, $options, $hostnamePattern);
$this->configureRoute($route, $class, $method, $annot); $this->configureRoute($route, $class, $method, $annot);