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

Skip to content

Commit 7a15e00

Browse files
committed
[Routing] added hostname matching support to AnnotationClassLoader
1 parent cab450c commit 7a15e00

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Route
2525
private $requirements;
2626
private $options;
2727
private $defaults;
28+
private $hostnamePattern;
2829

2930
/**
3031
* Constructor.
@@ -61,6 +62,16 @@ public function getPattern()
6162
return $this->pattern;
6263
}
6364

65+
public function setHostnamePattern($pattern)
66+
{
67+
$this->hostnamePattern = $pattern;
68+
}
69+
70+
public function getHostnamePattern()
71+
{
72+
return $this->hostnamePattern;
73+
}
74+
6475
public function setName($name)
6576
{
6677
$this->name = $name;

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ public function load($class, $type = null)
9797
}
9898

9999
$globals = array(
100-
'pattern' => '',
101-
'requirements' => array(),
102-
'options' => array(),
103-
'defaults' => array(),
100+
'pattern' => '',
101+
'requirements' => array(),
102+
'options' => array(),
103+
'defaults' => array(),
104+
'hostname_pattern' => null,
104105
);
105106

106107
$class = new \ReflectionClass($class);
@@ -124,6 +125,10 @@ public function load($class, $type = null)
124125
if (null !== $annot->getDefaults()) {
125126
$globals['defaults'] = $annot->getDefaults();
126127
}
128+
129+
if (null !== $annot->getHostnamePattern()) {
130+
$globals['hostname_pattern'] = $annot->getHostnamePattern();
131+
}
127132
}
128133

129134
$collection = new RouteCollection();
@@ -157,7 +162,12 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl
157162
$requirements = array_merge($globals['requirements'], $annot->getRequirements());
158163
$options = array_merge($globals['options'], $annot->getOptions());
159164

160-
$route = new Route($globals['pattern'].$annot->getPattern(), $defaults, $requirements, $options);
165+
$hostnamePattern = $annot->getHostnamePattern();
166+
if (null === $hostnamePattern) {
167+
$hostnamePattern = $globals['hostname_pattern'];
168+
}
169+
170+
$route = new Route($globals['pattern'].$annot->getPattern(), $defaults, $requirements, $options, $hostnamePattern);
161171

162172
$this->configureRoute($route, $class, $method, $annot);
163173

0 commit comments

Comments
 (0)