Welcome Guest, Not a member yet? Register   Sign In
Custom controller - request object empty in constructor
#13

(07-03-2022, 04:47 PM)kenjis Wrote: I think it is impossible.

If we will make it so, we need to change Request/Response to be mutable.
However, making them mutable is contrary to the PSR.
The significance of complying with the PSR will lost.

Therefore, I think that it is inevitable that some part will break.

I meant that PSR-7/15 is about working with messages, and services are about providing access to global objects. That is, changing the behavior of HTTP classes will not affect the provision of access to objects of these classes through services.

(07-03-2022, 04:47 PM)kenjis Wrote: Incoming Request object should be determined at the very early stage of the framework, and it should not be altered in the state,
It seems there is no problem that Services::request() returns the Request object.
Services::request() may be fine as it is now.
Changing the Request object state does not change the object returned by Service::request(), though.

But I don't know why you need it. Where do you use it?
In my opinion, the Request object is used only in Controllers or Controller Filters.

Any service can be dependent on Services::request().
Or, for example, you can validate data not only in the controller.

Laravel, Symfony - provide access to Request via CI/DI.
Yii - provide access to the Request through the global object.
CakePHP, despite being accessed via a property in the controller ($this->request), can also inject a Request via container dependencies.

My point is that accessing the Request object from anywhere in the application, not just in the controller, is normal practice.

(07-03-2022, 04:47 PM)kenjis Wrote: If we don't need service for Response class, it is a good news.
(I think we don't need it in App.)
The Response object is often changed in the state, so Services::response() seems to have more problems than Request.

The fact that the Response object retains its state is contrary to PSR-7 =)
Can you give an example where saving the state of the Response is critical for the application to work?
Reply


Messages In This Thread
RE: Custom controller - request object empty in constructor - by iRedds - 07-03-2022, 07:55 PM



Theme © iAndrew 2016 - Forum software by © MyBB