polus / adr
base for my version of adr
Installs: 5 796
Dependents: 5
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.4.0
- payload-interop/payload-interop: ^1.0
- polus/middleware-dispatcher: ^2.0
- polus/router: ^2.0
- psr/event-dispatcher: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- circli/event-dispatcher: ^2.2.0
- nyholm/psr7: ^1.0
- phpunit/phpunit: ^8.0
- polus/relay-middleware-dispatcher: ^2.0
README
This is my implementation of ADR
Installation
The preferred method of installing this library is with Composer by running the following from your project root:
$ composer require polus/adr
You will also need to include an implementation of a router and a middleware-dispatcher
Currently available routers
Currently available middleware dispatchers
Old versions
See polus/polus-adr for version 1 and 2
Example
<?php use Aura\Payload_Interface\PayloadInterface;use Aura\Router\RouterContainer;use Http\Factory\Diactoros\ResponseFactory;use Http\Factory\Diactoros\ServerRequestFactory;use Polus\Adr\Actions\AbstractDomainAction;use Polus\Adr\Adr;use Polus\Adr\Interfaces\Resolver;use Polus\Adr\ResponseHandler\HttpResponseHandler;use Polus\Router\AuraRouter\RouterCollection;use Polus\Router\RouterMiddleware;use Psr\Http\Message\ResponseInterface;use Psr\Http\Message\ServerRequestInterface; $responseFactory = new \Http\Factory\Diactoros\ResponseFactory(); $routerContainer = new RouterContainer(); $routerCollection = new RouterCollection($routerContainer->getMap()); $routerDispatcher = new Polus\Router\AuraRouter\Dispatcher($routerContainer); $actionResolver = new class implements Resolver { //.. }; $adr = new Adr( new ResponseFactory(), $actionResolver, $routerCollection, new HttpResponseHandler(), new \Polus\MiddlewareDispatcher\Factory( new \Polus\MiddlewareDispatcher\Relay\Dispatcher($responseFactory), [ new RouterMiddleware($routerDispatcher), //More psr-15 middlewares ] ) ); //Define routes and actions class Responder implements Responder { public function __invoke( ServerRequestInterface $request, ResponseInterface $response, PayloadInterface $payload ): ResponseInterface { $response->getBody()->write("Index responder\n"); return $response; } } $adr->get('/', new class extends AbstractDomainAction { protected $responder = Responder::class; }); //Run application $factory = new ServerRequestFactory(); $adr->run($factory->createServerRequestFromArray($_SERVER));