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: true
Use in route:
index:
path: /
controller: app.index_controller
Go to /
path.
Possible Solution
Change if statement to work with route without :
-notation, and not only with array-callables.
Workaround for me:
index:
path: /
controller: app.index_controller:__invoke
Additional context