8000 [Routing] added hostname matching support to AnnotationClassLoader · jeremymarc/symfony@2c9a045 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c9a045

Browse files
committed
[Routing] added hostname matching support to AnnotationClassLoader
1 parent dec62f9 commit 2c9a045

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
@@ -98,10 +98,11 @@ public function load($class, $type = null)
9898
}
9999

100100
$globals = array(
101-
'pattern' => '',
102-
'requirements' => array(),
103-
'options' => array(),
104-
'defaults' => array(),
101+
'pattern' => '',
102+
'requirements' => array(),
103+
'options' => array(),
104+
'defaults' => array(),
105+
'hostname_pattern' => null,
105106
);
106107

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

130135
$collection = new RouteCollection();
@@ -153,7 +158,12 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl
153158
$requirements = array_merge($globals['requirements'], $annot->getRequirements());
154159
$options = array_merge($globals['options'], $annot->getOptions());
155160

156-
$route = new Route($globals['pattern'].$annot->getPattern(), $defaults, $requirements, $options);
161+
$hostnamePattern = $annot->getHostnamePattern();
162+
if (null === $hostnamePattern) {
163+
$hostnamePattern = $globals['hostname_pattern'];
164+
}
165+
166+
$route = new Route($globals['pattern'].$annot->getPattern(), $defaults, $requirements, $options, $hostnamePattern);
157167

158168
$this->configureRoute($route, $class, $method, $annot);
159169

0 commit comments

Comments
 (0)
0