[FrameworkBundle] added support for services as controllers
This commit is contained in:
parent
82f6a68eb2
commit
2d80788e3a
@ -57,8 +57,18 @@ class ControllerResolver extends BaseControllerResolver
|
||||
protected function createController($controller)
|
||||
{
|
||||
if (false === strpos($controller, '::')) {
|
||||
// must be a controller in the a:b:c notation then
|
||||
$controller = $this->converter->fromShortNotation($controller);
|
||||
$count = substr_count($controller, ':');
|
||||
if (2 == $count) {
|
||||
// controller in the a:b:c notation then
|
||||
$controller = $this->converter->fromShortNotation($controller);
|
||||
} elseif (1 == $count) {
|
||||
// controller in the service:method notation
|
||||
list($service, $method) = explode(':', $controller);
|
||||
|
||||
return array($this->container->get($service), $method);
|
||||
} else {
|
||||
throw new \LogicException(sprintf('Unable to parse the controller name "%s".', $controller));
|
||||
}
|
||||
}
|
||||
|
||||
list($class, $method) = explode('::', $controller);
|
||||
|
@ -60,7 +60,7 @@ class DelegatingLoader extends BaseDelegatingLoader
|
||||
try {
|
||||
$controller = $this->converter->fromShortNotation($controller);
|
||||
} catch (\Exception $e) {
|
||||
throw new \RuntimeException(sprintf('%s (for route "%s" in resource "%s")', $e->getMessage(), $name, is_string($resource) ? $resource : 'RESOURCE'), $e->getCode(), $e);
|
||||
// unable to optimize unknown notation
|
||||
}
|
||||
|
||||
$route->setDefault('_controller', $controller);
|
||||
|
Reference in New Issue
Block a user