poa/httpserver

基于POA洋葱圈模型的中间件,定义Http服务器的处理逻辑

0.1.1 2021-10-30 12:28 UTC

This package is auto-updated.

Last update: 2024-04-29 04:41:05 UTC


README

Latest Version on Packagist Software License Total Downloads

基于POA洋葱圈模型的中间件,定义Http服务器的处理逻辑

作者

安装

{
  "require": {
    "poa/httpserver": "~0.1"
  }
}
composer update

composer install poa/httpserver

示例

use Poa\Http\Router\Router;
use Poa\Http\Server\HandleExceptionMiddleware;
use Poa\Http\Server\HttpApplication;
use Poa\Http\Server\HttpContext;
use Poa\Http\Server\HttpServerInterface;
use Poa\Middleware\ElapsedTimeMiddleware;
use Poa\Middleware\MiddlewareSystemInterface;

class FpmHttpServer implements HttpServerInterface
{
    protected MiddlewareSystemInterface $application;

    public function start()
    {
        $context = new HttpContext(null, null);
        $app = $this->application;
        $app($context);
    }

    public function stop()
    {
        // do nothing
    }

    public function delegateRequest(MiddlewareSystemInterface $application)
    {
        $this->application = $application;
    }
}

$app = new HttpApplication();
$app->use(new HandleExceptionMiddleware())
    ->use(new ElapsedTimeMiddleware())
    ->use(new Router());

$server = new FpmHttpServer();
$server->delegateRequest($app);
$server->start();

License

The MIT License (MIT). Please see License File for more information.