calgamo/middleware

This package is abandoned and no longer maintained. The author suggests using the knot-lib/middleware package instead.

Middleware and pipeline library for Calgamo framework.

0.8.1 2019-12-03 09:55 UTC

This package is auto-updated.

Last update: 2019-12-09 11:02:00 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Code Climate Total Downloads

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

MIT

Author

stk2k

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.