8000 Fix the injection of the container in invokable controllers · Seldaek/symfony@36e09da · GitHub
[go: up one dir, main page]

Skip to content

Commit 36e09da

Browse files
committed
Fix the injection of the container in invokable controllers
1 parent 6b08d3e commit 36e09da

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,20 @@ protected function createController($controller)
7070
}
7171
}
7272

73-
list($class, $method) = explode('::', $controller, 2);
73+
return parent::createController($controller);
74+
}
7475

75-
if (!class_exists($class)) {
76-
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
77-
}
76+
/**
77+
* {@inheritdoc}
78+
*/
79+
protected function instantiateController($class)
80+
{
81+
$controller = parent::instantiateController($class);
7882

79-
$controller = $this->instantiateController($class);
8083
if ($controller instanceof ContainerAwareInterface) {
8184
$controller->setContainer($this->container);
8285
}
8386

84-
return array($controller, $method);
87+
return $controller;
8588
}
8689
}

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerResolverTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ public function testGetControllerOnContainerAware()
3333
$this->assertSame('testAction', $controller[1]);
3434
}
3535

36+
public function testGetControllerOnContainerAwareInvokable()
37+
{
38+
$resolver = $this->createControllerResolver();
39+
$request = Request::create('/');
40+
$request->attributes->set('_controller', 'Symfony\Bundle\FrameworkBundle\Tests\Controller\ContainerAwareController');
41+
42+
$controller = $resolver->getController($request);
43+
44+
$this->assertInstanceOf('Symfony\Bundle\FrameworkBundle\Tests\Controller\ContainerAwareController', $controller);
45+
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerInterface', $controller->getContainer());
46+
}
47+
3648
public function testGetControllerWithBundleNotation()
3749
{
3850
$shortName = 'FooBundle:Default:test';
@@ -161,4 +173,8 @@ public function getContainer()
161173
public function testAction()
162174
{
163175
}
176+
177+
public function __invoke()
178+
{
179+
}
164180
}

0 commit comments

Comments
 (0)
0