known icon indicating copy to clipboard operation
known copied to clipboard

Streamlined Request/Response Interface

Open ipranjal opened this issue 3 years ago • 5 comments

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

ipranjal avatar Dec 12 '21 09:12 ipranjal

Where was this implemented?

lindner avatar Jul 12 '22 18:07 lindner

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

ipranjal avatar Jul 12 '22 22:07 ipranjal

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

mediaformat avatar Feb 05 '24 17:02 mediaformat

@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

ipranjal avatar Feb 14 '24 05:02 ipranjal

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

mediaformat avatar Feb 15 '24 07:02 mediaformat