From a3024e8a8a8874150a9068a88fdd270b337ee7be Mon Sep 17 00:00:00 2001 From: arp Date: Thu, 1 Mar 2018 15:31:36 +0100 Subject: [PATCH 1/4] update composer to use stratigility 3 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 713f0a1..cfab772 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,8 @@ ], "require" : { "php" : ">=7.0", - "mouf/mvc.splash-common": "^8.2", - "zendframework/zend-stratigility": "^2.0", + "mouf/mvc.splash-common": "^8.4", + "zendframework/zend-stratigility": "^3.0", "mouf/mouf": "~2.0.0" }, "autoload" : { From 7f3ac6056922314ee44a895085d79ad2240453eb Mon Sep 17 00:00:00 2001 From: arp Date: Fri, 2 Mar 2018 17:04:34 +0100 Subject: [PATCH 2/4] updated dependancies to use psr15, renamed SplashMiddleware into MiddlewarePipe --- composer.json | 2 +- src/Mouf/Mvc/Splash/MiddlewarePipe.php | 51 ++++++++++++++++++++++++ src/Mouf/Mvc/Splash/SplashMiddleware.php | 36 ----------------- 3 files changed, 52 insertions(+), 37 deletions(-) create mode 100644 src/Mouf/Mvc/Splash/MiddlewarePipe.php delete mode 100644 src/Mouf/Mvc/Splash/SplashMiddleware.php diff --git a/composer.json b/composer.json index cfab772..790e6e8 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ ], "require" : { "php" : ">=7.0", - "mouf/mvc.splash-common": "^8.4", + "mouf/mvc.splash-common": "^9.0", "zendframework/zend-stratigility": "^3.0", "mouf/mouf": "~2.0.0" }, diff --git a/src/Mouf/Mvc/Splash/MiddlewarePipe.php b/src/Mouf/Mvc/Splash/MiddlewarePipe.php new file mode 100644 index 0000000..10b306a --- /dev/null +++ b/src/Mouf/Mvc/Splash/MiddlewarePipe.php @@ -0,0 +1,51 @@ + + * It acts as a wrapper on Zend's MiddleWarePipe
+ * It is in charge of binding an Url to a Controller.
+ * There is one and only one instance of Splash per web application.
+ * The name of the instance MUST be "splashMiddleware".
+ *
+ * The SplashMiddleware component has several ways to bind an URL to a Controller.
+ * It can do so based on the @URL annotation, or based on the @Action annotation.
+ * Check out the Splash documentation here: + * https://github.com/thecodingmachine/mvc.splash/. + */ +class MiddlewarePipe implements MiddlewareInterface +{ + private $zendPipe; + + /** + * MiddlewarePipe constructor. + * @param MiddlewareInterface[] $middlewares + */ + public function __construct(array $middlewares) + { + $this->zendPipe = new ZendMiddleWarePipe(); + foreach ($middlewares as $middleware) { + /** @var Router $router */ + $this->zendPipe->pipe($middleware); + } + } + + /** + * Process an incoming server request and return a response, optionally delegating + * response creation to a handler. + */ + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface + { + return $this->zendPipe->process($request, $handler); + } + + +} diff --git a/src/Mouf/Mvc/Splash/SplashMiddleware.php b/src/Mouf/Mvc/Splash/SplashMiddleware.php deleted file mode 100644 index f9c91eb..0000000 --- a/src/Mouf/Mvc/Splash/SplashMiddleware.php +++ /dev/null @@ -1,36 +0,0 @@ - - * It is in charge of binding an Url to a Controller.
- * There is one and only one instance of Splash per web application.
- * The name of the instance MUST be "splashMiddleware".
- *
- * The SplashMiddleware component has several ways to bind an URL to a Controller.
- * It can do so based on the @URL annotation, or based on the @Action annotation.
- * Check out the Splash documentation here: - * https://github.com/thecodingmachine/mvc.splash/. - */ -class SplashMiddleware extends MiddlewarePipe -{ - /** - * @param RouterInterface[] $routers - */ - public function __construct(array $routers) - { - parent::__construct(); - $this->setResponsePrototype(new Response()); - foreach ($routers as $router) { - if ($router->isActive()) { - $this->pipe($router->getPath(), $router->getMiddleware()); - } - } - } -} From 08d13acbc9233b9f33fdc405a1c78337df0f702c Mon Sep 17 00:00:00 2001 From: arp Date: Fri, 2 Mar 2018 17:04:54 +0100 Subject: [PATCH 3/4] created the conditionMiddleware class --- src/Mouf/Mvc/Splash/ConditionMiddleware.php | 53 +++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/Mouf/Mvc/Splash/ConditionMiddleware.php diff --git a/src/Mouf/Mvc/Splash/ConditionMiddleware.php b/src/Mouf/Mvc/Splash/ConditionMiddleware.php new file mode 100644 index 0000000..012ad79 --- /dev/null +++ b/src/Mouf/Mvc/Splash/ConditionMiddleware.php @@ -0,0 +1,53 @@ +condition = $condition; + $this->ifMiddleware = $ifMiddleware; + $this->elseMiddleware = $elseMiddleware; + } + + /** + * Process an incoming server request and return a response, optionally delegating + * response creation to a handler. + */ + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface + { + if($this->condition->isOk()) { + $this->ifMiddleware->process($request, $handler); + } else if($this->elseMiddleware) { + $this->elseMiddleware->process($request, $handler); + } else { + $handler->handle($request); + } + } +} \ No newline at end of file From 148c9eb6aea601ada8c43e66ba8dc3ba2e8e58fc Mon Sep 17 00:00:00 2001 From: arp Date: Fri, 2 Mar 2018 17:05:29 +0100 Subject: [PATCH 4/4] removed router class and interface --- src/Mouf/Mvc/Splash/Routers/Router.php | 77 ------------------- .../Mvc/Splash/Routers/RouterInterface.php | 39 ---------- 2 files changed, 116 deletions(-) delete mode 100644 src/Mouf/Mvc/Splash/Routers/Router.php delete mode 100644 src/Mouf/Mvc/Splash/Routers/RouterInterface.php diff --git a/src/Mouf/Mvc/Splash/Routers/Router.php b/src/Mouf/Mvc/Splash/Routers/Router.php deleted file mode 100644 index 3f8f30c..0000000 --- a/src/Mouf/Mvc/Splash/Routers/Router.php +++ /dev/null @@ -1,77 +0,0 @@ -path = $path; - $this->middleware = $middleware; - $this->enableCondition = $enableCondition; - } - - /** - * The path to that middleware (defaults to /). - * - * @return string - */ - public function getPath() - { - return $this->path; - } - - /** - * The PSR-7 middleware to call. - * - * @return MiddlewareInterface - */ - public function getMiddleware() - { - return $this->middleware; - } - - /** - * If this returns false, the router is skipped. - * - * @return bool - */ - public function isActive() - { - if ($this->enableCondition !== null && $this->enableCondition->isOk() === false) { - return false; - } else { - return true; - } - } -} diff --git a/src/Mouf/Mvc/Splash/Routers/RouterInterface.php b/src/Mouf/Mvc/Splash/Routers/RouterInterface.php deleted file mode 100644 index c388260..0000000 --- a/src/Mouf/Mvc/Splash/Routers/RouterInterface.php +++ /dev/null @@ -1,39 +0,0 @@ -