1 | <?php |
||
19 | class EE_Dependency_Map { |
||
20 | |||
21 | |||
22 | /** |
||
23 | * This means that the requested class dependency is not present in the dependency map |
||
24 | */ |
||
25 | const not_registered = 0; |
||
26 | |||
27 | |||
28 | /** |
||
29 | * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
||
30 | */ |
||
31 | const load_new_object = 1; |
||
32 | |||
33 | /** |
||
34 | * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
||
35 | * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
||
36 | */ |
||
37 | const load_from_cache = 2; |
||
38 | |||
39 | /** |
||
40 | * @type EE_Dependency_Map $_instance |
||
41 | */ |
||
42 | protected static $_instance = null; |
||
43 | |||
44 | /** |
||
45 | * @type EE_Request $request |
||
46 | */ |
||
47 | protected $_request; |
||
48 | |||
49 | /** |
||
50 | * @type EE_Response $response |
||
51 | */ |
||
52 | protected $_response; |
||
53 | |||
54 | |||
55 | /** |
||
56 | * @type array $_dependency_map |
||
57 | */ |
||
58 | protected $_dependency_map = array(); |
||
59 | |||
60 | /** |
||
61 | * @type array $_class_loaders |
||
62 | */ |
||
63 | protected $_class_loaders = array(); |
||
64 | |||
65 | |||
66 | |||
67 | /** |
||
68 | * EE_Dependency_Map constructor. |
||
69 | * |
||
70 | * @param \EE_Request $request |
||
71 | * @param \EE_Response $response |
||
72 | */ |
||
73 | protected function __construct( EE_Request $request, EE_Response $response ) { |
||
79 | |||
80 | |||
81 | |||
82 | /** |
||
83 | */ |
||
84 | public function initialize() { |
||
88 | |||
89 | |||
90 | |||
91 | /** |
||
92 | * @singleton method used to instantiate class object |
||
93 | * @access public |
||
94 | * @param \EE_Request $request |
||
95 | * @param \EE_Response $response |
||
96 | * @return \EE_Dependency_Map instance |
||
97 | */ |
||
98 | public static function instance( EE_Request $request = null, EE_Response $response = null ) { |
||
105 | |||
106 | |||
107 | |||
108 | /** |
||
109 | * @param string $class |
||
110 | * @param array $dependencies |
||
111 | * @return boolean |
||
112 | */ |
||
113 | public static function register_dependencies( $class, $dependencies ) { |
||
120 | |||
121 | |||
122 | |||
123 | /** |
||
124 | * @param string $class_name |
||
125 | * @param string $loader |
||
126 | * @return bool |
||
127 | * @throws \EE_Error |
||
128 | */ |
||
129 | public static function register_class_loader( $class_name, $loader = 'load_core' ) { |
||
145 | |||
146 | |||
147 | |||
148 | /** |
||
149 | * @return array |
||
150 | */ |
||
151 | public function dependency_map() { |
||
154 | |||
155 | |||
156 | |||
157 | /** |
||
158 | * returns TRUE if dependency map contains a listing for the provided class name |
||
159 | * |
||
160 | * @param string $class_name |
||
161 | * @return boolean |
||
162 | */ |
||
163 | public function has( $class_name = '' ) { |
||
166 | |||
167 | |||
168 | |||
169 | /** |
||
170 | * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
||
171 | * |
||
172 | * @param string $class_name |
||
173 | * @param string $dependency |
||
174 | * @return bool |
||
175 | */ |
||
176 | public function has_dependency_for_class( $class_name = '', $dependency = '' ) { |
||
181 | |||
182 | |||
183 | |||
184 | /** |
||
185 | * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
||
186 | * |
||
187 | * @param string $class_name |
||
188 | * @param string $dependency |
||
189 | * @return int |
||
190 | */ |
||
191 | public function loading_strategy_for_class_dependency( $class_name = '', $dependency = '' ) { |
||
196 | |||
197 | |||
198 | |||
199 | /** |
||
200 | * @param string $class_name |
||
201 | * @return string | Closure |
||
202 | */ |
||
203 | public function class_loader( $class_name ) { |
||
206 | |||
207 | |||
208 | |||
209 | /** |
||
210 | * @return array |
||
211 | */ |
||
212 | public function class_loaders() { |
||
215 | |||
216 | |||
217 | |||
218 | /** |
||
219 | * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
||
220 | * if one exists, or whether a new object should be generated every time the requested class is loaded. |
||
221 | * This is done by using the following class constants: |
||
222 | * |
||
223 | * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
||
224 | * EE_Dependency_Map::load_new_object - generates a new object every time |
||
225 | */ |
||
226 | protected function _register_core_dependencies() { |
||
284 | |||
285 | |||
286 | |||
287 | /** |
||
288 | * Registers how core classes are loaded. |
||
289 | * |
||
290 | * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
||
291 | * |
||
292 | * 'EE_Request_Handler' => 'load_core' |
||
293 | * 'EE_Messages_Queue' => 'load_lib' |
||
294 | * 'EEH_Debug_Tools' => 'load_helper' |
||
295 | * |
||
296 | * or, if greater control is required, by providing a custom closure. For example: |
||
297 | * |
||
298 | * 'Some_Class' => function () { |
||
299 | * return new Some_Class(); |
||
300 | * }, |
||
301 | * |
||
302 | * This is required for instantiating dependencies |
||
303 | * where an interface has been type hinted in a class constructor. For example: |
||
304 | * |
||
305 | * 'Required_Interface' => function () { |
||
306 | * return new A_Class_That_Implements_Required_Interface(); |
||
307 | * }, |
||
308 | * |
||
309 | */ |
||
310 | protected function _register_core_class_loaders() { |
||
359 | |||
360 | |||
361 | /** |
||
362 | * This is used to reset the internal map and class_loaders to their original default state at the beginning of the request |
||
363 | * Primarily used by unit tests. |
||
364 | */ |
||
365 | public function reset() { |
||
369 | |||
370 | |||
371 | } |
||
372 | // End of file EE_Dependency_Map.core.php |
||
373 | // Location: /EE_Dependency_Map.core.php |
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):