Skip to content

Allow easier subclassing of ControllerInvoker #85

Open
@andrewnicols

Description

@andrewnicols

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']
    );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions