@@ -30,6 +30,7 @@ class RouteCollection implements \IteratorAggregate
30
30
private $ resources ;
31
31
private $ prefix ;
32
32
private $ parent ;
33
+ private $ hostnamePattern ;
33
34
34
35
/**
35
36
* Constructor.
@@ -41,6 +42,7 @@ public function __construct()
41
42
$ this ->routes = array ();
42
43
$ this ->resources = array ();
43
44
$ this ->prefix = '' ;
45
+ $ this ->hostnamePattern = null ;
44
46
}
45
47
46
48
public function __clone ()
@@ -173,12 +175,13 @@ public function remove($name)
173
175
* @param array $defaults An array of default values
174
176
* @param array $requirements An array of requirements
175
177
* @param array $options An array of options
178
+ * @param string $hostnamePattern Hostname pattern
176
179
*
177
180
* @throws \InvalidArgumentException When the RouteCollection already exists in the tree
178
181
*
179
182
* @api
180
183
*/
181
- public function addCollection (RouteCollection $ collection , $ prefix = '' , $ defaults = array (), $ requirements = array (), $ options = array ())
184
+ public function addCollection (RouteCollection $ collection , $ prefix = '' , $ defaults = array (), $ requirements = array (), $ options = array (), $ hostnamePattern = null )
182
185
{
183
186
// prevent infinite loops by recursive referencing
184
187
$ root = $ this ->getRoot ();
@@ -193,6 +196,12 @@ public function addCollection(RouteCollection $collection, $prefix = '', $defaul
193
196
// the sub-collection must have the prefix of the parent (current instance) prepended because it does not
194
197
// necessarily already have it applied (depending on the order RouteCollections are added to each other)
195
198
$ collection ->addPrefix ($ this ->getPrefix () . $ prefix , $ defaults , $ requirements , $ options );
199
+
200
+ // Allow child collection to have a different pattern
201
+ if (!$ collection ->getHostnamePattern ()) {
202
+ $ collection ->setHostnamePattern ($ hostnamePattern );
203
+ }
204
+
196
205
$ this ->routes [] = $ collection ;
197
206
}
198
207
@@ -326,4 +335,22 @@ private function hasCollection(RouteCollection $collection)
326
335
327
336
return false ;
328
337
}
338
+
339
+ public function getHostnamePattern ()
340
+ {
341
+ return $ this ->hostnamePattern ;
342
+ }
343
+
344
+ public function setHostnamePattern ($ pattern )
345
+ {
346
+ $ this ->hostnamePattern = $ pattern ;
347
+
348
+ foreach ($ this ->routes as $ name => $ route ) {
349
+ // Allow individual routes to have a different pattern
350
+ if (!$ route ->getHostnamePattern ()) {
351
+ $ route ->setHostnamePattern ($ pattern );
352
+ }
353
+ }
354
+ }
355
+
329
356
}
0 commit comments