Fix the injection of the container in invokable controllers
This commit is contained in:
parent
6b08d3eb16
commit
36e09da4b9
@ -70,17 +70,20 @@ class ControllerResolver extends BaseControllerResolver
|
||||
}
|
||||
}
|
||||
|
||||
list($class, $method) = explode('::', $controller, 2);
|
||||
return parent::createController($controller);
|
||||
}
|
||||
|
||||
if (!class_exists($class)) {
|
||||
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function instantiateController($class)
|
||||
{
|
||||
$controller = parent::instantiateController($class);
|
||||
|
||||
$controller = $this->instantiateController($class);
|
||||
if ($controller instanceof ContainerAwareInterface) {
|
||||
$controller->setContainer($this->container);
|
||||
}
|
||||
|
||||
return array($controller, $method);
|
||||
return $controller;
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,18 @@ class ControllerResolverTest extends BaseControllerResolverTest
|
||||
$this->assertSame('testAction', $controller[1]);
|
||||
}
|
||||
|
||||
public function testGetControllerOnContainerAwareInvokable()
|
||||
{
|
||||
$resolver = $this->createControllerResolver();
|
||||
$request = Request::create('/');
|
||||
$request->attributes->set('_controller', 'Symfony\Bundle\FrameworkBundle\Tests\Controller\ContainerAwareController');
|
||||
|
||||
$controller = $resolver->getController($request);
|
||||
|
||||
$this->assertInstanceOf('Symfony\Bundle\FrameworkBundle\Tests\Controller\ContainerAwareController', $controller);
|
||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerInterface', $controller->getContainer());
|
||||
}
|
||||
|
||||
public function testGetControllerWithBundleNotation()
|
||||
{
|
||||
$shortName = 'FooBundle:Default:test';
|
||||
@ -161,4 +173,8 @@ class ContainerAwareController implements ContainerAwareInterface
|
||||
public function testAction()
|
||||
{
|
||||
}
|
||||
|
||||
public function __invoke()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user