Download the PHP package yiisoft/middleware-dispatcher without Composer
On this page you can find all versions of the php package yiisoft/middleware-dispatcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yiisoft/middleware-dispatcher
More information about yiisoft/middleware-dispatcher
Files in yiisoft/middleware-dispatcher
Package middleware-dispatcher
Short Description PSR-15 middleware dispatcher
License BSD-3-Clause
Homepage https://www.yiiframework.com/
Informations about the package middleware-dispatcher
Yii Middleware Dispatcher
The package is a PSR-15 middleware dispatcher. Given a set of middleware and a request instance, dispatcher executes it and produces a response instance.
Requirements
- PHP 8.1 or higher.
Installation
The package could be installed with Composer:
General usage
To use a dispatcher, you need to create it first:
In the above $diContainer
is an instance of PSR-11 \Psr\Container\ContainerInterface
and $eventDispatcher
is an instance of PSR-14 Psr\EventDispatcher\EventDispatcherInterface
.
After dispatcher instance obtained, it should be fed with some middleware:
In the above we have used a callback. Overall the following options are available:
- A controller handler action in format
[TestController::class, 'index']
.TestController
instance will be created andindex()
method will be executed. - A name of PSR-15 middleware class. The middleware instance will be obtained from container.
- A name of PSR-15 request handler class. The request handler instance will be obtained from container and executed.
- A name or instance of invokable class. If the name of invokable class is provided, the instance will be obtained from container and executed.
-
A function returning a middleware such as
The middleware returned will be executed.
- A callback
function(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
. - An array definition (see syntax) of middleware:
For handler action and callable typed parameters are automatically injected using dependency injection container.
Current request and handler could be obtained by type-hinting for ServerRequestInterface
and RequestHandlerInterface
.
After middleware set is defined, you can do the dispatching:
Given a request dispatcher executes middleware in the set and produces response. First specified middleware will be
executed first. For each middleware
\Yiisoft\Middleware\Dispatcher\Event\BeforeMiddleware
and \Yiisoft\Middleware\Dispatcher\Event\AfterMiddleware
events are triggered.
Creating your own implementation of parameters resolver
Parameters resolver could be customized by providing your own ParametersResolverInterface
implementation:
Then it could be used like the following:
To combine several parameters' resolvers use CompositeParametersResolver
:
Documentation
- Internals
If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.
License
The Yii Middleware Dispatcher is free software. It is released under the terms of the BSD License.
Please see LICENSE
for more information.
Maintained by Yii Software.
Support the project
Follow updates
All versions of middleware-dispatcher with dependencies
psr/container Version ^1.0|^2.0
psr/event-dispatcher Version ^1.0
psr/http-message Version ^1.0|^2.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0
yiisoft/definitions Version ^2.0|^3.0
yiisoft/friendly-exception Version ^1.1
yiisoft/injector Version ^1.0