From 545a5a6d0064313a96646b8519d64e288c942f99 Mon Sep 17 00:00:00 2001 From: "Michael A." <39175160+michaelthedev@users.noreply.github.com> Date: Wed, 26 Jun 2024 09:52:41 +0100 Subject: [PATCH 1/7] chore(tests): add `DummyMiddlewareWithParam` middleware --- .../Dummy/DummyMiddlewareWithParam.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/Pecee/SimpleRouter/Dummy/DummyMiddlewareWithParam.php diff --git a/tests/Pecee/SimpleRouter/Dummy/DummyMiddlewareWithParam.php b/tests/Pecee/SimpleRouter/Dummy/DummyMiddlewareWithParam.php new file mode 100644 index 0000000..4059f25 --- /dev/null +++ b/tests/Pecee/SimpleRouter/Dummy/DummyMiddlewareWithParam.php @@ -0,0 +1,14 @@ + Date: Wed, 26 Jun 2024 09:53:01 +0100 Subject: [PATCH 2/7] chore(tests): add test for `DummyMiddlewareWithParam` middleware --- tests/Pecee/SimpleRouter/MiddlewareTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Pecee/SimpleRouter/MiddlewareTest.php b/tests/Pecee/SimpleRouter/MiddlewareTest.php index 0183c59..235efd1 100644 --- a/tests/Pecee/SimpleRouter/MiddlewareTest.php +++ b/tests/Pecee/SimpleRouter/MiddlewareTest.php @@ -1,6 +1,7 @@ assertTrue(true); } + public function testMiddlewareWithParameters() + { + $this->expectException(MiddlewareLoadedException::class); + + TestRouter::group(['exceptionHandler' => 'ExceptionHandler'], function () { + TestRouter::get('/my/test/url', 'DummyController@method1', ['middleware' => 'DummyMiddlewareWithParam,4,hello']); + }); + + TestRouter::debug('/my/test/url', 'get'); + + } } \ No newline at end of file From 8f5b956a36a098cfe721aa8ef626da2e4c471b73 Mon Sep 17 00:00:00 2001 From: "Michael A." <39175160+michaelthedev@users.noreply.github.com> Date: Wed, 26 Jun 2024 09:54:16 +0100 Subject: [PATCH 3/7] chore(route): allow comma separated values as Middleware parameters on `handle` --- src/Pecee/SimpleRouter/Route/LoadableRoute.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Pecee/SimpleRouter/Route/LoadableRoute.php b/src/Pecee/SimpleRouter/Route/LoadableRoute.php index 72d88f9..f21fa94 100644 --- a/src/Pecee/SimpleRouter/Route/LoadableRoute.php +++ b/src/Pecee/SimpleRouter/Route/LoadableRoute.php @@ -37,8 +37,19 @@ public function loadMiddleware(Request $request, Router $router): void $router->debug('Loading middlewares'); foreach ($this->getMiddlewares() as $middleware) { + $parameters = []; if (is_object($middleware) === false) { + if (str_contains($middleware, ',')) { + $options = explode(',', $middleware); + + //@todo: see efficiency of trim + $middleware = $options[0]; + + // set the rest of explode as parameters + $parameters = array_slice($options, 1); + } + $middleware = $router->getClassLoader()->loadClass($middleware); } @@ -49,7 +60,7 @@ public function loadMiddleware(Request $request, Router $router): void $className = get_class($middleware); $router->debug('Loading middleware "%s"', $className); - $middleware->handle($request); + $middleware->handle($request, ...$parameters); $router->debug('Finished loading middleware "%s"', $className); } From 4b0d67d34d38f7954ddc25df1f4101e5cac0bc4d Mon Sep 17 00:00:00 2001 From: "Michael A." <39175160+michaelthedev@users.noreply.github.com> Date: Wed, 26 Jun 2024 10:02:28 +0100 Subject: [PATCH 4/7] chore: change namespace for release purpose --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3208bfa..310928f 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "pecee/simple-router", + "name": "michaelthedev/simple-router", "description": "Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.", "keywords": [ "router", From c09f1c7000a0124353d5c72457092867e147f9f5 Mon Sep 17 00:00:00 2001 From: "Michael A." <39175160+michaelthedev@users.noreply.github.com> Date: Wed, 26 Jun 2024 10:06:33 +0100 Subject: [PATCH 5/7] chore: composer add author details --- composer.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/composer.json b/composer.json index 310928f..162250a 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,10 @@ "source": "https://github.com/skipperbent/simple-php-router/issues" }, "authors": [ + { + "name": "Michael Arawole", + "email": "michael@logad.net" + }, { "name": "Simon Sessingø", "email": "simon.sessingoe@gmail.com" From 034a71d9d2ff086e96802d6ea77a6bdc90246ebd Mon Sep 17 00:00:00 2001 From: "Michael A." <39175160+michaelthedev@users.noreply.github.com> Date: Sun, 7 Jul 2024 16:59:38 +0100 Subject: [PATCH 6/7] chore: composer modify author details --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 162250a..fc0e49c 100644 --- a/composer.json +++ b/composer.json @@ -21,13 +21,13 @@ "source": "https://github.com/skipperbent/simple-php-router/issues" }, "authors": [ - { - "name": "Michael Arawole", - "email": "michael@logad.net" - }, { "name": "Simon Sessingø", "email": "simon.sessingoe@gmail.com" + }, + { + "name": "Michael Arawole", + "email": "michael@logad.net" } ], "require": { @@ -49,7 +49,7 @@ }, "autoload": { "psr-4": { - "Pecee\\": "src/Pecee/" + "LogadApp\\": "src/Pecee/" } }, "config": { From 8915bd52a66caf7a3c04bfabdf0db08cca84c1d4 Mon Sep 17 00:00:00 2001 From: "Michael A." <39175160+michaelthedev@users.noreply.github.com> Date: Sun, 7 Jul 2024 17:03:29 +0100 Subject: [PATCH 7/7] chore: composer modify details --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fc0e49c..67b69bf 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "michaelthedev/simple-router", - "description": "Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.", + "description": "Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router. (Forked from skipperbent/simple-php-router)", "keywords": [ "router", "router",