PHP-DI / Slim-Bridge

PHP-DI integration with the Slim framework
http://php-di.org/doc/frameworks/slim.html
MIT License
176 stars 38 forks source link

container method call() does not autowire. #48

Closed adjenks closed 5 years ago

adjenks commented 5 years ago

As described on this page: http://php-di.org/doc/container.html#call Call should perform autowiring when the container has the available .

$app->get('', function (Request $request, Response $response) {
    return $this->call(function(Request $request, Response $response){
        return $response;
    });
});

Results in:

Unable to invoke the callable because no value was given for parameter 1 ($request)

Because get() correctly autowired, whereas call() did not.

adjenks commented 5 years ago

Type hinting does not work, however, this works:

$app->get('', function (Request $request, Response $response) {
    return $this->call(function(Request $request, Response $response){
        return $response;
    },[\DI\get('response')]); // "dependency injection based on explicit definition"
});
mnapoli commented 5 years ago

Requests and responses are not services, they are not autowired.

In controllers (get() method) they are injected not as services, but with a specific feature of https://github.com/PHP-DI/Invoker.