Skip to content

Commit

Permalink
[Routing] added hostname matching support to AnnotationClassLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-lb committed Nov 12, 2012
1 parent cab450c commit 7a15e00
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/Symfony/Component/Routing/Annotation/Route.php
Expand Up @@ -25,6 +25,7 @@ class Route
private $requirements;
private $options;
private $defaults;
private $hostnamePattern;

/**
* Constructor.
Expand Down Expand Up @@ -61,6 +62,16 @@ public function getPattern()
return $this->pattern;
}

public function setHostnamePattern($pattern)
{
$this->hostnamePattern = $pattern;
}

public function getHostnamePattern()
{
return $this->hostnamePattern;
}

public function setName($name)
{
$this->name = $name;
Expand Down
20 changes: 15 additions & 5 deletions src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php
Expand Up @@ -97,10 +97,11 @@ public function load($class, $type = null)
}

$globals = array(
'pattern' => '',
'requirements' => array(),
'options' => array(),
'defaults' => array(),
'pattern' => '',
'requirements' => array(),
'options' => array(),
'defaults' => array(),
'hostname_pattern' => null,
);

$class = new \ReflectionClass($class);
Expand All @@ -124,6 +125,10 @@ public function load($class, $type = null)
if (null !== $annot->getDefaults()) {
$globals['defaults'] = $annot->getDefaults();
}

if (null !== $annot->getHostnamePattern()) {
$globals['hostname_pattern'] = $annot->getHostnamePattern();
}
}

$collection = new RouteCollection();
Expand Down Expand Up @@ -157,7 +162,12 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl
$requirements = array_merge($globals['requirements'], $annot->getRequirements());
$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);

Expand Down

0 comments on commit 7a15e00

Please sign in to comment.