[FrameworkBundle] added support for services as controllers

This commit is contained in:
Fabien Potencier 2010-09-23 08:41:24 +02:00
parent 82f6a68eb2
commit 2d80788e3a
2 changed files with 13 additions and 3 deletions

View File

@ -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);

View File

@ -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);