n1215/

使用PSR-15 HTTP服务器请求处理器和中间件构建的简单HTTP应用程序。

v1.0.0 2018-02-21 10:03 UTC

This package is auto-updated.

Last update: 2024-09-11 20:16:56 UTC


README

Latest Stable Version License Build Status Code Coverage Scrutinizer Code Quality

使用PSR-15 HTTP服务器请求处理器和中间件构建的简单HTTP应用程序。

Jugoya是日本传统农历八月份十五日的满月节。

PSR-15 HTTP服务器处理器和中间件

psr15_middleware

php-fig/fig-standards

Jugoya的功能

Jugoya从RequestHandlerInterface的实例和MiddlewareInterface的实例中创建一个新的RequestHandlerInterface实例。composition

代码示例

// 1. register handler and middleware dependencies to the PSR-11 Container
/** @var \Psr\Container\ContainerInterface $container */
$container = new YourContainer();
//
// do stuff
//


// 2. create a builder
$builder = \N1215\Jugoya\RequestHandlerBuilder::fromContainer($container);

// LazyRequestHandlerBuilder resolves handler and middleware lazily.
// $builder = \N1215\Jugoya\LazyRequestHandlerBuilder::fromContainer($container);

// 3. build a request handler
/**
 * You can use one of
 *   * an instance of PSR-15 RequestHandlerInterface
 *   * a callable having the same signature with PSR-15 RequestHandlerInterface
 *   * a string identifier of a PSR-15 RequestHandlerInterface instance in the PSR-11 Container
 *
 * @var RequestHandlerInterface|callable|string $coreHandler
 *
 */
$coreHandler = new YourApplication();

/** @var RequestHandlerInterface $handler */
$handler = $builder->build($coreHandler, [

        // You can use instances of PSR-15 MiddlewareInterface
        new YourMiddleware(),

        // or callables having the same signature with PSR-15 MiddlewareInterface
        function(ServerRequestInterface $request, RequestHandlerInterface $handler) {
            // do stuff
            $response = $handler->handle($request);
            // do stuff
            return $response;
        },

        // or string identifiers of PSR-15 MiddlewareInterface instances in the PSR-11 Container
        YourMiddleware::class,
    ]);


// 4. handle a PSR-7 Sever Request
/** @var Psr\Http\Message\ServerRequestInterface $request */
$request = \Zend\Diactoros\ServerRequestBuilder::fromGlobals();
/** @var \Psr\Http\Message\ResponseInterface $response */
$response = $handler->handle($request);

类图

Jugoya

jugoya

解析器

resolver

包装器

wrapper

许可协议

MIT许可(MIT)。有关更多信息,请参阅LICENSE