1 | <?php |
||
53 | class ClassDefinition extends AbstractArgsDefinition implements DefinitionInterface |
||
54 | { |
||
55 | /** |
||
56 | * Name of the class to be instanciated |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $className; |
||
60 | |||
61 | /** |
||
62 | * List of class' methods to be called after instanciation |
||
63 | * @var array<string> |
||
64 | */ |
||
65 | protected $methodCalls = array(); |
||
66 | |||
67 | /** |
||
68 | * Constructor |
||
69 | * |
||
70 | * @param string $className Name of the class to be instanciated |
||
71 | * @param array<mixed> $arguments List of (constructor) arguments |
||
72 | * |
||
73 | * @return void |
||
|
|||
74 | */ |
||
75 | public function __construct($className, array $arguments = array()) |
||
80 | |||
81 | /** |
||
82 | * Instanciates $this->className and return the instance. |
||
83 | * |
||
84 | * @param Container $container The Di Container |
||
85 | * @param null|string $name Name of the current definition (if any) |
||
86 | * |
||
87 | * @return object |
||
88 | * @throws Exceptions\InvalidClassDefinitionException |
||
89 | */ |
||
90 | public function invoke(Container $container, $name = null) |
||
120 | |||
121 | /** |
||
122 | * Executes registered methods (in the order they were added) |
||
123 | * |
||
124 | * @param object $instance The class instance |
||
125 | * @param Container $container The Di Container |
||
126 | * @param null|string $definition Name of the current definition |
||
127 | * |
||
128 | * @return void |
||
129 | * @throws Exceptions\InvalidClassDefinitionException |
||
130 | */ |
||
131 | protected function executeMethodCalls($instance, Container $container, |
||
148 | |||
149 | /** |
||
150 | * Instanciates the class ($this->className) |
||
151 | * |
||
152 | * @param Container $container The Di Container |
||
153 | * @param null|string $definition Name of the current definition (if any) |
||
154 | * |
||
155 | * @return object |
||
156 | * @throws Exceptions\ClassNotFoundException |
||
157 | * @throws Exceptions\InvalidClassDefinitionException |
||
158 | */ |
||
159 | protected function newInstance(Container $container, $definition = null) |
||
189 | |||
190 | /** |
||
191 | * Returns the Class name |
||
192 | * |
||
193 | * @return string |
||
194 | */ |
||
195 | public function getClassName() |
||
199 | |||
200 | /** |
||
201 | * Defines the Class name |
||
202 | * |
||
203 | * @param string $className The class name |
||
204 | * |
||
205 | * @return void |
||
206 | */ |
||
207 | public function setClassName($className) |
||
211 | |||
212 | /** |
||
213 | * Adds a method to be called right after the class was instanciated |
||
214 | * |
||
215 | * @param string $methodName The name of the method to be called |
||
216 | * @param array<mixed> $arguments List of arguments (optional) |
||
217 | * |
||
218 | * @return ClassDefinition |
||
219 | */ |
||
220 | public function addMethodCall($methodName, array $arguments = array()) |
||
229 | |||
230 | /** |
||
231 | * Removes a call to a specified method |
||
232 | * |
||
233 | * @param string $methodName The method name |
||
234 | * |
||
235 | * @return ClassDefinition |
||
236 | */ |
||
237 | public function removeMethodClass($methodName) |
||
248 | } |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.