Skip to content

Commit

Permalink
Merge pull request #11 from reindert-vetter/hotfix/fix-permit-on-string
Browse files Browse the repository at this point in the history
Fix "Attempt to assign property "permit" on string"
  • Loading branch information
reindert-vetter authored Dec 21, 2021
2 parents 44a4b0c + ecea3f1 commit a777b41
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Collection/MiddlewareCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public function permitVersionStatement(): self
{
foreach ($this->flatten() as $pipe) {
if (method_exists($pipe, 'permitted')) {
if (is_string($pipe)) {
$pipe = new $pipe();
}
/** @var \ReindertVetter\ApiVersionControl\Concerns\VersionStatement $pipe */
/** @noinspection PhpUndefinedFieldInspection */
$pipe->permit = true;
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/ApiVersionControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions test/Unit/StatementVersion/VersionStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit a777b41

Please sign in to comment.