Download the PHP package fyre/middleware without Composer
On this page you can find all versions of the php package fyre/middleware. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package middleware
FyreMiddleware
FyreMiddleware is a free, open-source middleware library for PHP.
Table Of Contents
- Installation
- Basic Usage
- Methods
- Middleware Queues
- Middleware
- Request Handlers
Installation
Using Composer
In PHP:
Basic Usage
$container
is a Container.
It is recommended to bind the MiddlewareRegistry to the Container as a singleton.
Any dependencies will be injected automatically when loading from the Container.
Methods
Clear
Clear all aliases and middleware.
Map
Map an alias to middleware.
$alias
is a string representing the middleware alias.$middleware
is a string representing the Middleware class.$arguments
is an array containing additional arguments for creating the Middleware, and will default to [].
Resolve
Resolve Middleware.
$middleware
is a Middleware class instance, class name, alias or Closure.
You can pass additional arguments to the handle
method of the Middleware by appending a colon followed by a comma-separated list of arguments to the string.
Container.
Use
Load a shared Middleware instance.
$alias
is a string representing the middleware alias.
Container.
Middleware Queues
$middlewares
is an array containing the Middleware.
Add
Add Middleware.
$middleware
is a Closure.
Count
Get the Middleware count.
Current
Get the Middleware at the current index.
Insert At
Insert Middleware at a specified index.
$index
is a number representing the index.$middleware
is a Closure.
Key
Get the current index.
Next
Progress the index.
Prepend
Prepend Middleware.
$middleware
is a Closure.
Rewind
Reset the index.
Valid
Determine whether the current index is valid.
Middleware
Custom middleware can be created by extending \Fyre\Middleware\Middleware
, ensuring all below methods are implemented.
Handle
Handle a ServerRequest.
$request
is a ServerRequest.$next
is a Closure.
This method should call the $next
callback with the $request
, to handle the next middleware in the queue, then return the ClientResponse.
Closures
You can also provide custom middleware as a simple Closure.
Request Handlers
$container
is a Container.$middlewareRegistry
is a MiddlewareRegistry.$queue
is a MiddlewareQueue.$initialResponse
is a ClientResponse to be used as the initial response, and will default to null.
Any dependencies will be injected automatically when loading from the Container.
If the $initialResponse
is set to null, a new ClientResponse will be created.
Handle
Handle the next middleware in the queue.
$request
is a ServerRequest.
This method will return a ClientResponse.
The provided $request
will be automatically set as the ServerRequest instance in the Container.