1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace BEAR\QueryRepository; |
6
|
|
|
|
7
|
|
|
use BEAR\RepositoryModule\Annotation\CacheableResponse; |
8
|
|
|
use BEAR\RepositoryModule\Annotation\DonutCache; |
9
|
|
|
use BEAR\RepositoryModule\Annotation\RefreshCache; |
10
|
|
|
use Ray\Di\AbstractModule; |
11
|
|
|
use Ray\Di\Scope; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Provides ResourceStorageInterface and derived bindings |
15
|
|
|
* |
16
|
|
|
* The following bindings are provided: |
17
|
|
|
* |
18
|
|
|
* HeaderSetter |
19
|
|
|
* CdnCacheControlHeaderSetterInterface |
20
|
|
|
* DonutRepositoryInterface |
21
|
|
|
* RepositoryLoggerInterface |
22
|
|
|
* PurgerInterface |
23
|
|
|
* UriTagInterface |
24
|
|
|
* |
25
|
|
|
* The following interceptors are provided: |
26
|
|
|
* |
27
|
|
|
* DonutCacheableResponseInterceptor |
28
|
|
|
* DonutCacheInterceptor |
29
|
|
|
* DonutCommandInterceptor |
30
|
|
|
* DonutCacheInterceptor |
31
|
|
|
*/ |
32
|
|
|
final class DonutCacheModule extends AbstractModule |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* {@inheritDoc} |
36
|
|
|
*/ |
37
|
|
|
protected function configure(): void |
38
|
|
|
{ |
39
|
|
|
$this->bind(HeaderSetter::class); |
40
|
|
|
$this->bind(CdnCacheControlHeaderSetterInterface::class)->to(CdnCacheControlHeaderSetter::class); |
41
|
|
|
$this->bind(DonutRepositoryInterface::class)->to(DonutRepository::class)->in(Scope::SINGLETON); |
42
|
|
|
$this->bind(RepositoryLoggerInterface::class)->to(RepositoryLogger::class)->in(Scope::SINGLETON); |
43
|
|
|
$this->bind(PurgerInterface::class)->to(NullPurger::class); |
44
|
|
|
$this->bind(UriTagInterface::class)->to(UriTag::class); |
45
|
|
|
$this->installAopClassModule(); |
46
|
|
|
$this->installAopMethodModule(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
private function installAopClassModule(): void |
50
|
|
|
{ |
51
|
|
|
$this->bind(DonutRepository::class)->in(Scope::SINGLETON); |
52
|
|
|
$this->bind(DonutRendererInterface::class)->to(DonutRenderer::class); |
53
|
|
|
$this->bindPriorityInterceptor( |
54
|
|
|
$this->matcher->annotatedWith(CacheableResponse::class), |
55
|
|
|
$this->matcher->startsWith('onGet'), |
56
|
|
|
[DonutCacheableResponseInterceptor::class], |
57
|
|
|
); |
58
|
|
|
$this->bindPriorityInterceptor( |
59
|
|
|
$this->matcher->annotatedWith(DonutCache::class), |
60
|
|
|
$this->matcher->startsWith('onGet'), |
61
|
|
|
[DonutCacheInterceptor::class], |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
$this->bindInterceptor( |
65
|
|
|
$this->matcher->annotatedWith(CacheableResponse::class), |
66
|
|
|
$this->matcher->logicalOr( |
67
|
|
|
$this->matcher->startsWith('onPut'), |
68
|
|
|
$this->matcher->logicalOr( |
69
|
|
|
$this->matcher->startsWith('onPatch'), |
70
|
|
|
$this->matcher->startsWith('onDelete'), |
71
|
|
|
), |
72
|
|
|
), |
73
|
|
|
[DonutCommandInterceptor::class], |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
private function installAopMethodModule(): void |
78
|
|
|
{ |
79
|
|
|
$this->bindInterceptor( |
80
|
|
|
$this->matcher->any(), |
81
|
|
|
$this->matcher->annotatedWith(CacheableResponse::class), |
82
|
|
|
[DonutCacheInterceptor::class], |
83
|
|
|
); |
84
|
|
|
$this->bindInterceptor( |
85
|
|
|
$this->matcher->any(), |
86
|
|
|
$this->matcher->annotatedWith(RefreshCache::class), |
87
|
|
|
[DonutCacheInterceptor::class], |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|