From a7e6f750895f4831b2d7d6717af7cced31cc3bd6 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sun, 25 Feb 2018 10:47:39 -0600 Subject: [PATCH 1/9] Split the Radar.Adr repo, keep only middleware components. --- composer.json | 18 +- src/Adr.php | 140 --------- src/Boot.php | 107 ------- src/Config.php | 83 ------ src/Handler/ActionHandler.php | 4 +- src/Handler/RoutingHandler.php | 8 +- src/Input.php | 4 +- src/Resolver.php | 65 ----- src/Responder/Responder.php | 5 +- src/Responder/ResponderAcceptsInterface.php | 4 +- src/Responder/RoutingFailedResponder.php | 6 +- src/Route.php | 148 ---------- tests/AdrTest.php | 61 ---- tests/BootTest.php | 48 ---- tests/ConfigTest.php | 34 --- tests/Fake/Action/Input.php | 8 - tests/Fake/Action/Responder.php | 28 -- tests/Fake/FakeDomain.php | 16 -- tests/Fake/FakeMap.php | 17 -- tests/Fake/FakeMiddleware.php | 15 - tests/Fake/FakeRoutingFailedResponder.php | 13 - tests/Handler/ActionHandlerTest.php | 114 -------- tests/Handler/RoutingHandlerTest.php | 114 -------- tests/Responder/ResponderTest.php | 266 ------------------ .../Responder/RoutingFailedResponderTest.php | 92 ------ tests/_env | 1 - 26 files changed, 20 insertions(+), 1399 deletions(-) delete mode 100644 src/Adr.php delete mode 100644 src/Boot.php delete mode 100644 src/Config.php delete mode 100644 src/Resolver.php delete mode 100644 src/Route.php delete mode 100644 tests/AdrTest.php delete mode 100644 tests/BootTest.php delete mode 100644 tests/ConfigTest.php delete mode 100644 tests/Fake/Action/Input.php delete mode 100644 tests/Fake/Action/Responder.php delete mode 100644 tests/Fake/FakeDomain.php delete mode 100644 tests/Fake/FakeMap.php delete mode 100644 tests/Fake/FakeMiddleware.php delete mode 100644 tests/Fake/FakeRoutingFailedResponder.php delete mode 100644 tests/Handler/ActionHandlerTest.php delete mode 100644 tests/Handler/RoutingHandlerTest.php delete mode 100644 tests/Responder/ResponderTest.php delete mode 100644 tests/Responder/RoutingFailedResponderTest.php delete mode 100644 tests/_env diff --git a/composer.json b/composer.json index e9cca73..e58a375 100644 --- a/composer.json +++ b/composer.json @@ -1,29 +1,21 @@ { - "name": "radar/adr", + "name": "radar/middleware", "description": "The Action-Domain-Responder core library for Radar.", "type": "library", "homepage": "https://github.com/radarphp/Radar.Adr", "license": "MIT", "require": { - "aura/di": "~3.0", - "aura/payload": "~3.0", + "aura/payload-interface": "~3.0", "aura/router": "~3.0", - "relay/relay": "~1.0", - "relay/middleware": "~1.0", - "arbiter/arbiter": "~1.0" + "arbiter/arbiter": "~1.0", + "psr/http-message": "~1.0" }, "require-dev": { "zendframework/zend-diactoros": "~1.0" }, "autoload": { "psr-4": { - "Radar\\Adr\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "Radar\\Adr\\": "tests/", - "Aura\\Di\\": "vendor/aura/di/tests/" + "Radar\\Middleware\\": "src/" } } } diff --git a/src/Adr.php b/src/Adr.php deleted file mode 100644 index ecb935a..0000000 --- a/src/Adr.php +++ /dev/null @@ -1,140 +0,0 @@ -map = $map; - $this->rules = $rules; - $this->relayBuilder = $relayBuilder; - } - - /** - * - * Proxies method calls to the router map. - * - * @param string $method The Map method to call. - * - * @param array $params The params to pass to the method. - * - * @return mixed - * - */ - public function __call($method, array $params) - { - return call_user_func_array([$this->map, $method], $params); - } - - /** - * - * Returns the RuleIterator object. - * - * @return RuleIterator - * - */ - public function rules() - { - return $this->rules; - } - - /** - * - * Adds a middleware specification to the queue. - * - * @param mixed $spec The middleware specification. - * - */ - public function middle($spec) - { - $this->middle[] = $spec; - } - - /** - * - * Runs Radar using a Relay built with the middleware queue. - * - * @param Request $request The HTTP request object. - * - * @param Response $response The HTTP response object. - * - * @return Response - * - */ - public function run(Request $request, Response $response) - { - $relay = $this->relayBuilder->newInstance($this->middle); - return $relay($request, $response); - } -} diff --git a/src/Boot.php b/src/Boot.php deleted file mode 100644 index 0c9dadf..0000000 --- a/src/Boot.php +++ /dev/null @@ -1,107 +0,0 @@ -containerCache = $containerCache; - } - - /** - * - * Returns a new ADR instance using container configurations. - * - * @param array $config An array of container configuration class names - * and/or instances. - * - * @param bool $autoResolve Use the auto-resolving DI container? - * - * @return Adr - * - */ - public function adr(array $config = [], $autoResolve = false) - { - if ($this->containerCache) { - $di = $this->cachedContainer($config, $autoResolve); - } else { - $di = $this->newContainer($config, $autoResolve); - } - - return $di->get('radar/adr:adr'); - } - - /** - * - * Builds and returns a container using the container cache. - * - * @param array $config An array of container configuration class names - * and/or instances. - * - * @param bool $autoResolve Use the auto-resolving DI container? - * - * @return Container - * - */ - protected function cachedContainer(array $config, $autoResolve = false) - { - if (file_exists($this->containerCache)) { - return unserialize(file_get_contents($this->containerCache)); - } - - $di = $this->newContainer($config, $autoResolve); - file_put_contents($this->containerCache, serialize($di)); - return $di; - } - - /** - * - * Builds and returns a new, uncached container. - * - * @param array $config An array of container configuration class names - * and/or instances. - * - * @param bool $autoResolve Use the auto-resolving DI container? - * - * @return Container - * - */ - protected function newContainer(array $config, $autoResolve = false) - { - $config = array_merge(['Radar\Adr\Config'], $config); - return (new ContainerBuilder())->newConfiguredInstance($config, $autoResolve); - } -} diff --git a/src/Config.php b/src/Config.php deleted file mode 100644 index f58153d..0000000 --- a/src/Config.php +++ /dev/null @@ -1,83 +0,0 @@ -set('radar/adr:adr', $di->lazyNew('Radar\Adr\Adr')); - $di->set('radar/adr:resolver', $di->lazyNew('Radar\Adr\Resolver')); - $di->set('radar/adr:router', $di->lazyNew('Aura\Router\RouterContainer')); - - /** - * Aura\Router\Container - */ - $di->setters['Aura\Router\RouterContainer']['setRouteFactory'] = $di->newFactory('Radar\Adr\Route'); - - /** - * Relay\RelayBuilder - */ - $di->params['Relay\RelayBuilder']['resolver'] = $di->lazyGet('radar/adr:resolver'); - - /** - * Radar\Adr\Adr - */ - $di->params['Radar\Adr\Adr']['map'] = $di->lazyGetCall('radar/adr:router', 'getMap'); - $di->params['Radar\Adr\Adr']['rules'] = $di->lazyGetCall('radar/adr:router', 'getRuleIterator'); - $di->params['Radar\Adr\Adr']['relayBuilder'] = $di->lazyNew('Relay\RelayBuilder'); - - /** - * Radar\Adr\Handler\ActionHandler - */ - $di->params['Radar\Adr\Handler\ActionHandler']['resolver'] = $di->lazyGet('radar/adr:resolver'); - - /** - * Radar\Adr\Handler\RoutingHandler - */ - $di->params['Radar\Adr\Handler\RoutingHandler']['matcher'] = $di->lazyGetCall('radar/adr:router', 'getMatcher'); - $di->params['Radar\Adr\Handler\RoutingHandler']['actionFactory'] = $di->lazyNew('Arbiter\ActionFactory'); - - /** - * Radar\Adr\Resolver - */ - $di->params['Radar\Adr\Resolver']['injectionFactory'] = $di->getInjectionFactory(); - } - - /** - * - * Modifies constructed container objects. - * - * @param Container $di The DI container. - * - */ - public function modify(Container $di) - { - } -} diff --git a/src/Handler/ActionHandler.php b/src/Handler/ActionHandler.php index ba35262..3264232 100644 --- a/src/Handler/ActionHandler.php +++ b/src/Handler/ActionHandler.php @@ -6,7 +6,7 @@ * @license http://opensource.org/licenses/MIT MIT * */ -namespace Radar\Adr\Handler; +namespace Radar\Middleware\Handler; use Arbiter\ActionHandler as Arbiter; use Psr\Http\Message\ResponseInterface as Response; @@ -16,7 +16,7 @@ * * Dispatches to the Action stored in the `radar/adr:action` Request attribute. * - * @package radar/adr + * @package radar/middleware * */ class ActionHandler extends Arbiter diff --git a/src/Handler/RoutingHandler.php b/src/Handler/RoutingHandler.php index 4e0ee09..8cb1aa3 100644 --- a/src/Handler/RoutingHandler.php +++ b/src/Handler/RoutingHandler.php @@ -6,19 +6,19 @@ * @license http://opensource.org/licenses/MIT MIT * */ -namespace Radar\Adr\Handler; +namespace Radar\Middleware\Handler; use Arbiter\ActionFactory; use Aura\Router\Matcher; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -use Radar\Adr\Route; +use Radar\Framework\Route; /** * * Middleware to route (but not dispatch) the Request. * - * @package radar/adr + * @package radar/middleware * */ class RoutingHandler @@ -65,7 +65,7 @@ class RoutingHandler public function __construct( Matcher $matcher, ActionFactory $actionFactory, - $failResponder = 'Radar\Adr\Responder\RoutingFailedResponder' + $failResponder = 'Radar\Middleware\Responder\RoutingFailedResponder' ) { $this->matcher = $matcher; $this->actionFactory = $actionFactory; diff --git a/src/Input.php b/src/Input.php index e122d0c..4fa6499 100644 --- a/src/Input.php +++ b/src/Input.php @@ -6,7 +6,7 @@ * @license http://opensource.org/licenses/MIT MIT * */ -namespace Radar\Adr; +namespace Radar\Middleware; use Psr\Http\Message\ServerRequestInterface as Request; @@ -14,7 +14,7 @@ * * A generic input marshal. * - * @package radar/adr + * @package radar/middleware * */ class Input diff --git a/src/Resolver.php b/src/Resolver.php deleted file mode 100644 index 0281856..0000000 --- a/src/Resolver.php +++ /dev/null @@ -1,65 +0,0 @@ -injectionFactory = $injectionFactory; - } - - /** - * - * Resolves an object specification. - * - * @param mixed $spec The object specification. - * - * @return mixed - * - */ - public function __invoke($spec) - { - if (is_string($spec)) { - return $this->injectionFactory->newInstance($spec); - } - - if (is_array($spec) && is_string($spec[0])) { - $spec[0] = $this->injectionFactory->newInstance($spec[0]); - } - - return $spec; - } -} diff --git a/src/Responder/Responder.php b/src/Responder/Responder.php index 7e52a36..4054679 100644 --- a/src/Responder/Responder.php +++ b/src/Responder/Responder.php @@ -6,10 +6,9 @@ * @license http://opensource.org/licenses/MIT MIT * */ -namespace Radar\Adr\Responder; +namespace Radar\Middleware\Responder; use Aura\Payload_Interface\PayloadInterface; -use Aura\Payload\Payload; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ResponseInterface as Response; @@ -17,7 +16,7 @@ * * A generic Responder. * - * @package radar/adr + * @package radar/middleware * */ class Responder implements ResponderAcceptsInterface diff --git a/src/Responder/ResponderAcceptsInterface.php b/src/Responder/ResponderAcceptsInterface.php index 4b42e2d..404e2af 100644 --- a/src/Responder/ResponderAcceptsInterface.php +++ b/src/Responder/ResponderAcceptsInterface.php @@ -6,13 +6,13 @@ * @license http://opensource.org/licenses/MIT MIT * */ -namespace Radar\Adr\Responder; +namespace Radar\Middleware\Responder; /** * * Indicates that the Responder will examine the `Accepts` Request header. * - * @package radar/adr + * @package radar/middleware * */ interface ResponderAcceptsInterface diff --git a/src/Responder/RoutingFailedResponder.php b/src/Responder/RoutingFailedResponder.php index 483fc1f..3b2e48c 100644 --- a/src/Responder/RoutingFailedResponder.php +++ b/src/Responder/RoutingFailedResponder.php @@ -6,17 +6,17 @@ * @license http://opensource.org/licenses/MIT MIT * */ -namespace Radar\Adr\Responder; +namespace Radar\Middleware\Responder; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ResponseInterface as Response; -use Radar\Adr\Route; +use Radar\Framework\Route; /** * * A Responder for when there is no matching route. * - * @package radar/adr + * @package radar/middleware * */ class RoutingFailedResponder diff --git a/src/Route.php b/src/Route.php deleted file mode 100644 index 7ea5fca..0000000 --- a/src/Route.php +++ /dev/null @@ -1,148 +0,0 @@ -name . '\\Input'; - if (class_exists($input)) { - $this->input($input); - } - - $responder = $this->name . '\\Responder'; - if (class_exists($responder)) { - $this->responder($responder); - } - - return $this; - } - - /** - * - * Overrides `parent::handler()` to set the domain specification. - * - * @param string $handler The domain specification. - * - * @return self - * - */ - public function handler($handler) - { - $this->domain($handler); - return $this; - } - - /** - * - * Sets the input specification. - * - * @param string $input The input specification. - * - * @return self - * - */ - public function input($input) - { - $this->input = $input; - return $this; - } - - /** - * - * Sets the domain specification. - * - * @param string $handler The domain specification. - * - * @return self - * - */ - public function domain($domain) - { - $this->domain = $domain; - return $this; - } - - /** - * - * Sets the responder specification; if the responder is an instance of - * ResponderAcceptsInterface, also sets the `accepts()` on the route. - * - * @param string $responder The responder specification. - * - * @return self - * - */ - public function responder($responder) - { - $this->responder = $responder; - $this->accepts = []; - - $responderAcceptsInterface = is_subclass_of( - $responder, - 'Radar\Adr\Responder\ResponderAcceptsInterface', - true - ); - - if ($responderAcceptsInterface) { - $this->accepts($responder::accepts()); - } - - return $this; - } -} diff --git a/tests/AdrTest.php b/tests/AdrTest.php deleted file mode 100644 index e6f266b..0000000 --- a/tests/AdrTest.php +++ /dev/null @@ -1,61 +0,0 @@ -newInstance(); - $resolver = new Resolver($di->getInjectionFactory()); - - $this->fakeMap = new Fake\FakeMap(new Route()); - $this->fakeRules = new RuleIterator(); - $this->relayBuilder = new RelayBuilder($resolver); - - $this->adr = new Adr( - $this->fakeMap, - $this->fakeRules, - $this->relayBuilder - ); - } - - public function testRules() - { - $this->assertSame($this->adr->rules(), $this->fakeRules); - } - - public function testProxyToMap() - { - $expect = 'Radar\Adr\Fake\FakeMap::fakeMapMethod'; - $actual = $this->adr->fakeMapMethod(); - $this->assertSame($expect, $actual); - } - - public function testRun() - { - FakeMiddleware::$count = 0; - - $this->adr->middle('Radar\Adr\Fake\FakeMiddleware'); - $this->adr->middle('Radar\Adr\Fake\FakeMiddleware'); - $this->adr->middle('Radar\Adr\Fake\FakeMiddleware'); - - $response = $this->adr->run( - ServerRequestFactory::fromGlobals(), - new Response() - ); - - $actual = (string) $response->getBody(); - $this->assertSame('123456', $actual); - } -} diff --git a/tests/BootTest.php b/tests/BootTest.php deleted file mode 100644 index c12035b..0000000 --- a/tests/BootTest.php +++ /dev/null @@ -1,48 +0,0 @@ -containerCache = __DIR__ . DIRECTORY_SEPARATOR . 'container.serialized'; - if (file_exists($this->containerCache)) { - unlink($this->containerCache); - } - } - - protected function tearDown() - { - if (file_exists($this->containerCache)) { - unlink($this->containerCache); - } - } - - public function testUncached() - { - $this->assertFalse(file_exists($this->containerCache)); - $boot = new Boot(); - $adr = $boot->adr(); - $this->assertInstanceOf('Radar\Adr\Adr', $adr); - $this->assertFalse(file_exists($this->containerCache)); - } - - public function testCached() - { - $this->assertFalse(file_exists($this->containerCache)); - - // boot 'im! - $boot = new Boot($this->containerCache); - $adr = $boot->adr(); - $this->assertInstanceOf('Radar\Adr\Adr', $adr); - $this->assertTrue(file_exists($this->containerCache)); - - // boot 'im agin, paw! - $boot = new Boot($this->containerCache); - $adr = $boot->adr(); - $this->assertInstanceOf('Radar\Adr\Adr', $adr); - $this->assertTrue(file_exists($this->containerCache)); - } -} diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php deleted file mode 100644 index f934b22..0000000 --- a/tests/ConfigTest.php +++ /dev/null @@ -1,34 +0,0 @@ -getBody()->write($payload->getOutput()); - } else { - $response->getBody()->write('No payload.'); - } - return $response; - } -} diff --git a/tests/Fake/FakeDomain.php b/tests/Fake/FakeDomain.php deleted file mode 100644 index 07fe235..0000000 --- a/tests/Fake/FakeDomain.php +++ /dev/null @@ -1,16 +0,0 @@ -setStatus(PayloadStatus::FOUND) - ->setOutput(['domain' => 'value']); - } -} diff --git a/tests/Fake/FakeMap.php b/tests/Fake/FakeMap.php deleted file mode 100644 index 8d23dd4..0000000 --- a/tests/Fake/FakeMap.php +++ /dev/null @@ -1,17 +0,0 @@ -getBody()->write(++ static::$count); - $response = $next($request, $response); - $response->getBody()->write(++ static::$count); - return $response; - } -} diff --git a/tests/Fake/FakeRoutingFailedResponder.php b/tests/Fake/FakeRoutingFailedResponder.php deleted file mode 100644 index 8dd3548..0000000 --- a/tests/Fake/FakeRoutingFailedResponder.php +++ /dev/null @@ -1,13 +0,0 @@ -newInstance(); - $this->actionHandler = new ActionHandler( - new Resolver($di->getInjectionFactory()) - ); - } - - protected function assertResponse(Action $action, $expectStatus, $expectHeaders, $expectBody) - { - $request = ServerRequestFactory::fromGlobals(); - $request = $request->withAttribute('radar/adr:action', $action); - $response = $this->actionHandler->__invoke( - $request, - new Response(), - function ($request, $response) { return $response; } - ); - $this->assertEquals($expectStatus, $response->getStatusCode()); - $this->assertEquals($expectBody, $response->getBody()->__toString()); - $this->assertEquals($expectHeaders, $response->getHeaders()); - } - - public function testDomainClass() - { - $action = new Action( - null, - 'Radar\Adr\Fake\FakeDomain', - 'Radar\Adr\Responder\Responder' - ); - - $this->assertResponse( - $action, - 200, - [ - 'Content-Type' => [ - 'application/json', - ], - ], - '{"domain":"value"}' - ); - } - - public function testDomainArray() - { - $action = new Action( - null, - ['Radar\Adr\Fake\FakeDomain', '__invoke'], - 'Radar\Adr\Responder\Responder' - ); - - $this->assertResponse( - $action, - 200, - [ - 'Content-Type' => [ - 'application/json', - ], - ], - '{"domain":"value"}' - ); - } - - public function testDomainObject() - { - $action = new Action( - null, - new \Radar\Adr\Fake\FakeDomain(), - 'Radar\Adr\Responder\Responder' - ); - - $this->assertResponse( - $action, - 200, - [ - 'Content-Type' => [ - 'application/json', - ], - ], - '{"domain":"value"}' - ); - } - - public function testWithoutDomain() - { - $action = new Action( - null, - null, - 'Radar\Adr\Fake\Action\Responder' - ); - - $this->assertResponse( - $action, - 200, - [ - ], - 'No payload.' - ); - } -} diff --git a/tests/Handler/RoutingHandlerTest.php b/tests/Handler/RoutingHandlerTest.php deleted file mode 100644 index c9610d6..0000000 --- a/tests/Handler/RoutingHandlerTest.php +++ /dev/null @@ -1,114 +0,0 @@ -setMapFactory(function () { return new Map(new Route()); } ); - - $this->map = $actionr->getMap(); - $this->matcher = $actionr->getMatcher(); - $this->routingHandler = new RoutingHandler($this->matcher, new ActionFactory()); - } - - protected function newRequest($path) - { - $_SERVER['REQUEST_URI'] = $path; - return ServerRequestFactory::fromGlobals(); - } - - public function testFound() - { - $this->map->get('Radar\Adr\Fake\Action', '/fake/{id}', 'FakeDomain'); - $request = $this->newRequest('/fake/88'); - $response = new Response(); - $returnedResponse = $this->routingHandler->__invoke( - $request, - $response, - [$this, 'assertFound'] - ); - $this->assertSame($response, $returnedResponse); - } - - public function assertFound($request, $response) - { - $action = $request->getAttribute('radar/adr:action'); - $id = $request->getAttribute('id'); - $this->assertSame('88', $id); - return $response; - } - - public function testNotFound() - { - $this->map->get('Radar\Adr\Fake\Action', '/fake/{id}', 'FakeDomain'); - $request = $this->newRequest('/wrong/path'); - $response = new Response(); - $returnedResponse = $this->routingHandler->__invoke( - $request, - $response, - [$this, 'assertNotFound'] - ); - $this->assertSame($response, $returnedResponse); - } - - public function assertNotFound($request, $response) - { - $action = $request->getAttribute('radar/adr:action'); - $this->assertSame( - 'Radar\Adr\Responder\RoutingFailedResponder', - $action->getResponder() - ); - - $expect = $this->matcher->getFailedRoute(); - $actual = call_user_func($action->getDomain()); - $this->assertSame($expect, $actual); - - return $response; - } - - public function testCustomNotFound() - { - $routingHandler = new RoutingHandler( - $this->matcher, - new ActionFactory(), - 'Radar\Adr\Fake\FakeRoutingFailedResponder' - ); - - $this->map->get('Radar\Adr\Fake\Action', '/fake/{id}', 'FakeDomain'); - $request = $this->newRequest('/wrong/path'); - $response = new Response(); - $returnedResponse = $routingHandler->__invoke( - $request, - $response, - [$this, 'assertCustomNotFound'] - ); - } - - public function assertCustomNotFound($request, $response) - { - $action = $request->getAttribute('radar/adr:action'); - $this->assertSame( - 'Radar\Adr\Fake\FakeRoutingFailedResponder', - $action->getResponder() - ); - - $expect = $this->matcher->getFailedRoute(); - $actual = call_user_func($action->getDomain()); - $this->assertSame($expect, $actual); - - return $response; - } -} diff --git a/tests/Responder/ResponderTest.php b/tests/Responder/ResponderTest.php deleted file mode 100644 index 5250bd2..0000000 --- a/tests/Responder/ResponderTest.php +++ /dev/null @@ -1,266 +0,0 @@ -responder = new Responder(); - } - - public function testAccepts() - { - $expect = ['application/json']; - $actual = Responder::accepts(); - $this->assertSame($expect, $actual); - } - - protected function getResponse($payload) - { - $request = ServerRequestFactory::fromGlobals(); - $response = new Response(); - return $payload - ? $this->responder->__invoke($request, $response, $payload) - : $this->responder->__invoke($request, $response); - } - - protected function assertPayloadResponse($payload, $status, array $headers, $body) - { - $response = $this->getResponse($payload); - - $this->assertEquals($status, $response->getStatusCode()); - - foreach ($headers as $header => $expect) { - $this->assertEquals((array) $expect, $response->getHeader($header)); - } - - ob_start(); - echo $response->getBody(); - $actual = ob_get_clean(); - - $this->assertEquals($body, $actual); - } - - public function testAccepted() - { - $payload = (new Payload()) - ->setStatus(PayloadStatus::ACCEPTED) - ->setOutput(['foo' => 'bar']); - - $this->assertPayloadResponse( - $payload, - 202, - ['Content-Type' => 'application/json'], - '{"foo":"bar"}' - ); - } - - public function testCreated() - { - $payload = (new Payload()) - ->setStatus(PayloadStatus::CREATED) - ->setOutput(['foo' => 'bar']); - - $this->assertPayloadResponse( - $payload, - 201, - ['Content-Type' => 'application/json'], - '{"foo":"bar"}' - ); - } - - public function testDeleted() - { - $payload = (new Payload()) - ->setStatus(PayloadStatus::DELETED) - ->setOutput(['foo' => 'bar']); - - $this->assertPayloadResponse( - $payload, - 204, - ['Content-Type' => 'application/json'], - '{"foo":"bar"}' - ); - } - - public function testError() - { - $payload = (new Payload()) - ->setStatus(PayloadStatus::ERROR) - ->setInput(['foo' => 'bar']) - ->setOutput('96: wrong'); - - $this->assertPayloadResponse( - $payload, - 500, - ['Content-Type' => 'application/json'], - '{"input":{"foo":"bar"},"error":"96: wrong"}' - ); - } - - public function testFailure() - { - $payload = (new Payload()) - ->setStatus(PayloadStatus::FAILURE) - ->setInput(['foo' => 'bar']); - - $this->assertPayloadResponse( - $payload, - 400, - ['Content-Type' => 'application/json'], - '{"foo":"bar"}' - ); - } - - public function testFound() - { - $payload = (new Payload()) - ->setStatus(PayloadStatus::FOUND) - ->setOutput(['foo' => 'bar']); - - $this->assertPayloadResponse( - $payload, - 200, - ['Content-Type' => 'application/json'], - '{"foo":"bar"}' - ); - } - - public function testNoContent() - { - $this->assertPayloadResponse( - null, - 204, - [], - '' - ); - } - - public function testNotAuthenticated() - { - $payload = (new Payload()) - ->setStatus(PayloadStatus::NOT_AUTHENTICATED) - ->setInput(['foo' => 'bar']); - - $this->assertPayloadResponse( - $payload, - 401, - ['Content-Type' => 'application/json'], - '{"foo":"bar"}' - ); - } - - public function testNotAuthorized() - { - $payload = (new Payload()) - ->setStatus(PayloadStatus::NOT_AUTHORIZED) - ->setInput(['foo' => 'bar']); - - $this->assertPayloadResponse( - $payload, - 403, - ['Content-Type' => 'application/json'], - '{"foo":"bar"}' - ); - } - - public function testNotFound() - { - $payload = (new Payload()) - ->setStatus(PayloadStatus::NOT_FOUND) - ->setInput(['foo' => 'bar']); - - $this->assertPayloadResponse( - $payload, - 404, - ['Content-Type' => 'application/json'], - '{"foo":"bar"}' - ); - } - - public function testNotValid() - { - $payload = (new Payload()) - ->setStatus(PayloadStatus::NOT_VALID) - ->setInput(['foo' => 'bar']) - ->setOutput(['baz' => 'dib']) - ->setMessages(['zim' => 'gir']); - - $expect = json_encode([ - 'input' => ['foo' => 'bar'], - 'output' => ['baz' => 'dib'], - 'messages' => ['zim' => 'gir'], - ]); - - $this->assertPayloadResponse( - $payload, - 422, - ['Content-Type' => 'application/json'], - $expect - ); - } - - public function testProcessing() - { - $payload = (new Payload()) - ->setStatus(PayloadStatus::PROCESSING) - ->setOutput(['foo' => 'bar']); - - $this->assertPayloadResponse( - $payload, - 203, - ['Content-Type' => 'application/json'], - '{"foo":"bar"}' - ); - } - - public function testSuccess() - { - $payload = (new Payload()) - ->setStatus(PayloadStatus::SUCCESS) - ->setOutput(['foo' => 'bar']); - - $this->assertPayloadResponse( - $payload, - 200, - ['Content-Type' => 'application/json'], - '{"foo":"bar"}' - ); - } - - public function testUnknown() - { - $payload = (new Payload()) - ->setStatus('foobar') - ->setOutput(['foo' => 'bar']); - - $this->assertPayloadResponse( - $payload, - 500, - ['Content-Type' => 'application/json'], - '{"error":"Unknown domain payload status","status":"foobar"}' - ); - } - - public function testUpdated() - { - $payload = (new Payload()) - ->setStatus(PayloadStatus::UPDATED) - ->setOutput(['foo' => 'bar']); - - $this->assertPayloadResponse( - $payload, - 303, - ['Content-Type' => 'application/json'], - '{"foo":"bar"}' - ); - } -} diff --git a/tests/Responder/RoutingFailedResponderTest.php b/tests/Responder/RoutingFailedResponderTest.php deleted file mode 100644 index 56015ab..0000000 --- a/tests/Responder/RoutingFailedResponderTest.php +++ /dev/null @@ -1,92 +0,0 @@ -getResponse($failedRoute); - - $this->assertEquals($status, $response->getStatusCode()); - - foreach ($headers as $header => $expect) { - $this->assertEquals((array) $expect, $response->getHeader($header)); - } - - ob_start(); - echo $response->getBody(); - $actual = ob_get_clean(); - - $this->assertEquals($body, $actual); - } - - public function testMethodNotAllowed() - { - $failedRoute = (new Route()) - ->allows(['PUT', 'POST']) - ->failedRule('Aura\Router\Rule\Allows'); - - $this->assertResponse( - $failedRoute, - 405, - [ - 'Allow' => 'PUT, POST', - 'Content-Type' => 'application/json' - ], - '["PUT","POST"]' - ); - } - - public function testNotAcceptable() - { - $failedRoute = (new Route()) - ->accepts(['foo/bar', 'baz/dib']) - ->failedRule('Aura\Router\Rule\Accepts'); - - $this->assertResponse( - $failedRoute, - 406, - [], - '["foo\/bar","baz\/dib"]' - ); - } - - public function testNotFound() - { - $failedRoute = (new Route()) - ->failedRule('Aura\Router\Rule\Path'); - - $this->assertResponse( - $failedRoute, - 404, - [], - '404 Not Found' - ); - } - - public function testUnknown() - { - $failedRoute = (new Route()) - ->name('test') - ->failedRule('RandomRuleName'); - - $this->assertResponse( - $failedRoute, - 500, - [], - 'Route test failed rule RandomRuleName' - ); - } -} diff --git a/tests/_env b/tests/_env deleted file mode 100644 index 6ac867a..0000000 --- a/tests/_env +++ /dev/null @@ -1 +0,0 @@ -FOO=BAR From d3a07da90719d563c0a63ae22cdaae7ad174b924 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Tue, 27 Feb 2018 00:30:08 -0600 Subject: [PATCH 2/9] Convert RoutingHandler to PSR-15 middleware and decouple from Route subclass in Radar.Framework --- composer.json | 3 +- src/ActionSpecs.php | 110 +++++++++++++++++++++++++++++++++ src/Handler/RoutingHandler.php | 50 +++++++-------- 3 files changed, 137 insertions(+), 26 deletions(-) create mode 100644 src/ActionSpecs.php diff --git a/composer.json b/composer.json index e58a375..155be75 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,8 @@ "aura/payload-interface": "~3.0", "aura/router": "~3.0", "arbiter/arbiter": "~1.0", - "psr/http-message": "~1.0" + "psr/http-message": "~1.0", + "psr/http-server-middleware": "^1.0" }, "require-dev": { "zendframework/zend-diactoros": "~1.0" diff --git a/src/ActionSpecs.php b/src/ActionSpecs.php new file mode 100644 index 0000000..a86eb0b --- /dev/null +++ b/src/ActionSpecs.php @@ -0,0 +1,110 @@ +input($input); + } + + $this->domain($handler); + + $responder = $handler . '\\Responder'; + if (class_exists($responder)) { + $this->responder($responder); + } + } + + /** + * + * Sets the input specification. + * + * @param string $input The input specification. + * + * @return self + * + */ + protected function input($input): self + { + $this->input = $input; + return $this; + } + + /** + * + * Sets the domain specification. + * + * @param string $domain The domain specification. + * + * @return self + * + */ + protected function domain($domain): self + { + $this->domain = $domain; + return $this; + } + + /** + * + * Sets the responder specification. + * + * @param string $responder The responder specification. + * + * @return self + * + */ + protected function responder($responder): self + { + $this->responder = $responder; + return $this; + } +} diff --git a/src/Handler/RoutingHandler.php b/src/Handler/RoutingHandler.php index 8cb1aa3..3cd907d 100644 --- a/src/Handler/RoutingHandler.php +++ b/src/Handler/RoutingHandler.php @@ -9,10 +9,12 @@ namespace Radar\Middleware\Handler; use Arbiter\ActionFactory; -use Aura\Router\Matcher; +use Aura\Router\RouterContainer; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -use Radar\Framework\Route; +use Psr\Http\Server\MiddlewareInterface; +use Psr\Http\Server\RequestHandlerInterface; +use Radar\Middleware\ActionSpecs; /** * @@ -21,7 +23,7 @@ * @package radar/middleware * */ -class RoutingHandler +class RoutingHandler implements MiddlewareInterface { /** * @@ -43,31 +45,30 @@ class RoutingHandler /** * - * A route matcher. + * Routing container. * - * @var Matcher + * @var RouterContainer * */ - protected $matcher; + protected $router; /** * * Constructor. * - * @param Matcher $matcher A route matcher. + * @param RouterContainer $router * * @param ActionFactory $actionFactory An factory to create Action objects. * * @param string $failResponder The Responder class to use when there is no * matching route. - * */ public function __construct( - Matcher $matcher, + RouterContainer $router, ActionFactory $actionFactory, $failResponder = 'Radar\Middleware\Responder\RoutingFailedResponder' ) { - $this->matcher = $matcher; + $this->router = $router; $this->actionFactory = $actionFactory; $this->failResponder = $failResponder; } @@ -78,21 +79,17 @@ public function __construct( * * @param Request $request The HTTP request object. * - * @param Response $response The HTTP response object. - * - * @param callable $next The next middleware decorator. + * @param RequestHandlerInterface $handler The handler middleware decorator. * * @return Response - * */ - public function __invoke( - Request $request, - Response $response, - callable $next - ) { - $route = $this->matcher->match($request); + public function process(Request $request, RequestHandlerInterface $handler): Response + { + $matcher = $this->router->getMatcher(); + $route = $matcher->match($request); + $request = $this->addRouteToRequest($route, $request); - return $next($request, $response); + return $handler->handle($request); } /** @@ -106,8 +103,9 @@ public function __invoke( * @return Request with the Route and Action information. * */ - protected function addRouteToRequest($route, Request $request) + protected function addRouteToRequest($route, Request $request): Request { + if (! $route) { return $request ->withAttribute('radar/adr:route', false) @@ -125,14 +123,16 @@ protected function addRouteToRequest($route, Request $request) $request = $request->withAttribute($key, $val); } + $specs = new ActionSpecs($route->handler); + return $request ->withAttribute('radar/adr:route', $route) ->withAttribute( 'radar/adr:action', $this->actionFactory->newInstance( - $route->input, - $route->domain, - $route->responder + $specs->input, + $specs->domain, + $specs->responder ) ); } From 1cdd905e3d46271ee2e919992c1ba2e9b424c32b Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Tue, 27 Feb 2018 21:30:13 -0600 Subject: [PATCH 3/9] Convert ActionHandler to PSR-15 middleware and decouple from Aura.DI --- composer.json | 4 ++- src/Handler/ActionHandler.php | 29 ++++++++------- src/Resolver.php | 66 +++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 src/Resolver.php diff --git a/composer.json b/composer.json index 155be75..de42771 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,9 @@ "aura/router": "~3.0", "arbiter/arbiter": "~1.0", "psr/http-message": "~1.0", - "psr/http-server-middleware": "^1.0" + "psr/http-server-middleware": "^1.0", + "PHP-DI/invoker": "^2.0", + "psr/container": "^1.0" }, "require-dev": { "zendframework/zend-diactoros": "~1.0" diff --git a/src/Handler/ActionHandler.php b/src/Handler/ActionHandler.php index 3264232..8c809c8 100644 --- a/src/Handler/ActionHandler.php +++ b/src/Handler/ActionHandler.php @@ -9,8 +9,11 @@ namespace Radar\Middleware\Handler; use Arbiter\ActionHandler as Arbiter; -use Psr\Http\Message\ResponseInterface as Response; -use Psr\Http\Message\ServerRequestInterface as Request; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Server\MiddlewareInterface; +use Psr\Http\Server\RequestHandlerInterface; +use Zend\Diactoros\Response; /** * @@ -19,30 +22,26 @@ * @package radar/middleware * */ -class ActionHandler extends Arbiter +class ActionHandler extends Arbiter implements MiddlewareInterface { /** * * Dispatches to the Action stored in the `radar/adr:action` Request * attribute. * - * @param Request $request The HTTP request object. + * @param ServerRequestInterface $request The HTTP request object. * - * @param Response $response The HTTP response object. + * @param RequestHandlerInterface $handler The handler middleware decorator. * - * @param callable $next The next middleware decorator. - * - * @return Response + * @return ResponseInterface * + * @throws \InvalidArgumentException + * @throws \Arbiter\Exception */ - public function __invoke( - Request $request, - Response $response, - callable $next - ) { + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface + { $action = $request->getAttribute('radar/adr:action'); $request = $request->withoutAttribute('radar/adr:action'); - $response = $this->handle($action, $request, $response); - return $next($request, $response); + return $this->handle($action, $request, new Response()); } } diff --git a/src/Resolver.php b/src/Resolver.php new file mode 100644 index 0000000..1d627d8 --- /dev/null +++ b/src/Resolver.php @@ -0,0 +1,66 @@ +container = $container; + } + + /** + * + * Resolves an object specification. + * + * @param mixed $spec The object specification. + * + * @return mixed + * + * @throws \Invoker\Exception\InvocationException + * @throws \Invoker\Exception\NotCallableException + */ + public function __invoke($spec) + { + $invoker = new Invoker(null, $this->container); + + if (\is_string($spec)) { + return $invoker->getCallableResolver()->resolve($spec); + } + + if (\is_array($spec) && \is_string($spec[0])) { + $spec[0] = $invoker->getCallableResolver()->resolve($spec[0]); + } + + return $spec; + } +} From e81398edcd5d3a4f749ab03040600b436cf5c3f3 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Wed, 28 Feb 2018 06:53:45 -0600 Subject: [PATCH 4/9] Revert changing dependency from Matcher to RouterContainer. --- src/Handler/RoutingHandler.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Handler/RoutingHandler.php b/src/Handler/RoutingHandler.php index 3cd907d..dbb7a73 100644 --- a/src/Handler/RoutingHandler.php +++ b/src/Handler/RoutingHandler.php @@ -9,7 +9,7 @@ namespace Radar\Middleware\Handler; use Arbiter\ActionFactory; -use Aura\Router\RouterContainer; +use Aura\Router\Matcher; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Server\MiddlewareInterface; @@ -45,18 +45,18 @@ class RoutingHandler implements MiddlewareInterface /** * - * Routing container. + * A route matcher. * - * @var RouterContainer + * @var Matcher * */ - protected $router; + protected $matcher; /** * * Constructor. * - * @param RouterContainer $router + * @param Matcher $matcher * * @param ActionFactory $actionFactory An factory to create Action objects. * @@ -64,11 +64,11 @@ class RoutingHandler implements MiddlewareInterface * matching route. */ public function __construct( - RouterContainer $router, + Matcher $matcher, ActionFactory $actionFactory, $failResponder = 'Radar\Middleware\Responder\RoutingFailedResponder' ) { - $this->router = $router; + $this->matcher = $matcher; $this->actionFactory = $actionFactory; $this->failResponder = $failResponder; } @@ -85,8 +85,7 @@ public function __construct( */ public function process(Request $request, RequestHandlerInterface $handler): Response { - $matcher = $this->router->getMatcher(); - $route = $matcher->match($request); + $route = $this->matcher->match($request); $request = $this->addRouteToRequest($route, $request); return $handler->handle($request); From edb799b46cefadaab63b597aae2b85d82c6bf117 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Wed, 7 Mar 2018 08:54:21 -0600 Subject: [PATCH 5/9] Make ActionHandler compatible with generic routers. Like those found at https://github.com/middlewares/awesome-psr15-middlewares#router. This essentially converts this middleware package into an ADR-specific alternative to https://github.com/middlewares/request-handler. --- src/ActionSpecsFactory.php | 28 ++++ src/Handler/ActionHandler.php | 58 +++++++- src/Handler/RoutingHandler.php | 138 ------------------ src/Responder/Responder.php | 16 +- src/Responder/ResponderAcceptsInterface.php | 28 ---- src/Responder/RoutingFailedResponder.php | 153 -------------------- 6 files changed, 86 insertions(+), 335 deletions(-) create mode 100644 src/ActionSpecsFactory.php delete mode 100644 src/Handler/RoutingHandler.php delete mode 100644 src/Responder/ResponderAcceptsInterface.php delete mode 100644 src/Responder/RoutingFailedResponder.php diff --git a/src/ActionSpecsFactory.php b/src/ActionSpecsFactory.php new file mode 100644 index 0000000..c817ec1 --- /dev/null +++ b/src/ActionSpecsFactory.php @@ -0,0 +1,28 @@ +actionSpecsFactory = $actionSpecsFactory; + $this->actionFactory = $actionFactory; + } + + /** + * Set the attribute name to store handler reference. + * + * @param string $handlerAttribute + * @return ActionHandler + */ + public function handlerAttribute(string $handlerAttribute): self + { + $this->handlerAttribute = $handlerAttribute; + return $this; + } + /** * * Dispatches to the Action stored in the `radar/adr:action` Request @@ -40,8 +85,17 @@ class ActionHandler extends Arbiter implements MiddlewareInterface */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { - $action = $request->getAttribute('radar/adr:action'); - $request = $request->withoutAttribute('radar/adr:action'); + $requestHandler = $request->getAttribute($this->handlerAttribute); + $request = $request->withoutAttribute($this->handlerAttribute); + + $specs = $this->actionSpecsFactory->newInstance($requestHandler); + + $action = $this->actionFactory->newInstance( + $specs->input, + $specs->domain, + $specs->responder + ); + return $this->handle($action, $request, new Response()); } } diff --git a/src/Handler/RoutingHandler.php b/src/Handler/RoutingHandler.php deleted file mode 100644 index dbb7a73..0000000 --- a/src/Handler/RoutingHandler.php +++ /dev/null @@ -1,138 +0,0 @@ -matcher = $matcher; - $this->actionFactory = $actionFactory; - $this->failResponder = $failResponder; - } - - /** - * - * Adds the Action specification for the Route to the Request. - * - * @param Request $request The HTTP request object. - * - * @param RequestHandlerInterface $handler The handler middleware decorator. - * - * @return Response - */ - public function process(Request $request, RequestHandlerInterface $handler): Response - { - $route = $this->matcher->match($request); - - $request = $this->addRouteToRequest($route, $request); - return $handler->handle($request); - } - - /** - * - * Adds the Route and Action information to the Request. - * - * @param mixed $route The route matching the request (if any). - * - * @param Request $request The HTTP request object. - * - * @return Request with the Route and Action information. - * - */ - protected function addRouteToRequest($route, Request $request): Request - { - - if (! $route) { - return $request - ->withAttribute('radar/adr:route', false) - ->withAttribute( - 'radar/adr:action', - $this->actionFactory->newInstance( - null, - [$this->matcher, 'getFailedRoute'], - $this->failResponder - ) - ); - } - - foreach ($route->attributes as $key => $val) { - $request = $request->withAttribute($key, $val); - } - - $specs = new ActionSpecs($route->handler); - - return $request - ->withAttribute('radar/adr:route', $route) - ->withAttribute( - 'radar/adr:action', - $this->actionFactory->newInstance( - $specs->input, - $specs->domain, - $specs->responder - ) - ); - } -} diff --git a/src/Responder/Responder.php b/src/Responder/Responder.php index 4054679..bf708f9 100644 --- a/src/Responder/Responder.php +++ b/src/Responder/Responder.php @@ -9,8 +9,8 @@ namespace Radar\Middleware\Responder; use Aura\Payload_Interface\PayloadInterface; -use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ResponseInterface as Response; +use Psr\Http\Message\ServerRequestInterface as Request; /** * @@ -19,7 +19,7 @@ * @package radar/middleware * */ -class Responder implements ResponderAcceptsInterface +class Responder { /** * @@ -48,18 +48,6 @@ class Responder implements ResponderAcceptsInterface */ protected $response; - /** - * - * Returns the list of media types this Responder can generate. - * - * @return array - * - */ - public static function accepts() - { - return ['application/json']; - } - /** * * Builds and returns the Response using the Request and Payload. diff --git a/src/Responder/ResponderAcceptsInterface.php b/src/Responder/ResponderAcceptsInterface.php deleted file mode 100644 index 404e2af..0000000 --- a/src/Responder/ResponderAcceptsInterface.php +++ /dev/null @@ -1,28 +0,0 @@ -request = $request; - $this->response = $response; - $this->failedRoute = $failedRoute; - $method = $this->getMethodForFailedRoute(); - $this->$method(); - return $this->response; - } - - /** - * - * Returns the Responder method to call, based on the failed route. - * - * @return string - * - */ - protected function getMethodForFailedRoute() - { - switch ($this->failedRoute->failedRule) { - case 'Aura\Router\Rule\Allows': - return 'methodNotAllowed'; - case 'Aura\Router\Rule\Accepts': - return 'notAcceptable'; - case 'Aura\Router\Rule\Host': - case 'Aura\Router\Rule\Path': - return 'notFound'; - default: - return 'other'; - } - } - - /** - * - * Builds the Response when the failed route method was not allowed. - * - */ - protected function methodNotAllowed() - { - $this->response = $this->response - ->withStatus(405) - ->withHeader('Allow', implode(', ', $this->failedRoute->allows)) - ->withHeader('Content-Type', 'application/json'); - - $this->response->getBody()->write(json_encode($this->failedRoute->allows)); - } - - /** - * - * Builds the Response when the failed route could not accept the media type. - * - */ - protected function notAcceptable() - { - $this->response = $this->response - ->withStatus(406) - ->withHeader('Content-Type', 'application/json'); - - $this->response->getBody()->write(json_encode($this->failedRoute->accepts)); - } - - /** - * - * Builds the Response when the failed route host or path was not found. - * - */ - protected function notFound() - { - $this->response = $this->response->withStatus(404); - $this->response->getBody()->write('404 Not Found'); - } - - /** - * - * Builds the Response when routing failed for some other reason. - * - */ - protected function other() - { - $this->response = $this->response->withStatus(500); - - $message = "Route " . $this->failedRoute->name - . " failed rule " . $this->failedRoute->failedRule; - - $this->response->getBody()->write($message); - } -} From 646b762a91721158027699529a0d7e976406410a Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Wed, 7 Mar 2018 08:59:03 -0600 Subject: [PATCH 6/9] =?UTF-8?q?Flatten=20src=20directory=20structure=20sin?= =?UTF-8?q?ce=20we=E2=80=99re=20dealing=20with=20far=20fewer=20classes=20o?= =?UTF-8?q?verall.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{Handler => }/ActionHandler.php | 2 +- src/ActionSpecs.php | 2 +- src/{Responder => }/Responder.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/{Handler => }/ActionHandler.php (98%) rename src/{Responder => }/Responder.php (99%) diff --git a/src/Handler/ActionHandler.php b/src/ActionHandler.php similarity index 98% rename from src/Handler/ActionHandler.php rename to src/ActionHandler.php index 8ef7f6e..8b0f250 100644 --- a/src/Handler/ActionHandler.php +++ b/src/ActionHandler.php @@ -6,7 +6,7 @@ * @license http://opensource.org/licenses/MIT MIT * */ -namespace Radar\Middleware\Handler; +namespace Radar\Middleware; use Arbiter\ActionFactory; use Arbiter\ActionHandler as Arbiter; diff --git a/src/ActionSpecs.php b/src/ActionSpecs.php index a86eb0b..b0cc269 100644 --- a/src/ActionSpecs.php +++ b/src/ActionSpecs.php @@ -41,7 +41,7 @@ class ActionSpecs * @var string * */ - public $responder = 'Radar\Middleware\Responder\Responder'; + public $responder = 'Radar\Middleware\Responder'; /** * ActionSpecs constructor. diff --git a/src/Responder/Responder.php b/src/Responder.php similarity index 99% rename from src/Responder/Responder.php rename to src/Responder.php index bf708f9..9dd0729 100644 --- a/src/Responder/Responder.php +++ b/src/Responder.php @@ -6,7 +6,7 @@ * @license http://opensource.org/licenses/MIT MIT * */ -namespace Radar\Middleware\Responder; +namespace Radar\Middleware; use Aura\Payload_Interface\PayloadInterface; use Psr\Http\Message\ResponseInterface as Response; From 6ec447498ac9d20483cc919fb4b41f196b5babb3 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Wed, 7 Mar 2018 09:18:02 -0600 Subject: [PATCH 7/9] Remove un-used import. --- src/ActionHandler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ActionHandler.php b/src/ActionHandler.php index 8b0f250..8b2cbe5 100644 --- a/src/ActionHandler.php +++ b/src/ActionHandler.php @@ -14,7 +14,6 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -use Radar\Middleware\ActionSpecsFactory; use Zend\Diactoros\Response; /** From 1af5aa471331e0291edcc5233454104d39304528 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Wed, 7 Mar 2018 09:18:47 -0600 Subject: [PATCH 8/9] =?UTF-8?q?Remove=20aura/router=20since=20it=E2=80=99s?= =?UTF-8?q?=20no=20longer=20tied=20to=20the=20middleware.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index de42771..c28d260 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,6 @@ "license": "MIT", "require": { "aura/payload-interface": "~3.0", - "aura/router": "~3.0", "arbiter/arbiter": "~1.0", "psr/http-message": "~1.0", "psr/http-server-middleware": "^1.0", From faf838c8d5f26c3274d10cfbe920b3645e186c48 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Wed, 7 Mar 2018 10:34:06 -0600 Subject: [PATCH 9/9] Update composer package meta. --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c28d260..7f5daa7 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { "name": "radar/middleware", - "description": "The Action-Domain-Responder core library for Radar.", + "description": "A PSR-15 compatible Action-Domain-Responder route handler.", "type": "library", - "homepage": "https://github.com/radarphp/Radar.Adr", + "homepage": "https://github.com/radarphp/Radar.Middleware", "license": "MIT", "require": { "aura/payload-interface": "~3.0",