Skip to content

Commit

Permalink
Merge pull request #12 from reindert-vetter/hotfix/fix-permit-on-string
Browse files Browse the repository at this point in the history
Fix cache \ReindertVetter\ApiVersionControl\Middleware\Version\Bind
  • Loading branch information
reindert-vetter committed Dec 21, 2021
2 parents a777b41 + 721c519 commit b2aa8fa
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/Concerns/CacheableVersion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace ReindertVetter\ApiVersionControl\Concerns;

trait CacheableVersion
{
/**
* Allow laravel to cache this class
* @noinspection MagicMethodsValidityInspection
*/
public static function __set_state(array $array)
{
return new self(...array_values($array));
}
}
11 changes: 7 additions & 4 deletions src/Middleware/Version/Bind.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@

use Closure;
use Illuminate\Http\Request;
use ReindertVetter\ApiVersionControl\Concerns\CacheableVersion;

class Bind
{
use CacheableVersion;

private $abstract;
private $conrete;
private $concrete;

public function __construct($abstract, $conrete)
public function __construct($abstract, $concrete)
{
$this->abstract = $abstract;
$this->conrete = $conrete;
$this->concrete = $concrete;
}

public function handle(Request $request, Closure $next)
{
app()->bind($this->abstract, $this->conrete);
app()->bind($this->abstract, $this->concrete);

return $next($request);
}
Expand Down
21 changes: 21 additions & 0 deletions test/Unit/SerializeConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace ReindertVetter\ApiVersionControl\Tests\Unit;

use PHPUnit\Framework\TestCase;
use ReindertVetter\ApiVersionControl\Middleware\Version\Bind;

class SerializeConfigTest extends TestCase
{
public function testSerializeVersion(): void
{
$result = Bind::__set_state([
'abstract' => 'App\\Http\\TheAbstractClass',
'concrete' => 'App\\Http\\TheConcreteClass',
]);

self::assertEquals(new Bind('App\\Http\\TheAbstractClass', 'App\\Http\\TheConcreteClass'), $result);
}
}

0 comments on commit b2aa8fa

Please sign in to comment.