From 13d14d2a2fece66630c34ed407cdae7729285cf3 Mon Sep 17 00:00:00 2001 From: Rougin Gutib Date: Tue, 5 Dec 2023 11:41:50 +0800 Subject: [PATCH] Move "Server" back to "Middleware" --- phpstan.neon | 4 +- src/Component/Collection.php | 14 +- src/{Server => Middleware}/Callback.php | 6 +- src/Middleware/Delegate.php | 2 - src/Middleware/Dispatcher.php | 142 ++++++++++++++++- src/Middleware/DispatcherInterface.php | 20 ++- src/{Server => Middleware}/Doublepass.php | 2 +- src/{Server => Middleware}/Handler.php | 12 +- src/Middleware/HandlerInterface.php | 9 +- .../Handlers/Handler030.php | 8 +- .../Handlers/Handler041.php | 8 +- .../Handlers/Handler050.php | 8 +- .../Handlers/Handler100.php | 10 +- src/{Server => Middleware}/Interop.php | 38 +++-- src/Middleware/MiddlewareIntegration.php | 3 +- src/Middleware/MiddlewareInterface.php | 13 +- src/Middleware/StratigilityDispatcher.php | 15 +- src/{Server => Middleware}/Version.php | 2 +- src/{Server => Middleware}/Wrapper.php | 6 +- src/Server/Dispatch.php | 146 ------------------ src/Server/DispatchInterface.php | 27 ---- src/Server/HandlerInterface.php | 18 --- src/Server/MiddlewareInterface.php | 19 --- src/System.php | 4 +- src/System/Endofline.php | 2 +- src/System/Handler.php | 2 +- tests/Application/AurynContainerTest.php | 8 +- tests/Application/ContainerInterfaceTest.php | 4 +- .../Middlewares/BodyParametersMiddleware.php | 4 +- tests/Fixture/Middlewares/CorsMiddleware.php | 4 +- tests/Fixture/Middlewares/EmptyMiddleware.php | 4 +- tests/Middleware/DispatcherTestCases.php | 20 ++- tests/Sample/Handlers/Cors.php | 4 +- tests/Sample/Handlers/Parsed/Request.php | 4 +- tests/Sample/Handlers/Parsed/Response.php | 4 +- tests/Sample/Handlers/ToJson.php | 4 +- tests/Sample/SampleTest.php | 6 + 37 files changed, 291 insertions(+), 315 deletions(-) rename src/{Server => Middleware}/Callback.php (91%) rename src/{Server => Middleware}/Doublepass.php (96%) rename src/{Server => Middleware}/Handler.php (78%) rename src/{Server => Middleware}/Handlers/Handler030.php (80%) rename src/{Server => Middleware}/Handlers/Handler041.php (80%) rename src/{Server => Middleware}/Handlers/Handler050.php (80%) rename src/{Server => Middleware}/Handlers/Handler100.php (81%) rename src/{Server => Middleware}/Interop.php (73%) rename src/{Server => Middleware}/Version.php (96%) rename src/{Server => Middleware}/Wrapper.php (84%) delete mode 100644 src/Server/Dispatch.php delete mode 100644 src/Server/DispatchInterface.php delete mode 100644 src/Server/HandlerInterface.php delete mode 100644 src/Server/MiddlewareInterface.php diff --git a/phpstan.neon b/phpstan.neon index b7d24fcc..bc1bfd76 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,5 +4,5 @@ parameters: - src excludePaths: analyse: - - src/Server/Handlers - - src/Server/Interop.php \ No newline at end of file + - src/Middleware/Handlers + - src/Middleware/Interop.php \ No newline at end of file diff --git a/src/Component/Collection.php b/src/Component/Collection.php index 41418b6b..00f72a69 100644 --- a/src/Component/Collection.php +++ b/src/Component/Collection.php @@ -7,8 +7,8 @@ use Psr\Http\Message\ServerRequestInterface; use Rougin\Slytherin\Container\VanillaContainer; use Rougin\Slytherin\Debug\ErrorHandlerInterface; -use Rougin\Slytherin\Routing\DispatcherInterface as RouteDispatcher; -use Rougin\Slytherin\Server\DispatchInterface as MiddlewareDispatcher; +use Rougin\Slytherin\Middleware\DispatcherInterface as Middleware; +use Rougin\Slytherin\Routing\DispatcherInterface as Routing; use Rougin\Slytherin\System; /** @@ -67,7 +67,7 @@ public function getDispatcher() * @param \Rougin\Slytherin\Routing\DispatcherInterface $dispatcher * @return self */ - public function setDispatcher(RouteDispatcher $dispatcher) + public function setDispatcher(Routing $dispatcher) { $this->set(System::DISPATCHER, $dispatcher); @@ -206,13 +206,13 @@ public function setHttpResponse(ResponseInterface $response) * * Gets the middleware. * - * @return \Rougin\Slytherin\Server\DispatchInterface|null + * @return \Rougin\Slytherin\Middleware\DispatcherInterface|null */ public function getMiddleware() { if (! $this->has(System::MIDDLEWARE)) return null; - /** @var \Rougin\Slytherin\Server\DispatchInterface */ + /** @var \Rougin\Slytherin\Middleware\DispatcherInterface */ return $this->get(System::MIDDLEWARE); } @@ -221,10 +221,10 @@ public function getMiddleware() * * Sets the middleware. * - * @param \Rougin\Slytherin\Server\DispatchInterface $middleware + * @param \Rougin\Slytherin\Middleware\DispatcherInterface $middleware * @return self */ - public function setMiddleware(MiddlewareDispatcher $middleware) + public function setMiddleware(Middleware $middleware) { $this->set(System::MIDDLEWARE, $middleware); diff --git a/src/Server/Callback.php b/src/Middleware/Callback.php similarity index 91% rename from src/Server/Callback.php rename to src/Middleware/Callback.php index 0b2fcf0b..d0e3587b 100644 --- a/src/Server/Callback.php +++ b/src/Middleware/Callback.php @@ -1,6 +1,6 @@ - * @author Rasmus Schultz */ -class Dispatcher extends Dispatch +class Dispatcher implements DispatcherInterface { + /** + * @var \Rougin\Slytherin\Middleware\MiddlewareInterface[] + */ + protected $stack = array(); + + /** + * @var \Psr\Http\Message\ResponseInterface|null + */ + protected $response = null; + + /** + * @param mixed[] $stack + */ + public function __construct($stack = array()) + { + if ($stack) $this->setStack($stack); + } + + /** + * @return \Rougin\Slytherin\Middleware\MiddlewareInterface[] + */ + public function getStack() + { + return $this->stack; + } + + /** + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Rougin\Slytherin\Middleware\HandlerInterface $handler + * @return \Psr\Http\Message\ResponseInterface + */ + public function process(ServerRequestInterface $request, HandlerInterface $handler) + { + $stack = (array) $this->getStack(); + + $handler = new Handler($stack, $handler); + + return $handler->handle($request); + } + + /** + * @param mixed $middleware + * @return self + */ + public function push($middleware) + { + if (! is_array($middleware)) + { + $item = $this->transform($middleware); + + array_push($this->stack, $item); + + return $this; + } + + foreach ($middleware as $item) $this->push($item); + + return $this; + } + + /** + * @param mixed[] $stack + * @return self + */ + public function setStack($stack) + { + $result = array(); + + foreach ($stack as $item) + { + $result[] = $this->transform($item); + } + + $this->stack = $result; + + return $this; + } + + /** + * NOTE: To be removed in v1.0.0. Use $this->getStack() instead. + * + * @return \Rougin\Slytherin\Middleware\MiddlewareInterface[] + */ + public function stack() + { + return $this->getStack(); + } + + /** + * @param mixed $middleware + * @return \Rougin\Slytherin\Middleware\MiddlewareInterface + */ + protected function transform($middleware) + { + if ($middleware instanceof MiddlewareInterface) + { + return $middleware; + } + + // Set empty response for double pass middlewares --- + if (! $this->response) + { + $this->response = new Response; + } + // -------------------------------------------------- + + if ($this->isCallable($middleware)) + { + /** @var callable $middleware */ + return new Callback($middleware, $this->response); + } + + return new Wrapper($middleware); + } + + /** + * @param mixed $item + * @return boolean + */ + protected function isCallable($item) + { + /** @var object|string $item */ + $method = method_exists($item, '__invoke'); + + $callable = is_callable($item); + + $object = is_object($item); + + $closure = (! $object) || $item instanceof \Closure; + + return ($method || $callable) && $closure; + } } diff --git a/src/Middleware/DispatcherInterface.php b/src/Middleware/DispatcherInterface.php index 4e02633d..5f46435a 100644 --- a/src/Middleware/DispatcherInterface.php +++ b/src/Middleware/DispatcherInterface.php @@ -2,8 +2,6 @@ namespace Rougin\Slytherin\Middleware; -use Rougin\Slytherin\Server\DispatchInterface; - /** * Dispatcher Interface * @@ -12,6 +10,22 @@ * @package Slytherin * @author Rougin Gutib */ -interface DispatcherInterface extends DispatchInterface +interface DispatcherInterface extends MiddlewareInterface { + /** + * @return \Rougin\Slytherin\Middleware\MiddlewareInterface[] + */ + public function getStack(); + + /** + * @param mixed $middleware + * @return self + */ + public function push($middleware); + + /** + * @param mixed[] $stack + * @return self + */ + public function setStack($stack); } diff --git a/src/Server/Doublepass.php b/src/Middleware/Doublepass.php similarity index 96% rename from src/Server/Doublepass.php rename to src/Middleware/Doublepass.php index 90da5ef0..3da8d6b3 100644 --- a/src/Server/Doublepass.php +++ b/src/Middleware/Doublepass.php @@ -1,6 +1,6 @@ */ -interface HandlerInterface extends Slytherin +interface HandlerInterface { + /** + * @param \Psr\Http\Message\ServerRequestInterface $request + * @return \Psr\Http\Message\ResponseInterface + */ + public function handle(ServerRequestInterface $request); } diff --git a/src/Server/Handlers/Handler030.php b/src/Middleware/Handlers/Handler030.php similarity index 80% rename from src/Server/Handlers/Handler030.php rename to src/Middleware/Handlers/Handler030.php index ed669943..693dc8ad 100644 --- a/src/Server/Handlers/Handler030.php +++ b/src/Middleware/Handlers/Handler030.php @@ -1,11 +1,11 @@ */ $stack = $config->get('app.middlewares', array()); - $dispatch = new Dispatch($stack); + $dispatch = new Dispatcher($stack); $empty = $this->preferred === null; diff --git a/src/Middleware/MiddlewareInterface.php b/src/Middleware/MiddlewareInterface.php index ccd33170..aa27c5e3 100644 --- a/src/Middleware/MiddlewareInterface.php +++ b/src/Middleware/MiddlewareInterface.php @@ -2,17 +2,22 @@ namespace Rougin\Slytherin\Middleware; -use Interop\Http\ServerMiddleware\MiddlewareInterface as InteropMiddlewareInterface; +use Psr\Http\Message\ServerRequestInterface; /** * Middleware Interface * - * An interface for handling third party middlewares. - * NOTE: To be removed in v1.0.0. Use DispatcherInterface instead. + * An interface for handling middlewares to Slytherin. * * @package Slytherin * @author Rougin Gutib */ -interface MiddlewareInterface extends InteropMiddlewareInterface +interface MiddlewareInterface { + /** + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Rougin\Slytherin\Middleware\HandlerInterface $handler + * @return \Psr\Http\Message\ResponseInterface + */ + public function process(ServerRequestInterface $request, HandlerInterface $handler); } diff --git a/src/Middleware/StratigilityDispatcher.php b/src/Middleware/StratigilityDispatcher.php index 7ec7b306..8b555b16 100644 --- a/src/Middleware/StratigilityDispatcher.php +++ b/src/Middleware/StratigilityDispatcher.php @@ -5,10 +5,10 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Rougin\Slytherin\Http\Response; -use Rougin\Slytherin\Server\Doublepass; -use Rougin\Slytherin\Server\HandlerInterface; -use Rougin\Slytherin\Server\Interop; -use Rougin\Slytherin\Server\MiddlewareInterface; +use Rougin\Slytherin\Middleware\Doublepass; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\Interop; +use Rougin\Slytherin\Middleware\MiddlewareInterface; use Zend\Stratigility\MiddlewarePipe; /** @@ -55,8 +55,8 @@ public function hasPsr() } /** - * @param \Psr\Http\Message\ServerRequestInterface $request - * @param \Rougin\Slytherin\Server\HandlerInterface $handler + * @param \Psr\Http\Message\ServerRequestInterface $request + * @param \Rougin\Slytherin\Middleware\HandlerInterface $handler * @return \Psr\Http\Message\ResponseInterface */ public function process(ServerRequestInterface $request, HandlerInterface $handler) @@ -74,7 +74,6 @@ public function process(ServerRequestInterface $request, HandlerInterface $handl $item = $this->setPsrMiddleware($item); } - /** @phpstan-ignore-next-line */ $this->zend->pipe($item); } @@ -119,7 +118,7 @@ protected function setFactory(ResponseInterface $response) } /** - * @param \Rougin\Slytherin\Server\MiddlewareInterface $item + * @param \Rougin\Slytherin\Middleware\MiddlewareInterface $item * @return callable */ protected function setMiddleware(MiddlewareInterface $item) diff --git a/src/Server/Version.php b/src/Middleware/Version.php similarity index 96% rename from src/Server/Version.php rename to src/Middleware/Version.php index f220e1d8..5775f4d8 100644 --- a/src/Server/Version.php +++ b/src/Middleware/Version.php @@ -1,6 +1,6 @@ - */ -class Dispatch implements DispatchInterface -{ - /** - * @var \Rougin\Slytherin\Server\MiddlewareInterface[] - */ - protected $stack = array(); - - /** - * @var \Psr\Http\Message\ResponseInterface|null - */ - protected $response = null; - - /** - * @param mixed[] $stack - */ - public function __construct($stack = array()) - { - if ($stack) $this->setStack($stack); - } - - /** - * @return \Rougin\Slytherin\Server\MiddlewareInterface[] - */ - public function getStack() - { - return $this->stack; - } - - /** - * @param \Psr\Http\Message\ServerRequestInterface $request - * @param \Rougin\Slytherin\Server\HandlerInterface $handler - * @return \Psr\Http\Message\ResponseInterface - */ - public function process(ServerRequestInterface $request, HandlerInterface $handler) - { - $stack = (array) $this->getStack(); - - $handler = new Handler($stack, $handler); - - return $handler->handle($request); - } - - /** - * @param mixed $middleware - * @return self - */ - public function push($middleware) - { - if (! is_array($middleware)) - { - $item = $this->transform($middleware); - - array_push($this->stack, $item); - - return $this; - } - - foreach ($middleware as $item) $this->push($item); - - return $this; - } - - /** - * @param mixed[] $stack - * @return self - */ - public function setStack($stack) - { - $result = array(); - - foreach ($stack as $item) - { - $result[] = $this->transform($item); - } - - $this->stack = $result; - - return $this; - } - - /** - * NOTE: To be removed in v1.0.0. Use $this->getStack() instead. - * - * @return \Rougin\Slytherin\Server\MiddlewareInterface[] - */ - public function stack() - { - return $this->getStack(); - } - - /** - * @param mixed $middleware - * @return \Rougin\Slytherin\Server\MiddlewareInterface - */ - protected function transform($middleware) - { - if ($middleware instanceof MiddlewareInterface) - { - return $middleware; - } - - // Set empty response for double pass middlewares --- - if (! $this->response) - { - $this->response = new Response; - } - // -------------------------------------------------- - - if ($this->isCallable($middleware)) - { - /** @var callable $middleware */ - return new Callback($middleware, $this->response); - } - - return new Wrapper($middleware); - } - - /** - * @param mixed $item - * @return boolean - */ - protected function isCallable($item) - { - /** @var object|string $item */ - $method = method_exists($item, '__invoke'); - - $callable = is_callable($item); - - $object = is_object($item); - - $closure = (! $object) || $item instanceof \Closure; - - return ($method || $callable) && $closure; - } -} diff --git a/src/Server/DispatchInterface.php b/src/Server/DispatchInterface.php deleted file mode 100644 index 355ff883..00000000 --- a/src/Server/DispatchInterface.php +++ /dev/null @@ -1,27 +0,0 @@ - - */ -interface DispatchInterface extends MiddlewareInterface -{ - /** - * @return \Rougin\Slytherin\Server\MiddlewareInterface[] - */ - public function getStack(); - - /** - * @param mixed $middleware - * @return self - */ - public function push($middleware); - - /** - * @param mixed[] $stack - * @return self - */ - public function setStack($stack); -} diff --git a/src/Server/HandlerInterface.php b/src/Server/HandlerInterface.php deleted file mode 100644 index 32f2c6fc..00000000 --- a/src/Server/HandlerInterface.php +++ /dev/null @@ -1,18 +0,0 @@ - - */ -interface HandlerInterface -{ - /** - * @param \Psr\Http\Message\ServerRequestInterface $request - * @return \Psr\Http\Message\ResponseInterface - */ - public function handle(ServerRequestInterface $request); -} diff --git a/src/Server/MiddlewareInterface.php b/src/Server/MiddlewareInterface.php deleted file mode 100644 index f2d92417..00000000 --- a/src/Server/MiddlewareInterface.php +++ /dev/null @@ -1,19 +0,0 @@ - - */ -interface MiddlewareInterface -{ - /** - * @param \Psr\Http\Message\ServerRequestInterface $request - * @param \Rougin\Slytherin\Server\HandlerInterface $handler - * @return \Psr\Http\Message\ResponseInterface - */ - public function process(ServerRequestInterface $request, HandlerInterface $handler); -} diff --git a/src/System.php b/src/System.php index 9037bdbc..19da2a5a 100644 --- a/src/System.php +++ b/src/System.php @@ -16,7 +16,7 @@ class System const ERREPORT = 'Rougin\Slytherin\Ereport\EreportInterface'; - const MIDDLEWARE = 'Rougin\Slytherin\Server\DispatchInterface'; + const MIDDLEWARE = 'Rougin\Slytherin\Middleware\DispatcherInterface'; const RENDERER = 'Rougin\Slytherin\Template\RendererInterface'; @@ -101,7 +101,7 @@ public function handle(ServerRequestInterface $request) return $handler->handle($request); } - /** @var \Rougin\Slytherin\Server\DispatchInterface */ + /** @var \Rougin\Slytherin\Middleware\DispatcherInterface */ $middleware = $this->container->get(self::MIDDLEWARE); $stack = $middleware->getStack(); diff --git a/src/System/Endofline.php b/src/System/Endofline.php index 2ed1efea..7af3de8e 100644 --- a/src/System/Endofline.php +++ b/src/System/Endofline.php @@ -4,7 +4,7 @@ use Psr\Http\Message\ServerRequestInterface; use Rougin\Slytherin\Http\Response; -use Rougin\Slytherin\Server\HandlerInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; /** * @package Slytherin diff --git a/src/System/Handler.php b/src/System/Handler.php index bb14276c..903dcea3 100644 --- a/src/System/Handler.php +++ b/src/System/Handler.php @@ -5,8 +5,8 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Rougin\Slytherin\Container\ContainerInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; use Rougin\Slytherin\Routing\RouteInterface; -use Rougin\Slytherin\Server\HandlerInterface; use Rougin\Slytherin\System; /** diff --git a/tests/Application/AurynContainerTest.php b/tests/Application/AurynContainerTest.php index d89d2e74..cb044657 100644 --- a/tests/Application/AurynContainerTest.php +++ b/tests/Application/AurynContainerTest.php @@ -4,8 +4,8 @@ use Rougin\Slytherin\Container\AurynContainer; use Rougin\Slytherin\Http\Response; +use Rougin\Slytherin\Middleware\Dispatcher as Middleware; use Rougin\Slytherin\Routing\Dispatcher; -use Rougin\Slytherin\Server\Dispatch; use Rougin\Slytherin\System; /** @@ -38,10 +38,8 @@ protected function doSetUp() $container->share(new Dispatcher($router)); $container->alias(System::DISPATCHER, 'Rougin\Slytherin\Routing\Dispatcher'); - // TODO: Reimplement "Server" with "Middleware" -------------------------- - $container->share(new Dispatch); - $container->alias(System::MIDDLEWARE, 'Rougin\Slytherin\Server\Dispatch'); - // ----------------------------------------------------------------------- + $container->share(new Middleware); + $container->alias(System::MIDDLEWARE, 'Rougin\Slytherin\Middleware\Dispatcher'); $this->application = new Application($container); } diff --git a/tests/Application/ContainerInterfaceTest.php b/tests/Application/ContainerInterfaceTest.php index bfe23381..496fdc9d 100644 --- a/tests/Application/ContainerInterfaceTest.php +++ b/tests/Application/ContainerInterfaceTest.php @@ -5,8 +5,8 @@ use Rougin\Slytherin\Application; use Rougin\Slytherin\Container\Container; use Rougin\Slytherin\Http\Response; +use Rougin\Slytherin\Middleware\Dispatcher as Middleware; use Rougin\Slytherin\Routing\Dispatcher; -use Rougin\Slytherin\Server\Dispatch; use Rougin\Slytherin\System; /** @@ -35,7 +35,7 @@ protected function doSetUp() $response = new Response; $container->set(System::RESPONSE, $response); - $dispatch = new Dispatch; + $dispatch = new Middleware; $container->set(System::MIDDLEWARE, $dispatch); $this->application = new Application($container); diff --git a/tests/Fixture/Middlewares/BodyParametersMiddleware.php b/tests/Fixture/Middlewares/BodyParametersMiddleware.php index 2ea6a73d..35281a6c 100644 --- a/tests/Fixture/Middlewares/BodyParametersMiddleware.php +++ b/tests/Fixture/Middlewares/BodyParametersMiddleware.php @@ -3,8 +3,8 @@ namespace Rougin\Slytherin\Fixture\Middlewares; use Psr\Http\Message\ServerRequestInterface; -use Rougin\Slytherin\Server\HandlerInterface; -use Rougin\Slytherin\Server\MiddlewareInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; /** * @package Slytherin diff --git a/tests/Fixture/Middlewares/CorsMiddleware.php b/tests/Fixture/Middlewares/CorsMiddleware.php index ce4caf92..dbd1c157 100644 --- a/tests/Fixture/Middlewares/CorsMiddleware.php +++ b/tests/Fixture/Middlewares/CorsMiddleware.php @@ -4,8 +4,8 @@ use Psr\Http\Message\ServerRequestInterface; use Rougin\Slytherin\Http\Response; -use Rougin\Slytherin\Server\HandlerInterface; -use Rougin\Slytherin\Server\MiddlewareInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; /** * @package Slytherin diff --git a/tests/Fixture/Middlewares/EmptyMiddleware.php b/tests/Fixture/Middlewares/EmptyMiddleware.php index d8a7d580..4a9b34d0 100644 --- a/tests/Fixture/Middlewares/EmptyMiddleware.php +++ b/tests/Fixture/Middlewares/EmptyMiddleware.php @@ -4,8 +4,8 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Rougin\Slytherin\Server\HandlerInterface; -use Rougin\Slytherin\Server\MiddlewareInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; /** * @package Slytherin diff --git a/tests/Middleware/DispatcherTestCases.php b/tests/Middleware/DispatcherTestCases.php index 93c5655e..f6232552 100644 --- a/tests/Middleware/DispatcherTestCases.php +++ b/tests/Middleware/DispatcherTestCases.php @@ -3,7 +3,8 @@ namespace Rougin\Slytherin\Middleware; use Rougin\Slytherin\Http\ServerRequest; -use Rougin\Slytherin\Server\Wrapper; +use Rougin\Slytherin\Middleware\Interop; +use Rougin\Slytherin\Middleware\Wrapper; use Rougin\Slytherin\System\Endofline; use Rougin\Slytherin\Testcase; @@ -16,7 +17,7 @@ class DispatcherTestCases extends Testcase { /** - * @var \Rougin\Slytherin\Server\Dispatch + * @var \Rougin\Slytherin\Middleware\Dispatch */ protected $dispatcher; @@ -124,6 +125,11 @@ public function testProcessMethodWithDelagateInterfaceCallback() */ public function testProcessMethodWithString() { + if (! Interop::exists()) + { + $this->markTestSkipped('Interop middleware/s not yet installed'); + } + $interop = 'Rougin\Slytherin\Fixture\Middlewares\InteropMiddleware'; $this->dispatcher->push($interop); @@ -142,6 +148,11 @@ public function testProcessMethodWithString() */ public function testPushMethodWithArray() { + if (! Interop::exists()) + { + $this->markTestSkipped('Interop middleware/s not yet installed'); + } + $interop = 'Rougin\Slytherin\Fixture\Middlewares\InteropMiddleware'; $expected = array(new Wrapper($interop)); @@ -160,6 +171,11 @@ public function testPushMethodWithArray() */ public function testStackMethod() { + if (! Interop::exists()) + { + $this->markTestSkipped('Interop middleware/s not yet installed'); + } + $this->dispatcher->push('Rougin\Slytherin\Fixture\Middlewares\InteropMiddleware'); $actual = $this->dispatcher->stack(); diff --git a/tests/Sample/Handlers/Cors.php b/tests/Sample/Handlers/Cors.php index 641764bc..3fc189fe 100644 --- a/tests/Sample/Handlers/Cors.php +++ b/tests/Sample/Handlers/Cors.php @@ -4,8 +4,8 @@ use Psr\Http\Message\ServerRequestInterface; use Rougin\Slytherin\Http\Response; -use Rougin\Slytherin\Server\HandlerInterface; -use Rougin\Slytherin\Server\MiddlewareInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; /** * @package Slytherin diff --git a/tests/Sample/Handlers/Parsed/Request.php b/tests/Sample/Handlers/Parsed/Request.php index 78a485fd..734fe9e7 100644 --- a/tests/Sample/Handlers/Parsed/Request.php +++ b/tests/Sample/Handlers/Parsed/Request.php @@ -3,8 +3,8 @@ namespace Rougin\Slytherin\Sample\Handlers\Parsed; use Psr\Http\Message\ServerRequestInterface; -use Rougin\Slytherin\Server\HandlerInterface; -use Rougin\Slytherin\Server\MiddlewareInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; /** * @package Slytherin diff --git a/tests/Sample/Handlers/Parsed/Response.php b/tests/Sample/Handlers/Parsed/Response.php index 75da95a0..dd012eb8 100644 --- a/tests/Sample/Handlers/Parsed/Response.php +++ b/tests/Sample/Handlers/Parsed/Response.php @@ -3,8 +3,8 @@ namespace Rougin\Slytherin\Sample\Handlers\Parsed; use Psr\Http\Message\ServerRequestInterface; -use Rougin\Slytherin\Server\HandlerInterface; -use Rougin\Slytherin\Server\MiddlewareInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; /** * @package Slytherin diff --git a/tests/Sample/Handlers/ToJson.php b/tests/Sample/Handlers/ToJson.php index d8085155..ea3352a3 100644 --- a/tests/Sample/Handlers/ToJson.php +++ b/tests/Sample/Handlers/ToJson.php @@ -3,8 +3,8 @@ namespace Rougin\Slytherin\Sample\Handlers; use Psr\Http\Message\ServerRequestInterface; -use Rougin\Slytherin\Server\HandlerInterface; -use Rougin\Slytherin\Server\MiddlewareInterface; +use Rougin\Slytherin\Middleware\HandlerInterface; +use Rougin\Slytherin\Middleware\MiddlewareInterface; /** * @package Slytherin diff --git a/tests/Sample/SampleTest.php b/tests/Sample/SampleTest.php index d06eedc9..d24e4e89 100644 --- a/tests/Sample/SampleTest.php +++ b/tests/Sample/SampleTest.php @@ -2,6 +2,7 @@ namespace Rougin\Slytherin\Forward; +use Rougin\Slytherin\Middleware\Interop; use Rougin\Slytherin\Sample\Builder; use Rougin\Slytherin\Sample\Handlers\Parsed\Request; use Rougin\Slytherin\Sample\Handlers\Parsed\Response; @@ -227,6 +228,11 @@ public function test_callable_middleware_changing_the_response_parameter() */ public function test_interop_middleware_changing_the_response_parameter() { + if (! Interop::exists()) + { + $this->markTestSkipped('Interop middleware/s not yet installed'); + } + $this->builder->setUrl('GET', '/interop'); $this->expectOutputString('From interop!');