Comments (4)
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.
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.
Yeah, my plan is to remove the interface and the swoole class from this package
from http-emitter.
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)
- Close HTTP connections after emit HOT 4
- Multi-byte string assumption in SapiStreamEmitter::emitBodyRange() ? HOT 12
- Caching issue HOT 4
- Move SwooleEmitter out of this package HOT 2
- Removing EmitterInterface
- Don't stream the entire response into memory HOT 3
- Dependabot can't resolve your PHP dependency files
- upgraded min php version to 7.2 and added php 7.4 to travis
- upgrade narrowspark/coding-standard to v3 and phpunit/phpunit to v8
- add connection_status check on while list
- add test for headers_sent exception
- Update composer.json to make it work with PHP8 HOT 4
- SapiStreamEmitter that does not consider Content-Range HOT 4
- Dependency Dashboard HOT 1
- PHP Version 8.x compatibility HOT 2
- Stop PHP from overriding response header silently
- remove container-interop-implementation
- Add a comment when a headers already sent can happen
- Add a swoole emitter
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http-emitter.