1 | <?php |
||
11 | class ClosureDefinition implements DumpableInterface |
||
12 | { |
||
13 | /** |
||
14 | * The identifier of the instance in the container. |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | private $identifier; |
||
19 | |||
20 | /** |
||
21 | * The closure. |
||
22 | * |
||
23 | * @var \Closure |
||
24 | */ |
||
25 | private $closure; |
||
26 | |||
27 | /** |
||
28 | * Constructs an instance definition. |
||
29 | * |
||
30 | * @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) |
||
31 | * @param \Closure $closure The closure. It should not contain context (i.e. no "use" keyword in the closure definition). It should accept one compulsory parameter: the container. |
||
32 | */ |
||
33 | public function __construct($identifier, \Closure $closure) |
||
34 | { |
||
35 | $this->identifier = $identifier; |
||
36 | $this->closure = $closure; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Returns the identifier of the instance. |
||
41 | * |
||
42 | * @return string |
||
43 | */ |
||
44 | public function getIdentifier() |
||
48 | |||
49 | /** |
||
50 | * Returns the closure of the parameter. |
||
51 | * |
||
52 | * @return mixed |
||
53 | */ |
||
54 | public function getClosure() |
||
58 | |||
59 | /** |
||
60 | * Returns an InlineEntryInterface object representing the PHP code necessary to generate |
||
61 | * the container entry. |
||
62 | * |
||
63 | * @param string $containerVariable The name of the variable that allows access to the container instance. For instance: "$container", or "$this->container" |
||
64 | * @param array $usedVariables An array of variables that are already used and that should not be used when generating this code. |
||
65 | * |
||
66 | * @return InlineEntryInterface |
||
67 | * |
||
68 | * @throws DefinitionException |
||
69 | */ |
||
70 | public function toPhpCode($containerVariable, array $usedVariables = array()) |
||
89 | } |
||
90 |