@@ -30,6 +30,7 @@ class RouteCollection implements \IteratorAggregate, \Countable
3030 private $ resources ;
3131 private $ prefix ;
3232 private $ parent ;
33+ private $ hostnamePattern ;
3334
3435 /**
3536 * Constructor.
@@ -41,6 +42,7 @@ public function __construct()
4142 $ this ->routes = array ();
4243 $ this ->resources = array ();
4344 $ this ->prefix = '' ;
45+ $ this ->hostnamePattern = null ;
4446 }
4547
4648 public function __clone ()
@@ -188,12 +190,13 @@ public function remove($name)
188190 * @param array $defaults An array of default values
189191 * @param array $requirements An array of requirements
190192 * @param array $options An array of options
193+ * @param string $hostnamePattern Hostname pattern
191194 *
192195 * @throws \InvalidArgumentException When the RouteCollection already exists in the tree
193196 *
194197 * @api
195198 */
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 )
197200 {
198201 // prevent infinite loops by recursive referencing
199202 $ root = $ this ->getRoot ();
@@ -208,6 +211,12 @@ public function addCollection(RouteCollection $collection, $prefix = '', $defaul
208211 // the sub-collection must have the prefix of the parent (current instance) prepended because it does not
209212 // necessarily already have it applied (depending on the order RouteCollections are added to each other)
210213 $ 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+
211220 $ this ->routes [] = $ collection ;
212221 }
213222
@@ -341,4 +350,22 @@ private function hasCollection(RouteCollection $collection)
341350
342351 return false ;
343352 }
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+
344371}
0 commit comments