calgamo / middleware
Middleware and pipeline library for Calgamo framework.
Installs: 3 683
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
- calgamo/kernel: ~0.41
- psr/container: ^1.0
- psr/log: ^1.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^6.3.0
README
Description
Middleware and pipeline library for Calgamo framework.
Feature
Demo
Example 1: how to use middleware and pipeline
use Calgamo\Kernel\MiddlewareInterface; use Calgamo\Kernel\RequestInterface; use Calgamo\Kernel\RequestHandlerInterface; use Calgamo\Kernel\Request\PhpArrayRequest; use Calgamo\Middleware\Pipeline\Pipeline; class FirstMiddleware implements MiddlewareInterface { public function process(RequestInterface $request, RequestHandlerInterface $handler) { echo 'FirstMiddleware: 1' . PHP_EOL; $response = $handler->handle($request); echo 'FirstMiddleware: 2' . PHP_EOL; return $response; } } class SecondMiddleware implements MiddlewareInterface { public function process(RequestInterface $request, RequestHandlerInterface $handler) { echo 'SecondMiddleware: 1' . PHP_EOL; $response = $handler->handle($request); echo 'SecondMiddleware: 2' . PHP_EOL; return $response; } } class ThirdMiddleware implements MiddlewareInterface { public function process(RequestInterface $request, RequestHandlerInterface $handler) { echo 'ThirdMiddleware: 1' . PHP_EOL; $response = $handler->handle($request); echo 'ThirdMiddleware: 2' . PHP_EOL; return $response; } } $pipeline = new Pipeline(); $pipeline->push(new FirstMiddleware()); $pipeline->push(new SecondMiddleware()); $pipeline->push(new ThirdMiddleware()); $pipeline->run(new PhpArrayRequest);
Output:
ThirdMiddleware: 1 SecondMiddleware: 1 FirstMiddleware: 1 FirstMiddleware: 2 SecondMiddleware: 2 ThirdMiddleware: 2
Usage
Requirement
PHP 7.1 or later
Installing calgamo/middleware
The recommended way to install calgamo/middleware is through Composer.
composer require calgamo/middleware
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
License
Author
Disclaimer
This software is no warranty.
We are not responsible for any results caused by the use of this software.
Please use the responsibility of the your self.