n1215/jugoya

A simple HTTP application builder using PSR-15 HTTP Server Request Handler and Middleware.

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

This package is auto-updated.

Last update: 2024-04-11 19:27:22 UTC


README

Latest Stable Version License Build Status Code Coverage Scrutinizer Code Quality

A simple HTTP application builder using PSR-15 HTTP Server Request Handler and Middleware.

Jugoya is the Japanese full moon festival on the 15th day of the eighth month of the traditional Japanese calendar.

PSR-15 HTTP Server Handler and Middleware

psr15_middleware

See php-fig/fig-standards

What Jugoya does

Jugoya create a new instance of RequestHandlerInterface from a instance of RequestHandlerInterface and instances of MiddlewareInterface. composition

Code Example

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

Class diagrams

Jugoya

jugoya

Resolver

resolver

Wrapper

wrapper

License

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