Skip to content

Commit b2aa8fa

Browse files
Merge pull request #12 from reindert-vetter/hotfix/fix-permit-on-string
Fix cache \ReindertVetter\ApiVersionControl\Middleware\Version\Bind
2 parents a777b41 + 721c519 commit b2aa8fa

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

src/Concerns/CacheableVersion.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ReindertVetter\ApiVersionControl\Concerns;
6+
7+
trait CacheableVersion
8+
{
9+
/**
10+
* Allow laravel to cache this class
11+
* @noinspection MagicMethodsValidityInspection
12+
*/
13+
public static function __set_state(array $array)
14+
{
15+
return new self(...array_values($array));
16+
}
17+
}

src/Middleware/Version/Bind.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@
55

66
use Closure;
77
use Illuminate\Http\Request;
8+
use ReindertVetter\ApiVersionControl\Concerns\CacheableVersion;
89

910
class Bind
1011
{
12+
use CacheableVersion;
13+
1114
private $abstract;
12-
private $conrete;
15+
private $concrete;
1316

14-
public function __construct($abstract, $conrete)
17+
public function __construct($abstract, $concrete)
1518
{
1619
$this->abstract = $abstract;
17-
$this->conrete = $conrete;
20+
$this->concrete = $concrete;
1821
}
1922

2023
public function handle(Request $request, Closure $next)
2124
{
22-
app()->bind($this->abstract, $this->conrete);
25+
app()->bind($this->abstract, $this->concrete);
2326

2427
return $next($request);
2528
}

test/Unit/SerializeConfigTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ReindertVetter\ApiVersionControl\Tests\Unit;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use ReindertVetter\ApiVersionControl\Middleware\Version\Bind;
9+
10+
class SerializeConfigTest extends TestCase
11+
{
12+
public function testSerializeVersion(): void
13+
{
14+
$result = Bind::__set_state([
15+
'abstract' => 'App\\Http\\TheAbstractClass',
16+
'concrete' => 'App\\Http\\TheConcreteClass',
17+
]);
18+
19+
self::assertEquals(new Bind('App\\Http\\TheAbstractClass', 'App\\Http\\TheConcreteClass'), $result);
20+
}
21+
}

0 commit comments

Comments
 (0)