laminas-mvc
laminas-mvc copied to clipboard
Implement and abstract controller that implement RequestHandlerInterface
Feature Request
Abstract controller that will implement RequestHandlerInterface and dispatch the request to the specific restful action.
Summary
Extending of this controller can allow to add a specific controller to a PipeSpec list. And therefor providing a link between Middleware PSR-15 specification and mvc controllers based application. The feature can be useful in previously or new applications that use mvc controllers and require middleware process before a particular actions call (validate some params, add attributes etc.).
Linked also to https://github.com/laminas/laminas-psr7bridge/issues/20. Added a draft of the idea: https://github.com/laminas/laminas-mvc/pull/117
Isn't this what laminas-mvc-middleware already does?
13 hours ago If we add a controller that extends AbstractRestfulController to the PipeSpec list, there will be an error InvalidMiddlewareException, as it has to implement one of RequestHandlerInterface or MiddlewareInterface.
Controllers running in pipeline behind middleware have some fundamental issues. Request/Response mutability, MvcEvent mutability and necessity to have event state to flow back up the call stack for followup events.
You can add decorator that would work for your specific application but I do not think it is something that can be supported here as generic approach because it has to necessarily make multiple assumptions about controller implementation.
Proposed draft approach does not really make much sense since it would be better to provide straight up psr request handler if controller has to extend psr aware abstract class. Psr decorator would be better but it would have to do a lot of brittle application specific wiring.