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
Requires
- php: >=7.1.0
- psr/container: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- phpunit/phpunit: ^6.5
- zendframework/zend-diactoros: ^1.4
README
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
What Jugoya does
Jugoya create a new instance of RequestHandlerInterface from a instance of RequestHandlerInterface and instances of MiddlewareInterface.
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
Resolver
Wrapper
License
The MIT License (MIT). Please see LICENSE for more information.