Download the PHP package davidecesarano/embryo-middleware without Composer
On this page you can find all versions of the php package davidecesarano/embryo-middleware. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download davidecesarano/embryo-middleware
More information about davidecesarano/embryo-middleware
Files in davidecesarano/embryo-middleware
Package embryo-middleware
Short Description A PSR-15 middleware dispatcher.
License MIT
Homepage https://github.com/davidecesarano/embryo-middleware
Informations about the package embryo-middleware
Embryo Middleware
Simple dispatcher (PSR-15 server request handler) for a queue of PSR-15 middleware entries. Request handlers and middleware components are a fundamental part of any web application. Server side code receives a request message, processes it, and produces a response message. HTTP middleware is a way to move common request and response processing away from the application layer.
Requirements
- PHP >= 7.1
- A PSR-7 http message implementation and PSR-17 http factory implementation (ex. Embryo-Http)
Installation
Using Composer:
Usage
The RequestHandler is a container for a queue of PSR-15 middleware. It takes three methods:
- the method
addadd a middleware to the end of the queue. - the method
prependadd a middleware to the beginning of the queue. - the method
dispatchrequires two arguments, aServerRequestobject and aResponseobject (used by terminator to return an empty response).
Set ServerRequest and Response
Create ServerRequest and Response objects.
Add middleware
Create a queue of PSR-15 middleware with the add method or constructor.
The add (and prepend) method must be a string or a instance of MiddlewareInterface. In constructor you may create a queue with array of string or instance of MiddlewareInterface.
In this example we use two PSR-15 compatible middleware: Uuid Middleware and ResponseTime Middleware.
Result
The dispatch produces a response messages.
Example
You may quickly test this using the built-in PHP server going to http://localhost:8000.
All versions of embryo-middleware with dependencies
psr/http-server-handler Version 1.0.0
psr/http-server-middleware Version 1.0.0
davidecesarano/embryo-http Version dev-master