laminas / laminas-mvc

Laminas's event-driven MVC layer, including MVC Applications, Controllers, and Plugins
https://docs.laminas.dev/laminas-mvc/
BSD 3-Clause "New" or "Revised" License
139 stars 51 forks source link

Implement and abstract controller that implement RequestHandlerInterface #116

Open ruslanbaidan opened 2 years ago

ruslanbaidan commented 2 years ago

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

rieschl commented 2 years ago

Isn't this what laminas-mvc-middleware already does?

ruslanbaidan commented 2 years ago

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.

Xerkus commented 1 year ago

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.