diff --git a/.gitignore b/.gitignore index bcd11a3..d0888a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.phpunit.result.cache build composer.lock docs diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d26701..5e0a5d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to `Weasley` will be documented in this file. +## [0.6.5](https://github.com/rougin/weasley/compare/v0.6.4...v0.6.5) - Unreleased + +### Changed +- Conformed HTTP middlewares from `http-interop/http-middleware` to `rougin/slytherin`'s own middleware + +### Fixed +- Unit tests in running `SessionIntegration` + ## [0.6.4](https://github.com/rougin/weasley/compare/v0.6.3...v0.6.4) - 2023-11-16 ### Changed diff --git a/src/Console.php b/src/Console.php index 9d07394..8b587e0 100644 --- a/src/Console.php +++ b/src/Console.php @@ -12,7 +12,7 @@ */ class Console extends Application { - const VERSION = '0.6.4'; + const VERSION = '0.6.5'; /** * Instantiates the console application. diff --git a/src/Middleware/CrossOriginHeaders.php b/src/Middleware/CrossOriginHeaders.php index 911ed34..78517da 100644 --- a/src/Middleware/CrossOriginHeaders.php +++ b/src/Middleware/CrossOriginHeaders.php @@ -2,9 +2,9 @@ namespace Rougin\Weasley\Middleware; -use Interop\Http\ServerMiddleware\DelegateInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface; use Psr\Http\Message\ServerRequestInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; use Rougin\Slytherin\Http\Response; /** @@ -46,15 +46,15 @@ public function __construct(array $allowed = null, array $methods = null) * Process an incoming server request and return a response, optionally * delegating to the next middleware component to create the response. * - * @param \Psr\Http\Message\ServerRequestInterface $request - * @param \Interop\Http\ServerMiddleware\DelegateInterface $delegate + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Rougin\Slytherin\Middleware\HandlerInterface $handler * @return \Psr\Http\Message\ResponseInterface */ - public function process(ServerRequestInterface $request, DelegateInterface $delegate) + public function process(ServerRequestInterface $request, HandlerInterface $handler) { $options = $request->getMethod() === 'OPTIONS'; - $response = $options ? new Response : $delegate->process($request); + $response = $options ? new Response : $handler->handle($request); $response = $response->withHeader(self::ORIGIN, $this->allowed); diff --git a/src/Middleware/JsonHeaders.php b/src/Middleware/JsonHeaders.php index 8ea681b..e738a06 100644 --- a/src/Middleware/JsonHeaders.php +++ b/src/Middleware/JsonHeaders.php @@ -2,9 +2,9 @@ namespace Rougin\Weasley\Middleware; -use Interop\Http\ServerMiddleware\DelegateInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface; use Psr\Http\Message\ServerRequestInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; /** * JSON Headers Middleware @@ -18,13 +18,13 @@ class JsonHeaders implements MiddlewareInterface * Process an incoming server request and return a response, optionally * delegating to the next middleware component to create the response. * - * @param \Psr\Http\Message\ServerRequestInterface $request - * @param \Interop\Http\ServerMiddleware\DelegateInterface $delegate + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Rougin\Slytherin\Middleware\HandlerInterface $handler * @return \Psr\Http\Message\ResponseInterface */ - public function process(ServerRequestInterface $request, DelegateInterface $delegate) + public function process(ServerRequestInterface $request, HandlerInterface $handler) { - $response = $delegate->process($request); + $response = $handler->handle($request); $new = $response->withHeader('Content-Type', 'application/json'); diff --git a/src/Middleware/SpoofFormMethod.php b/src/Middleware/SpoofFormMethod.php index 61caf69..84c86ed 100644 --- a/src/Middleware/SpoofFormMethod.php +++ b/src/Middleware/SpoofFormMethod.php @@ -2,9 +2,9 @@ namespace Rougin\Weasley\Middleware; -use Interop\Http\ServerMiddleware\DelegateInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface; use Psr\Http\Message\ServerRequestInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; /** * Spoof Form Method Middleware @@ -33,11 +33,11 @@ public function __construct($key = null) * Process an incoming server request and return a response, optionally * delegating to the next middleware component to create the response. * - * @param \Psr\Http\Message\ServerRequestInterface $request - * @param \Interop\Http\ServerMiddleware\DelegateInterface $delegate + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Rougin\Slytherin\Middleware\HandlerInterface $handler * @return \Psr\Http\Message\ResponseInterface */ - public function process(ServerRequestInterface $request, DelegateInterface $delegate) + public function process(ServerRequestInterface $request, HandlerInterface $handler) { $parsed = $request->getParsedBody(); @@ -47,7 +47,7 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele $request = $request->withMethod($method); } - return $delegate->process($request); + return $handler->handle($request); } /** diff --git a/src/Middleware/TransformRequest.php b/src/Middleware/TransformRequest.php index d08ce06..7b311c7 100644 --- a/src/Middleware/TransformRequest.php +++ b/src/Middleware/TransformRequest.php @@ -2,9 +2,9 @@ namespace Rougin\Weasley\Middleware; -use Interop\Http\ServerMiddleware\DelegateInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface; use Psr\Http\Message\ServerRequestInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; /** * Transform Request Middleware @@ -18,11 +18,11 @@ class TransformRequest implements MiddlewareInterface * Process an incoming server request and return a response, optionally * delegating to the next middleware component to create the response. * - * @param \Psr\Http\Message\ServerRequestInterface $request - * @param \Interop\Http\ServerMiddleware\DelegateInterface $delegate + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Rougin\Slytherin\Middleware\HandlerInterface $handler * @return \Psr\Http\Message\ResponseInterface */ - public function process(ServerRequestInterface $request, DelegateInterface $delegate) + public function process(ServerRequestInterface $request, HandlerInterface $handler) { $get = $this->map($request->getQueryParams()); @@ -34,7 +34,7 @@ public function process(ServerRequestInterface $request, DelegateInterface $dele $post = $request->withParsedBody($post); - return $delegate->process($post); + return $handler->handle($post); } /** diff --git a/src/Session/SessionIntegration.php b/src/Session/SessionIntegration.php index 0e69beb..01c22e5 100644 --- a/src/Session/SessionIntegration.php +++ b/src/Session/SessionIntegration.php @@ -31,7 +31,7 @@ public function define(ContainerInterface $container, Configuration $config) { $name = $config->get('session.cookies', 'weasley_session'); - list($container, $handler) = $this->handler($container, $config); + $container->set(self::HANDLER, $handler = $this->handler($config)); if (! $cookie = $config->get("app.http.cookies.$name", null)) { @@ -50,27 +50,25 @@ public function define(ContainerInterface $container, Configuration $config) /** * Returns the specified SessionHandlerInterface. * - * @param \Rougin\Slytherin\Container\ContainerInterface $container - * @param \Rougin\Slytherin\Integration\Configuration $config + * @param \Rougin\Slytherin\Integration\Configuration $config * @return \SessionHandlerInterface */ - protected function handler(ContainerInterface $container, Configuration $config) + protected function handler(Configuration $config) { - $default = array('file' => 'Rougin\Weasley\Session\FileSessionHandler'); - - $handlers = $config->get('session.handlers', $default); + $items = array('file' => new FileSessionHandler); - $handler = $handlers[$config->get('session.driver', 'file')]; + $handlers = $config->get('session.handlers', $items); - $instance = $container->get($handler); + $driver = $config->get('session.driver', 'file'); - return array($container->set(self::HANDLER, $instance), $instance); + return $handlers[$driver]; } /** - * Generates a random string. * NOTE: Should be in a single function (or class). * + * Generates a random string. + * * @param integer $length * @return string */ diff --git a/src/Templates/Middleware.stub b/src/Templates/Middleware.stub index d05ddb8..2182711 100644 --- a/src/Templates/Middleware.stub +++ b/src/Templates/Middleware.stub @@ -2,9 +2,9 @@ namespace $NAMESPACE; -use Interop\Http\ServerMiddleware\DelegateInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface; use Psr\Http\Message\ServerRequestInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; /** * $CLASS @@ -18,14 +18,14 @@ class $CLASS implements MiddlewareInterface * Process an incoming server request and return a response, optionally * delegating to the next middleware component to create the response. * - * @param \Psr\Http\Message\ServerRequestInterface $request - * @param \Interop\Http\ServerMiddleware\DelegateInterface $delegate + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Rougin\Slytherin\Middleware\HandlerInterface $handler * @return \Psr\Http\Message\ResponseInterface */ - public function process(ServerRequestInterface $request, DelegateInterface $delegate) + public function process(ServerRequestInterface $request, HandlerInterface $handler) { // - return $delegate->process($request); + return $handler->handle($request); } } diff --git a/tests/Fixture/Middleware/CheckPatchMethod.php b/tests/Fixture/Middleware/CheckPatchMethod.php index c5185ae..c7e2717 100644 --- a/tests/Fixture/Middleware/CheckPatchMethod.php +++ b/tests/Fixture/Middleware/CheckPatchMethod.php @@ -2,9 +2,9 @@ namespace Rougin\Weasley\Fixture\Middleware; -use Interop\Http\ServerMiddleware\DelegateInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface; use Psr\Http\Message\ServerRequestInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; /** * "Check PATCH Method" Middleware @@ -18,13 +18,13 @@ class CheckPatchMethod implements MiddlewareInterface * Process an incoming server request and return a response, optionally * delegating to the next middleware component to create the response. * - * @param \Psr\Http\Message\ServerRequestInterface $request - * @param \Interop\Http\ServerMiddleware\DelegateInterface $delegate + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Rougin\Slytherin\Middleware\HandlerInterface $handler * @return \Psr\Http\Message\ResponseInterface */ - public function process(ServerRequestInterface $request, DelegateInterface $delegate) + public function process(ServerRequestInterface $request, HandlerInterface $handler) { - $response = $delegate->process($request); + $response = $handler->handle($request); if ($request->getMethod() === 'PATCH') { $key = 'Weasley-Has-PATCH-Method'; diff --git a/tests/Fixture/Middleware/CheckQueryParams.php b/tests/Fixture/Middleware/CheckQueryParams.php index 879c54b..15f448a 100644 --- a/tests/Fixture/Middleware/CheckQueryParams.php +++ b/tests/Fixture/Middleware/CheckQueryParams.php @@ -2,9 +2,9 @@ namespace Rougin\Weasley\Fixture\Middleware; -use Interop\Http\ServerMiddleware\DelegateInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface; use Psr\Http\Message\ServerRequestInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; /** * "Check $_GET Parameters" Middleware @@ -18,13 +18,13 @@ class CheckQueryParams implements MiddlewareInterface * Process an incoming server request and return a response, optionally * delegating to the next middleware component to create the response. * - * @param \Psr\Http\Message\ServerRequestInterface $request - * @param \Interop\Http\ServerMiddleware\DelegateInterface $delegate + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Rougin\Slytherin\Middleware\HandlerInterface $handler * @return \Psr\Http\Message\ResponseInterface */ - public function process(ServerRequestInterface $request, DelegateInterface $delegate) + public function process(ServerRequestInterface $request, HandlerInterface $handler) { - $response = $delegate->process($request); + $response = $handler->handle($request); $query = $request->getQueryParams(); diff --git a/tests/Fixture/Middleware/CheckTrimmedString.php b/tests/Fixture/Middleware/CheckTrimmedString.php index ca4ea34..9fc245a 100644 --- a/tests/Fixture/Middleware/CheckTrimmedString.php +++ b/tests/Fixture/Middleware/CheckTrimmedString.php @@ -2,9 +2,9 @@ namespace Rougin\Weasley\Fixture\Middleware; -use Interop\Http\ServerMiddleware\DelegateInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface; use Psr\Http\Message\ServerRequestInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; /** * "Check Trimmed String" Middleware @@ -18,13 +18,13 @@ class CheckTrimmedString implements MiddlewareInterface * Process an incoming server request and return a response, optionally * delegating to the next middleware component to create the response. * - * @param \Psr\Http\Message\ServerRequestInterface $request - * @param \Interop\Http\ServerMiddleware\DelegateInterface $delegate + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Rougin\Slytherin\Middleware\HandlerInterface $handler * @return \Psr\Http\Message\ResponseInterface */ - public function process(ServerRequestInterface $request, DelegateInterface $delegate) + public function process(ServerRequestInterface $request, HandlerInterface $handler) { - $response = $delegate->process($request); + $response = $handler->handle($request); $query = $request->getQueryParams(); diff --git a/tests/Fixture/Middleware/FinalDelegate.php b/tests/Fixture/Middleware/FinalDelegate.php index 10d035b..eb1db95 100644 --- a/tests/Fixture/Middleware/FinalDelegate.php +++ b/tests/Fixture/Middleware/FinalDelegate.php @@ -2,7 +2,7 @@ namespace Rougin\Weasley\Fixture\Middleware; -use Interop\Http\ServerMiddleware\DelegateInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -12,7 +12,7 @@ * @package Weasley * @author Rougin Gutib */ -class FinalDelegate implements DelegateInterface +class FinalDelegate implements HandlerInterface { /** * @var \Psr\Http\Message\ResponseInterface @@ -20,7 +20,7 @@ class FinalDelegate implements DelegateInterface protected $response; /** - * Initializes the delegate instance. + * Initializes the handler instance. * * @param \Psr\Http\Message\ResponseInterface $response */ @@ -35,7 +35,7 @@ public function __construct(ResponseInterface $response) * @param \Psr\Http\Message\ServerRequestInterface $request * @return \Psr\Http\Message\ResponseInterface */ - public function process(ServerRequestInterface $request) + public function handle(ServerRequestInterface $request) { return $this->response; } diff --git a/tests/Fixture/Middleware/ReturnQueryParams.php b/tests/Fixture/Middleware/ReturnQueryParams.php index ead2f9b..db193e6 100644 --- a/tests/Fixture/Middleware/ReturnQueryParams.php +++ b/tests/Fixture/Middleware/ReturnQueryParams.php @@ -2,9 +2,9 @@ namespace Rougin\Weasley\Fixture\Middleware; -use Interop\Http\ServerMiddleware\DelegateInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface; use Psr\Http\Message\ServerRequestInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; /** * "Return $_GET Parameters" Middleware @@ -18,13 +18,13 @@ class ReturnQueryParams implements MiddlewareInterface * Process an incoming server request and return a response, optionally * delegating to the next middleware component to create the response. * - * @param \Psr\Http\Message\ServerRequestInterface $request - * @param \Interop\Http\ServerMiddleware\DelegateInterface $delegate + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Rougin\Slytherin\Middleware\HandlerInterface $handler * @return \Psr\Http\Message\ResponseInterface */ - public function process(ServerRequestInterface $request, DelegateInterface $delegate) + public function process(ServerRequestInterface $request, HandlerInterface $handler) { - $response = $delegate->process($request); + $response = $handler->handle($request); $query = $request->getQueryParams(); diff --git a/tests/Fixture/Templates/TestMiddleware.php b/tests/Fixture/Templates/TestMiddleware.php index a5be7b7..e2e175d 100644 --- a/tests/Fixture/Templates/TestMiddleware.php +++ b/tests/Fixture/Templates/TestMiddleware.php @@ -2,9 +2,9 @@ namespace App\Http\Middleware; -use Interop\Http\ServerMiddleware\DelegateInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface; use Psr\Http\Message\ServerRequestInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; /** * TestMiddleware @@ -18,14 +18,14 @@ class TestMiddleware implements MiddlewareInterface * Process an incoming server request and return a response, optionally * delegating to the next middleware component to create the response. * - * @param \Psr\Http\Message\ServerRequestInterface $request - * @param \Interop\Http\ServerMiddleware\DelegateInterface $delegate + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Rougin\Slytherin\Middleware\HandlerInterface $handler * @return \Psr\Http\Message\ResponseInterface */ - public function process(ServerRequestInterface $request, DelegateInterface $delegate) + public function process(ServerRequestInterface $request, HandlerInterface $handler) { // - return $delegate->process($request); + return $handler->handle($request); } } diff --git a/tests/Middleware/AbstractTestCase.php b/tests/Middleware/AbstractTestCase.php index 7f5c01e..0d87235 100644 --- a/tests/Middleware/AbstractTestCase.php +++ b/tests/Middleware/AbstractTestCase.php @@ -23,9 +23,9 @@ abstract class AbstractTestCase extends \Rougin\Weasley\Testcase const RESPONSE = 'Psr\Http\Message\ResponseInterface'; /** - * @var \Interop\Http\ServerMiddleware\DelegateInterface + * @var \Rougin\Slytherin\Middleware\HandlerInterface */ - protected $delegate; + protected $handler; /** * @var \Rougin\Slytherin\Middleware\DispatcherInterface @@ -45,7 +45,7 @@ protected function doSetUp() $response = $container->get(self::RESPONSE); - $this->delegate = new FinalDelegate($response); + $this->handler = new FinalDelegate($response); $this->dispatcher = new Dispatcher; diff --git a/tests/Middleware/CrossOriginHeadersTest.php b/tests/Middleware/CrossOriginHeadersTest.php index 02701c7..550443c 100644 --- a/tests/Middleware/CrossOriginHeadersTest.php +++ b/tests/Middleware/CrossOriginHeadersTest.php @@ -21,7 +21,7 @@ public function testProcessMethod() { $dispatcher = $this->dispatcher->push(new Cors); - $response = $dispatcher->process($this->request, $this->delegate); + $response = $dispatcher->process($this->request, $this->handler); $header = 'Access-Control-Allow-Origin'; @@ -37,7 +37,7 @@ public function testProcessMethodWithAllowedMethods() { $dispatcher = $this->dispatcher->push(new Cors); - $response = $dispatcher->process($this->request, $this->delegate); + $response = $dispatcher->process($this->request, $this->handler); $expected = array('GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'); @@ -57,7 +57,7 @@ public function testProcessMethodWithAllowedOrigin() $dispatcher = $this->dispatcher->push(new Cors($expected)); - $response = $dispatcher->process($this->request, $this->delegate); + $response = $dispatcher->process($this->request, $this->handler); $result = $response->getHeader(Cors::ORIGIN); diff --git a/tests/Middleware/EmptyStringToNullTest.php b/tests/Middleware/EmptyStringToNullTest.php index 63e4e7f..9a122c0 100644 --- a/tests/Middleware/EmptyStringToNullTest.php +++ b/tests/Middleware/EmptyStringToNullTest.php @@ -27,7 +27,7 @@ public function testProcessMethod() $dispatcher = $this->dispatcher->push(new CheckQueryParams); - $response = $dispatcher->process($request, $this->delegate); + $response = $dispatcher->process($request, $this->handler); $expected = array('age' => null, 'address' => null); diff --git a/tests/Middleware/JsonHeadersTest.php b/tests/Middleware/JsonHeadersTest.php index a321b19..bfdcff5 100644 --- a/tests/Middleware/JsonHeadersTest.php +++ b/tests/Middleware/JsonHeadersTest.php @@ -21,7 +21,7 @@ public function testProcessMethod() { $dispatcher = $this->dispatcher->push(new Json); - $response = $dispatcher->process($this->request, $this->delegate); + $response = $dispatcher->process($this->request, $this->handler); $expected = array('application/json'); diff --git a/tests/Middleware/SpoofFormMethodTest.php b/tests/Middleware/SpoofFormMethodTest.php index 36ceabc..accedc7 100644 --- a/tests/Middleware/SpoofFormMethodTest.php +++ b/tests/Middleware/SpoofFormMethodTest.php @@ -27,7 +27,7 @@ public function testProcessMethod() $dispatcher = $this->dispatcher->push(new CheckPatchMethod); - $response = $dispatcher->process($request, $this->delegate); + $response = $dispatcher->process($request, $this->handler); $expected = array(true); diff --git a/tests/Middleware/TransformRequestTest.php b/tests/Middleware/TransformRequestTest.php index 5caca17..1a0f00b 100644 --- a/tests/Middleware/TransformRequestTest.php +++ b/tests/Middleware/TransformRequestTest.php @@ -27,7 +27,7 @@ public function testProcessMethod() $dispatcher = $this->dispatcher->push(new ReturnQueryParams); - $response = $dispatcher->process($request, $this->delegate); + $response = $dispatcher->process($request, $this->handler); $result = $response->getHeader('Query-Params'); diff --git a/tests/Middleware/TrimStringTest.php b/tests/Middleware/TrimStringTest.php index 4c5a9a6..878eb59 100644 --- a/tests/Middleware/TrimStringTest.php +++ b/tests/Middleware/TrimStringTest.php @@ -27,7 +27,7 @@ public function testProcessMethod() $dispatcher = $this->dispatcher->push(new CheckTrimmedString); - $response = $dispatcher->process($request, $this->delegate); + $response = $dispatcher->process($request, $this->handler); $expected = array('name' => 'Rougin', 'address' => 'Secret');