PSR-7.5 Some more things to address

98 views
Skip to first unread message

Dracony

unread,
Apr 26, 2015, 7:00:18 PM4/26/15
to php...@googlegroups.com
So today I finally finished PHPixie HTTP lib with PSR-7 support and my biggest afterthough is that Cookies and Session also need standardizing. Here is what I mean:

Even though Requets/Response processing I pretty much done in one place ( Controller etc.) the need to modify cookies and especially session may arise in other parts of the application. These are also part of the HTTP processing and need to be addressed ina an interpolated fashion. Another big problem is that if you use a peristent HTTP server to process request you can no longer realy on $_SESSION at all without manually swapping session_id() for each request.

In my library I got around that like in this way:
1) There is a Context class that has 2 methods session() and cookies() which acts as a registry for a cookie and session handler
2) These Context instances are created for each individual request
3) Use can get and set the data using those two handlers
4) There is a method that "merges" data from the context to the actual response. E.g. buy specifying necessary Set-Cookie headers

After much thought I believe this the best way of handling 'persistant' data, since cookies and session represent users state the definitely fit as parts of seprate state-re[resenting context.
The interfaces to those would be fairy simple ( https://github.com/PHPixie/HTTP/tree/master/src/PHPixie/HTTP/Context ) and I think might be a good idea for a PSR.

So what I am ultimately proposing is a PSR that handles persistent HTTP state (cookies and session) so that with it the entirety of the HTTP use cases can be coverd in a reusable way. I don't think I need to prove that every framework out there has its own implementations for this, because obviouslt they do.

What do you think?
Reply all
Reply to author
Forward
0 new messages