idno / known

A social publishing platform.
https://withknown.com/opensource
Other
1.05k stars 195 forks source link

Streamlined Request/Response Interface #3029

Open ipranjal opened 2 years ago

ipranjal commented 2 years ago

What ?

We should probably start using something like https://symfony.com/components/HttpFoundation or PSR 7 implementation like https://github.com/Nyholm/psr7 to work with Request,Response and session and stop using superglobals like $_SERVER , $_REQUEST, $_SESSION etc.

Why ?

While current implementation works good for a apache server it completely kills opportunity for known(idno) to run on faster runtimes like Swoole, Roadrunner or ReactPHP based faster runtime environments

How ?

1) Create a Request and Response objects from one of the methods given above 2) Modify Toro to get data from Request object rather than directly accessing super globals 3) Create a handle() method probably inside Idno/Core/Idno which takes in Request as parameter and returns the Response object after running the whole known flow 4) Create &Request() &Response() method to get instance of current request and response object 5) handle() method can internally call PageHandler::serve() and other method known utilises

Other Benefits

using echo,echo,echo is never a good idea , if we have a streamlined Response object, before it is served to the user those response can be used by plugin developers to optimize , cache or slightly change the response to suit there needs. Opens up a whole new world of possibility for plugin developers . Also on a side note developing middleware would be possible to tweak Request and Response during the lifecycle of known application

lindner commented 2 years ago

Where was this implemented?

ipranjal commented 2 years ago

I probably closed it by mistake thinking it to be old stale issue I raised 😅, I was working on a POC , been long will revisit it probably this week

mediaformat commented 7 months ago

A quick evaluation of the effort, to start using http-foundation Requests for use with landrok/activitypub.

$_SERVER: 122 results across 42 files $_SESSION: 38 results across 6 files $_REQUEST: 19 results across 3 files $_FILES: 26 results across 6 files $_SESSION: 38 results across 6 files

I think replacing the echos with a http-foundation Response across the whole project, however would be out of scope for #3186

ipranjal commented 7 months ago

@mediaformat i am intrested in co-working for sprint 3 to implement request response interface , let me know if you have started , we should work on this in a seprate branch

mediaformat commented 7 months ago

I had already started on this, I'll try to publish my WIP branch tomorrow