1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace BEAR\QueryRepository; |
6
|
|
|
|
7
|
|
|
use BEAR\RepositoryModule\Annotation\RedisDsn; |
8
|
|
|
use BEAR\RepositoryModule\Annotation\RedisDsnOptions; |
9
|
|
|
use BEAR\RepositoryModule\Annotation\ResourceObjectPool; |
10
|
|
|
use Ray\Di\AbstractModule; |
11
|
|
|
use Ray\Di\ProviderInterface; |
12
|
|
|
use Ray\PsrCacheModule\Annotation\CacheNamespace; |
13
|
|
|
use ReflectionException; |
14
|
|
|
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter; |
15
|
|
|
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Provides ResourceStorageInterface and derived bindings |
19
|
|
|
* * |
20
|
|
|
* * The following bindings are provided: |
21
|
|
|
* * |
22
|
|
|
* * CacheItemPoolInterface-EtagPool::class |
23
|
|
|
* * |
24
|
|
|
* * The following module are installed: |
25
|
|
|
* * |
26
|
|
|
* * Psr6RedisModule |
27
|
|
|
* Provides CacheItemPool and derived bindings |
28
|
|
|
* |
29
|
|
|
* [...] |
30
|
|
|
* |
31
|
|
|
* The following bindings are provided: |
32
|
|
|
* |
33
|
|
|
* ::RedisDsn |
34
|
|
|
* CacheItemPoolInterface::Local |
35
|
|
|
* CacheItemPoolInterface::Shared |
36
|
|
|
*/ |
37
|
|
|
final class StorageRedisDsnModule extends AbstractModule |
38
|
|
|
{ |
39
|
|
|
/** |
40
|
|
|
* Redis configuration DSN |
41
|
|
|
* |
42
|
|
|
* @param string $dsn Redis DSN |
43
|
|
|
* @param array<string, bool|int|string|array<string, mixed>|null> $options Redis DSN Options |
44
|
|
|
*/ |
45
|
|
|
public function __construct( |
46
|
|
|
private readonly string $dsn, |
47
|
|
|
private readonly array $options = [], |
48
|
|
|
AbstractModule|null $module = null, |
49
|
|
|
) { |
50
|
|
|
parent::__construct($module); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** @throws ReflectionException */ |
54
|
|
|
protected function configure(): void |
55
|
|
|
{ |
56
|
|
|
$this->bind()->annotatedWith(RedisDsn::class)->toInstance($this->dsn); |
57
|
|
|
$this->bind()->annotatedWith(RedisDsnOptions::class)->toInstance($this->options); |
58
|
|
|
$this->bind(ProviderInterface::class)->annotatedWith('redis')->to(RedisDsnProvider::class); |
59
|
|
|
$this->bind()->annotatedWith('redis')->toProvider(RedisDsnProvider::class); |
60
|
|
|
$this->bind(TagAwareAdapterInterface::class)->annotatedWith(ResourceObjectPool::class)->toConstructor( |
61
|
|
|
RedisTagAwareAdapter::class, |
62
|
|
|
[ |
63
|
|
|
'redis' => 'redis', |
64
|
|
|
'namespace' => CacheNamespace::class, |
65
|
|
|
], |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|