Unverified Commit aca89d4c authored by alexpott's avatar alexpott
Browse files

Issue #2988152 by slootjes, tim.plunkett: Allow invokable services as controllers

parent 95479590
......@@ -66,9 +66,7 @@ public function getControllerFromDefinition($controller, $path = '') {
if (function_exists($controller)) {
return $controller;
}
elseif (method_exists($controller, '__invoke')) {
return new $controller();
}
return $this->classResolver->getInstanceFromDefinition($controller);
}
$callable = $this->createController($controller);
......
......@@ -171,6 +171,7 @@ public function providerTestGetController() {
* @dataProvider providerTestGetControllerFromDefinition
*/
public function testGetControllerFromDefinition($definition, $output) {
$this->container->set('invoke_service', new MockInvokeController());
$controller = $this->controllerResolver->getControllerFromDefinition($definition);
$this->assertCallableController($controller, NULL, $output);
}
......@@ -188,6 +189,8 @@ public function providerTestGetControllerFromDefinition() {
[new MockInvokeController(), 'This used __invoke().'],
// Tests a class using __invoke().
['Drupal\Tests\Core\Controller\MockInvokeController', 'This used __invoke().'],
// Tests a service from the container using __invoke().
['invoke_service', 'This used __invoke().'],
];
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment