Browse files

switch from addConfigs() to dedicated addDefaults, addRequirements, a…

…ddOptions
  • Loading branch information...
1 parent b6d1e22 commit 8c1aa53a813eac4385d1a25122d8afcd063dae03 @Tobion committed Dec 6, 2012
View
12 src/Symfony/Component/Routing/CHANGELOG.md
@@ -37,13 +37,15 @@ CHANGELOG
* [DEPRECATION] The methods `RouteCollection::getParent()` and `RouteCollection::getRoot()`
have been deprecated and will be removed in Symfony 2.3.
- * [BC BREAK] Misusing the `RouteCollection::addPrefix` method to add requirements or options
- without adding a prefix is not supported anymore. There is now a dedicated method named
- `setConfigs()` for this. So if you used something like `addPrefix('', array(...), array(...))`
- you need to call `setConfigs(array(...), array(...))` instead.
+ * [BC BREAK] Misusing the `RouteCollection::addPrefix` method to add defaults, requirements
+ or options without adding a prefix is not supported anymore. So if you called `addPrefix`
+ with an empty prefix or `/` only (both have no relevance), like
+ `addPrefix('', $defaultsArray, $requirementsArray, $optionsArray)`
+ you need to use the new dedicated methods `addDefaults($defaultsArray)`,
+ `addRequirements($requirementsArray)` or `addOptions($optionsArray)` instead.
* [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()`.
+ to all child routes of a RouteCollection, you can use `addOptions()`.
* [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
View
7 src/Symfony/Component/Routing/Loader/XmlFileLoader.php
@@ -107,12 +107,15 @@ protected function parseNode(RouteCollection $collection, \DOMElement $node, $pa
$this->setCurrentDir(dirname($path));
$subCollection = $this->import($resource, ('' !== $type ? $type : null), false, $file);
- /* @var RouteCollection $subCollection */
+ /* @var $subCollection RouteCollection */
$subCollection->addPrefix($prefix);
if (null !== $hostnamePattern) {
$subCollection->setHostnamePattern($hostnamePattern);
}
- $subCollection->addConfigs($defaults, $requirements, $options);
+ $subCollection->addDefaults($defaults);
+ $subCollection->addRequirements($requirements);
+ $subCollection->addOptions($options);
+
$collection->addCollection($subCollection);
break;
default:
View
7 src/Symfony/Component/Routing/Loader/YamlFileLoader.php
@@ -75,12 +75,15 @@ public function load($file, $type = null)
$this->setCurrentDir(dirname($path));
$subCollection = $this->import($config['resource'], $type, false, $file);
- /* @var RouteCollection $subCollection */
+ /* @var $subCollection RouteCollection */
$subCollection->addPrefix($prefix);
if (null !== $hostnamePattern) {
$subCollection->setHostnamePattern($hostnamePattern);
}
- $subCollection->addConfigs($defaults, $requirements, $options);
+ $subCollection->addDefaults($defaults);
+ $subCollection->addRequirements($requirements);
+ $subCollection->addOptions($options);
+
$collection->addCollection($subCollection);
} else {
$this->parseRoute($collection, $name, $config, $path);
View
63 src/Symfony/Component/Routing/RouteCollection.php
@@ -184,13 +184,14 @@ public function addCollection(RouteCollection $collection)
$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);
+ $collection->addDefaults(func_get_arg(2));
+ if ($numargs > 3) {
+ $collection->addRequirements(func_get_arg(3));
+ if ($numargs > 4) {
+ $collection->addOptions(func_get_arg(4));
+ }
+ }
}
} else {
// the sub-collection must have the prefix of the parent (current instance) prepended because it does not
@@ -266,20 +267,50 @@ public function setHostnamePattern($pattern, array $defaults = array(), array $r
}
/**
- * Adds defaults, requirements and options to all routes.
+ * Adds defaults to all routes.
*
- * Any existing config under the same name in a route will be overridden.
+ * An existing default value under the same name in a route will be overridden.
*
- * @param array $defaults An array of default values
- * @param array $requirements An array of requirements
- * @param array $options An array of options
+ * @param array $defaults An array of default values
*/
- public function addConfigs(array $defaults = array(), array $requirements = array(), array $options = array())
+ public function addDefaults(array $defaults)
{
- foreach ($this->routes as $route) {
- $route->addDefaults($defaults);
- $route->addRequirements($requirements);
- $route->addOptions($options);
+ if ($defaults) {
+ foreach ($this->routes as $route) {
+ $route->addDefaults($defaults);
+ }
+ }
+ }
+
+ /**
+ * Adds requirements to all routes.
+ *
+ * An existing requirement under the same name in a route will be overridden.
+ *
+ * @param array $requirements An array of requirements
+ */
+ public function addRequirements(array $requirements)
+ {
+ if ($requirements) {
+ foreach ($this->routes as $route) {
+ $route->addRequirements($requirements);
+ }
+ }
+ }
+
+ /**
+ * Adds options to all routes.
+ *
+ * An existing option value under the same name in a route will be overridden.
+ *
+ * @param array $options An array of options
+ */
+ public function addOptions(array $options)
+ {
+ if ($options) {
+ foreach ($this->routes as $route) {
+ $route->addOptions($options);
+ }
}
}

0 comments on commit 8c1aa53

Please sign in to comment.