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