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.
Jugoya create a new instance of RequestHandlerInterface from a instance of RequestHandlerInterface and instances of MiddlewareInterface.
// 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);
The MIT License (MIT). Please see LICENSE for more information.