Commit 74372712 authored by Fabien Potencier's avatar Fabien Potencier

made the default route name binding as late as possible

parent fb31ac4d
......@@ -34,7 +34,6 @@ class Controller
public function __construct(Route $route)
{
$this->route = $route;
$this->bind($this->defaultRouteName());
}
/**
......@@ -140,7 +139,7 @@ class Controller
$this->isFrozen = true;
}
private function defaultRouteName()
public function bindDefaultRouteName()
{
$requirements = $this->route->getRequirements();
$method = isset($requirements['_method']) ? $requirements['_method'] : '';
......@@ -149,6 +148,6 @@ class Controller
$routeName = str_replace(array('/', ':', '|', '-'), '_', $routeName);
$routeName = preg_replace('/[^a-z0-9A-Z_.]+/', '', $routeName);
return $routeName;
$this->routeName = $routeName;
}
}
......@@ -48,6 +48,9 @@ class ControllerCollection
public function flush()
{
foreach ($this->controllers as $controller) {
if (!$controller->getRouteName()) {
$controller->bindDefaultRouteName();
}
$this->routes->add($controller->getRouteName(), $controller->getRoute());
$controller->freeze();
}
......
......@@ -75,6 +75,7 @@ class ControllerTest extends \PHPUnit_Framework_TestCase
public function testDefaultRouteNameGeneration(Route $route, $expectedRouteName)
{
$controller = new Controller($route);
$controller->bindDefaultRouteName();
$this->assertEquals($expectedRouteName, $controller->getRouteName());
}
......
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