Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like EE_Registry often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EE_Registry, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class EE_Registry implements ResettableInterface |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * EE_Registry Object |
||
24 | * |
||
25 | * @var EE_Registry $_instance |
||
26 | * @access private |
||
27 | */ |
||
28 | private static $_instance = null; |
||
29 | |||
30 | /** |
||
31 | * @var EE_Dependency_Map $_dependency_map |
||
32 | * @access protected |
||
33 | */ |
||
34 | protected $_dependency_map = null; |
||
35 | |||
36 | /** |
||
37 | * @var array $_class_abbreviations |
||
38 | * @access protected |
||
39 | */ |
||
40 | protected $_class_abbreviations = array(); |
||
41 | |||
42 | /** |
||
43 | * @access public |
||
44 | * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
||
45 | */ |
||
46 | public $BUS; |
||
47 | |||
48 | /** |
||
49 | * EE_Cart Object |
||
50 | * |
||
51 | * @access public |
||
52 | * @var EE_Cart $CART |
||
53 | */ |
||
54 | public $CART = null; |
||
55 | |||
56 | /** |
||
57 | * EE_Config Object |
||
58 | * |
||
59 | * @access public |
||
60 | * @var EE_Config $CFG |
||
61 | */ |
||
62 | public $CFG = null; |
||
63 | |||
64 | /** |
||
65 | * EE_Network_Config Object |
||
66 | * |
||
67 | * @access public |
||
68 | * @var EE_Network_Config $NET_CFG |
||
69 | */ |
||
70 | public $NET_CFG = null; |
||
71 | |||
72 | /** |
||
73 | * StdClass object for storing library classes in |
||
74 | * |
||
75 | * @public LIB |
||
76 | * @var StdClass $LIB |
||
77 | */ |
||
78 | public $LIB = null; |
||
79 | |||
80 | /** |
||
81 | * EE_Request_Handler Object |
||
82 | * |
||
83 | * @access public |
||
84 | * @var EE_Request_Handler $REQ |
||
85 | */ |
||
86 | public $REQ = null; |
||
87 | |||
88 | /** |
||
89 | * EE_Session Object |
||
90 | * |
||
91 | * @access public |
||
92 | * @var EE_Session $SSN |
||
93 | */ |
||
94 | public $SSN = null; |
||
95 | |||
96 | /** |
||
97 | * holds the ee capabilities object. |
||
98 | * |
||
99 | * @since 4.5.0 |
||
100 | * @var EE_Capabilities |
||
101 | */ |
||
102 | public $CAP = null; |
||
103 | |||
104 | /** |
||
105 | * holds the EE_Message_Resource_Manager object. |
||
106 | * |
||
107 | * @since 4.9.0 |
||
108 | * @var EE_Message_Resource_Manager |
||
109 | */ |
||
110 | public $MRM = null; |
||
111 | |||
112 | |||
113 | /** |
||
114 | * Holds the Assets Registry instance |
||
115 | * @var Registry |
||
116 | */ |
||
117 | public $AssetsRegistry = null; |
||
118 | |||
119 | /** |
||
120 | * StdClass object for holding addons which have registered themselves to work with EE core |
||
121 | * |
||
122 | * @var StdClass |
||
123 | */ |
||
124 | public $addons = null; |
||
125 | |||
126 | /** |
||
127 | * $models |
||
128 | * @access public |
||
129 | * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
||
130 | */ |
||
131 | public $models = array(); |
||
132 | |||
133 | /** |
||
134 | * $modules |
||
135 | * @access public |
||
136 | * @var EED_Module[] $modules |
||
137 | */ |
||
138 | public $modules = null; |
||
139 | |||
140 | /** |
||
141 | * $shortcodes |
||
142 | * @access public |
||
143 | * @var EES_Shortcode[] $shortcodes |
||
144 | */ |
||
145 | public $shortcodes = null; |
||
146 | |||
147 | /** |
||
148 | * $widgets |
||
149 | * @access public |
||
150 | * @var WP_Widget[] $widgets |
||
151 | */ |
||
152 | public $widgets = null; |
||
153 | |||
154 | /** |
||
155 | * $non_abstract_db_models |
||
156 | * @access public |
||
157 | * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
||
158 | * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
||
159 | * Keys are model "short names" (eg "Event") as used in model relations, and values are |
||
160 | * classnames (eg "EEM_Event") |
||
161 | */ |
||
162 | public $non_abstract_db_models = array(); |
||
163 | |||
164 | |||
165 | /** |
||
166 | * $i18n_js_strings - internationalization for JS strings |
||
167 | * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
||
168 | * in js file: var translatedString = eei18n.string_key; |
||
169 | * |
||
170 | * @access public |
||
171 | * @var array |
||
172 | */ |
||
173 | public static $i18n_js_strings = array(); |
||
174 | |||
175 | |||
176 | /** |
||
177 | * $main_file - path to espresso.php |
||
178 | * |
||
179 | * @access public |
||
180 | * @var array |
||
181 | */ |
||
182 | public $main_file; |
||
183 | |||
184 | /** |
||
185 | * array of ReflectionClass objects where the key is the class name |
||
186 | * |
||
187 | * @access public |
||
188 | * @var ReflectionClass[] |
||
189 | */ |
||
190 | public $_reflectors; |
||
191 | |||
192 | /** |
||
193 | * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
||
194 | * |
||
195 | * @access protected |
||
196 | * @var boolean $_cache_on |
||
197 | */ |
||
198 | protected $_cache_on = true; |
||
199 | |||
200 | |||
201 | |||
202 | /** |
||
203 | * @singleton method used to instantiate class object |
||
204 | * @access public |
||
205 | * @param \EE_Dependency_Map $dependency_map |
||
206 | * @return \EE_Registry instance |
||
207 | */ |
||
208 | public static function instance(\EE_Dependency_Map $dependency_map = null) |
||
209 | { |
||
210 | // check if class object is instantiated |
||
211 | if ( ! self::$_instance instanceof EE_Registry) { |
||
212 | self::$_instance = new EE_Registry($dependency_map); |
||
|
|||
213 | } |
||
214 | return self::$_instance; |
||
215 | } |
||
216 | |||
217 | |||
218 | |||
219 | /** |
||
220 | *protected constructor to prevent direct creation |
||
221 | * |
||
222 | * @Constructor |
||
223 | * @access protected |
||
224 | * @param \EE_Dependency_Map $dependency_map |
||
225 | */ |
||
226 | protected function __construct(\EE_Dependency_Map $dependency_map) |
||
227 | { |
||
228 | $this->_dependency_map = $dependency_map; |
||
229 | $this->LIB = new stdClass(); |
||
230 | $this->addons = new stdClass(); |
||
231 | $this->modules = new stdClass(); |
||
232 | $this->shortcodes = new stdClass(); |
||
233 | $this->widgets = new stdClass(); |
||
234 | add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
||
235 | } |
||
236 | |||
237 | |||
238 | |||
239 | /** |
||
240 | * initialize |
||
241 | */ |
||
242 | public function initialize() |
||
243 | { |
||
244 | $this->_class_abbreviations = apply_filters( |
||
245 | 'FHEE__EE_Registry____construct___class_abbreviations', |
||
246 | array( |
||
247 | 'EE_Config' => 'CFG', |
||
248 | 'EE_Session' => 'SSN', |
||
249 | 'EE_Capabilities' => 'CAP', |
||
250 | 'EE_Cart' => 'CART', |
||
251 | 'EE_Network_Config' => 'NET_CFG', |
||
252 | 'EE_Request_Handler' => 'REQ', |
||
253 | 'EE_Message_Resource_Manager' => 'MRM', |
||
254 | 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
||
255 | 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
||
256 | ) |
||
257 | ); |
||
258 | $this->load_core('Base', array(), true); |
||
259 | // add our request and response objects to the cache |
||
260 | $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
||
261 | $this->_set_cached_class( |
||
262 | $request_loader(), |
||
263 | 'EE_Request' |
||
264 | ); |
||
265 | $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
||
266 | $this->_set_cached_class( |
||
267 | $response_loader(), |
||
268 | 'EE_Response' |
||
269 | ); |
||
270 | add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
||
271 | } |
||
272 | |||
273 | |||
274 | |||
275 | /** |
||
276 | * init |
||
277 | * |
||
278 | * @access public |
||
279 | * @return void |
||
280 | */ |
||
281 | public function init() |
||
282 | { |
||
283 | // Get current page protocol |
||
284 | $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
||
285 | // Output admin-ajax.php URL with same protocol as current page |
||
286 | self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
||
287 | self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
||
288 | } |
||
289 | |||
290 | |||
291 | |||
292 | /** |
||
293 | * localize_i18n_js_strings |
||
294 | * |
||
295 | * @return string |
||
296 | */ |
||
297 | public static function localize_i18n_js_strings() |
||
307 | |||
308 | |||
309 | |||
310 | /** |
||
311 | * @param mixed string | EED_Module $module |
||
312 | */ |
||
313 | public function add_module($module) |
||
325 | |||
326 | |||
327 | |||
328 | /** |
||
329 | * @param string $module_name |
||
330 | * @return mixed EED_Module | NULL |
||
331 | */ |
||
332 | public function get_module($module_name = '') |
||
336 | |||
337 | |||
338 | |||
339 | /** |
||
340 | * loads core classes - must be singletons |
||
341 | * |
||
342 | * @access public |
||
343 | * @param string $class_name - simple class name ie: session |
||
344 | * @param mixed $arguments |
||
345 | * @param bool $load_only |
||
346 | * @return mixed |
||
347 | */ |
||
348 | public function load_core($class_name, $arguments = array(), $load_only = false) |
||
364 | |||
365 | |||
366 | |||
367 | /** |
||
368 | * loads service classes |
||
369 | * |
||
370 | * @access public |
||
371 | * @param string $class_name - simple class name ie: session |
||
372 | * @param mixed $arguments |
||
373 | * @param bool $load_only |
||
374 | * @return mixed |
||
375 | */ |
||
376 | public function load_service($class_name, $arguments = array(), $load_only = false) |
||
387 | |||
388 | |||
389 | |||
390 | /** |
||
391 | * loads data_migration_scripts |
||
392 | * |
||
393 | * @access public |
||
394 | * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
||
395 | * @param mixed $arguments |
||
396 | * @return EE_Data_Migration_Script_Base|mixed |
||
397 | */ |
||
398 | public function load_dms($class_name, $arguments = array()) |
||
403 | |||
404 | |||
405 | |||
406 | /** |
||
407 | * loads object creating classes - must be singletons |
||
408 | * |
||
409 | * @param string $class_name - simple class name ie: attendee |
||
410 | * @param mixed $arguments - an array of arguments to pass to the class |
||
411 | * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
||
412 | * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
||
413 | * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
||
414 | * @return EE_Base_Class | bool |
||
415 | */ |
||
416 | public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
||
426 | |||
427 | |||
428 | |||
429 | /** |
||
430 | * loads helper classes - must be singletons |
||
431 | * |
||
432 | * @param string $class_name - simple class name ie: price |
||
433 | * @param mixed $arguments |
||
434 | * @param bool $load_only |
||
435 | * @return EEH_Base | bool |
||
436 | */ |
||
437 | public function load_helper($class_name, $arguments = array(), $load_only = true) |
||
444 | |||
445 | |||
446 | |||
447 | /** |
||
448 | * loads core classes - must be singletons |
||
449 | * |
||
450 | * @access public |
||
451 | * @param string $class_name - simple class name ie: session |
||
452 | * @param mixed $arguments |
||
453 | * @param bool $load_only |
||
454 | * @param bool $cache whether to cache the object or not. |
||
455 | * @return mixed |
||
456 | */ |
||
457 | public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
||
469 | |||
470 | |||
471 | |||
472 | /** |
||
473 | * loads model classes - must be singletons |
||
474 | * |
||
475 | * @param string $class_name - simple class name ie: price |
||
476 | * @param mixed $arguments |
||
477 | * @param bool $load_only |
||
478 | * @return EEM_Base | bool |
||
479 | */ |
||
480 | public function load_model($class_name, $arguments = array(), $load_only = false) |
||
489 | |||
490 | |||
491 | |||
492 | /** |
||
493 | * loads model classes - must be singletons |
||
494 | * |
||
495 | * @param string $class_name - simple class name ie: price |
||
496 | * @param mixed $arguments |
||
497 | * @param bool $load_only |
||
498 | * @return mixed | bool |
||
499 | */ |
||
500 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
||
511 | |||
512 | |||
513 | |||
514 | /** |
||
515 | * Determines if $model_name is the name of an actual EE model. |
||
516 | * |
||
517 | * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
||
518 | * @return boolean |
||
519 | */ |
||
520 | public function is_model_name($model_name) |
||
524 | |||
525 | |||
526 | |||
527 | /** |
||
528 | * generic class loader |
||
529 | * |
||
530 | * @param string $path_to_file - directory path to file location, not including filename |
||
531 | * @param string $file_name - file name ie: my_file.php, including extension |
||
532 | * @param string $type - file type - core? class? helper? model? |
||
533 | * @param mixed $arguments |
||
534 | * @param bool $load_only |
||
535 | * @return mixed |
||
536 | */ |
||
537 | public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
||
542 | |||
543 | |||
544 | |||
545 | /** |
||
546 | * load_addon |
||
547 | * |
||
548 | * @param string $path_to_file - directory path to file location, not including filename |
||
549 | * @param string $class_name - full class name ie: My_Class |
||
550 | * @param string $type - file type - core? class? helper? model? |
||
551 | * @param mixed $arguments |
||
552 | * @param bool $load_only |
||
553 | * @return EE_Addon |
||
554 | */ |
||
555 | public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
||
560 | |||
561 | |||
562 | |||
563 | /** |
||
564 | * instantiates, caches, and automatically resolves dependencies |
||
565 | * for classes that use a Fully Qualified Class Name. |
||
566 | * if the class is not capable of being loaded using PSR-4 autoloading, |
||
567 | * then you need to use one of the existing load_*() methods |
||
568 | * which can resolve the classname and filepath from the passed arguments |
||
569 | * |
||
570 | * @param bool|string $class_name Fully Qualified Class Name |
||
571 | * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
||
572 | * @param bool $cache whether to cache the instantiated object for reuse |
||
573 | * @param bool $from_db some classes are instantiated from the db |
||
574 | * and thus call a different method to instantiate |
||
575 | * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
||
576 | * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
||
577 | * @return mixed null = failure to load or instantiate class object. |
||
578 | * object = class loaded and instantiated successfully. |
||
579 | * bool = fail or success when $load_only is true |
||
580 | * @throws EE_Error |
||
581 | */ |
||
582 | public function create( |
||
625 | |||
626 | |||
627 | |||
628 | /** |
||
629 | * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
||
630 | * |
||
631 | * @param string $class_name |
||
632 | * @param array $arguments |
||
633 | * @param int $attempt |
||
634 | * @return mixed |
||
635 | */ |
||
636 | private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) { |
||
661 | |||
662 | |||
663 | |||
664 | /** |
||
665 | * instantiates, caches, and injects dependencies for classes |
||
666 | * |
||
667 | * @param array $file_paths an array of paths to folders to look in |
||
668 | * @param string $class_prefix EE or EEM or... ??? |
||
669 | * @param bool|string $class_name $class name |
||
670 | * @param string $type file type - core? class? helper? model? |
||
671 | * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
||
672 | * @param bool $from_db some classes are instantiated from the db |
||
673 | * and thus call a different method to instantiate |
||
674 | * @param bool $cache whether to cache the instantiated object for reuse |
||
675 | * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
||
676 | * @return bool|null|object null = failure to load or instantiate class object. |
||
677 | * object = class loaded and instantiated successfully. |
||
678 | * bool = fail or success when $load_only is true |
||
679 | * @throws EE_Error |
||
680 | */ |
||
681 | protected function _load( |
||
738 | |||
739 | |||
740 | |||
741 | |||
742 | /** |
||
743 | * _get_cached_class |
||
744 | * attempts to find a cached version of the requested class |
||
745 | * by looking in the following places: |
||
746 | * $this->{$class_abbreviation} ie: $this->CART |
||
747 | * $this->{$class_name} ie: $this->Some_Class |
||
748 | * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
||
749 | * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
||
750 | * |
||
751 | * @access protected |
||
752 | * @param string $class_name |
||
753 | * @param string $class_prefix |
||
754 | * @return mixed |
||
755 | */ |
||
756 | protected function _get_cached_class($class_name, $class_prefix = '') |
||
781 | |||
782 | |||
783 | |||
784 | /** |
||
785 | * removes a cached version of the requested class |
||
786 | * |
||
787 | * @param string $class_name |
||
788 | * @param boolean $addon |
||
789 | * @return boolean |
||
790 | */ |
||
791 | public function clear_cached_class($class_name, $addon = false) |
||
817 | |||
818 | |||
819 | /** |
||
820 | * _resolve_path |
||
821 | * attempts to find a full valid filepath for the requested class. |
||
822 | * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
||
823 | * then returns that path if the target file has been found and is readable |
||
824 | * |
||
825 | * @access protected |
||
826 | * @param string $class_name |
||
827 | * @param string $type |
||
828 | * @param array $file_paths |
||
829 | * @return string | bool |
||
830 | */ |
||
831 | protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
||
850 | |||
851 | |||
852 | |||
853 | /** |
||
854 | * _require_file |
||
855 | * basically just performs a require_once() |
||
856 | * but with some error handling |
||
857 | * |
||
858 | * @access protected |
||
859 | * @param string $path |
||
860 | * @param string $class_name |
||
861 | * @param string $type |
||
862 | * @param array $file_paths |
||
863 | * @return boolean |
||
864 | * @throws \EE_Error |
||
865 | */ |
||
866 | protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
||
902 | |||
903 | |||
904 | |||
905 | /** |
||
906 | * _create_object |
||
907 | * Attempts to instantiate the requested class via any of the |
||
908 | * commonly used instantiation methods employed throughout EE. |
||
909 | * The priority for instantiation is as follows: |
||
910 | * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
||
911 | * - model objects via their 'new_instance_from_db' method |
||
912 | * - model objects via their 'new_instance' method |
||
913 | * - "singleton" classes" via their 'instance' method |
||
914 | * - standard instantiable classes via their __constructor |
||
915 | * Prior to instantiation, if the classname exists in the dependency_map, |
||
916 | * then the constructor for the requested class will be examined to determine |
||
917 | * if any dependencies exist, and if they can be injected. |
||
918 | * If so, then those classes will be added to the array of arguments passed to the constructor |
||
919 | * |
||
920 | * @access protected |
||
921 | * @param string $class_name |
||
922 | * @param array $arguments |
||
923 | * @param string $type |
||
924 | * @param bool $from_db |
||
925 | * @return null | object |
||
926 | * @throws \EE_Error |
||
927 | */ |
||
928 | protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
||
995 | |||
996 | |||
997 | |||
998 | /** |
||
999 | * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
||
1000 | * @param array $array |
||
1001 | * @return bool |
||
1002 | */ |
||
1003 | protected function _array_is_numerically_and_sequentially_indexed(array $array) |
||
1007 | |||
1008 | |||
1009 | |||
1010 | /** |
||
1011 | * getReflectionClass |
||
1012 | * checks if a ReflectionClass object has already been generated for a class |
||
1013 | * and returns that instead of creating a new one |
||
1014 | * |
||
1015 | * @access public |
||
1016 | * @param string $class_name |
||
1017 | * @return ReflectionClass |
||
1018 | */ |
||
1019 | View Code Duplication | public function get_ReflectionClass($class_name) |
|
1029 | |||
1030 | |||
1031 | |||
1032 | /** |
||
1033 | * _resolve_dependencies |
||
1034 | * examines the constructor for the requested class to determine |
||
1035 | * if any dependencies exist, and if they can be injected. |
||
1036 | * If so, then those classes will be added to the array of arguments passed to the constructor |
||
1037 | * PLZ NOTE: this is achieved by type hinting the constructor params |
||
1038 | * For example: |
||
1039 | * if attempting to load a class "Foo" with the following constructor: |
||
1040 | * __construct( Bar $bar_class, Fighter $grohl_class ) |
||
1041 | * then $bar_class and $grohl_class will be added to the $arguments array, |
||
1042 | * but only IF they are NOT already present in the incoming arguments array, |
||
1043 | * and the correct classes can be loaded |
||
1044 | * |
||
1045 | * @access protected |
||
1046 | * @param ReflectionClass $reflector |
||
1047 | * @param string $class_name |
||
1048 | * @param array $arguments |
||
1049 | * @return array |
||
1050 | * @throws \ReflectionException |
||
1051 | */ |
||
1052 | protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
||
1112 | |||
1113 | |||
1114 | |||
1115 | /** |
||
1116 | * @access protected |
||
1117 | * @param string $class_name |
||
1118 | * @param string $param_class |
||
1119 | * @param array $arguments |
||
1120 | * @param mixed $index |
||
1121 | * @return array |
||
1122 | */ |
||
1123 | protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
||
1165 | |||
1166 | |||
1167 | |||
1168 | /** |
||
1169 | * _set_cached_class |
||
1170 | * attempts to cache the instantiated class locally |
||
1171 | * in one of the following places, in the following order: |
||
1172 | * $this->{class_abbreviation} ie: $this->CART |
||
1173 | * $this->{$class_name} ie: $this->Some_Class |
||
1174 | * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
||
1175 | * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
||
1176 | * |
||
1177 | * @access protected |
||
1178 | * @param object $class_obj |
||
1179 | * @param string $class_name |
||
1180 | * @param string $class_prefix |
||
1181 | * @param bool $from_db |
||
1182 | * @return void |
||
1183 | */ |
||
1184 | protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
||
1208 | |||
1209 | |||
1210 | |||
1211 | /** |
||
1212 | * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
||
1213 | * |
||
1214 | * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
||
1215 | * in the EE_Dependency_Map::$_class_loaders array, |
||
1216 | * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
||
1217 | * @param array $arguments |
||
1218 | * @return object |
||
1219 | */ |
||
1220 | public static function factory($classname, $arguments = array()) |
||
1231 | |||
1232 | |||
1233 | |||
1234 | /** |
||
1235 | * Gets the addon by its name/slug (not classname. For that, just |
||
1236 | * use the classname as the property name on EE_Config::instance()->addons) |
||
1237 | * |
||
1238 | * @param string $name |
||
1239 | * @return EE_Addon |
||
1240 | */ |
||
1241 | public function get_addon_by_name($name) |
||
1250 | |||
1251 | |||
1252 | |||
1253 | /** |
||
1254 | * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
||
1255 | * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
||
1256 | * |
||
1257 | * @return EE_Addon[] where the KEYS are the addon's name() |
||
1258 | */ |
||
1259 | public function get_addons_by_name() |
||
1267 | |||
1268 | |||
1269 | |||
1270 | /** |
||
1271 | * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
||
1272 | * a stale copy of it around |
||
1273 | * |
||
1274 | * @param string $model_name |
||
1275 | * @return \EEM_Base |
||
1276 | * @throws \EE_Error |
||
1277 | */ |
||
1278 | public function reset_model($model_name) |
||
1292 | |||
1293 | |||
1294 | |||
1295 | /** |
||
1296 | * Resets the registry. |
||
1297 | * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
||
1298 | * is used in a multisite install. Here is a list of things that are NOT reset. |
||
1299 | * - $_dependency_map |
||
1300 | * - $_class_abbreviations |
||
1301 | * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
||
1302 | * - $REQ: Still on the same request so no need to change. |
||
1303 | * - $CAP: There is no site specific state in the EE_Capability class. |
||
1304 | * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
||
1305 | * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
||
1306 | * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
||
1307 | * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
||
1308 | * switch or on the restore. |
||
1309 | * - $modules |
||
1310 | * - $shortcodes |
||
1311 | * - $widgets |
||
1312 | * |
||
1313 | * @param boolean $hard whether to reset data in the database too, or just refresh |
||
1314 | * the Registry to its state at the beginning of the request |
||
1315 | * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
||
1316 | * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
||
1317 | * currently reinstantiate the singletons at the moment) |
||
1318 | * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
||
1319 | * code instead can just change the model context to a different blog id if necessary |
||
1320 | * @return EE_Registry |
||
1321 | */ |
||
1322 | public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
||
1345 | |||
1346 | |||
1347 | |||
1348 | /** |
||
1349 | * if passed object implements ResettableInterface, then call it's reset() method |
||
1350 | * if passed object implements InterminableInterface, then return false, |
||
1351 | * to indicate that it should NOT be cleared from the Registry cache |
||
1352 | * |
||
1353 | * @param $object |
||
1354 | * @param bool $reset_models |
||
1355 | * @return bool returns true if cached object should be unset |
||
1356 | */ |
||
1357 | private static function _reset_and_unset_object($object, $reset_models) |
||
1377 | |||
1378 | |||
1379 | |||
1380 | /** |
||
1381 | * @override magic methods |
||
1382 | * @return void |
||
1383 | */ |
||
1384 | public final function __destruct() |
||
1387 | |||
1388 | |||
1389 | |||
1390 | /** |
||
1391 | * @param $a |
||
1392 | * @param $b |
||
1393 | */ |
||
1394 | public final function __call($a, $b) |
||
1397 | |||
1398 | |||
1399 | |||
1400 | /** |
||
1401 | * @param $a |
||
1402 | */ |
||
1403 | public final function __get($a) |
||
1406 | |||
1407 | |||
1408 | |||
1409 | /** |
||
1410 | * @param $a |
||
1411 | * @param $b |
||
1412 | */ |
||
1413 | public final function __set($a, $b) |
||
1416 | |||
1417 | |||
1418 | |||
1419 | /** |
||
1420 | * @param $a |
||
1421 | */ |
||
1422 | public final function __isset($a) |
||
1425 | |||
1426 | |||
1427 | |||
1428 | /** |
||
1429 | * @param $a |
||
1430 | */ |
||
1431 | public final function __unset($a) |
||
1434 | |||
1435 | |||
1436 | |||
1437 | /** |
||
1438 | * @return array |
||
1439 | */ |
||
1440 | public final function __sleep() |
||
1444 | |||
1445 | |||
1446 | |||
1447 | public final function __wakeup() |
||
1450 | |||
1451 | |||
1452 | |||
1453 | /** |
||
1454 | * @return string |
||
1455 | */ |
||
1456 | public final function __toString() |
||
1460 | |||
1461 | |||
1462 | |||
1463 | public final function __invoke() |
||
1466 | |||
1467 | |||
1468 | |||
1469 | public final static function __set_state($array = array()) |
||
1473 | |||
1474 | |||
1475 | |||
1476 | public final function __clone() |
||
1479 | |||
1480 | |||
1481 | |||
1482 | /** |
||
1483 | * @param $a |
||
1484 | * @param $b |
||
1485 | */ |
||
1486 | public final static function __callStatic($a, $b) |
||
1489 | |||
1490 | |||
1491 | |||
1492 | /** |
||
1493 | * Gets all the custom post type models defined |
||
1494 | * |
||
1495 | * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
||
1496 | */ |
||
1497 | public function cpt_models() |
||
1507 | |||
1508 | |||
1509 | |||
1510 | /** |
||
1511 | * @return \EE_Config |
||
1512 | */ |
||
1513 | public static function CFG() |
||
1517 | |||
1518 | |||
1519 | } |
||
1520 | // End of file EE_Registry.core.php |
||
1522 |
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):