middlewares / utils

Common utils used by PSR-15 middlewares
MIT License
51 stars 12 forks source link

Dispatcher can implement RequestHandlerInterface #16

Closed Sevavietl closed 5 years ago

Sevavietl commented 5 years ago

Hi. Thank you for the great libraries.

What do you think about making Middlewares\Utils\Dispatcher to implement Psr\Http\Server\RequestHandlerInterface?

Dispatcher already has method dispatch(ServerRequestInterface $request): ResponseInterface, that, except the name, resemble handle(ServerRequestInterface $request): ResponseInterface from RequestHandlerInterface.

Making Dispatcher a middleware composite enables to pass it to some runners, for example zendframework/zend-httphandlerrunner:

$runner = new RequestHandlerRunner(
    $container->get(ApplicationRequestHandler::class),
    $container->get(EmitterStack::class),
    $container->get('ServerRequestFactory'),
    $container->get('ServerRequestErrorResponseGenerator')
);
$runner->run();

What do you think about this?

I have tested such approach localy, so can provide PR if needed.

Thak you in advance.

oscarotero commented 5 years ago

Yes, why not. Your PR is welcome! 👍

Sevavietl commented 5 years ago

@oscarotero thank you for merging PR. Can you, please, make a new patch release?

oscarotero commented 5 years ago

Sorry for the late. New version released.