1 | <?php |
||
88 | class Container extends ObjectAbstract implements ContainerInterface, ResolverAwareInterface, FactoryAwareInterface, ScopeInterface, ExtendedContainerInterface, DelegatorAwareInterface, \ArrayAccess, WritableInterface |
||
89 | { |
||
90 | use ContainerTrait, ArrayAccessTrait, DelegatorAwareTrait; |
||
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 ConfigInterface $config inject the config instance |
||
124 | * @param string $baseNode container's starting node in $config |
||
125 | * @param bool $writable able to inject object to the container |
||
126 | * @access public |
||
127 | */ |
||
128 | public function __construct( |
||
156 | |||
157 | /** |
||
158 | * Extensions to the Interop\Container\ContainerInterface |
||
159 | * |
||
160 | * - Accepting second param as object constructor arguments |
||
161 | * - Accpeting $id with scope appended, e.g. 'cache@myScope' |
||
162 | * |
||
163 | * {@inheritDoc} |
||
164 | */ |
||
165 | public function get($id) |
||
180 | |||
181 | /** |
||
182 | * Extensions to the Interop\Container\ContainerInterface |
||
183 | * |
||
184 | * - Accpeting $id with scope appended, e.g. 'cache@myScope' |
||
185 | * |
||
186 | * {@inheritDoc} |
||
187 | */ |
||
188 | public function has($id) |
||
197 | |||
198 | /** |
||
199 | * {@inheritDoc} |
||
200 | */ |
||
201 | public function set(/*# string */ $id, $value) |
||
217 | |||
218 | /** |
||
219 | * {@inheritDoc} |
||
220 | */ |
||
221 | public function one(/*# string */ $id, array $arguments = []) |
||
229 | |||
230 | /** |
||
231 | * {@inheritDoc} |
||
232 | */ |
||
233 | public function run($callable, array $arguments = []) |
||
241 | |||
242 | /** |
||
243 | * {@inheritDoc} |
||
244 | */ |
||
245 | public function resolve(&$toResolve) |
||
250 | |||
251 | /** |
||
252 | * - Overwrite `setDelegator()` from DelegatorAwareTrait |
||
253 | * - Update resolver $object_resolver |
||
254 | * |
||
255 | * {@inheritDoc} |
||
256 | */ |
||
257 | public function setDelegator(DelegatorInterface $delegator) |
||
263 | |||
264 | /** |
||
265 | * Register $this as 'di.service.container' |
||
266 | * |
||
267 | * - Later, $this can be referenced as '${#container}' anywhere |
||
268 | * |
||
269 | * - $skipCommon is to demonstrate skipping execute common methods for objects. |
||
270 | * |
||
271 | * instead of just do |
||
272 | * `$container->set($name, $object)` |
||
273 | * |
||
274 | * you may do |
||
275 | * $container->set($name, ['class' => $object, 'skip' => true]); |
||
276 | * |
||
277 | * @param bool $skipCommon skip common methods normally after instantiation |
||
278 | * @return $this |
||
279 | * @access protected |
||
280 | */ |
||
281 | protected function registerSelf(/*# bool */ $skipCommon = false) |
||
291 | } |
||
292 |