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

Allow easier subclassing of ControllerInvoker #85

Open andrewnicols opened 10 months ago

andrewnicols commented 10 months ago

I'm looking to modify the ControllerInvoker to allow the route to return a different response which can be converted to a ResponseInterface at a later stage. Specifically I'm looking to implement something like juliangut/slim-routing (https://github.com/juliangut/slim-routing/blob/master/src/Strategy/RequestResponseNamedArgs.php).

Would you be open to adding a call to an intermediary methodin the __invoke method, for example:

public function __invoke(): ResponseInterface
{
    // ...
    return $this->processResponse($this->invoker->call($callable, $parameters));
}

protected function processResponse($response): ResponseInterface
{
     return $response;
}

This would allow for sub-classing for the ControllerInvoker, such that alternative response types could be cast to the ResponseInterface after invocation, for example a controller may return:


public function example(
    // ...
): PayloadResponse
{
    return new PayloadResponse(
        request: $request,
        response: $response,
        data: ['some', 'data', 'here']
    );
}