1 | <?php |
||
49 | class Container implements ArrayAccess |
||
50 | { |
||
51 | /** |
||
52 | * The objects store |
||
53 | * @var array |
||
54 | */ |
||
55 | protected $store = array(); |
||
56 | |||
57 | /** |
||
58 | * Informations about stored objects |
||
59 | * @var array |
||
60 | */ |
||
61 | protected $storeData = array(); |
||
62 | |||
63 | /** |
||
64 | * Container Properties |
||
65 | * @var array |
||
66 | */ |
||
67 | protected $properties = array(); |
||
68 | |||
69 | /** |
||
70 | * Properties Keys (cached) |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $propertiesMap = array(); |
||
74 | |||
75 | /** |
||
76 | * Constructor |
||
77 | * |
||
78 | * @return void |
||
|
|||
79 | */ |
||
80 | 35 | public function __construct() |
|
84 | |||
85 | /** |
||
86 | * Registers a definition |
||
87 | * |
||
88 | * @param string $name Identifier |
||
89 | * @param mixed $definition Definition, callable or value |
||
90 | * @param boolean $shared Should the instance be "shared" (singleton) |
||
91 | * @param array $data Meta-data associated with this definition |
||
92 | * |
||
93 | * @return Container |
||
94 | */ |
||
95 | 35 | public function set($name, $definition, $shared = false, |
|
110 | |||
111 | /** |
||
112 | * Load and returns a definition |
||
113 | * |
||
114 | * @param string $name Identifier |
||
115 | * |
||
116 | * @throws Exceptions\DefinitionNotFound if $name isn't a valid identifier |
||
117 | * @return mixed |
||
118 | */ |
||
119 | 21 | public function get($name) |
|
153 | |||
154 | /** |
||
155 | * Loads properties from an INI file as definitions. |
||
156 | * Theses properties can then be referenced like @propName in other |
||
157 | * definitions. |
||
158 | * |
||
159 | * @param string $iniFile Path/to/file.ini |
||
160 | * @param null|string $category The INI category to be parsed |
||
161 | * |
||
162 | * @return Container |
||
163 | * @throws Exception |
||
164 | */ |
||
165 | 4 | public function iniProperties($iniFile, $category = null) |
|
187 | |||
188 | /** |
||
189 | * Returns a property (or $default if not defined) |
||
190 | * |
||
191 | * @param string $propName The property name |
||
192 | * @param mixed $default Default value if the property is not defined |
||
193 | * |
||
194 | * @return mixed |
||
195 | */ |
||
196 | 3 | public function getProperty($propName, $default = null) |
|
206 | |||
207 | /** |
||
208 | * Defines a property. |
||
209 | * |
||
210 | * If the $value is null, the property will be unset. |
||
211 | * |
||
212 | * It recommended to store only strings as property values. Register a |
||
213 | * new Di definition for any other type. |
||
214 | * |
||
215 | * @param string $propName Property name |
||
216 | * @param null|string $value The prop value |
||
217 | * |
||
218 | * @return Container |
||
219 | */ |
||
220 | 6 | public function setProperty($propName, $value = null) |
|
233 | |||
234 | |||
235 | /** |
||
236 | * Transform properties references to their respective value |
||
237 | * |
||
238 | * @param string $str String to be transformed |
||
239 | * |
||
240 | * @return string |
||
241 | */ |
||
242 | 20 | public function propertizeString($str) |
|
250 | |||
251 | /** |
||
252 | * Unregisters a definition |
||
253 | * |
||
254 | * @param string $name Identifier |
||
255 | * |
||
256 | * @throws Exceptions\DefinitionNotFound if $name isn't a valid identifier |
||
257 | * @return boolean true on success |
||
258 | */ |
||
259 | 3 | public function unregister($name) |
|
270 | |||
271 | /** |
||
272 | * Tells if a definition has been flagged has "shared" (singleton) |
||
273 | * |
||
274 | * @param string $name Identifier |
||
275 | * |
||
276 | * @throws Exceptions\DefinitionNotFound if $name isn't a valid identifier |
||
277 | * @return boolean |
||
278 | */ |
||
279 | 9 | public function isShared($name) |
|
289 | |||
290 | /** |
||
291 | * Tells if a definition exists at $offset |
||
292 | * |
||
293 | * @param string $name Identifier |
||
294 | * |
||
295 | * @return boolean |
||
296 | */ |
||
297 | 23 | public function exists($name) |
|
301 | |||
302 | /** |
||
303 | * Tells if a definition is registered at $offset |
||
304 | * |
||
305 | * @param string $offset Identifier |
||
306 | * |
||
307 | * @return boolean |
||
308 | */ |
||
309 | public function offsetExists($offset) |
||
313 | |||
314 | /** |
||
315 | * Loads and returns a definition |
||
316 | * |
||
317 | * @param string $offset Identifier |
||
318 | * |
||
319 | * @return mixed |
||
320 | */ |
||
321 | public function offsetGet($offset) |
||
325 | |||
326 | /** |
||
327 | * Registers a definition |
||
328 | * |
||
329 | * @param string $offset Identifier |
||
330 | * @param mixed $value Definition |
||
331 | * |
||
332 | * @return Container |
||
333 | */ |
||
334 | 16 | public function offsetSet($offset, $value) |
|
338 | |||
339 | /** |
||
340 | * Unregisters a Definition |
||
341 | * |
||
342 | * @param string $offset Identifier |
||
343 | * |
||
344 | * @return boolean |
||
345 | */ |
||
346 | public function offsetUnset($offset) |
||
350 | } |
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.