Permalink
Browse files

deprecated additional param of RouteCollection::addCollection

these prefix, defaults, requirements params were redundant to the behavior of addPrefix. and with the addition of hostnamePattern, this method did basically everything although there are already specific methods for these use-cases. the single responsibility of the methods provides a better API
  • Loading branch information...
1 parent 606f0ba commit 930bdc4ab152f1f2e234ab1145f967a7eb3a9dfe @Tobion committed Nov 15, 2012
Showing with 27 additions and 13 deletions.
  1. +10 −0 src/Symfony/Component/Routing/CHANGELOG.md
  2. +17 −13 src/Symfony/Component/Routing/RouteCollection.php
@@ -44,6 +44,16 @@ CHANGELOG
* [DEPRECATION] The `$options` parameter to `RouteCollection::addPrefix()` has been deprecated
because adding options has nothing to do with adding a path prefix. If you want to add options
to all child routes of a RouteCollection, you can use `setConfigs()`.
+ * [DEPRECATION] `RouteCollection::addCollection(RouteCollection $collection)` should now only be
+ used with a single parameter. The other params `$prefix`, `$default`, `$requirements` and `$options`
+ will still work, but have been deprecated. The `addPrefix` method should be used for this
+ use-case instead.
+ Before: `$parentCollection->addCollection($collection, '/prefix', array(...), array(...))`
+ After:
+ ```
+ $collection->addPrefix('/prefix', array(...), array(...));
+ $parentCollection->addCollection($collection);
+ ```
* added support for the method default argument values when defining a @Route
* Adjacent placeholders without separator work now, e.g. `/{x}{y}{z}.{_format}`.
* Characters that function as separator between placeholders are now whitelisted
@@ -169,29 +169,33 @@ public function remove($name)
* routes of the added 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
- * @param array $options An array of options
- * @param string $hostnamePattern Hostname pattern
*
* @api
*/
- public function addCollection(RouteCollection $collection, $prefix = '', $defaults = array(), $requirements = array(), $options = array(), $hostnamePattern = '')
+ public function addCollection(RouteCollection $collection)
{
// This is to keep BC for getParent() and getRoot(). It does not prevent
// infinite loops by recursive referencing. But we don't need that logic
// anymore as the tree logic has been deprecated and we are just widening
// the accepted range.
$collection->parent = $this;
- // the sub-collection must have the prefix of the parent (current instance) prepended because it does not
- // necessarily already have it applied (depending on the order RouteCollections are added to each other)
- $collection->addPrefix($this->getPrefix() . $prefix, $defaults, $requirements);
- $collection->addConfigs($defaults, $requirements, $options);
-
- if ('' !== $hostnamePattern) {
- $collection->setHostnamePattern($hostnamePattern);
+ // this is to keep BC
+ $numargs = func_num_args();
+ if ($numargs > 1) {
+ $collection->addPrefix($this->getPrefix() . func_get_arg(1));
+
+ if ($numargs > 2) {
+ $defaults = func_get_arg(2);
+ $requirements = $numargs > 3 ? func_get_arg(3) : array();
+ $options = $numargs > 4 ? func_get_arg(4) : array();
+
+ $collection->addConfigs($defaults, $requirements, $options);
+ }
+ } else {
+ // the sub-collection must have the prefix of the parent (current instance) prepended because it does not
+ // necessarily already have it applied (depending on the order RouteCollections are added to each other)
+ $collection->addPrefix($this->getPrefix());
}
// we need to remove all routes with the same names first because just replacing them

0 comments on commit 930bdc4

Please sign in to comment.