poa/httprouter

基于POA洋葱圈模型的路由器中间件,通过实现路由规则来定制路由器具体的动作

0.1.0 2021-10-24 16:17 UTC

This package is auto-updated.

Last update: 2024-10-24 22:51:18 UTC


README

Latest Version on Packagist Software License Total Downloads

基于POA洋葱圈模型的路由器中间件,通过实现路由规则来定制路由器具体的动作

作者

安装

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

composer install poa/httprouter

示例

use Poa\Http\Router\CallableResult;
use Poa\Http\Router\Router;
use Poa\Http\Router\RouteResultInterface;
use Poa\Http\Router\RouteRulerInterface;
use Poa\Http\Server\HttpApplication;
use Poa\Http\Server\HttpContext;

class SimpleRuler implements RouteRulerInterface
{
    public function process(HttpContext $context): ?RouteResultInterface
    {
        if ($context->request->getMethod() === 'get') {
            return new CallableResult(function () {
                echo 'do something';
            });
        }
        return null;
    }
}

$router = new Router();
$router->addRuler(new SimpleRuler());

$app = new HttpApplication();
$app->use($router);

$app->handle(new HttpContext($request, $responst));

License

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