* This class represents an alias to another entry in the container.
7
*/
8
class AliasDefinition implements DumpableInterface
9
{
10
/**
11
* The identifier of the entry in the container.
12
*
13
* @var string
14
*/
15
private $identifier;
16
17
/**
18
* The identifier of the entry we are aliasing.
19
*
20
* @var string
21
*/
22
private $alias;
23
24
/**
25
* Constructs an instance definition.
26
*
27
* @param string|null $identifier The identifier of the entry in the container. Can be null if the entry is anonymous (declared inline in other instances)
28
* @param string $alias The identifier of the entry we are aliasing.
29
*/
30
public function __construct($identifier, $alias)
31
{
32
$this->identifier = $identifier;
33
$this->alias = $alias;
34
}
35
36
/**
37
* Returns the identifier of the instance.
38
*
39
* @return string
40
*/
41
public function getIdentifier()
42
{
43
return $this->identifier;
44
}
45
46
/**
47
* The identifier of the entry we are aliasing.
48
*
49
* @return mixed
50
*/
51
public function getAlias()
52
{
53
return $this->alias;
54
}
55
56
/**
57
* Returns an InlineEntryInterface object representing the PHP code necessary to generate
58
* the container entry.
59
*
60
* @param string $containerVariable The name of the variable that allows access to the container instance. For instance: "$container", or "$this->container"
61
* @param array $usedVariables An array of variables that are already used and that should not be used when generating this code.
62
*
63
* @return InlineEntryInterface
64
*/
65
public function toPhpCode($containerVariable, array $usedVariables = array())
66
{
67
return new InlineEntry(sprintf('%s->get(%s)', $containerVariable, var_export($this->alias, true)), null, $usedVariables);