-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
…ents for placeholders in prefix
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,15 +165,17 @@ public function remove($name) | |
/** | ||
* Adds a route collection to the current set of routes (at the end of the current set). | ||
* | ||
* @param RouteCollection $collection A RouteCollection instance | ||
* @param string $prefix An optional prefix to add before each pattern of the route collection | ||
* @param RouteCollection $collection A RouteCollection instance | ||
* @param string $prefix An optional prefix to add before each pattern of the route collection | ||
* @param array $defaults An array of default values | ||
* @param array $requirements An array of requirements | ||
* | ||
* @api | ||
*/ | ||
public function addCollection(RouteCollection $collection, $prefix = '') | ||
public function addCollection(RouteCollection $collection, $prefix = '', $defaults = array(), $requirements = array()) | ||
{ | ||
$collection->setParent($this); | ||
$collection->addPrefix($prefix); | ||
$collection->addPrefix($prefix, $defaults, $requirements); | ||
|
||
// remove all routes with the same name in all existing collections | ||
foreach (array_keys($collection->all()) as $name) { | ||
|
@@ -186,11 +188,13 @@ public function addCollection(RouteCollection $collection, $prefix = '') | |
/** | ||
* Adds a prefix to all routes in the current set. | ||
* | ||
* @param string $prefix An optional prefix to add before each pattern of the route collection | ||
* @param string $prefix An optional prefix to add before each pattern of the route collection | ||
* @param array $defaults An array of default values | ||
* @param array $requirements An array of requirements | ||
* | ||
* @api | ||
*/ | ||
public function addPrefix($prefix) | ||
public function addPrefix($prefix, $defaults = array(), $requirements = array()) | ||
{ | ||
// a prefix must not end with a slash | ||
$prefix = rtrim($prefix, '/'); | ||
|
@@ -208,9 +212,11 @@ public function addPrefix($prefix) | |
|
||
foreach ($this->routes as $name => $route) { | ||
if ($route instanceof RouteCollection) { | ||
$route->addPrefix($prefix); | ||
$route->addPrefix($prefix, $defaults, $requirements); | ||
} else { | ||
$route->setPattern($prefix.$route->getPattern()); | ||
$route->addDefaults($defaults); | ||
$route->addRequirements($requirements); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
fabpot
Author
Member
|
||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
blog_show: | ||
resource: validpattern.yml | ||
resource: validpattern.yml | ||
prefix: /{foo} | ||
defaults: { 'foo': 'foo' } | ||
requirements: { 'foo': '\d+' } |
1 comment
on commit 2e1344e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this support default values for special routing parameters like _locale
in prefix?
This implementation let me think that requirements and defaults set when importing the file win over requirements specified directly for the route. Am I right ? and if yes, is it the intended behavior ?