Skip to content
This repository has been archived by the owner on Jul 4, 2018. It is now read-only.

Commit

Permalink
cascade route configuration for embedded route collection
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jun 12, 2015
1 parent cfb6ed0 commit 48727b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Silex/ControllerCollection.php
Expand Up @@ -171,9 +171,7 @@ public function __call($method, $arguments)
call_user_func_array(array($this->defaultRoute, $method), $arguments);

foreach ($this->controllers as $controller) {
if ($controller instanceof Controller) {
call_user_func_array(array($controller, $method), $arguments);
}
call_user_func_array(array($controller, $method), $arguments);
}

return $this;
Expand Down
18 changes: 18 additions & 0 deletions tests/Silex/Tests/ControllerCollectionTest.php
Expand Up @@ -176,6 +176,24 @@ public function testRouteMethodDoesNotExist()
$controller = new ControllerCollection($route);
$controller->bar();
}

public function testNestedCollectionRouteCallbacks()
{
$cl1 = new ControllerCollection(new MyRoute1());
$cl2 = new ControllerCollection(new MyRoute1());

$c1 = $cl2->match('/c1', function () {});
$cl1->mount('/foo', $cl2);
$c2 = $cl2->match('/c2', function () {});
$cl1->before('before');
$c3 = $cl2->match('/c3', function () {});

$cl1->flush();

$this->assertEquals(array('before'), $c1->getRoute()->getOption('_before_middlewares'));
$this->assertEquals(array('before'), $c2->getRoute()->getOption('_before_middlewares'));
$this->assertEquals(array('before'), $c3->getRoute()->getOption('_before_middlewares'));
}
}

class MyRoute1 extends Route
Expand Down

0 comments on commit 48727b4

Please sign in to comment.