Normally when using services in Symfony PHP I would inject them into controllers like so:
use App\Services\Utilities;
class Home extends Controller {
public function __construct(Utilities $u){
$u->doSomething();
}
}
But I would only have access to this service if the Home controller is called (/ route matched).
I'd like to invoke a method on every request in Symfony 4 - even requests that are redirected or return 404's - before the response is returned.
So..
Request --> $u->doSomething() --> Response
What would be the best place in the application to inject this service?
You can creates subscriber to request event, something like that: