@@ -30,6 +30,7 @@ class RouteCollection implements \IteratorAggregate, \Countable
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 ()
@@ -188,12 +190,13 @@ public function remove($name)
188
190
* @param array $defaults An array of default values
189
191
* @param array $requirements An array of requirements
190
192
* @param array $options An array of options
193
+ * @param string $hostnamePattern Hostname pattern
191
194
*
192
195
* @throws \InvalidArgumentException When the RouteCollection already exists in the tree
193
196
*
194
197
* @api
195
198
*/
196
- public function addCollection (RouteCollection $ collection , $ prefix = '' , $ defaults = array (), $ requirements = array (), $ options = array ())
199
+ public function addCollection (RouteCollection $ collection , $ prefix = '' , $ defaults = array (), $ requirements = array (), $ options = array (), $ hostnamePattern = null )
197
200
{
198
201
// prevent infinite loops by recursive referencing
199
202
$ root = $ this ->getRoot ();
@@ -208,6 +211,12 @@ public function addCollection(RouteCollection $collection, $prefix = '', $defaul
208
211
// the sub-collection must have the prefix of the parent (current instance) prepended because it does not
209
212
// necessarily already have it applied (depending on the order RouteCollections are added to each other)
210
213
$ collection ->addPrefix ($ this ->getPrefix () . $ prefix , $ defaults , $ requirements , $ options );
214
+
215
+ // Allow child collection to have a different pattern
216
+ if (!$ collection ->getHostnamePattern ()) {
217
+ $ collection ->setHostnamePattern ($ hostnamePattern );
218
+ }
219
+
211
220
$ this ->routes [] = $ collection ;
212
221
}
213
222
@@ -341,4 +350,22 @@ private function hasCollection(RouteCollection $collection)
341
350
342
351
return false ;
343
352
}
353
+
354
+ public function getHostnamePattern ()
355
+ {
356
+ return $ this ->hostnamePattern ;
357
+ }
358
+
359
+ public function setHostnamePattern ($ pattern )
360
+ {
361
+ $ this ->hostnamePattern = $ pattern ;
362
+
363
+ foreach ($ this ->routes as $ name => $ route ) {
364
+ // Allow individual routes to have a different pattern
365
+ if (!$ route ->getHostnamePattern ()) {
366
+ $ route ->setHostnamePattern ($ pattern );
367
+ }
368
+ }
369
+ }
370
+
344
371
}
0 commit comments