laminas-mvc icon indicating copy to clipboard operation
laminas-mvc copied to clipboard

Implement and abstract controller that implement RequestHandlerInterface

Open ruslanbaidan opened this issue 2 years ago • 3 comments

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

ruslanbaidan avatar May 19 '22 14:05 ruslanbaidan

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

rieschl avatar May 19 '22 18:05 rieschl

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.

ruslanbaidan avatar May 20 '22 07:05 ruslanbaidan

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.

Xerkus avatar Mar 15 '23 14:03 Xerkus