1 | <?php |
||
9 | class ObjectDefinition implements DumpableInterface |
||
10 | { |
||
11 | /** |
||
12 | * The identifier of the instance in the container. |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | private $identifier; |
||
17 | |||
18 | /** |
||
19 | * The fully qualified class name of this instance. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | private $className; |
||
24 | |||
25 | /** |
||
26 | * A list of arguments passed to the constructor. |
||
27 | * |
||
28 | * @var array Array of scalars or ReferenceInterface, or array mixing scalars, arrays, and ReferenceInterface |
||
29 | */ |
||
30 | private $constructorArguments = array(); |
||
31 | |||
32 | /** |
||
33 | * A list of actions to be executed (can be either a method call or a public property assignation). |
||
34 | * |
||
35 | * @var ActionInterface[] |
||
36 | */ |
||
37 | private $actions = array(); |
||
38 | |||
39 | /** |
||
40 | * Constructs an instance definition. |
||
41 | * |
||
42 | * @param string|null $identifier The identifier of the instance in the container. Can be null if the instance is anonymous (declared inline of other instances) |
||
43 | * @param string $className The fully qualified class name of this instance. |
||
44 | * @param array $constructorArguments A list of constructor arguments. |
||
45 | */ |
||
46 | public function __construct($identifier, $className, array $constructorArguments = array()) |
||
47 | { |
||
48 | $this->identifier = $identifier; |
||
49 | $this->className = '\\'.ltrim($className, '\\'); |
||
50 | $this->constructorArguments = $constructorArguments; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Returns the identifier of the instance. |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | public function getIdentifier() |
||
62 | |||
63 | /** |
||
64 | * @return string |
||
65 | */ |
||
66 | public function getClassName() |
||
70 | |||
71 | /** |
||
72 | * @return array |
||
73 | */ |
||
74 | public function getConstructorParameters() |
||
78 | |||
79 | /** |
||
80 | * Adds an argument to the list of arguments to be passed to the constructor. |
||
81 | * |
||
82 | * @param mixed $argument |
||
83 | * |
||
84 | * @return self |
||
85 | */ |
||
86 | public function addConstructorArgument($argument) |
||
92 | |||
93 | /** |
||
94 | * Adds a method call. |
||
95 | * |
||
96 | * @param string $methodName |
||
97 | * @param array $arguments |
||
98 | * |
||
99 | * @return MethodCall |
||
100 | */ |
||
101 | public function addMethodCall($methodName, array $arguments = array()) |
||
107 | |||
108 | /** |
||
109 | * Adds a method call. |
||
110 | * |
||
111 | * @param string $propertyName |
||
112 | * @param mixed $value |
||
113 | * |
||
114 | * @return self |
||
115 | */ |
||
116 | public function setProperty($propertyName, $value) |
||
122 | |||
123 | /** |
||
124 | * Returns an InlineEntryInterface object representing the PHP code necessary to generate |
||
125 | * the container entry. |
||
126 | * |
||
127 | * @param string $containerVariable The name of the variable that allows access to the container instance. For instance: "$container", or "$this->container" |
||
128 | * @param array $usedVariables An array of variables that are already used and that should not be used when generating this code. |
||
129 | * |
||
130 | * @return InlineEntryInterface |
||
131 | */ |
||
132 | public function toPhpCode($containerVariable, array $usedVariables = array()) |
||
153 | } |
||
154 |