Completed
Push — master ( 1feeef...279c4f )
by Matthieu
8s
created

ValueDefinition::__toString()   A

↳ Parent: ValueDefinition

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 4
Code Lines 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace DI\Definition;
4
5
use DI\Scope;
6
use Interop\Container\ContainerInterface;
7
8
/**
9
 * Definition of a value for dependency injection.
10
 *
11
 * @author Matthieu Napoli <[email protected]>
12
 */
13
class ValueDefinition implements Definition, SelfResolvingDefinition
14
{
15
    /**
16
     * Entry name.
17
     * @var string
18
     */
19
    private $name;
20
21
    /**
22
     * @var mixed
23
     */
24
    private $value;
25
26
    /**
27
     * @param string $name Entry name
28
     * @param mixed $value
29
     */
30
    public function __construct($name, $value)
31
    {
32
        $this->name = $name;
33
        $this->value = $value;
34
    }
35
36
    /**
37
     * @return string Entry name
38
     */
39
    public function getName()
40
    {
41
        return $this->name;
42
    }
43
44
    /**
45
     * A value definition is like a constant, there is nothing to compute, the value is the same for everyone.
46
     *
47
     * [email protected]}
48
     */
49
    public function getScope()
50
    {
51
        return Scope::SINGLETON;
52
    }
53
54
    /**
55
     * @return mixed
56
     */
57
    public function getValue()
58
    {
59
        return $this->value;
60
    }
61
62
    public function resolve(ContainerInterface $container)
63
    {
64
        return $this->getValue();
65
    }
66
67
    public function isResolvable(ContainerInterface $container)
68
    {
69
        return true;
70
    }
71
72
    public function __toString()
73
    {
74
        return sprintf('Value (%s)', var_export($this->value, true));
75
    }
76
}
77