QueryRepositoryModule::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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