Commit e98dd5f7 authored by Fabien Potencier's avatar Fabien Potencier

Merge branch '1.3'

* 1.3:
  updated CHANGELOG
  moved logic to an internal method
  simplified previous merge
  Use shared RouteCollection among nested routes and apply prefix to route path before generating unique route name
parents 3fed3e48 b3bb4fc0
...@@ -22,6 +22,7 @@ Changelog ...@@ -22,6 +22,7 @@ Changelog
1.3.1 (2015-XX-XX) 1.3.1 (2015-XX-XX)
------------------ ------------------
* fixed sub-mounts with same name clash
* fixed session logout handler when a firewall is stateless * fixed session logout handler when a firewall is stateless
1.3.0 (2015-06-05) 1.3.0 (2015-06-05)
......
...@@ -194,10 +194,20 @@ class ControllerCollection ...@@ -194,10 +194,20 @@ class ControllerCollection
$routes = $this->routesFactory; $routes = $this->routesFactory;
} }
return $this->doFlush($prefix, $routes);
}
private function doFlush($prefix, RouteCollection $routes)
{
if ($prefix !== '') {
$prefix = '/'.trim(trim($prefix), '/');
}
foreach ($this->controllers as $controller) { foreach ($this->controllers as $controller) {
if ($controller instanceof Controller) { if ($controller instanceof Controller) {
$controller->getRoute()->setPath($prefix.$controller->getRoute()->getPath());
if (!$name = $controller->getRouteName()) { if (!$name = $controller->getRouteName()) {
$name = $controller->generateRouteName($prefix); $name = $controller->generateRouteName('');
while ($routes->get($name)) { while ($routes->get($name)) {
$name .= '_'; $name .= '_';
} }
...@@ -206,12 +216,10 @@ class ControllerCollection ...@@ -206,12 +216,10 @@ class ControllerCollection
$routes->add($name, $controller->getRoute()); $routes->add($name, $controller->getRoute());
$controller->freeze(); $controller->freeze();
} else { } else {
$routes->addCollection($controller->flush($controller->prefix)); $routes->addCollection($controller->doFlush($prefix.$controller->prefix, $routes));
} }
} }
$routes->addPrefix($prefix);
$this->controllers = array(); $this->controllers = array();
return $routes; return $routes;
......
...@@ -91,6 +91,41 @@ class ControllerCollectionTest extends \PHPUnit_Framework_TestCase ...@@ -91,6 +91,41 @@ class ControllerCollectionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array('_a_a', '_a_a_'), array_keys($routes->all())); $this->assertEquals(array('_a_a', '_a_a_'), array_keys($routes->all()));
} }
public function testUniqueGeneratedRouteNamesAmongMounts()
{
$controllers = new ControllerCollection(new Route());
$controllers->mount('/root-a', $rootA = new ControllerCollection(new Route()));
$controllers->mount('/root_a', $rootB = new ControllerCollection(new Route()));
$rootA->match('/leaf', function () {});
$rootB->match('/leaf', function () {});
$routes = $controllers->flush();
$this->assertCount(2, $routes->all());
$this->assertEquals(array('_root_a_leaf', '_root_a_leaf_'), array_keys($routes->all()));
}
public function testUniqueGeneratedRouteNamesAmongNestedMounts()
{
$controllers = new ControllerCollection(new Route());
$controllers->mount('/root-a', $rootA = new ControllerCollection(new Route()));
$controllers->mount('/root_a', $rootB = new ControllerCollection(new Route()));
$rootA->mount('/tree', $treeA = new ControllerCollection(new Route()));
$rootB->mount('/tree', $treeB = new ControllerCollection(new Route()));
$treeA->match('/leaf', function () {});
$treeB->match('/leaf', function () {});
$routes = $controllers->flush();
$this->assertCount(2, $routes->all());
$this->assertEquals(array('_root_a_tree_leaf', '_root_a_tree_leaf_'), array_keys($routes->all()));
}
public function testAssert() public function testAssert()
{ {
$controllers = new ControllerCollection(new Route()); $controllers = new ControllerCollection(new Route());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment