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