1 | <?php |
||
88 | class Container extends ObjectAbstract implements ContainerInterface, ResolverAwareInterface, FactoryAwareInterface, ScopeInterface, ExtendedContainerInterface, DelegatorAwareInterface, \ArrayAccess, WritableInterface |
||
89 | { |
||
90 | use ContainerTrait, ArrayAccessTrait, DelegatorAwareTrait, WritableTrait; |
||
91 | |||
92 | /** |
||
93 | * Inject a Phossa2\Config\Config |
||
94 | * |
||
95 | * ```php |
||
96 | * $configData = [ |
||
97 | * // container class |
||
98 | * 'di.class' => 'Phossa2\\Di\\Container', |
||
99 | * |
||
100 | * // container service definitions |
||
101 | * 'di.service' => [ |
||
102 | * // ... |
||
103 | * ], |
||
104 | * |
||
105 | * // interface/classname mappings |
||
106 | * 'di.mapping' => [ |
||
107 | * ], |
||
108 | * |
||
109 | * // init methods to run after container created |
||
110 | * 'di.init' => [ |
||
111 | * 'default' => [], |
||
112 | * 'mystuff' => [ ... ], |
||
113 | * ], |
||
114 | * ]; |
||
115 | * |
||
116 | * // instantiate $config |
||
117 | * $config = new Config(null, null, $configData); |
||
118 | * |
||
119 | * // instantiate container |
||
120 | * $container = new $config['di.class']($config); |
||
121 | * ``` |
||
122 | * |
||
123 | * @param Config $config inject the config instance |
||
124 | * @param string $baseNode container's starting node in $config |
||
125 | * @access public |
||
126 | */ |
||
127 | public function __construct( |
||
140 | |||
141 | /** |
||
142 | * Extensions to the Interop\Container\ContainerInterface |
||
143 | * |
||
144 | * - Accepting second param as object constructor arguments |
||
145 | * - Accpeting $id with scope appended, e.g. 'cache@myScope' |
||
146 | * |
||
147 | * {@inheritDoc} |
||
148 | */ |
||
149 | public function get($id) |
||
164 | |||
165 | /** |
||
166 | * Extensions to the Interop\Container\ContainerInterface |
||
167 | * |
||
168 | * - Accpeting $id with scope appended, e.g. 'cache@myScope' |
||
169 | * |
||
170 | * {@inheritDoc} |
||
171 | */ |
||
172 | public function has($id) |
||
181 | |||
182 | /** |
||
183 | * {@inheritDoc} |
||
184 | */ |
||
185 | public function set(/*# string */ $id, $value) |
||
201 | |||
202 | /** |
||
203 | * {@inheritDoc} |
||
204 | */ |
||
205 | public function one(/*# string */ $id, array $arguments = []) |
||
213 | |||
214 | /** |
||
215 | * {@inheritDoc} |
||
216 | */ |
||
217 | public function run($callable, array $arguments = []) |
||
225 | |||
226 | /** |
||
227 | * {@inheritDoc} |
||
228 | */ |
||
229 | public function map(/*# string */ $from, $to) |
||
234 | |||
235 | /** |
||
236 | * {@inheritDoc} |
||
237 | */ |
||
238 | public function auto(/*# bool */ $on = true) |
||
243 | |||
244 | /** |
||
245 | * {@inheritDoc} |
||
246 | */ |
||
247 | public function param(/*# string */ $name, $value) |
||
252 | |||
253 | /** |
||
254 | * {@inheritDoc} |
||
255 | */ |
||
256 | public function resolve(&$toResolve) |
||
261 | |||
262 | /** |
||
263 | * Override `setDelegator()` from 'Phossa2\Shared\Reference\DelegatorAwareTrait' |
||
264 | * |
||
265 | * {@inheritDoc} |
||
266 | */ |
||
267 | public function setDelegator(DelegatorInterface $delegator) |
||
276 | |||
277 | /** |
||
278 | * Override 'isWritable()' in 'Phossa2\Config\Traits\WritableTrait' |
||
279 | * |
||
280 | * Container's writability is depend on its resolver |
||
281 | * |
||
282 | * {@inheritDoc} |
||
283 | */ |
||
284 | public function isWritable()/*# : bool */ |
||
288 | |||
289 | /** |
||
290 | * Override 'setWritable()' in 'Phossa2\Config\Traits\WritableTrait' |
||
291 | * |
||
292 | * Container's writability is depend on its resolver |
||
293 | * |
||
294 | * {@inheritDoc} |
||
295 | */ |
||
296 | public function setWritable($writable)/*# : bool */ |
||
301 | |||
302 | /** |
||
303 | * Register object in 'di.service' with $name |
||
304 | * |
||
305 | * e.g. `$this->registerObject('container', $this)` |
||
306 | * |
||
307 | * - Later, $this can be referenced as '${#container}' anywhere |
||
308 | * |
||
309 | * - $object will skip execute common methods for created instances. |
||
310 | * |
||
311 | * instead of just do |
||
312 | * `$container->set($name, $object)` |
||
313 | * |
||
314 | * you may do |
||
315 | * $container->set($name, ['class' => $object, 'skip' => true]); |
||
316 | * |
||
317 | * @param string $name name to register with |
||
318 | * @param object $object |
||
319 | * @return $this |
||
320 | * @access protected |
||
321 | */ |
||
322 | protected function registerObject(/*# string */ $name, $object) |
||
329 | } |
||
330 |