Skip to content

Commit

Permalink
Fix the injection of the container in invokable controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
stof committed Sep 9, 2015
1 parent 6b08d3e commit 36e09da
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Expand Up @@ -70,17 +70,20 @@ protected function createController($controller)
}
}

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;
}
}
Expand Up @@ -33,6 +33,18 @@ public function testGetControllerOnContainerAware()
$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';
Expand Down Expand Up @@ -161,4 +173,8 @@ public function getContainer()
public function testAction()
{
}

public function __invoke()
{
}
}

0 comments on commit 36e09da

Please sign in to comment.