From cacf4869a7b77d4bad13877db3007b2f6a5a7b76 Mon Sep 17 00:00:00 2001 From: Reindert Vetter Date: Tue, 21 Dec 2021 22:16:54 +0100 Subject: [PATCH 1/3] Fix "Attempt to assign property "permit" on string" --- src/Collection/MiddlewareCollection.php | 3 +++ test/Unit/StatementVersion/VersionStatementTest.php | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/Collection/MiddlewareCollection.php b/src/Collection/MiddlewareCollection.php index 0b43731..8c330ca 100644 --- a/src/Collection/MiddlewareCollection.php +++ b/src/Collection/MiddlewareCollection.php @@ -75,6 +75,9 @@ function ($pipes, $rawVersionRule) use ($requestVersion) { public function permitVersionStatement(): self { foreach ($this->flatten() as $pipe) { + if (is_string($pipe)) { + $pipe = new $pipe(); + } if (method_exists($pipe, 'permitted')) { /** @var \ReindertVetter\ApiVersionControl\Concerns\VersionStatement $pipe */ /** @noinspection PhpUndefinedFieldInspection */ diff --git a/test/Unit/StatementVersion/VersionStatementTest.php b/test/Unit/StatementVersion/VersionStatementTest.php index 85cf6b7..5cecf39 100644 --- a/test/Unit/StatementVersion/VersionStatementTest.php +++ b/test/Unit/StatementVersion/VersionStatementTest.php @@ -38,6 +38,15 @@ public function testNotPermitVersionStatement(): void $this->assertFalse(MockVersionStatementSecond::permitted()); } + public function testPermitVersionStatementStringClass(): void + { + $goodVersionStatement = MockVersionStatementFirst::class; + $middlewareCollection = new MiddlewareCollection([$goodVersionStatement]); + $middlewareCollection->permitVersionStatement(); + + $this->assertFalse(MockVersionStatementSecond::permitted()); + } + public function testRejectVersionStatement(): void { $middlewareCollection = new MiddlewareCollection( From c199ff4e7692f7a2c12e13b6773d1529a62d52d2 Mon Sep 17 00:00:00 2001 From: Reindert Vetter Date: Tue, 21 Dec 2021 22:33:57 +0100 Subject: [PATCH 2/3] Fix "Attempt to assign property "permit" on string" --- src/Collection/MiddlewareCollection.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Collection/MiddlewareCollection.php b/src/Collection/MiddlewareCollection.php index 8c330ca..5457619 100644 --- a/src/Collection/MiddlewareCollection.php +++ b/src/Collection/MiddlewareCollection.php @@ -75,10 +75,10 @@ function ($pipes, $rawVersionRule) use ($requestVersion) { public function permitVersionStatement(): self { foreach ($this->flatten() as $pipe) { - if (is_string($pipe)) { - $pipe = new $pipe(); - } if (method_exists($pipe, 'permitted')) { + if (is_string($pipe)) { + $pipe = new $pipe(); + } /** @var \ReindertVetter\ApiVersionControl\Concerns\VersionStatement $pipe */ /** @noinspection PhpUndefinedFieldInspection */ $pipe->permit = true; From ecea3f10a17739d5e99dd340be6db021ac0272c0 Mon Sep 17 00:00:00 2001 From: Reindert Vetter Date: Tue, 21 Dec 2021 23:34:28 +0100 Subject: [PATCH 3/3] Fix "The VersionStatement $permit would be set to true always" --- src/Middleware/ApiVersionControl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Middleware/ApiVersionControl.php b/src/Middleware/ApiVersionControl.php index 334e3a6..c1e9993 100644 --- a/src/Middleware/ApiVersionControl.php +++ b/src/Middleware/ApiVersionControl.php @@ -25,8 +25,8 @@ public function __construct(array $config = null) public function handle(Request $request, Closure $next): SymfonyResponse { $pipes = MiddlewareCollection::createFromConfig($request, $this->config) - ->permitVersionStatement() ->filterByVersionCompare() + ->permitVersionStatement() ->flatten() ->rejectNonPipe() ->unique()