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 |
||
22 | class EE_Registry implements ResettableInterface |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * @var EE_Registry $_instance |
||
27 | */ |
||
28 | private static $_instance; |
||
29 | |||
30 | /** |
||
31 | * @var EE_Dependency_Map $_dependency_map |
||
32 | */ |
||
33 | protected $_dependency_map; |
||
34 | |||
35 | /** |
||
36 | * @var array $_class_abbreviations |
||
37 | */ |
||
38 | protected $_class_abbreviations = array(); |
||
39 | |||
40 | /** |
||
41 | * @var CommandBusInterface $BUS |
||
42 | */ |
||
43 | public $BUS; |
||
44 | |||
45 | /** |
||
46 | * @var EE_Cart $CART |
||
47 | */ |
||
48 | public $CART; |
||
49 | |||
50 | /** |
||
51 | * @var EE_Config $CFG |
||
52 | */ |
||
53 | public $CFG; |
||
54 | |||
55 | /** |
||
56 | * @var EE_Network_Config $NET_CFG |
||
57 | */ |
||
58 | public $NET_CFG; |
||
59 | |||
60 | /** |
||
61 | * StdClass object for storing library classes in |
||
62 | * |
||
63 | * @var StdClass $LIB |
||
64 | */ |
||
65 | public $LIB; |
||
66 | |||
67 | /** |
||
68 | * @var EE_Request_Handler $REQ |
||
69 | */ |
||
70 | public $REQ; |
||
71 | |||
72 | /** |
||
73 | * @var EE_Session $SSN |
||
74 | */ |
||
75 | public $SSN; |
||
76 | |||
77 | /** |
||
78 | * @since 4.5.0 |
||
79 | * @var EE_Capabilities $CAP |
||
80 | */ |
||
81 | public $CAP; |
||
82 | |||
83 | /** |
||
84 | * @since 4.9.0 |
||
85 | * @var EE_Message_Resource_Manager $MRM |
||
86 | */ |
||
87 | public $MRM; |
||
88 | |||
89 | |||
90 | /** |
||
91 | * @var Registry $AssetsRegistry |
||
92 | */ |
||
93 | public $AssetsRegistry; |
||
94 | |||
95 | /** |
||
96 | * StdClass object for holding addons which have registered themselves to work with EE core |
||
97 | * |
||
98 | * @var EE_Addon[] $addons |
||
99 | */ |
||
100 | public $addons; |
||
101 | |||
102 | /** |
||
103 | * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
||
104 | * |
||
105 | * @var EEM_Base[] $models |
||
106 | */ |
||
107 | public $models = array(); |
||
108 | |||
109 | /** |
||
110 | * @var EED_Module[] $modules |
||
111 | */ |
||
112 | public $modules; |
||
113 | |||
114 | /** |
||
115 | * @var EES_Shortcode[] $shortcodes |
||
116 | */ |
||
117 | public $shortcodes; |
||
118 | |||
119 | /** |
||
120 | * @var WP_Widget[] $widgets |
||
121 | */ |
||
122 | public $widgets; |
||
123 | |||
124 | /** |
||
125 | * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
||
126 | * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
||
127 | * Keys are model "short names" (eg "Event") as used in model relations, and values are |
||
128 | * classnames (eg "EEM_Event") |
||
129 | * |
||
130 | * @var array $non_abstract_db_models |
||
131 | */ |
||
132 | public $non_abstract_db_models = array(); |
||
133 | |||
134 | |||
135 | /** |
||
136 | * internationalization for JS strings |
||
137 | * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
||
138 | * in js file: var translatedString = eei18n.string_key; |
||
139 | * |
||
140 | * @var array $i18n_js_strings |
||
141 | */ |
||
142 | public static $i18n_js_strings = array(); |
||
143 | |||
144 | |||
145 | /** |
||
146 | * $main_file - path to espresso.php |
||
147 | * |
||
148 | * @var array $main_file |
||
149 | */ |
||
150 | public $main_file; |
||
151 | |||
152 | /** |
||
153 | * array of ReflectionClass objects where the key is the class name |
||
154 | * |
||
155 | * @var ReflectionClass[] $_reflectors |
||
156 | */ |
||
157 | public $_reflectors; |
||
158 | |||
159 | /** |
||
160 | * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
||
161 | * |
||
162 | * @var boolean $_cache_on |
||
163 | */ |
||
164 | protected $_cache_on = true; |
||
165 | |||
166 | |||
167 | |||
168 | /** |
||
169 | * @singleton method used to instantiate class object |
||
170 | * @param EE_Dependency_Map $dependency_map |
||
171 | * @return EE_Registry instance |
||
172 | * @throws InvalidArgumentException |
||
173 | * @throws InvalidInterfaceException |
||
174 | * @throws InvalidDataTypeException |
||
175 | */ |
||
176 | public static function instance(EE_Dependency_Map $dependency_map = null) |
||
184 | |||
185 | |||
186 | |||
187 | /** |
||
188 | * protected constructor to prevent direct creation |
||
189 | * |
||
190 | * @Constructor |
||
191 | * @param EE_Dependency_Map $dependency_map |
||
192 | * @throws InvalidDataTypeException |
||
193 | * @throws InvalidInterfaceException |
||
194 | * @throws InvalidArgumentException |
||
195 | */ |
||
196 | protected function __construct(EE_Dependency_Map $dependency_map) |
||
206 | |||
207 | |||
208 | |||
209 | /** |
||
210 | * initialize |
||
211 | * |
||
212 | * @throws EE_Error |
||
213 | * @throws ReflectionException |
||
214 | */ |
||
215 | public function initialize() |
||
245 | |||
246 | |||
247 | |||
248 | /** |
||
249 | * @return void |
||
250 | */ |
||
251 | public function init() |
||
259 | |||
260 | |||
261 | |||
262 | /** |
||
263 | * localize_i18n_js_strings |
||
264 | * |
||
265 | * @return string |
||
266 | */ |
||
267 | public static function localize_i18n_js_strings() |
||
277 | |||
278 | |||
279 | |||
280 | /** |
||
281 | * @param mixed string | EED_Module $module |
||
282 | * @throws EE_Error |
||
283 | * @throws ReflectionException |
||
284 | */ |
||
285 | public function add_module($module) |
||
297 | |||
298 | |||
299 | |||
300 | /** |
||
301 | * @param string $module_name |
||
302 | * @return mixed EED_Module | NULL |
||
303 | */ |
||
304 | public function get_module($module_name = '') |
||
310 | |||
311 | |||
312 | |||
313 | /** |
||
314 | * loads core classes - must be singletons |
||
315 | * |
||
316 | * @param string $class_name - simple class name ie: session |
||
317 | * @param mixed $arguments |
||
318 | * @param bool $load_only |
||
319 | * @return mixed |
||
320 | * @throws EE_Error |
||
321 | * @throws ReflectionException |
||
322 | */ |
||
323 | public function load_core($class_name, $arguments = array(), $load_only = false) |
||
349 | |||
350 | |||
351 | |||
352 | /** |
||
353 | * loads service classes |
||
354 | * |
||
355 | * @param string $class_name - simple class name ie: session |
||
356 | * @param mixed $arguments |
||
357 | * @param bool $load_only |
||
358 | * @return mixed |
||
359 | * @throws EE_Error |
||
360 | * @throws ReflectionException |
||
361 | */ |
||
362 | public function load_service($class_name, $arguments = array(), $load_only = false) |
||
382 | |||
383 | |||
384 | |||
385 | /** |
||
386 | * loads data_migration_scripts |
||
387 | * |
||
388 | * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
||
389 | * @param mixed $arguments |
||
390 | * @return EE_Data_Migration_Script_Base|mixed |
||
391 | * @throws EE_Error |
||
392 | * @throws ReflectionException |
||
393 | */ |
||
394 | public function load_dms($class_name, $arguments = array()) |
||
407 | |||
408 | |||
409 | |||
410 | /** |
||
411 | * loads object creating classes - must be singletons |
||
412 | * |
||
413 | * @param string $class_name - simple class name ie: attendee |
||
414 | * @param mixed $arguments - an array of arguments to pass to the class |
||
415 | * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
||
416 | * instantiate |
||
417 | * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
||
418 | * set this to FALSE (ie. when instantiating model objects from client in a loop) |
||
419 | * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
||
420 | * (default) |
||
421 | * @return EE_Base_Class | bool |
||
422 | * @throws EE_Error |
||
423 | * @throws ReflectionException |
||
424 | */ |
||
425 | public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
||
446 | |||
447 | |||
448 | |||
449 | /** |
||
450 | * loads helper classes - must be singletons |
||
451 | * |
||
452 | * @param string $class_name - simple class name ie: price |
||
453 | * @param mixed $arguments |
||
454 | * @param bool $load_only |
||
455 | * @return EEH_Base | bool |
||
456 | * @throws EE_Error |
||
457 | * @throws ReflectionException |
||
458 | */ |
||
459 | public function load_helper($class_name, $arguments = array(), $load_only = true) |
||
475 | |||
476 | |||
477 | |||
478 | /** |
||
479 | * loads core classes - must be singletons |
||
480 | * |
||
481 | * @param string $class_name - simple class name ie: session |
||
482 | * @param mixed $arguments |
||
483 | * @param bool $load_only |
||
484 | * @param bool $cache whether to cache the object or not. |
||
485 | * @return mixed |
||
486 | * @throws EE_Error |
||
487 | * @throws ReflectionException |
||
488 | */ |
||
489 | public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
||
510 | |||
511 | |||
512 | |||
513 | /** |
||
514 | * loads model classes - must be singletons |
||
515 | * |
||
516 | * @param string $class_name - simple class name ie: price |
||
517 | * @param mixed $arguments |
||
518 | * @param bool $load_only |
||
519 | * @return EEM_Base | bool |
||
520 | * @throws EE_Error |
||
521 | * @throws ReflectionException |
||
522 | */ |
||
523 | public function load_model($class_name, $arguments = array(), $load_only = false) |
||
543 | |||
544 | |||
545 | |||
546 | /** |
||
547 | * loads model classes - must be singletons |
||
548 | * |
||
549 | * @param string $class_name - simple class name ie: price |
||
550 | * @param mixed $arguments |
||
551 | * @param bool $load_only |
||
552 | * @return mixed | bool |
||
553 | * @throws EE_Error |
||
554 | * @throws ReflectionException |
||
555 | */ |
||
556 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
||
576 | |||
577 | |||
578 | |||
579 | /** |
||
580 | * Determines if $model_name is the name of an actual EE model. |
||
581 | * |
||
582 | * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
||
583 | * @return boolean |
||
584 | */ |
||
585 | public function is_model_name($model_name) |
||
589 | |||
590 | |||
591 | |||
592 | /** |
||
593 | * generic class loader |
||
594 | * |
||
595 | * @param string $path_to_file - directory path to file location, not including filename |
||
596 | * @param string $file_name - file name ie: my_file.php, including extension |
||
597 | * @param string $type - file type - core? class? helper? model? |
||
598 | * @param mixed $arguments |
||
599 | * @param bool $load_only |
||
600 | * @return mixed |
||
601 | * @throws EE_Error |
||
602 | * @throws ReflectionException |
||
603 | */ |
||
604 | public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
||
618 | |||
619 | |||
620 | |||
621 | /** |
||
622 | * @param string $path_to_file - directory path to file location, not including filename |
||
623 | * @param string $class_name - full class name ie: My_Class |
||
624 | * @param string $type - file type - core? class? helper? model? |
||
625 | * @param mixed $arguments |
||
626 | * @param bool $load_only |
||
627 | * @return bool|EE_Addon|object |
||
628 | * @throws EE_Error |
||
629 | * @throws ReflectionException |
||
630 | */ |
||
631 | public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
||
645 | |||
646 | |||
647 | |||
648 | /** |
||
649 | * instantiates, caches, and automatically resolves dependencies |
||
650 | * for classes that use a Fully Qualified Class Name. |
||
651 | * if the class is not capable of being loaded using PSR-4 autoloading, |
||
652 | * then you need to use one of the existing load_*() methods |
||
653 | * which can resolve the classname and filepath from the passed arguments |
||
654 | * |
||
655 | * @param bool|string $class_name Fully Qualified Class Name |
||
656 | * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
||
657 | * @param bool $cache whether to cache the instantiated object for reuse |
||
658 | * @param bool $from_db some classes are instantiated from the db |
||
659 | * and thus call a different method to instantiate |
||
660 | * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
||
661 | * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
||
662 | * @return bool|null|mixed null = failure to load or instantiate class object. |
||
663 | * object = class loaded and instantiated successfully. |
||
664 | * bool = fail or success when $load_only is true |
||
665 | * @throws EE_Error |
||
666 | * @throws ReflectionException |
||
667 | */ |
||
668 | public function create( |
||
720 | |||
721 | |||
722 | |||
723 | /** |
||
724 | * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
||
725 | * |
||
726 | * @param string $class_name |
||
727 | * @param array $arguments |
||
728 | * @param int $attempt |
||
729 | * @return mixed |
||
730 | */ |
||
731 | private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) { |
||
756 | |||
757 | |||
758 | |||
759 | /** |
||
760 | * instantiates, caches, and injects dependencies for classes |
||
761 | * |
||
762 | * @param array $file_paths an array of paths to folders to look in |
||
763 | * @param string $class_prefix EE or EEM or... ??? |
||
764 | * @param bool|string $class_name $class name |
||
765 | * @param string $type file type - core? class? helper? model? |
||
766 | * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
||
767 | * @param bool $from_db some classes are instantiated from the db |
||
768 | * and thus call a different method to instantiate |
||
769 | * @param bool $cache whether to cache the instantiated object for reuse |
||
770 | * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
||
771 | * @return bool|null|object null = failure to load or instantiate class object. |
||
772 | * object = class loaded and instantiated successfully. |
||
773 | * bool = fail or success when $load_only is true |
||
774 | * @throws EE_Error |
||
775 | * @throws ReflectionException |
||
776 | */ |
||
777 | protected function _load( |
||
836 | |||
837 | |||
838 | |||
839 | /** |
||
840 | * @param string $class_name |
||
841 | * @param string $default have to specify something, but not anything that will conflict |
||
842 | * @return mixed|string |
||
843 | */ |
||
844 | protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
||
850 | |||
851 | /** |
||
852 | * attempts to find a cached version of the requested class |
||
853 | * by looking in the following places: |
||
854 | * $this->{$class_abbreviation} ie: $this->CART |
||
855 | * $this->{$class_name} ie: $this->Some_Class |
||
856 | * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
||
857 | * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
||
858 | * |
||
859 | * @param string $class_name |
||
860 | * @param string $class_prefix |
||
861 | * @return mixed |
||
862 | */ |
||
863 | protected function _get_cached_class($class_name, $class_prefix = '') |
||
885 | |||
886 | |||
887 | |||
888 | /** |
||
889 | * removes a cached version of the requested class |
||
890 | * |
||
891 | * @param string $class_name |
||
892 | * @param boolean $addon |
||
893 | * @return boolean |
||
894 | */ |
||
895 | public function clear_cached_class($class_name, $addon = false) |
||
918 | |||
919 | |||
920 | |||
921 | /** |
||
922 | * attempts to find a full valid filepath for the requested class. |
||
923 | * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
||
924 | * then returns that path if the target file has been found and is readable |
||
925 | * |
||
926 | * @param string $class_name |
||
927 | * @param string $type |
||
928 | * @param array $file_paths |
||
929 | * @return string | bool |
||
930 | */ |
||
931 | protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
||
956 | |||
957 | |||
958 | |||
959 | /** |
||
960 | * basically just performs a require_once() |
||
961 | * but with some error handling |
||
962 | * |
||
963 | * @param string $path |
||
964 | * @param string $class_name |
||
965 | * @param string $type |
||
966 | * @param array $file_paths |
||
967 | * @return bool |
||
968 | * @throws EE_Error |
||
969 | * @throws ReflectionException |
||
970 | */ |
||
971 | protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
||
1010 | |||
1011 | |||
1012 | |||
1013 | /** |
||
1014 | * _create_object |
||
1015 | * Attempts to instantiate the requested class via any of the |
||
1016 | * commonly used instantiation methods employed throughout EE. |
||
1017 | * The priority for instantiation is as follows: |
||
1018 | * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
||
1019 | * - model objects via their 'new_instance_from_db' method |
||
1020 | * - model objects via their 'new_instance' method |
||
1021 | * - "singleton" classes" via their 'instance' method |
||
1022 | * - standard instantiable classes via their __constructor |
||
1023 | * Prior to instantiation, if the classname exists in the dependency_map, |
||
1024 | * then the constructor for the requested class will be examined to determine |
||
1025 | * if any dependencies exist, and if they can be injected. |
||
1026 | * If so, then those classes will be added to the array of arguments passed to the constructor |
||
1027 | * |
||
1028 | * @param string $class_name |
||
1029 | * @param array $arguments |
||
1030 | * @param string $type |
||
1031 | * @param bool $from_db |
||
1032 | * @return null|object |
||
1033 | * @throws EE_Error |
||
1034 | * @throws ReflectionException |
||
1035 | */ |
||
1036 | protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
||
1090 | |||
1091 | |||
1092 | |||
1093 | /** |
||
1094 | * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
||
1095 | * @param array $array |
||
1096 | * @return bool |
||
1097 | */ |
||
1098 | protected function _array_is_numerically_and_sequentially_indexed(array $array) |
||
1104 | |||
1105 | |||
1106 | |||
1107 | /** |
||
1108 | * getReflectionClass |
||
1109 | * checks if a ReflectionClass object has already been generated for a class |
||
1110 | * and returns that instead of creating a new one |
||
1111 | * |
||
1112 | * @param string $class_name |
||
1113 | * @return ReflectionClass |
||
1114 | * @throws ReflectionException |
||
1115 | */ |
||
1116 | View Code Duplication | public function get_ReflectionClass($class_name) |
|
1126 | |||
1127 | |||
1128 | |||
1129 | /** |
||
1130 | * _resolve_dependencies |
||
1131 | * examines the constructor for the requested class to determine |
||
1132 | * if any dependencies exist, and if they can be injected. |
||
1133 | * If so, then those classes will be added to the array of arguments passed to the constructor |
||
1134 | * PLZ NOTE: this is achieved by type hinting the constructor params |
||
1135 | * For example: |
||
1136 | * if attempting to load a class "Foo" with the following constructor: |
||
1137 | * __construct( Bar $bar_class, Fighter $grohl_class ) |
||
1138 | * then $bar_class and $grohl_class will be added to the $arguments array, |
||
1139 | * but only IF they are NOT already present in the incoming arguments array, |
||
1140 | * and the correct classes can be loaded |
||
1141 | * |
||
1142 | * @param ReflectionClass $reflector |
||
1143 | * @param string $class_name |
||
1144 | * @param array $arguments |
||
1145 | * @return array |
||
1146 | * @throws EE_Error |
||
1147 | * @throws ReflectionException |
||
1148 | */ |
||
1149 | protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
||
1221 | |||
1222 | |||
1223 | |||
1224 | /** |
||
1225 | * @param string $class_name |
||
1226 | * @param string $param_class |
||
1227 | * @param array $arguments |
||
1228 | * @param mixed $index |
||
1229 | * @param array $argument_keys |
||
1230 | * @return array |
||
1231 | * @throws EE_Error |
||
1232 | * @throws ReflectionException |
||
1233 | * @throws InvalidArgumentException |
||
1234 | * @throws InvalidInterfaceException |
||
1235 | * @throws InvalidDataTypeException |
||
1236 | */ |
||
1237 | protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys) |
||
1282 | |||
1283 | |||
1284 | |||
1285 | /** |
||
1286 | * _set_cached_class |
||
1287 | * attempts to cache the instantiated class locally |
||
1288 | * in one of the following places, in the following order: |
||
1289 | * $this->{class_abbreviation} ie: $this->CART |
||
1290 | * $this->{$class_name} ie: $this->Some_Class |
||
1291 | * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
||
1292 | * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
||
1293 | * |
||
1294 | * @param object $class_obj |
||
1295 | * @param string $class_name |
||
1296 | * @param string $class_prefix |
||
1297 | * @param bool $from_db |
||
1298 | * @return void |
||
1299 | */ |
||
1300 | protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
||
1324 | |||
1325 | |||
1326 | |||
1327 | /** |
||
1328 | * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
||
1329 | * |
||
1330 | * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
||
1331 | * in the EE_Dependency_Map::$_class_loaders array, |
||
1332 | * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
||
1333 | * @param array $arguments |
||
1334 | * @return object |
||
1335 | */ |
||
1336 | public static function factory($classname, $arguments = array()) |
||
1347 | |||
1348 | |||
1349 | |||
1350 | /** |
||
1351 | * Gets the addon by its name/slug (not classname. For that, just |
||
1352 | * use the classname as the property name on EE_Config::instance()->addons) |
||
1353 | * |
||
1354 | * @param string $name |
||
1355 | * @return EE_Addon |
||
1356 | */ |
||
1357 | public function get_addon_by_name($name) |
||
1366 | |||
1367 | |||
1368 | |||
1369 | /** |
||
1370 | * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their |
||
1371 | * name() function) They're already available on EE_Config::instance()->addons as properties, where each property's |
||
1372 | * name is the addon's classname. So if you just want to get the addon by classname, use |
||
1373 | * EE_Config::instance()->addons->{classname} |
||
1374 | * |
||
1375 | * @return EE_Addon[] where the KEYS are the addon's name() |
||
1376 | */ |
||
1377 | public function get_addons_by_name() |
||
1385 | |||
1386 | |||
1387 | |||
1388 | /** |
||
1389 | * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
||
1390 | * a stale copy of it around |
||
1391 | * |
||
1392 | * @param string $model_name |
||
1393 | * @return \EEM_Base |
||
1394 | * @throws \EE_Error |
||
1395 | */ |
||
1396 | public function reset_model($model_name) |
||
1415 | |||
1416 | |||
1417 | |||
1418 | /** |
||
1419 | * Resets the registry. |
||
1420 | * The criteria for what gets reset is based on what can be shared between sites on the same request when |
||
1421 | * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
||
1422 | * - $_dependency_map |
||
1423 | * - $_class_abbreviations |
||
1424 | * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
||
1425 | * - $REQ: Still on the same request so no need to change. |
||
1426 | * - $CAP: There is no site specific state in the EE_Capability class. |
||
1427 | * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
||
1428 | * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
||
1429 | * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
||
1430 | * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
||
1431 | * switch or on the restore. |
||
1432 | * - $modules |
||
1433 | * - $shortcodes |
||
1434 | * - $widgets |
||
1435 | * |
||
1436 | * @param boolean $hard [deprecated] |
||
1437 | * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
||
1438 | * or just reset without re-instantiating (handy to set to FALSE if you're not |
||
1439 | * sure if you CAN currently reinstantiate the singletons at the moment) |
||
1440 | * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
||
1441 | * client |
||
1442 | * code instead can just change the model context to a different blog id if |
||
1443 | * necessary |
||
1444 | * @return EE_Registry |
||
1445 | * @throws EE_Error |
||
1446 | * @throws ReflectionException |
||
1447 | */ |
||
1448 | public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
||
1471 | |||
1472 | |||
1473 | |||
1474 | /** |
||
1475 | * if passed object implements ResettableInterface, then call it's reset() method |
||
1476 | * if passed object implements InterminableInterface, then return false, |
||
1477 | * to indicate that it should NOT be cleared from the Registry cache |
||
1478 | * |
||
1479 | * @param $object |
||
1480 | * @param bool $reset_models |
||
1481 | * @return bool returns true if cached object should be unset |
||
1482 | */ |
||
1483 | private static function _reset_and_unset_object($object, $reset_models) |
||
1510 | |||
1511 | |||
1512 | |||
1513 | /** |
||
1514 | * Gets all the custom post type models defined |
||
1515 | * |
||
1516 | * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
||
1517 | */ |
||
1518 | public function cpt_models() |
||
1528 | |||
1529 | |||
1530 | |||
1531 | /** |
||
1532 | * @return \EE_Config |
||
1533 | */ |
||
1534 | public static function CFG() |
||
1538 | |||
1539 | |||
1540 | } |
||
1541 | // End of file EE_Registry.core.php |
||
1543 |
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):