Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow easier subclassing of ControllerInvoker #85

Open
andrewnicols opened this issue Oct 30, 2023 · 0 comments
Open

Allow easier subclassing of ControllerInvoker #85

andrewnicols opened this issue Oct 30, 2023 · 0 comments

Comments

@andrewnicols
Copy link

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']
    );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant