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 |
||
23 | class EE_Registry implements ResettableInterface |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * @var EE_Registry $_instance |
||
28 | */ |
||
29 | private static $_instance; |
||
30 | |||
31 | /** |
||
32 | * @var EE_Dependency_Map $_dependency_map |
||
33 | */ |
||
34 | protected $_dependency_map; |
||
35 | |||
36 | /** |
||
37 | * @var array $_class_abbreviations |
||
38 | */ |
||
39 | protected $_class_abbreviations = array(); |
||
40 | |||
41 | /** |
||
42 | * @var CommandBusInterface $BUS |
||
43 | */ |
||
44 | public $BUS; |
||
45 | |||
46 | /** |
||
47 | * @var EE_Cart $CART |
||
48 | */ |
||
49 | public $CART; |
||
50 | |||
51 | /** |
||
52 | * @var EE_Config $CFG |
||
53 | */ |
||
54 | public $CFG; |
||
55 | |||
56 | /** |
||
57 | * @var EE_Network_Config $NET_CFG |
||
58 | */ |
||
59 | public $NET_CFG; |
||
60 | |||
61 | /** |
||
62 | * StdClass object for storing library classes in |
||
63 | * |
||
64 | * @var StdClass $LIB |
||
65 | */ |
||
66 | public $LIB; |
||
67 | |||
68 | /** |
||
69 | * @var EE_Request_Handler $REQ |
||
70 | */ |
||
71 | public $REQ; |
||
72 | |||
73 | /** |
||
74 | * @var EE_Session $SSN |
||
75 | */ |
||
76 | public $SSN; |
||
77 | |||
78 | /** |
||
79 | * @since 4.5.0 |
||
80 | * @var EE_Capabilities $CAP |
||
81 | */ |
||
82 | public $CAP; |
||
83 | |||
84 | /** |
||
85 | * @since 4.9.0 |
||
86 | * @var EE_Message_Resource_Manager $MRM |
||
87 | */ |
||
88 | public $MRM; |
||
89 | |||
90 | |||
91 | /** |
||
92 | * @var Registry $AssetsRegistry |
||
93 | */ |
||
94 | public $AssetsRegistry; |
||
95 | |||
96 | /** |
||
97 | * StdClass object for holding addons which have registered themselves to work with EE core |
||
98 | * |
||
99 | * @var EE_Addon[] $addons |
||
100 | */ |
||
101 | public $addons; |
||
102 | |||
103 | /** |
||
104 | * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
||
105 | * |
||
106 | * @var EEM_Base[] $models |
||
107 | */ |
||
108 | public $models = array(); |
||
109 | |||
110 | /** |
||
111 | * @var EED_Module[] $modules |
||
112 | */ |
||
113 | public $modules; |
||
114 | |||
115 | /** |
||
116 | * @var EES_Shortcode[] $shortcodes |
||
117 | */ |
||
118 | public $shortcodes; |
||
119 | |||
120 | /** |
||
121 | * @var WP_Widget[] $widgets |
||
122 | */ |
||
123 | public $widgets; |
||
124 | |||
125 | /** |
||
126 | * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
||
127 | * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
||
128 | * Keys are model "short names" (eg "Event") as used in model relations, and values are |
||
129 | * classnames (eg "EEM_Event") |
||
130 | * |
||
131 | * @var array $non_abstract_db_models |
||
132 | */ |
||
133 | public $non_abstract_db_models = array(); |
||
134 | |||
135 | |||
136 | /** |
||
137 | * internationalization for JS strings |
||
138 | * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
||
139 | * in js file: var translatedString = eei18n.string_key; |
||
140 | * |
||
141 | * @var array $i18n_js_strings |
||
142 | */ |
||
143 | public static $i18n_js_strings = array(); |
||
144 | |||
145 | |||
146 | /** |
||
147 | * $main_file - path to espresso.php |
||
148 | * |
||
149 | * @var array $main_file |
||
150 | */ |
||
151 | public $main_file; |
||
152 | |||
153 | /** |
||
154 | * array of ReflectionClass objects where the key is the class name |
||
155 | * |
||
156 | * @var ReflectionClass[] $_reflectors |
||
157 | */ |
||
158 | public $_reflectors; |
||
159 | |||
160 | /** |
||
161 | * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
||
162 | * |
||
163 | * @var boolean $_cache_on |
||
164 | */ |
||
165 | protected $_cache_on = true; |
||
166 | |||
167 | |||
168 | |||
169 | /** |
||
170 | * @singleton method used to instantiate class object |
||
171 | * @param EE_Dependency_Map $dependency_map |
||
172 | * @return EE_Registry instance |
||
173 | * @throws InvalidArgumentException |
||
174 | * @throws InvalidInterfaceException |
||
175 | * @throws InvalidDataTypeException |
||
176 | */ |
||
177 | public static function instance(EE_Dependency_Map $dependency_map = null) |
||
185 | |||
186 | |||
187 | |||
188 | /** |
||
189 | * protected constructor to prevent direct creation |
||
190 | * |
||
191 | * @Constructor |
||
192 | * @param EE_Dependency_Map $dependency_map |
||
193 | * @throws InvalidDataTypeException |
||
194 | * @throws InvalidInterfaceException |
||
195 | * @throws InvalidArgumentException |
||
196 | */ |
||
197 | protected function __construct(EE_Dependency_Map $dependency_map) |
||
208 | |||
209 | |||
210 | |||
211 | /** |
||
212 | * initialize |
||
213 | * |
||
214 | * @throws EE_Error |
||
215 | * @throws ReflectionException |
||
216 | */ |
||
217 | public function initialize() |
||
247 | |||
248 | |||
249 | |||
250 | /** |
||
251 | * @return void |
||
252 | */ |
||
253 | public function init() |
||
261 | |||
262 | |||
263 | |||
264 | /** |
||
265 | * localize_i18n_js_strings |
||
266 | * |
||
267 | * @return string |
||
268 | */ |
||
269 | public static function localize_i18n_js_strings() |
||
279 | |||
280 | |||
281 | |||
282 | /** |
||
283 | * @param mixed string | EED_Module $module |
||
284 | * @throws EE_Error |
||
285 | * @throws ReflectionException |
||
286 | */ |
||
287 | public function add_module($module) |
||
299 | |||
300 | |||
301 | |||
302 | /** |
||
303 | * @param string $module_name |
||
304 | * @return mixed EED_Module | NULL |
||
305 | */ |
||
306 | public function get_module($module_name = '') |
||
312 | |||
313 | |||
314 | |||
315 | /** |
||
316 | * loads core classes - must be singletons |
||
317 | * |
||
318 | * @param string $class_name - simple class name ie: session |
||
319 | * @param mixed $arguments |
||
320 | * @param bool $load_only |
||
321 | * @return mixed |
||
322 | * @throws EE_Error |
||
323 | * @throws ReflectionException |
||
324 | */ |
||
325 | public function load_core($class_name, $arguments = array(), $load_only = false) |
||
351 | |||
352 | |||
353 | |||
354 | /** |
||
355 | * loads service classes |
||
356 | * |
||
357 | * @param string $class_name - simple class name ie: session |
||
358 | * @param mixed $arguments |
||
359 | * @param bool $load_only |
||
360 | * @return mixed |
||
361 | * @throws EE_Error |
||
362 | * @throws ReflectionException |
||
363 | */ |
||
364 | public function load_service($class_name, $arguments = array(), $load_only = false) |
||
384 | |||
385 | |||
386 | |||
387 | /** |
||
388 | * loads data_migration_scripts |
||
389 | * |
||
390 | * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
||
391 | * @param mixed $arguments |
||
392 | * @return EE_Data_Migration_Script_Base|mixed |
||
393 | * @throws EE_Error |
||
394 | * @throws ReflectionException |
||
395 | */ |
||
396 | public function load_dms($class_name, $arguments = array()) |
||
409 | |||
410 | |||
411 | |||
412 | /** |
||
413 | * loads object creating classes - must be singletons |
||
414 | * |
||
415 | * @param string $class_name - simple class name ie: attendee |
||
416 | * @param mixed $arguments - an array of arguments to pass to the class |
||
417 | * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
||
418 | * instantiate |
||
419 | * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
||
420 | * set this to FALSE (ie. when instantiating model objects from client in a loop) |
||
421 | * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
||
422 | * (default) |
||
423 | * @return EE_Base_Class | bool |
||
424 | * @throws EE_Error |
||
425 | * @throws ReflectionException |
||
426 | */ |
||
427 | public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
||
448 | |||
449 | |||
450 | |||
451 | /** |
||
452 | * loads helper classes - must be singletons |
||
453 | * |
||
454 | * @param string $class_name - simple class name ie: price |
||
455 | * @param mixed $arguments |
||
456 | * @param bool $load_only |
||
457 | * @return EEH_Base | bool |
||
458 | * @throws EE_Error |
||
459 | * @throws ReflectionException |
||
460 | */ |
||
461 | public function load_helper($class_name, $arguments = array(), $load_only = true) |
||
477 | |||
478 | |||
479 | |||
480 | /** |
||
481 | * loads core classes - must be singletons |
||
482 | * |
||
483 | * @param string $class_name - simple class name ie: session |
||
484 | * @param mixed $arguments |
||
485 | * @param bool $load_only |
||
486 | * @param bool $cache whether to cache the object or not. |
||
487 | * @return mixed |
||
488 | * @throws EE_Error |
||
489 | * @throws ReflectionException |
||
490 | */ |
||
491 | public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
||
512 | |||
513 | |||
514 | |||
515 | /** |
||
516 | * loads model classes - must be singletons |
||
517 | * |
||
518 | * @param string $class_name - simple class name ie: price |
||
519 | * @param mixed $arguments |
||
520 | * @param bool $load_only |
||
521 | * @return EEM_Base | bool |
||
522 | * @throws EE_Error |
||
523 | * @throws ReflectionException |
||
524 | */ |
||
525 | public function load_model($class_name, $arguments = array(), $load_only = false) |
||
545 | |||
546 | |||
547 | |||
548 | /** |
||
549 | * loads model classes - must be singletons |
||
550 | * |
||
551 | * @param string $class_name - simple class name ie: price |
||
552 | * @param mixed $arguments |
||
553 | * @param bool $load_only |
||
554 | * @return mixed | bool |
||
555 | * @throws EE_Error |
||
556 | * @throws ReflectionException |
||
557 | */ |
||
558 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
||
578 | |||
579 | |||
580 | |||
581 | /** |
||
582 | * Determines if $model_name is the name of an actual EE model. |
||
583 | * |
||
584 | * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
||
585 | * @return boolean |
||
586 | */ |
||
587 | public function is_model_name($model_name) |
||
591 | |||
592 | |||
593 | |||
594 | /** |
||
595 | * generic class loader |
||
596 | * |
||
597 | * @param string $path_to_file - directory path to file location, not including filename |
||
598 | * @param string $file_name - file name ie: my_file.php, including extension |
||
599 | * @param string $type - file type - core? class? helper? model? |
||
600 | * @param mixed $arguments |
||
601 | * @param bool $load_only |
||
602 | * @return mixed |
||
603 | * @throws EE_Error |
||
604 | * @throws ReflectionException |
||
605 | */ |
||
606 | public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
||
620 | |||
621 | |||
622 | |||
623 | /** |
||
624 | * @param string $path_to_file - directory path to file location, not including filename |
||
625 | * @param string $class_name - full class name ie: My_Class |
||
626 | * @param string $type - file type - core? class? helper? model? |
||
627 | * @param mixed $arguments |
||
628 | * @param bool $load_only |
||
629 | * @return bool|EE_Addon|object |
||
630 | * @throws EE_Error |
||
631 | * @throws ReflectionException |
||
632 | */ |
||
633 | public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
||
647 | |||
648 | |||
649 | |||
650 | /** |
||
651 | * instantiates, caches, and automatically resolves dependencies |
||
652 | * for classes that use a Fully Qualified Class Name. |
||
653 | * if the class is not capable of being loaded using PSR-4 autoloading, |
||
654 | * then you need to use one of the existing load_*() methods |
||
655 | * which can resolve the classname and filepath from the passed arguments |
||
656 | * |
||
657 | * @param bool|string $class_name Fully Qualified Class Name |
||
658 | * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
||
659 | * @param bool $cache whether to cache the instantiated object for reuse |
||
660 | * @param bool $from_db some classes are instantiated from the db |
||
661 | * and thus call a different method to instantiate |
||
662 | * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
||
663 | * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
||
664 | * @return bool|null|mixed null = failure to load or instantiate class object. |
||
665 | * object = class loaded and instantiated successfully. |
||
666 | * bool = fail or success when $load_only is true |
||
667 | * @throws EE_Error |
||
668 | * @throws ReflectionException |
||
669 | */ |
||
670 | public function create( |
||
722 | |||
723 | |||
724 | |||
725 | /** |
||
726 | * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
||
727 | * |
||
728 | * @param string $class_name |
||
729 | * @param array $arguments |
||
730 | * @param int $attempt |
||
731 | * @return mixed |
||
732 | */ |
||
733 | private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) { |
||
758 | |||
759 | |||
760 | |||
761 | /** |
||
762 | * instantiates, caches, and injects dependencies for classes |
||
763 | * |
||
764 | * @param array $file_paths an array of paths to folders to look in |
||
765 | * @param string $class_prefix EE or EEM or... ??? |
||
766 | * @param bool|string $class_name $class name |
||
767 | * @param string $type file type - core? class? helper? model? |
||
768 | * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
||
769 | * @param bool $from_db some classes are instantiated from the db |
||
770 | * and thus call a different method to instantiate |
||
771 | * @param bool $cache whether to cache the instantiated object for reuse |
||
772 | * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
||
773 | * @return bool|null|object null = failure to load or instantiate class object. |
||
774 | * object = class loaded and instantiated successfully. |
||
775 | * bool = fail or success when $load_only is true |
||
776 | * @throws EE_Error |
||
777 | * @throws ReflectionException |
||
778 | */ |
||
779 | protected function _load( |
||
838 | |||
839 | |||
840 | |||
841 | /** |
||
842 | * @param string $class_name |
||
843 | * @param string $default have to specify something, but not anything that will conflict |
||
844 | * @return mixed|string |
||
845 | */ |
||
846 | protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
||
852 | |||
853 | /** |
||
854 | * attempts to find a cached version of the requested class |
||
855 | * by looking in the following places: |
||
856 | * $this->{$class_abbreviation} ie: $this->CART |
||
857 | * $this->{$class_name} ie: $this->Some_Class |
||
858 | * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
||
859 | * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
||
860 | * |
||
861 | * @param string $class_name |
||
862 | * @param string $class_prefix |
||
863 | * @return mixed |
||
864 | */ |
||
865 | protected function _get_cached_class($class_name, $class_prefix = '') |
||
887 | |||
888 | |||
889 | |||
890 | /** |
||
891 | * removes a cached version of the requested class |
||
892 | * |
||
893 | * @param string $class_name |
||
894 | * @param boolean $addon |
||
895 | * @return boolean |
||
896 | */ |
||
897 | public function clear_cached_class($class_name, $addon = false) |
||
920 | |||
921 | |||
922 | |||
923 | /** |
||
924 | * attempts to find a full valid filepath for the requested class. |
||
925 | * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
||
926 | * then returns that path if the target file has been found and is readable |
||
927 | * |
||
928 | * @param string $class_name |
||
929 | * @param string $type |
||
930 | * @param array $file_paths |
||
931 | * @return string | bool |
||
932 | */ |
||
933 | protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
||
958 | |||
959 | |||
960 | |||
961 | /** |
||
962 | * basically just performs a require_once() |
||
963 | * but with some error handling |
||
964 | * |
||
965 | * @param string $path |
||
966 | * @param string $class_name |
||
967 | * @param string $type |
||
968 | * @param array $file_paths |
||
969 | * @return bool |
||
970 | * @throws EE_Error |
||
971 | * @throws ReflectionException |
||
972 | */ |
||
973 | protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
||
1021 | |||
1022 | |||
1023 | |||
1024 | /** |
||
1025 | * Some of our legacy classes that extended a parent class would simply use a require() statement |
||
1026 | * before their class declaration in order to ensure that the parent class was loaded. |
||
1027 | * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
||
1028 | * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
||
1029 | * |
||
1030 | * @param string $class_name |
||
1031 | */ |
||
1032 | protected function resolve_legacy_class_parent($class_name = '') |
||
1044 | |||
1045 | |||
1046 | |||
1047 | /** |
||
1048 | * _create_object |
||
1049 | * Attempts to instantiate the requested class via any of the |
||
1050 | * commonly used instantiation methods employed throughout EE. |
||
1051 | * The priority for instantiation is as follows: |
||
1052 | * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
||
1053 | * - model objects via their 'new_instance_from_db' method |
||
1054 | * - model objects via their 'new_instance' method |
||
1055 | * - "singleton" classes" via their 'instance' method |
||
1056 | * - standard instantiable classes via their __constructor |
||
1057 | * Prior to instantiation, if the classname exists in the dependency_map, |
||
1058 | * then the constructor for the requested class will be examined to determine |
||
1059 | * if any dependencies exist, and if they can be injected. |
||
1060 | * If so, then those classes will be added to the array of arguments passed to the constructor |
||
1061 | * |
||
1062 | * @param string $class_name |
||
1063 | * @param array $arguments |
||
1064 | * @param string $type |
||
1065 | * @param bool $from_db |
||
1066 | * @return null|object |
||
1067 | * @throws EE_Error |
||
1068 | * @throws ReflectionException |
||
1069 | */ |
||
1070 | protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
||
1124 | |||
1125 | |||
1126 | |||
1127 | /** |
||
1128 | * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
||
1129 | * @param array $array |
||
1130 | * @return bool |
||
1131 | */ |
||
1132 | protected function _array_is_numerically_and_sequentially_indexed(array $array) |
||
1138 | |||
1139 | |||
1140 | |||
1141 | /** |
||
1142 | * getReflectionClass |
||
1143 | * checks if a ReflectionClass object has already been generated for a class |
||
1144 | * and returns that instead of creating a new one |
||
1145 | * |
||
1146 | * @param string $class_name |
||
1147 | * @return ReflectionClass |
||
1148 | * @throws ReflectionException |
||
1149 | */ |
||
1150 | View Code Duplication | public function get_ReflectionClass($class_name) |
|
1160 | |||
1161 | |||
1162 | |||
1163 | /** |
||
1164 | * _resolve_dependencies |
||
1165 | * examines the constructor for the requested class to determine |
||
1166 | * if any dependencies exist, and if they can be injected. |
||
1167 | * If so, then those classes will be added to the array of arguments passed to the constructor |
||
1168 | * PLZ NOTE: this is achieved by type hinting the constructor params |
||
1169 | * For example: |
||
1170 | * if attempting to load a class "Foo" with the following constructor: |
||
1171 | * __construct( Bar $bar_class, Fighter $grohl_class ) |
||
1172 | * then $bar_class and $grohl_class will be added to the $arguments array, |
||
1173 | * but only IF they are NOT already present in the incoming arguments array, |
||
1174 | * and the correct classes can be loaded |
||
1175 | * |
||
1176 | * @param ReflectionClass $reflector |
||
1177 | * @param string $class_name |
||
1178 | * @param array $arguments |
||
1179 | * @return array |
||
1180 | * @throws EE_Error |
||
1181 | * @throws ReflectionException |
||
1182 | */ |
||
1183 | protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
||
1255 | |||
1256 | |||
1257 | |||
1258 | /** |
||
1259 | * @param string $class_name |
||
1260 | * @param string $param_class |
||
1261 | * @param array $arguments |
||
1262 | * @param mixed $index |
||
1263 | * @param array $argument_keys |
||
1264 | * @return array |
||
1265 | * @throws EE_Error |
||
1266 | * @throws ReflectionException |
||
1267 | * @throws InvalidArgumentException |
||
1268 | * @throws InvalidInterfaceException |
||
1269 | * @throws InvalidDataTypeException |
||
1270 | */ |
||
1271 | protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys) |
||
1316 | |||
1317 | |||
1318 | |||
1319 | /** |
||
1320 | * _set_cached_class |
||
1321 | * attempts to cache the instantiated class locally |
||
1322 | * in one of the following places, in the following order: |
||
1323 | * $this->{class_abbreviation} ie: $this->CART |
||
1324 | * $this->{$class_name} ie: $this->Some_Class |
||
1325 | * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
||
1326 | * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
||
1327 | * |
||
1328 | * @param object $class_obj |
||
1329 | * @param string $class_name |
||
1330 | * @param string $class_prefix |
||
1331 | * @param bool $from_db |
||
1332 | * @return void |
||
1333 | */ |
||
1334 | protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
||
1358 | |||
1359 | |||
1360 | |||
1361 | /** |
||
1362 | * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
||
1363 | * |
||
1364 | * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
||
1365 | * in the EE_Dependency_Map::$_class_loaders array, |
||
1366 | * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
||
1367 | * @param array $arguments |
||
1368 | * @return object |
||
1369 | */ |
||
1370 | public static function factory($classname, $arguments = array()) |
||
1381 | |||
1382 | |||
1383 | |||
1384 | /** |
||
1385 | * Gets the addon by its class name |
||
1386 | * |
||
1387 | * @param string $class_name |
||
1388 | * @return EE_Addon |
||
1389 | */ |
||
1390 | public function getAddon($class_name) |
||
1395 | |||
1396 | |||
1397 | /** |
||
1398 | * removes the addon from the internal cache |
||
1399 | * |
||
1400 | * @param string $class_name |
||
1401 | * @return void |
||
1402 | */ |
||
1403 | public function removeAddon($class_name) |
||
1408 | |||
1409 | |||
1410 | |||
1411 | /** |
||
1412 | * Gets the addon by its name/slug (not classname. For that, just |
||
1413 | * use the get_addon() method above |
||
1414 | * |
||
1415 | * @param string $name |
||
1416 | * @return EE_Addon |
||
1417 | */ |
||
1418 | public function get_addon_by_name($name) |
||
1427 | |||
1428 | |||
1429 | |||
1430 | /** |
||
1431 | * Gets an array of all the registered addons, where the keys are their names. |
||
1432 | * (ie, what each returns for their name() function) |
||
1433 | * They're already available on EE_Registry::instance()->addons as properties, |
||
1434 | * where each property's name is the addon's classname, |
||
1435 | * So if you just want to get the addon by classname, |
||
1436 | * OR use the get_addon() method above. |
||
1437 | * PLEASE NOTE: |
||
1438 | * addons with Fully Qualified Class Names |
||
1439 | * have had the namespace separators converted to underscores, |
||
1440 | * so a classname like Fully\Qualified\ClassName |
||
1441 | * would have been converted to Fully_Qualified_ClassName |
||
1442 | * |
||
1443 | * @return EE_Addon[] where the KEYS are the addon's name() |
||
1444 | */ |
||
1445 | public function get_addons_by_name() |
||
1453 | |||
1454 | |||
1455 | /** |
||
1456 | * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
||
1457 | * a stale copy of it around |
||
1458 | * |
||
1459 | * @param string $model_name |
||
1460 | * @return \EEM_Base |
||
1461 | * @throws \EE_Error |
||
1462 | */ |
||
1463 | public function reset_model($model_name) |
||
1482 | |||
1483 | |||
1484 | |||
1485 | /** |
||
1486 | * Resets the registry. |
||
1487 | * The criteria for what gets reset is based on what can be shared between sites on the same request when |
||
1488 | * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
||
1489 | * - $_dependency_map |
||
1490 | * - $_class_abbreviations |
||
1491 | * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
||
1492 | * - $REQ: Still on the same request so no need to change. |
||
1493 | * - $CAP: There is no site specific state in the EE_Capability class. |
||
1494 | * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
||
1495 | * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
||
1496 | * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
||
1497 | * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
||
1498 | * switch or on the restore. |
||
1499 | * - $modules |
||
1500 | * - $shortcodes |
||
1501 | * - $widgets |
||
1502 | * |
||
1503 | * @param boolean $hard [deprecated] |
||
1504 | * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
||
1505 | * or just reset without re-instantiating (handy to set to FALSE if you're not |
||
1506 | * sure if you CAN currently reinstantiate the singletons at the moment) |
||
1507 | * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
||
1508 | * client |
||
1509 | * code instead can just change the model context to a different blog id if |
||
1510 | * necessary |
||
1511 | * @return EE_Registry |
||
1512 | * @throws EE_Error |
||
1513 | * @throws ReflectionException |
||
1514 | */ |
||
1515 | public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
||
1538 | |||
1539 | |||
1540 | |||
1541 | /** |
||
1542 | * if passed object implements ResettableInterface, then call it's reset() method |
||
1543 | * if passed object implements InterminableInterface, then return false, |
||
1544 | * to indicate that it should NOT be cleared from the Registry cache |
||
1545 | * |
||
1546 | * @param $object |
||
1547 | * @param bool $reset_models |
||
1548 | * @return bool returns true if cached object should be unset |
||
1549 | */ |
||
1550 | private static function _reset_and_unset_object($object, $reset_models) |
||
1577 | |||
1578 | |||
1579 | |||
1580 | /** |
||
1581 | * Gets all the custom post type models defined |
||
1582 | * |
||
1583 | * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
||
1584 | */ |
||
1585 | public function cpt_models() |
||
1595 | |||
1596 | |||
1597 | |||
1598 | /** |
||
1599 | * @return \EE_Config |
||
1600 | */ |
||
1601 | public static function CFG() |
||
1605 | |||
1606 | |||
1607 | } |
||
1608 | // End of file EE_Registry.core.php |
||
1610 |
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):