Commit f27c0af9 authored by Fabien Potencier's avatar Fabien Potencier

fixed before handlers not executed under mounts

parent f33d8c9d
Changelog Changelog
========= =========
2.2.2 (2017-XX-XX) 2.2.2 (2018-01-12)
------------------ ------------------
* n/a * [SECURITY] fixed before handlers not executed under mounts
2.2.1 (2017-12-14) 2.2.1 (2017-12-14)
------------------ ------------------
......
...@@ -68,6 +68,7 @@ class ControllerCollection ...@@ -68,6 +68,7 @@ class ControllerCollection
{ {
if (is_callable($controllers)) { if (is_callable($controllers)) {
$collection = $this->controllersFactory ? call_user_func($this->controllersFactory) : new static(new Route(), new RouteCollection()); $collection = $this->controllersFactory ? call_user_func($this->controllersFactory) : new static(new Route(), new RouteCollection());
$collection->defaultRoute = clone $this->defaultRoute;
call_user_func($controllers, $collection); call_user_func($controllers, $collection);
$controllers = $collection; $controllers = $collection;
} elseif (!$controllers instanceof self) { } elseif (!$controllers instanceof self) {
......
...@@ -191,6 +191,23 @@ class ControllerCollectionTest extends TestCase ...@@ -191,6 +191,23 @@ class ControllerCollectionTest extends TestCase
$this->assertEquals('\w+', $controller->getRoute()->getRequirement('extra')); $this->assertEquals('\w+', $controller->getRoute()->getRequirement('extra'));
} }
public function testAssertWithMountCallable()
{
$controllers = new ControllerCollection(new Route());
$controller = null;
$controllers->mount('/{name}', function ($mounted) use (&$controller) {
$mounted->assert('name', '\w+');
$mounted->mount('/{id}', function ($mounted2) use (&$controller) {
$mounted2->assert('id', '\d+');
$controller = $mounted2->match('/{extra}', function () {})->assert('extra', '\w+');
});
});
$this->assertEquals('\d+', $controller->getRoute()->getRequirement('id'));
$this->assertEquals('\w+', $controller->getRoute()->getRequirement('name'));
$this->assertEquals('\w+', $controller->getRoute()->getRequirement('extra'));
}
public function testValue() public function testValue()
{ {
$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