From 737682e848c94932f1a1fb3c0b61288c29826f4e Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Thu, 10 Nov 2016 22:36:10 +0100 Subject: [PATCH 1/4] Priority method --- src/MiddlewareInterface.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/MiddlewareInterface.php b/src/MiddlewareInterface.php index 97718bc..36f4c53 100644 --- a/src/MiddlewareInterface.php +++ b/src/MiddlewareInterface.php @@ -11,6 +11,14 @@ */ interface MiddlewareInterface { + /** + * Priority ranging from 0 to 1000. Where 1000 will be executed first on `pre` and 0 last on `pre`. + * For `post` the order is reversed. + * + * @return int + */ + public function priority(): int; + /** * Return the processed $request via a fulfilled promise. * When implementing cache or other feature that returns a response, do it with a rejected promise. From c524d3017e93525649b86ff607232a68c80dc659 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Thu, 10 Nov 2016 22:38:55 +0100 Subject: [PATCH 2/4] Default priority trait --- src/DefaultPriorityTrait.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/DefaultPriorityTrait.php diff --git a/src/DefaultPriorityTrait.php b/src/DefaultPriorityTrait.php new file mode 100644 index 0000000..8002268 --- /dev/null +++ b/src/DefaultPriorityTrait.php @@ -0,0 +1,14 @@ + Date: Thu, 10 Nov 2016 22:39:17 +0100 Subject: [PATCH 3/4] Use the new priority trait in the dummy middle ware --- tests/DummyMiddleware.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/DummyMiddleware.php b/tests/DummyMiddleware.php index c88a6fc..8041ba1 100644 --- a/tests/DummyMiddleware.php +++ b/tests/DummyMiddleware.php @@ -3,12 +3,14 @@ namespace ApiClients\Tests\Foundation\Middleware; +use ApiClients\Foundation\Middleware\DefaultPriorityTrait; use ApiClients\Foundation\Middleware\MiddlewareInterface; use ApiClients\Foundation\Middleware\PostTrait; use ApiClients\Foundation\Middleware\PreTrait; class DummyMiddleware implements MiddlewareInterface { + use DefaultPriorityTrait; use PreTrait; use PostTrait; } From 2d5091f46a9877e63272620933d2f08e2994931d Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Thu, 10 Nov 2016 22:39:54 +0100 Subject: [PATCH 4/4] Updated the test to also test the priority trait --- tests/DummyMiddlewareTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/DummyMiddlewareTest.php b/tests/DummyMiddlewareTest.php index c6f3f31..84e0a64 100644 --- a/tests/DummyMiddlewareTest.php +++ b/tests/DummyMiddlewareTest.php @@ -11,6 +11,15 @@ class DummyMiddlewareTest extends TestCase { + public function testPriority() + { + $middleware = new DummyMiddleware(); + $this->assertSame( + 500, + $middleware->priority() + ); + } + public function testPre() { $middleware = new DummyMiddleware();