@@ -42,7 +42,7 @@ public function __construct()
4242 $ this ->routes = array ();
4343 $ this ->resources = array ();
4444 $ this ->prefix = '' ;
45- $ this ->hostnamePattern = null ;
45+ $ this ->hostnamePattern = '' ;
4646 }
4747
4848 public function __clone ()
@@ -185,18 +185,18 @@ public function remove($name)
185185 /**
186186 * Adds a route collection to the current set of routes (at the end of the current set).
187187 *
188- * @param RouteCollection $collection A RouteCollection instance
189- * @param string $prefix An optional prefix to add before each pattern of the route collection
190- * @param array $defaults An array of default values
191- * @param array $requirements An array of requirements
192- * @param array $options An array of options
193- * @param string $hostnamePattern Hostname pattern
188+ * @param RouteCollection $collection A RouteCollection instance
189+ * @param string $prefix An optional prefix to add before each pattern of the route collection
190+ * @param array $defaults An array of default values
191+ * @param array $requirements An array of requirements
192+ * @param array $options An array of options
193+ * @param string $hostnamePattern Hostname pattern
194194 *
195195 * @throws \InvalidArgumentException When the RouteCollection already exists in the tree
196196 *
197197 * @api
198198 */
199- public function addCollection (RouteCollection $ collection , $ prefix = '' , $ defaults = array (), $ requirements = array (), $ options = array (), $ hostnamePattern = null )
199+ public function addCollection (RouteCollection $ collection , $ prefix = '' , $ defaults = array (), $ requirements = array (), $ options = array (), $ hostnamePattern = '' )
200200 {
201201 // prevent infinite loops by recursive referencing
202202 $ root = $ this ->getRoot ();
@@ -212,10 +212,7 @@ public function addCollection(RouteCollection $collection, $prefix = '', $defaul
212212 // necessarily already have it applied (depending on the order RouteCollections are added to each other)
213213 $ collection ->addPrefix ($ this ->getPrefix () . $ prefix , $ defaults , $ requirements , $ options );
214214
215- // Allow child collection to have a different pattern
216- if (!$ collection ->getHostnamePattern ()) {
217- $ collection ->setHostnamePattern ($ hostnamePattern );
218- }
215+ $ collection ->setHostnamePattern ($ hostnamePattern );
219216
220217 $ this ->routes [] = $ collection ;
221218 }
@@ -268,6 +265,34 @@ public function getPrefix()
268265 return $ this ->prefix ;
269266 }
270267
268+ /**
269+ * Returns the hostname pattern.
270+ *
271+ * @return string The pattern
272+ */
273+ public function getHostnamePattern ()
274+ {
275+ return $ this ->hostnamePattern ;
276+ }
277+
278+ /**
279+ * Sets the hostname pattern on this collection and all children.
280+ *
281+ * @param string $pattern The pattern
282+ */
283+ public function setHostnamePattern ($ pattern )
284+ {
285+ $ this ->hostnamePattern = $ pattern ;
286+
287+ if ('' === $ pattern ) {
288+ return ;
289+ }
290+
291+ foreach ($ this ->routes as $ name => $ route ) {
292+ $ route ->setHostnamePattern ($ pattern );
293+ }
294+ }
295+
271296 /**
272297 * Returns an array of resources loaded to build this collection.
273298 *
@@ -350,21 +375,4 @@ private function hasCollection(RouteCollection $collection)
350375
351376 return false ;
352377 }
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- }
370378}
0 commit comments