use TheCodingMachine\Yaco\Definition\DumpableInterface;
8
use TheCodingMachine\Yaco\Definition\InlineEntry;
9
use TheCodingMachine\Yaco\Definition\InlineEntryInterface;
10
11
/**
12
* A definition that points to "$this" container.
13
*/
14
class ContainerDefinition implements DumpableInterface
15
{
16
/**
17
* The identifier of the instance in the container.
18
*
19
* @var string|null
20
*/
21
private $identifier;
22
23
/**
24
* @param null|string $identifier
25
*/
26
public function __construct($identifier = null)
27
{
28
$this->identifier = $identifier;
29
}
30
31
/**
32
* Returns the identifier for this object in the container.
33
* If null, classes consuming this definition should assume the definition must be inlined.
34
*
35
* @return string|null
36
*/
37
public function getIdentifier()
38
{
39
return $this->identifier;
40
}
41
42
/**
43
* Returns an InlineEntryInterface object representing the PHP code necessary to generate
44
* the container entry.
45
*
46
* @param string $containerVariable The name of the variable that allows access to the container instance. For instance: "$container", or "$this->container"
47
* @param array $usedVariables An array of variables that are already used and that should not be used when generating this code.
48
*
49
* @return InlineEntryInterface
50
*/
51
public function toPhpCode($containerVariable, array $usedVariables = array())
52
{
53
return new InlineEntry($containerVariable, null, $usedVariables);