How to use Symfony HttpFoundation with PHP-DI for MVC

one text

Solution:

Nothing in PHP-DI suggests that dependency injection happens according to parameter names but instead the class is relevant. PHP-DI magically injects any class, if it is not (yet) defined. (The AnnotationBasedAutowiring will create a class from nothing if no definition is provided)

However, actually using annotations to trigger injections looks very different, and IMHO isn't apparently what you want, or you would have done so.

Since your definitions only contain an entry for request but not for Symfony\Component\HttpFoundation\Request, the container will happily create one for you.

To fix this, you have to set a different key, one that matches:

use Symfony\Component\HttpFoundation\Request; // <-- added

return [
    Request::class => function() {
        return Request::createFromGlobals();
    },
    // ...
];

Source