Completed
Push — refresh ( bee4c5...1d01e3 )
by Akihito
02:47
created

QueryRepositoryAopModule::configure()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 8.8571
cc 2
eloc 17
nc 2
nop 0
1
<?php
2
/**
3
 * This file is part of the BEAR.QueryRepository package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\QueryRepository;
8
9
use BEAR\RepositoryModule\Annotation\Cacheable;
10
use BEAR\RepositoryModule\Annotation\Purge;
11
use BEAR\RepositoryModule\Annotation\Refresh;
12
use Ray\Di\AbstractModule;
13
14
class QueryRepositoryAopModule extends AbstractModule
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    protected function configure()
20
    {
21
        // @Cacheable
22
        $this->bindPriorityInterceptor(
23
            $this->matcher->annotatedWith(Cacheable::class),
24
            $this->matcher->startsWith('onGet'),
25
            [CacheInterceptor::class]
26
        );
27
        foreach (['onPost', 'onPut', 'onPatch', 'onDelete'] as $starts) {
28
            $this->bindInterceptor(
29
                $this->matcher->annotatedWith(Cacheable::class),
30
                $this->matcher->startsWith($starts),
31
                [CommandInterceptor::class]
32
            );
33
            $this->bindInterceptor(
34
                $this->matcher->logicalNot(
35
                    $this->matcher->annotatedWith(Cacheable::class)
36
                ),
37
                $this->matcher->logicalOr(
38
                    $this->matcher->annotatedWith(Purge::class),
39
                    $this->matcher->annotatedWith(Refresh::class)
40
                ),
41
                [RefreshInterceptor::class]
42
            );
43
        }
44
    }
45
}
46