1 | <?php |
||
48 | class ClassDefinition extends AbstractDefinition implements Invokable |
||
49 | { |
||
50 | /** |
||
51 | * Name of the class to be instanciated |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $className; |
||
55 | |||
56 | /** |
||
57 | * List of class' methods to be called after instanciation |
||
58 | * @var array<string> |
||
59 | */ |
||
60 | protected $methodCalls = array(); |
||
61 | |||
62 | /** |
||
63 | * Constructor |
||
64 | * |
||
65 | * @param string $className Name of the class to be instanciated |
||
66 | * @param array<mixed> $arguments List of (constructor) arguments |
||
67 | * |
||
68 | * @return void |
||
|
|||
69 | */ |
||
70 | 20 | public function __construct($className, array $arguments = array()) |
|
75 | |||
76 | /** |
||
77 | * Instanciates $this->className and return the instance. |
||
78 | * |
||
79 | * @param Container $container The Di Container |
||
80 | * @param null|string $name Name of the current definition (if any) |
||
81 | * |
||
82 | * @return object |
||
83 | * @throws Exceptions\InvalidClassDefinition |
||
84 | */ |
||
85 | 16 | public function invoke(Container $container, $name = null) |
|
115 | |||
116 | /** |
||
117 | * Executes registered methods (in the order they were added) |
||
118 | * |
||
119 | * @param object $instance The class instance |
||
120 | * @param Container $container The Di Container |
||
121 | * @param null|string $definition Name of the current definition |
||
122 | * |
||
123 | * @return void |
||
124 | * @throws Exceptions\InvalidClassDefinition |
||
125 | */ |
||
126 | 12 | protected function executeMethodCalls($instance, Container $container, |
|
143 | |||
144 | /** |
||
145 | * Instanciates the class ($this->className) |
||
146 | * |
||
147 | * @param Container $container The Di Container |
||
148 | * @param null|string $definition Name of the current definition (if any) |
||
149 | * |
||
150 | * @return object |
||
151 | * @throws Exceptions\ClassNotFound |
||
152 | * @throws Exceptions\InvalidClassDefinition |
||
153 | */ |
||
154 | 14 | protected function newInstance(Container $container, $definition = null) |
|
184 | |||
185 | /** |
||
186 | * Returns the Class name |
||
187 | * |
||
188 | * @return string |
||
189 | */ |
||
190 | 2 | public function getClassName() |
|
194 | |||
195 | /** |
||
196 | * Defines the Class name |
||
197 | * |
||
198 | * @param string $className The class name |
||
199 | * |
||
200 | * @return void |
||
201 | */ |
||
202 | 2 | public function setClassName($className) |
|
206 | |||
207 | /** |
||
208 | * Adds a method to be called right after the class was instanciated |
||
209 | * |
||
210 | * @param string $methodName The name of the method to be called |
||
211 | * @param array<mixed> $arguments List of arguments (optional) |
||
212 | * |
||
213 | * @return ClassDefinition |
||
214 | */ |
||
215 | 7 | public function addMethodCall($methodName, array $arguments = array()) |
|
224 | |||
225 | /** |
||
226 | * Removes a call to a specified method |
||
227 | * |
||
228 | * @param string $methodName The method name |
||
229 | * |
||
230 | * @return ClassDefinition |
||
231 | */ |
||
232 | 1 | public function removeMethodClass($methodName) |
|
243 | } |
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.