-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathCacheableModule.php
More file actions
76 lines (70 loc) · 2.31 KB
/
CacheableModule.php
File metadata and controls
76 lines (70 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
declare(strict_types=1);
namespace BEAR\QueryRepository;
use BEAR\RepositoryModule\Annotation\AbstractCacheControl;
use BEAR\RepositoryModule\Annotation\Cacheable;
use BEAR\RepositoryModule\Annotation\Commands;
use BEAR\RepositoryModule\Annotation\Purge;
use BEAR\RepositoryModule\Annotation\Refresh;
use BEAR\Sunday\Extension\Transfer\HttpCacheInterface;
use Override;
use Ray\Di\AbstractModule;
/**
* Provides HttpCacheInterface and derived bindings
*
* The following bindings are provided:
*
* HttpCacheInterface
* -Commands
* RefreshInterceptor
* StorageExpiryModule
*/
final class CacheableModule extends AbstractModule
{
/**
* {@inheritDoc}
*/
#[Override]
protected function configure(): void
{
$this->bind(HttpCacheInterface::class)->to(HttpCache::class);
$this->bind()->annotatedWith(Commands::class)->toProvider(CommandsProvider::class);
$this->bind(RefreshInterceptor::class);
$this->install(new StorageExpiryModule(60, 60 * 60, 60 * 60 * 24));
$this->installAopModule();
}
protected function installAopModule(): void
{
$this->bindPriorityInterceptor(
$this->matcher->annotatedWith(Cacheable::class),
$this->matcher->startsWith('onGet'),
[CacheInterceptor::class],
);
$this->bindInterceptor(
$this->matcher->annotatedWith(Cacheable::class),
$this->matcher->logicalOr(
$this->matcher->startsWith('onPut'),
$this->matcher->logicalOr(
$this->matcher->startsWith('onPatch'),
$this->matcher->startsWith('onDelete'),
),
),
[CommandInterceptor::class],
);
$this->bindInterceptor(
$this->matcher->logicalNot(
$this->matcher->annotatedWith(Cacheable::class),
),
$this->matcher->logicalOr(
$this->matcher->annotatedWith(Purge::class),
$this->matcher->annotatedWith(Refresh::class),
),
[RefreshInterceptor::class],
);
$this->bindInterceptor(
$this->matcher->annotatedWith(AbstractCacheControl::class),
$this->matcher->startsWith('onGet'),
[HttpCacheInterceptor::class],
);
}
}