1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace BEAR\QueryRepository; |
6
|
|
|
|
7
|
|
|
use BEAR\RepositoryModule\Annotation\EtagPool; |
8
|
|
|
use BEAR\RepositoryModule\Annotation\ResourceObjectPool; |
9
|
|
|
use BEAR\RepositoryModule\Annotation\TagsPool; |
10
|
|
|
use BEAR\Resource\NamedParameter; |
11
|
|
|
use BEAR\Resource\NamedParameterInterface; |
12
|
|
|
use Override; |
13
|
|
|
use Ray\Di\AbstractModule; |
14
|
|
|
use Ray\Di\Scope; |
15
|
|
|
use Symfony\Component\Cache\Adapter\AdapterInterface; |
16
|
|
|
use Symfony\Component\Cache\Adapter\NullAdapter; |
17
|
|
|
use Symfony\Component\Cache\Adapter\TagAwareAdapter; |
18
|
|
|
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Provides ResourceStorageInterface and derived bindings |
22
|
|
|
* |
23
|
|
|
* The following bindings are provided: |
24
|
|
|
* |
25
|
|
|
* CacheItemPoolInterface-EtagPool::class |
26
|
|
|
* QueryRepositoryInterface |
27
|
|
|
* CacheDependencyInterface |
28
|
|
|
* EtagSetterInterface |
29
|
|
|
* NamedParameterInterface |
30
|
|
|
* ResourceStorageInterface |
31
|
|
|
* MatchQueryInterface |
32
|
|
|
* UriTag |
33
|
|
|
* MatchQueryInterface |
34
|
|
|
* |
35
|
|
|
* The following module are installed. |
36
|
|
|
* |
37
|
|
|
* CacheableModule |
38
|
|
|
* DonutCacheModule |
39
|
|
|
*/ |
40
|
15 |
|
final class QueryRepositoryModule extends AbstractModule |
41
|
|
|
{ |
42
|
15 |
|
/** |
43
|
15 |
|
* {@inheritDoc} |
44
|
15 |
|
*/ |
45
|
15 |
|
#[Override] |
46
|
15 |
|
protected function configure(): void |
47
|
15 |
|
{ |
48
|
15 |
|
// Null cache engine default |
49
|
15 |
|
$this->bind(AdapterInterface::class)->annotatedWith(ResourceObjectPool::class)->to(NullAdapter::class); |
50
|
15 |
|
// When null is bound, the same adapter as the one assigned to the ResourceObjectPool is used. |
51
|
15 |
|
$this->bind(AdapterInterface::class)->annotatedWith(TagsPool::class)->toInstance(null); |
52
|
15 |
|
// TagAwareAdapterInterface is injected into ResourceStorage |
53
|
15 |
|
$this->bind(TagAwareAdapterInterface::class)->annotatedWith(ResourceObjectPool::class)->toConstructor( |
54
|
|
|
TagAwareAdapter::class, |
55
|
|
|
[ |
56
|
|
|
'itemsPool' => ResourceObjectPool::class, |
57
|
|
|
'tagsPool' => TagsPool::class, |
58
|
|
|
], |
59
|
|
|
); |
60
|
|
|
// When null is bound, the same adapter as the one assigned to the ResourceObjectPool is used. |
61
|
|
|
$this->bind(TagAwareAdapterInterface::class)->annotatedWith(EtagPool::class)->toInstance(null); |
62
|
|
|
// core |
63
|
|
|
$this->bind(QueryRepositoryInterface::class)->to(QueryRepository::class)->in(Scope::SINGLETON); |
64
|
|
|
$this->bind(CacheDependencyInterface::class)->to(CacheDependency::class); |
65
|
|
|
$this->bind(EtagSetterInterface::class)->to(EtagSetter::class); |
66
|
|
|
$this->bind(NamedParameterInterface::class)->to(NamedParameter::class); |
67
|
|
|
$this->bind(ResourceStorageInterface::class)->to(ResourceStorage::class)->in(Scope::SINGLETON); |
68
|
|
|
$this->bind(MatchQueryInterface::class)->to(MatchQuery::class); |
69
|
|
|
$this->bind(RefreshAnnotatedCommand::class); |
70
|
|
|
$this->bind(RefreshSameCommand::class); |
71
|
|
|
$this->bind(ResourceStorageSaver::class); |
72
|
|
|
// #[Cacheable] |
73
|
|
|
$this->install(new CacheableModule()); |
74
|
|
|
// #[CacheableResponse] |
75
|
|
|
$this->install(new DonutCacheModule()); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|