1 | <?php |
||
23 | class ServiceLocator implements LocatorInterface |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * Configuration for aliases. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $_config = []; |
||
32 | |||
33 | /** |
||
34 | * Instances that belong to the registry. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $_instances = []; |
||
39 | |||
40 | /** |
||
41 | * Contains a list of Method objects that were created out of the |
||
42 | * built-in Method class. The list is indexed by method names |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $_fallbacked = []; |
||
47 | |||
48 | /** |
||
49 | * Contains a list of options that were passed to get() method. |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $_options = []; |
||
54 | |||
55 | /** |
||
56 | * Stores a list of options to be used when instantiating an object |
||
57 | * with a matching alias. |
||
58 | * |
||
59 | * @param string|array $alias Name of the alias or array to completely overwrite current config. |
||
60 | * @param array|null $options list of options for the alias |
||
61 | * @return $this |
||
62 | * @throws \RuntimeException When you attempt to configure an existing table instance. |
||
63 | */ |
||
64 | public function setConfig($alias, $options = null) |
||
83 | |||
84 | /** |
||
85 | * Returns configuration for an alias or the full configuration array for all aliases. |
||
86 | * |
||
87 | * @param string|null $alias Alias to get config for, null for complete config. |
||
88 | * @return array The config data. |
||
89 | */ |
||
90 | public function getConfig($alias = null) |
||
98 | |||
99 | /** |
||
100 | * Stores a list of options to be used when instantiating an object |
||
101 | * with a matching alias. |
||
102 | * |
||
103 | * The options that can be stored are those that are recognized by `get()` |
||
104 | * If second argument is omitted, it will return the current settings |
||
105 | * for $alias. |
||
106 | * |
||
107 | * If no arguments are passed it will return the full configuration array for |
||
108 | * all aliases |
||
109 | * |
||
110 | * @param string|null $alias Name of the alias |
||
111 | * @param array|null $options list of options for the alias |
||
112 | * @return array The config data. |
||
113 | * @throws RuntimeException When you attempt to configure an existing method instance. |
||
114 | * @deprecated 3.6.0 Use setConfig()/getConfig() instead. |
||
115 | */ |
||
116 | public function config($alias = null, $options = null) |
||
132 | |||
133 | /** |
||
134 | * Get a method instance from the registry. |
||
135 | * |
||
136 | * Methods are only created once until the registry is flushed. |
||
137 | * This means that aliases must be unique across your application. |
||
138 | * This is important because method associations are resolved at runtime |
||
139 | * and cyclic references need to be handled correctly. |
||
140 | * |
||
141 | * The options that can be passed are the same as in `Method::__construct()`, but the |
||
142 | * key `className` is also recognized. |
||
143 | * |
||
144 | * If $options does not contain `className` CakePHP will attempt to construct the |
||
145 | * class name based on the alias. If this class does not exist, |
||
146 | * then the default `CakeDC\OracleDriver\ORM\Method` class will be used. By setting the `className` |
||
147 | * option you can define the specific class to use. This className can |
||
148 | * use a plugin short class reference. |
||
149 | * |
||
150 | * If you use a `$name` that uses plugin syntax only the name part will be used as |
||
151 | * key in the registry. This means that if two plugins, or a plugin and app provide |
||
152 | * the same alias, the registry will only store the first instance. |
||
153 | * |
||
154 | * If no `method` option is passed, the method name will be the underscored version |
||
155 | * of the provided $alias. |
||
156 | * |
||
157 | * If no `connection` option is passed the method's defaultConnectionName() method |
||
158 | * will be called to get the default connection name to use. |
||
159 | * |
||
160 | * @param string $alias The alias name you want to get. |
||
161 | * @param array $options The options you want to build the method with. |
||
162 | * If a method has already been loaded the options will be ignored. |
||
163 | * @return \CakeDC\Api\Service\Service |
||
164 | * @throws \RuntimeException When you try to configure an alias that already exists. |
||
165 | */ |
||
166 | 91 | public function get($alias, array $options = []) |
|
214 | |||
215 | /** |
||
216 | * Gets the method class name. |
||
217 | * |
||
218 | * @param string $alias The alias name you want to get. |
||
219 | * @param array $options Method options array. |
||
220 | * @return string |
||
221 | */ |
||
222 | 91 | protected function _getClassName($alias, array $options = []) |
|
243 | |||
244 | /** |
||
245 | * Wrapper for creating method instances |
||
246 | * |
||
247 | * @param array $options The alias to check for. |
||
248 | * @return \CakeDC\Api\Service\Service |
||
249 | */ |
||
250 | 91 | protected function _create(array $options) |
|
254 | |||
255 | /** |
||
256 | * {@inheritDoc} |
||
257 | */ |
||
258 | public function exists($alias) |
||
262 | |||
263 | /** |
||
264 | * {@inheritDoc} |
||
265 | */ |
||
266 | public function set($alias, Service $object) |
||
270 | |||
271 | /** |
||
272 | * {@inheritDoc} |
||
273 | */ |
||
274 | 108 | public function clear() |
|
280 | |||
281 | /** |
||
282 | * Returns the list of methods that were created by this registry that could |
||
283 | * not be instantiated from a specific subclass. This method is useful for |
||
284 | * debugging common mistakes when setting up associations or created new method |
||
285 | * classes. |
||
286 | * |
||
287 | * @return array |
||
288 | */ |
||
289 | public function genericInstances() |
||
293 | |||
294 | /** |
||
295 | * {@inheritDoc} |
||
296 | */ |
||
297 | public function remove($alias) |
||
305 | |||
306 | /** |
||
307 | * Compare services options. |
||
308 | * |
||
309 | * @param string $alias Service alias. |
||
310 | * @param array $options Options. |
||
311 | * @return bool |
||
312 | */ |
||
313 | protected function _compareOptions($alias, array $options) |
||
321 | } |
||
322 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: