1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace BEAR\QueryRepository; |
6
|
|
|
|
7
|
|
|
use BEAR\RepositoryModule\Annotation\EtagPool; |
8
|
|
|
use Psr\Cache\CacheItemPoolInterface; |
9
|
|
|
use Ray\Di\Di\Inject; |
10
|
|
|
use Ray\Di\InjectorInterface; |
11
|
|
|
use Ray\PsrCacheModule\Annotation\Shared; |
12
|
|
|
use Symfony\Component\Cache\Adapter\AdapterInterface; |
13
|
|
|
use Symfony\Component\Cache\Adapter\TagAwareAdapter; |
14
|
|
|
|
15
|
|
|
use function assert; |
16
|
|
|
|
17
|
|
|
trait ResourceStorageCacheableTrait |
18
|
|
|
{ |
19
|
|
|
use Php73BcSerializableTrait; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var ?InjectorInterface |
23
|
|
|
* @psalm-suppress PropertyNotSetInConstructor |
24
|
|
|
*/ |
25
|
|
|
protected $injector; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @Inject |
29
|
|
|
*/ |
30
|
|
|
#[Inject] |
31
|
|
|
final public function setInjector(InjectorInterface $injector): void |
32
|
|
|
{ |
33
|
|
|
$this->injector = $injector; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return array{logger: RepositoryLoggerInterface, purger: PurgerInterface, uriTag: UriTagInterface, saver: ResourceStorageSaver, knownTagTtl: float, injector: InjectorInterface} |
38
|
|
|
*/ |
39
|
|
|
final public function __serialize(): array |
40
|
|
|
{ |
41
|
|
|
assert($this->injector instanceof InjectorInterface); |
42
|
|
|
|
43
|
|
|
return [ |
44
|
|
|
'logger' => $this->logger, |
45
|
|
|
'purger' => $this->purger, |
46
|
|
|
'uriTag' => $this->uriTag, |
47
|
|
|
'saver' => $this->saver, |
48
|
|
|
'knownTagTtl' => $this->knownTagTtl, |
49
|
|
|
'injector' => $this->injector, |
50
|
|
|
]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param array{logger: RepositoryLoggerInterface, purger: PurgerInterface, uriTag: UriTagInterface, saver: ResourceStorageSaver, knownTagTtl: float, injector: InjectorInterface} $data |
55
|
|
|
*/ |
56
|
|
|
final public function __unserialize(array $data): void |
57
|
|
|
{ |
58
|
|
|
$this->logger = $data['logger']; |
|
|
|
|
59
|
|
|
$this->purger = $data['purger']; |
|
|
|
|
60
|
|
|
$this->uriTag = $data['uriTag']; |
|
|
|
|
61
|
|
|
$this->saver = $data['saver']; |
|
|
|
|
62
|
|
|
$pool = $data['injector']->getInstance(CacheItemPoolInterface::class, Shared::class); |
63
|
|
|
$etagPool = $data['injector']->getInstance(CacheItemPoolInterface::class, EtagPool::class); |
64
|
|
|
assert($pool instanceof AdapterInterface); |
65
|
|
|
assert($etagPool instanceof AdapterInterface); |
66
|
|
|
$this->roPool = new TagAwareAdapter($pool, $etagPool, $data['knownTagTtl']); |
|
|
|
|
67
|
|
|
$this->etagPool = new TagAwareAdapter($etagPool, $etagPool, $data['knownTagTtl']); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|