8000 Fix the injection of the container in invokable controllers by stof · Pull Request #15737 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix the injection of the container in invokable controllers #15737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix the injection of the container in invokable controllers
  • Loading branch information
stof committed Sep 9, 2015
commit 36e09da4b9e75b7a47e9aa51aa3d5376dbcb0c35
Original file line number Diff line number Diff line change
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;
}
}
Original file line number Diff line number Diff line change
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