Completed
Push — param-inject ( 83c5f6 )
by Akihito
01:11
created

Inject::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di\Di;
6
7
use Attribute;
8
9
/**
10
 * Annotates your class methods into which the Injector should inject values
11
 *
12
 * @Annotation
13
 * @Target("METHOD")
14
 */
15
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER)]
16
final class Inject implements InjectInterface
17
{
18
    /**
19
     * If true, and the appropriate binding is not found, the Injector will skip injection of this method or field rather than produce an error.
20
     *
21
     * @var bool
22
     */
23
    public $optional = false;
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function isOptional(): bool
29
    {
30
        return $this->optional;
31
    }
32
33
    public function __construct(array $value = [], bool $optional = false)
34
    {
35
        $this->optional = $value['optional'] ?? $optional;
36
    }
37
}
38