GithubHelp home page GithubHelp logo

Comments (4)

mindplay-dk avatar mindplay-dk commented on May 26, 2024

PSR-15 RequestHandlerInterface might be an obvious choice for a common interface for these "hosts" - if so, some middleware-stacks might even permit you to simply plug this in as the "final" handler after the middleware-stack.

from http-emitter.

mindplay-dk avatar mindplay-dk commented on May 26, 2024

PSR-15 RequestHandlerInterface might be an obvious choice for a common interface for these "hosts" - if so, some middleware-stacks might even permit you to simply plug this in as the "final" handler after the middleware-stack.

In hindsight, this sounds completely wrong to me now.

Having thought more about this, I don't think these "hosts" need to implement a common interface, at all. The only abstraction we need is already there - it's RequestHandlerInterface.

A SAPI host and a Swoole host don't have the same behavior, same use-cases or same life-cycle - nothing is won by making them implement the same interface, because that doesn't make them interchangeable in the first place.

For example, a SAPI host is used in an index.php and processes a single request, whereas a Swoole host is used from a CLI script and processes many request.

Any type of host can accept a RequestHandlerInterface instance via the constructor, which completely addresses the problem, since "request handlers", obviously, handle the requests, while creating the request, and emitting the response, are both completely implementation-specific to the hosts.

Emitters and request factories don't generalize at all.

Make sense?

from http-emitter.

prisis avatar prisis commented on May 26, 2024

Yeah, my plan is to remove the interface and the swoole class from this package

from http-emitter.

mindplay-dk avatar mindplay-dk commented on May 26, 2024

Is there any particular reason why we need two SAPI emitters to begin with?

I'm working on PSR-15/17 integration and I'd like to just refactor the whole thing to a single class - there's really no point in having more than one dependency for something that performs a single function.

So usage from index.php will look like this:

$host = new SAPIHost(
    $serverRequestFactory, // ServerRequestFactoryInterface
    $uriFactory,           // UriFactoryInterface
    $uploadedFileFactory,  // UploadedFileFactoryInterface
    $streamFactory,        // StreamFactoryInterface
    $responseFactory       // ReaponseFactoryInterface
);

$host->dispatch($handler); // where $handler is HandlerInterface (PSR-15)

There's really no point in even having an instance, since you will run this once from index.php and it will modify global state, but... I'll keep it as an instance, for the sake of testing at least, and since it will have dependencies on the PSR-17 factories.

(I will completely understand if this change is too drastic - if you don't want to merge this when it's done, I'll just fork the project, no problem. I'll let you take a look and decide first though...)

from http-emitter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.