From a3024e8a8a8874150a9068a88fdd270b337ee7be Mon Sep 17 00:00:00 2001 From: arp Date: Thu, 1 Mar 2018 15:31:36 +0100 Subject: [PATCH 1/9] 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/9] 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/9] 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/9] 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 @@ - Date: Mon, 5 Mar 2018 15:40:46 +0100 Subject: [PATCH 5/9] updated composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 790e6e8..8d95e4b 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ ], "require" : { "php" : ">=7.0", - "mouf/mvc.splash-common": "^9.0", + "thecodingmachine/splash-router": "^9.0", "zendframework/zend-stratigility": "^3.0", "mouf/mouf": "~2.0.0" }, From 6c5a682251a21b9f52b9e3829b5fca4d07722a1e Mon Sep 17 00:00:00 2001 From: arp Date: Tue, 6 Mar 2018 16:53:54 +0100 Subject: [PATCH 6/9] temp --- .../Controllers/Admin/SplashCreateControllerController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Mouf/Mvc/Splash/Controllers/Admin/SplashCreateControllerController.php b/src/Mouf/Mvc/Splash/Controllers/Admin/SplashCreateControllerController.php index 96af82b..ae3dfcc 100644 --- a/src/Mouf/Mvc/Splash/Controllers/Admin/SplashCreateControllerController.php +++ b/src/Mouf/Mvc/Splash/Controllers/Admin/SplashCreateControllerController.php @@ -3,13 +3,13 @@ namespace Mouf\Mvc\Splash\Controllers\Admin; use Mouf\Composer\ClassNameMapper; -use Mouf\Mvc\Splash\Controllers\Controller; use Mouf\Html\Template\TemplateInterface; use Mouf\Html\HtmlElement\HtmlBlock; use Mouf\Html\Utils\WebLibraryManager\WebLibrary; -use Mouf\Mvc\Splash\Services\SplashCreateControllerService; -use Mouf\Mvc\Splash\Services\SplashCreateControllerServiceException; use Mouf\MoufManager; +use TheCodingMachine\Splash\Controllers\Controller; +use TheCodingMachine\Splash\Services\SplashCreateControllerService; +use TheCodingMachine\Splash\Services\SplashCreateControllerServiceException; /** * A controller used to create controllers in Splash. From d25534ae4670184fb1e801793d047615d717bc17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 19 Jul 2018 13:46:17 +0200 Subject: [PATCH 7/9] Changing dependencies to bring back mouf/mvc.splash --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8d95e4b..a0906c4 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ ], "require" : { "php" : ">=7.0", - "thecodingmachine/splash-router": "^9.0", + "mouf/mvc.splash-common": "^10.0", "zendframework/zend-stratigility": "^3.0", "mouf/mouf": "~2.0.0" }, From e33191ab9474f7b7ce1e9efabf8fdb7477d362ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 19 Jul 2018 14:22:08 +0200 Subject: [PATCH 8/9] Fixing namespace --- .../Controllers/Admin/SplashCreateControllerController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mouf/Mvc/Splash/Controllers/Admin/SplashCreateControllerController.php b/src/Mouf/Mvc/Splash/Controllers/Admin/SplashCreateControllerController.php index ae3dfcc..33ad43e 100644 --- a/src/Mouf/Mvc/Splash/Controllers/Admin/SplashCreateControllerController.php +++ b/src/Mouf/Mvc/Splash/Controllers/Admin/SplashCreateControllerController.php @@ -7,7 +7,7 @@ use Mouf\Html\HtmlElement\HtmlBlock; use Mouf\Html\Utils\WebLibraryManager\WebLibrary; use Mouf\MoufManager; -use TheCodingMachine\Splash\Controllers\Controller; +use Mouf\Mvc\Splash\Controllers\Controller; use TheCodingMachine\Splash\Services\SplashCreateControllerService; use TheCodingMachine\Splash\Services\SplashCreateControllerServiceException; From 74c2acd6975430738df3654cd80936f869383eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 19 Jul 2018 15:01:50 +0200 Subject: [PATCH 9/9] Fixing ConditionMiddleware, addning requesthandler capability to MiddlewarePipe --- src/Mouf/Mvc/Splash/ConditionMiddleware.php | 6 +++--- src/Mouf/Mvc/Splash/MiddlewarePipe.php | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Mouf/Mvc/Splash/ConditionMiddleware.php b/src/Mouf/Mvc/Splash/ConditionMiddleware.php index 012ad79..77f833f 100644 --- a/src/Mouf/Mvc/Splash/ConditionMiddleware.php +++ b/src/Mouf/Mvc/Splash/ConditionMiddleware.php @@ -43,11 +43,11 @@ public function __construct(ToCondition $condition, MiddlewareInterface $ifMiddl public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { if($this->condition->isOk()) { - $this->ifMiddleware->process($request, $handler); + return $this->ifMiddleware->process($request, $handler); } else if($this->elseMiddleware) { - $this->elseMiddleware->process($request, $handler); + return $this->elseMiddleware->process($request, $handler); } else { - $handler->handle($request); + return $handler->handle($request); } } } \ No newline at end of file diff --git a/src/Mouf/Mvc/Splash/MiddlewarePipe.php b/src/Mouf/Mvc/Splash/MiddlewarePipe.php index 10b306a..5018eae 100644 --- a/src/Mouf/Mvc/Splash/MiddlewarePipe.php +++ b/src/Mouf/Mvc/Splash/MiddlewarePipe.php @@ -21,7 +21,7 @@ * Check out the Splash documentation here: * https://github.com/thecodingmachine/mvc.splash/. */ -class MiddlewarePipe implements MiddlewareInterface +class MiddlewarePipe implements MiddlewareInterface, RequestHandlerInterface { private $zendPipe; @@ -47,5 +47,24 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface return $this->zendPipe->process($request, $handler); } + /** + * Handle an incoming request. + * + * Attempts to handle an incoming request by doing the following: + * + * - Cloning itself, to produce a request handler. + * - Dequeuing the first middleware in the cloned handler. + * - Processing the first middleware using the request and the cloned handler. + * + * If the pipeline is empty at the time this method is invoked, it will + * raise an exception. + * + * @throws Exception\EmptyPipelineException if no middleware is present in + * the instance in order to process the request. + */ + public function handle(ServerRequestInterface $request) : ResponseInterface + { + return $this->zendPipe->handle($request); + } }