Completed
Push — master ( b2a65d...63a169 )
by Kirill
02:18
created

DefinitionInterceptor::match()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Frontend\Interceptor;
11
12
use Railt\SDL\Frontend\Context\ContextInterface;
13
use Railt\SDL\Frontend\Deferred\Deferred;
14
use Railt\SDL\Frontend\Definition\DefinitionInterface;
15
use Railt\SDL\Frontend\Definition\Storage;
16
17
/**
18
 * Class DefinitionInterceptor
19
 */
20
class DefinitionInterceptor implements InterceptorInterface
21
{
22
    /**
23
     * @var Storage
24
     */
25
    private $definitions;
26
27
    /**
28
     * DefinitionInterceptor constructor.
29
     * @param Storage $definitions
30
     */
31
    public function __construct(Storage $definitions)
32
    {
33
        $this->definitions = $definitions;
34
    }
35
36
    /**
37
     * @param mixed $value
38
     * @return bool
39
     */
40
    public function match($value): bool
41
    {
42
        return $value instanceof DefinitionInterface;
43
    }
44
45
    /**
46
     * @param ContextInterface $context
47
     * @param mixed $value
48
     * @return array
49
     */
50
    public function resolve(ContextInterface $context, $value): array
51
    {
52
        $deferred = new Deferred();
53
54
        $this->definitions->remember($value, $deferred);
55
56
        return [$context, $deferred];
57
    }
58
}
59