knot-lib / pipeline
Pipeline library for kNot Framework.
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 1 210
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.2
- knot-lib/kernel: ~0.8
- psr/container: ^1.0
- psr/log: ^1.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^8.5.15
This package is auto-updated.
Last update: 2023-09-06 12:44:58 UTC
README
Description
pipeline library for kNot Framework.
Feature
Demo
Example 1: how to use middleware and pipeline
use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use knotlib\kernel\Request\PhpArrayRequest; use knotlib\pipeline\pipeline; class FirstMiddleware implements MiddlewareInterface { public function process(ServerRequestInterface $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(ServerRequestInterface $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(ServerRequestInterface $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.2 or later
Installing knot-lib/pipeline
The recommended way to install knot-lib/pipeline is through Composer.
composer require knot-lib/pipeline
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.