merged branch ericclemmons/3194-router-prefix-imports (PR #3245)

Commits
-------

534843d Updated CHANGELOG-2.1 to reflect imported route support of default values and requirements
3c28ab7 No prefix is required to override imported RouteCollections
c373d5b Added RouteCollectionTest#testAddCollectionOverridesDefaultsAndRequirements

Discussion
----------

[Router] RouteCollection `prefix` optional for default values/requirements

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #3194

[![Build Status](https://secure.travis-ci.org/ericclemmons/symfony.png)](https://secure.travis-ci.org/ericclemmons/symfony.png)

With the commit 2e1344eb7e (thanks @vicb!), imported routes could have `defaults` and `requirements` set, but only as long as there is a `prefix`.

Thisfix allows any imported route to have defaults set, whether or not `prefix` is set.

(See #3194 for specifics)

---------------------------------------------------------------------------

by vicb at 2012-02-02T06:01:51Z

Behavior is now consistent.

_FYI, You should thank `git-dag` here, `gitk` & `git-cola` are also helpful to filter commits._
This commit is contained in:
Fabien Potencier 2012-02-02 07:50:10 +01:00
commit 42dbdd9f3d
3 changed files with 15 additions and 6 deletions

View File

@ -228,7 +228,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
### Routing
* added a TraceableUrlMatcher
* added the possibility to define default values and requirements for placeholders in prefix
* added the possibility to define default values and requirements for placeholders in prefix, including imported routes
* added RouterInterface::getRouteCollection
### Security

View File

@ -209,12 +209,8 @@ class RouteCollection implements \IteratorAggregate
// a prefix must not end with a slash
$prefix = rtrim($prefix, '/');
if (!$prefix) {
return;
}
// a prefix must start with a slash
if ('/' !== $prefix[0]) {
if ($prefix && '/' !== $prefix[0]) {
$prefix = '/'.$prefix;
}

View File

@ -141,6 +141,19 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('https', $collection->get('bar')->getRequirement('_scheme'), '->addPrefix() overrides existing requirements');
}
public function testAddCollectionOverridesDefaultsAndRequirements()
{
$imported = new RouteCollection();
$imported->add('foo', $foo = new Route('/foo'));
$imported->add('bar', $bar = new Route('/bar', array(), array('_scheme' => 'http')));
$collection = new RouteCollection();
$collection->addCollection($imported, null, array(), array('_scheme' => 'https'));
$this->assertEquals('https', $collection->get('foo')->getRequirement('_scheme'), '->addCollection() overrides existing requirements');
$this->assertEquals('https', $collection->get('bar')->getRequirement('_scheme'), '->addCollection() overrides existing requirements');
}
public function testResource()
{
$collection = new RouteCollection();