Completed
Push — master ( a051a7...500db5 )
by Matthieu
02:31
created

AliasDefinition::resolve()   A

↳ Parent: AliasDefinition

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
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace DI\Definition;
4
5
use DI\Scope;
6
use Interop\Container\ContainerInterface;
7
8
/**
9
 * Defines an alias from an entry to another.
10
 *
11
 * @author Matthieu Napoli <[email protected]>
12
 */
13
class AliasDefinition implements CacheableDefinition, SelfResolvingDefinition
14
{
15
    /**
16
     * Entry name.
17
     * @var string
18
     */
19
    private $name;
20
21
    /**
22
     * Name of the target entry.
23
     * @var string
24
     */
25
    private $targetEntryName;
26
27
    /**
28
     * @param string $name            Entry name
29
     * @param string $targetEntryName Name of the target entry
30
     */
31
    public function __construct($name, $targetEntryName)
32
    {
33
        $this->name = $name;
34
        $this->targetEntryName = $targetEntryName;
35
    }
36
37
    /**
38
     * @return string Entry name
39
     */
40
    public function getName()
41
    {
42
        return $this->name;
43
    }
44
45
    /**
46
     * [email protected]}
47
     */
48
    public function getScope()
49
    {
50
        return Scope::PROTOTYPE;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getTargetEntryName()
57
    {
58
        return $this->targetEntryName;
59
    }
60
61
    public function resolve(ContainerInterface $container)
62
    {
63
        return $container->get($this->getTargetEntryName());
64
    }
65
66
    public function isResolvable(ContainerInterface $container)
67
    {
68
        return $container->has($this->getTargetEntryName());
69
    }
70
}
71