calgamo/http-kernel

This package is abandoned and no longer maintained. No replacement package was suggested.

Simple and generic library of HTTP request/response

0.3.3 2018-07-29 17:26 UTC

This package is not auto-updated.

Last update: 2018-07-29 17:27:11 UTC


README

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

Description

Calgamo/HttpKernel is a HTTP foundation library for Calgamo Framwwork.

Feature

Demo

Example 1: how to use middleware and pipeline

use Calgamo\HttpKernel\MiddlewareInterface;
use Calgamo\HttpKernel\RequestInterface;
use Calgamo\HttpKernel\RequestHandlerInterface;
use Calgamo\HttpKernel\Middleware\Pipeline;
use Calgamo\HttpKernel\Request;

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 Request);

Output:

ThirdMiddleware: 1
SecondMiddleware: 1
FirstMiddleware: 1
FirstMiddleware: 2
SecondMiddleware: 2
ThirdMiddleware: 2

Usage

Requirement

PHP 7.0 or later

Installing Calgamo/HttpKernel

The recommended way to install Calgamo/HttpKernel is through Composer.

composer require calgamo/http-kernel

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.