-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Closed
Description
Symfony version(s) affected: 3.4.26
Description
Got fatal Call to a member function has() on null due to not injected container (service locator) in controller, extended from Symfony\Bundle\FrameworkBundle\Controller\AbstractController.
Actual when in route I use DI service id for invokable controller.
How to reproduce
Create controller
<?php
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
class IndexController extends AbstractController
{
public function __invoke()
{
$hasRouter = $this->has('router');
$response = $hasRouter ? 'router exists' : 'router not found';
return new Response($response);
}
}Register in services:
services:
app.index_controller:
class: IndexController
public: trueUse in route:
index:
path: /
controller: app.index_controllerGo to / path.
Possible Solution
Change if statement to work with route without :-notation, and not only with array-callables.
| if (1 === substr_count($controller, ':') && \is_array($resolvedController)) { |
Workaround for me:
index:
path: /
controller: app.index_controller:__invokeAdditional context