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 | * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
||
121 | * |
||
122 | * @access public |
||
123 | * @var EE_Addon[] |
||
124 | */ |
||
125 | public $addons = null; |
||
126 | |||
127 | /** |
||
128 | * $models |
||
129 | * @access public |
||
130 | * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
||
131 | */ |
||
132 | public $models = array(); |
||
133 | |||
134 | /** |
||
135 | * $modules |
||
136 | * @access public |
||
137 | * @var EED_Module[] $modules |
||
138 | */ |
||
139 | public $modules = null; |
||
140 | |||
141 | /** |
||
142 | * $shortcodes |
||
143 | * @access public |
||
144 | * @var EES_Shortcode[] $shortcodes |
||
145 | */ |
||
146 | public $shortcodes = null; |
||
147 | |||
148 | /** |
||
149 | * $widgets |
||
150 | * @access public |
||
151 | * @var WP_Widget[] $widgets |
||
152 | */ |
||
153 | public $widgets = null; |
||
154 | |||
155 | /** |
||
156 | * $non_abstract_db_models |
||
157 | * @access public |
||
158 | * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
||
159 | * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
||
160 | * Keys are model "short names" (eg "Event") as used in model relations, and values are |
||
161 | * classnames (eg "EEM_Event") |
||
162 | */ |
||
163 | public $non_abstract_db_models = array(); |
||
164 | |||
165 | |||
166 | /** |
||
167 | * $i18n_js_strings - internationalization for JS strings |
||
168 | * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
||
169 | * in js file: var translatedString = eei18n.string_key; |
||
170 | * |
||
171 | * @access public |
||
172 | * @var array |
||
173 | */ |
||
174 | public static $i18n_js_strings = array(); |
||
175 | |||
176 | |||
177 | /** |
||
178 | * $main_file - path to espresso.php |
||
179 | * |
||
180 | * @access public |
||
181 | * @var array |
||
182 | */ |
||
183 | public $main_file; |
||
184 | |||
185 | /** |
||
186 | * array of ReflectionClass objects where the key is the class name |
||
187 | * |
||
188 | * @access public |
||
189 | * @var ReflectionClass[] |
||
190 | */ |
||
191 | public $_reflectors; |
||
192 | |||
193 | /** |
||
194 | * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
||
195 | * |
||
196 | * @access protected |
||
197 | * @var boolean $_cache_on |
||
198 | */ |
||
199 | protected $_cache_on = true; |
||
200 | |||
201 | |||
202 | |||
203 | /** |
||
204 | * @singleton method used to instantiate class object |
||
205 | * @access public |
||
206 | * @param \EE_Dependency_Map $dependency_map |
||
207 | * @return \EE_Registry instance |
||
208 | */ |
||
209 | public static function instance(\EE_Dependency_Map $dependency_map = null) |
||
217 | |||
218 | |||
219 | |||
220 | /** |
||
221 | *protected constructor to prevent direct creation |
||
222 | * |
||
223 | * @Constructor |
||
224 | * @access protected |
||
225 | * @param \EE_Dependency_Map $dependency_map |
||
226 | * @return \EE_Registry |
||
227 | */ |
||
228 | protected function __construct(\EE_Dependency_Map $dependency_map) |
||
233 | |||
234 | |||
235 | |||
236 | /** |
||
237 | * initialize |
||
238 | */ |
||
239 | public function initialize() |
||
240 | { |
||
241 | $this->_class_abbreviations = apply_filters( |
||
242 | 'FHEE__EE_Registry____construct___class_abbreviations', |
||
243 | array( |
||
244 | 'EE_Config' => 'CFG', |
||
245 | 'EE_Session' => 'SSN', |
||
246 | 'EE_Capabilities' => 'CAP', |
||
247 | 'EE_Cart' => 'CART', |
||
248 | 'EE_Network_Config' => 'NET_CFG', |
||
249 | 'EE_Request_Handler' => 'REQ', |
||
250 | 'EE_Message_Resource_Manager' => 'MRM', |
||
251 | 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
||
252 | 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
||
253 | ) |
||
254 | ); |
||
255 | // class library |
||
256 | $this->LIB = new stdClass(); |
||
257 | $this->addons = new stdClass(); |
||
258 | $this->modules = new stdClass(); |
||
259 | $this->shortcodes = new stdClass(); |
||
260 | $this->widgets = new stdClass(); |
||
261 | $this->load_core('Base', array(), true); |
||
262 | // add our request and response objects to the cache |
||
263 | $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
||
264 | $this->_set_cached_class( |
||
265 | $request_loader(), |
||
266 | 'EE_Request' |
||
267 | ); |
||
268 | $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
||
269 | $this->_set_cached_class( |
||
270 | $response_loader(), |
||
271 | 'EE_Response' |
||
272 | ); |
||
273 | add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
||
274 | } |
||
275 | |||
276 | |||
277 | |||
278 | /** |
||
279 | * init |
||
280 | * |
||
281 | * @access public |
||
282 | * @return void |
||
283 | */ |
||
284 | public function init() |
||
285 | { |
||
286 | // Get current page protocol |
||
287 | $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
||
288 | // Output admin-ajax.php URL with same protocol as current page |
||
289 | self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
||
290 | self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
||
291 | } |
||
292 | |||
293 | |||
294 | |||
295 | /** |
||
296 | * localize_i18n_js_strings |
||
297 | * |
||
298 | * @return string |
||
299 | */ |
||
300 | public static function localize_i18n_js_strings() |
||
310 | |||
311 | |||
312 | |||
313 | /** |
||
314 | * @param mixed string | EED_Module $module |
||
315 | */ |
||
316 | public function add_module($module) |
||
328 | |||
329 | |||
330 | |||
331 | /** |
||
332 | * @param string $module_name |
||
333 | * @return mixed EED_Module | NULL |
||
334 | */ |
||
335 | public function get_module($module_name = '') |
||
339 | |||
340 | |||
341 | |||
342 | /** |
||
343 | * loads core classes - must be singletons |
||
344 | * |
||
345 | * @access public |
||
346 | * @param string $class_name - simple class name ie: session |
||
347 | * @param mixed $arguments |
||
348 | * @param bool $load_only |
||
349 | * @return mixed |
||
350 | */ |
||
351 | public function load_core($class_name, $arguments = array(), $load_only = false) |
||
367 | |||
368 | |||
369 | |||
370 | /** |
||
371 | * loads service classes |
||
372 | * |
||
373 | * @access public |
||
374 | * @param string $class_name - simple class name ie: session |
||
375 | * @param mixed $arguments |
||
376 | * @param bool $load_only |
||
377 | * @return mixed |
||
378 | */ |
||
379 | public function load_service($class_name, $arguments = array(), $load_only = false) |
||
390 | |||
391 | |||
392 | |||
393 | /** |
||
394 | * loads data_migration_scripts |
||
395 | * |
||
396 | * @access public |
||
397 | * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
||
398 | * @param mixed $arguments |
||
399 | * @return EE_Data_Migration_Script_Base|mixed |
||
400 | */ |
||
401 | public function load_dms($class_name, $arguments = array()) |
||
406 | |||
407 | |||
408 | |||
409 | /** |
||
410 | * loads object creating classes - must be singletons |
||
411 | * |
||
412 | * @param string $class_name - simple class name ie: attendee |
||
413 | * @param mixed $arguments - an array of arguments to pass to the class |
||
414 | * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
||
415 | * @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) |
||
416 | * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
||
417 | * @return EE_Base_Class | bool |
||
418 | */ |
||
419 | public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
||
429 | |||
430 | |||
431 | |||
432 | /** |
||
433 | * loads helper classes - must be singletons |
||
434 | * |
||
435 | * @param string $class_name - simple class name ie: price |
||
436 | * @param mixed $arguments |
||
437 | * @param bool $load_only |
||
438 | * @return EEH_Base | bool |
||
439 | */ |
||
440 | public function load_helper($class_name, $arguments = array(), $load_only = true) |
||
447 | |||
448 | |||
449 | |||
450 | /** |
||
451 | * loads core classes - must be singletons |
||
452 | * |
||
453 | * @access public |
||
454 | * @param string $class_name - simple class name ie: session |
||
455 | * @param mixed $arguments |
||
456 | * @param bool $load_only |
||
457 | * @param bool $cache whether to cache the object or not. |
||
458 | * @return mixed |
||
459 | */ |
||
460 | public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
||
472 | |||
473 | |||
474 | |||
475 | /** |
||
476 | * loads model classes - must be singletons |
||
477 | * |
||
478 | * @param string $class_name - simple class name ie: price |
||
479 | * @param mixed $arguments |
||
480 | * @param bool $load_only |
||
481 | * @return EEM_Base | bool |
||
482 | */ |
||
483 | public function load_model($class_name, $arguments = array(), $load_only = false) |
||
492 | |||
493 | |||
494 | |||
495 | /** |
||
496 | * loads model classes - must be singletons |
||
497 | * |
||
498 | * @param string $class_name - simple class name ie: price |
||
499 | * @param mixed $arguments |
||
500 | * @param bool $load_only |
||
501 | * @return mixed | bool |
||
502 | */ |
||
503 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
||
514 | |||
515 | |||
516 | |||
517 | /** |
||
518 | * Determines if $model_name is the name of an actual EE model. |
||
519 | * |
||
520 | * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
||
521 | * @return boolean |
||
522 | */ |
||
523 | public function is_model_name($model_name) |
||
527 | |||
528 | |||
529 | |||
530 | /** |
||
531 | * generic class loader |
||
532 | * |
||
533 | * @param string $path_to_file - directory path to file location, not including filename |
||
534 | * @param string $file_name - file name ie: my_file.php, including extension |
||
535 | * @param string $type - file type - core? class? helper? model? |
||
536 | * @param mixed $arguments |
||
537 | * @param bool $load_only |
||
538 | * @return mixed |
||
539 | */ |
||
540 | public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
||
545 | |||
546 | |||
547 | |||
548 | /** |
||
549 | * load_addon |
||
550 | * |
||
551 | * @param string $path_to_file - directory path to file location, not including filename |
||
552 | * @param string $class_name - full class name ie: My_Class |
||
553 | * @param string $type - file type - core? class? helper? model? |
||
554 | * @param mixed $arguments |
||
555 | * @param bool $load_only |
||
556 | * @return EE_Addon |
||
557 | */ |
||
558 | public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
||
563 | |||
564 | |||
565 | |||
566 | /** |
||
567 | * instantiates, caches, and automatically resolves dependencies |
||
568 | * for classes that use a Fully Qualified Class Name. |
||
569 | * if the class is not capable of being loaded using PSR-4 autoloading, |
||
570 | * then you need to use one of the existing load_*() methods |
||
571 | * which can resolve the classname and filepath from the passed arguments |
||
572 | * |
||
573 | * @param bool|string $class_name Fully Qualified Class Name |
||
574 | * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
||
575 | * @param bool $cache whether to cache the instantiated object for reuse |
||
576 | * @param bool $from_db some classes are instantiated from the db |
||
577 | * and thus call a different method to instantiate |
||
578 | * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
||
579 | * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
||
580 | * @return mixed null = failure to load or instantiate class object. |
||
581 | * object = class loaded and instantiated successfully. |
||
582 | * bool = fail or success when $load_only is true |
||
583 | */ |
||
584 | public function create( |
||
626 | |||
627 | |||
628 | |||
629 | /** |
||
630 | * instantiates, caches, and injects dependencies for classes |
||
631 | * |
||
632 | * @param array $file_paths an array of paths to folders to look in |
||
633 | * @param string $class_prefix EE or EEM or... ??? |
||
634 | * @param bool|string $class_name $class name |
||
635 | * @param string $type file type - core? class? helper? model? |
||
636 | * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
||
637 | * @param bool $from_db some classes are instantiated from the db |
||
638 | * and thus call a different method to instantiate |
||
639 | * @param bool $cache whether to cache the instantiated object for reuse |
||
640 | * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
||
641 | * @return null|object|bool null = failure to load or instantiate class object. |
||
642 | * object = class loaded and instantiated successfully. |
||
643 | * bool = fail or success when $load_only is true |
||
644 | */ |
||
645 | protected function _load( |
||
702 | |||
703 | |||
704 | |||
705 | /** |
||
706 | * _get_cached_class |
||
707 | * attempts to find a cached version of the requested class |
||
708 | * by looking in the following places: |
||
709 | * $this->{$class_abbreviation} ie: $this->CART |
||
710 | * $this->{$class_name} ie: $this->Some_Class |
||
711 | * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
||
712 | * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
||
713 | * |
||
714 | * @access protected |
||
715 | * @param string $class_name |
||
716 | * @param string $class_prefix |
||
717 | * @return mixed |
||
718 | */ |
||
719 | protected function _get_cached_class($class_name, $class_prefix = '') |
||
742 | |||
743 | |||
744 | |||
745 | /** |
||
746 | * _resolve_path |
||
747 | * attempts to find a full valid filepath for the requested class. |
||
748 | * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
||
749 | * then returns that path if the target file has been found and is readable |
||
750 | * |
||
751 | * @access protected |
||
752 | * @param string $class_name |
||
753 | * @param string $type |
||
754 | * @param array $file_paths |
||
755 | * @return string | bool |
||
756 | */ |
||
757 | protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
||
776 | |||
777 | |||
778 | |||
779 | /** |
||
780 | * _require_file |
||
781 | * basically just performs a require_once() |
||
782 | * but with some error handling |
||
783 | * |
||
784 | * @access protected |
||
785 | * @param string $path |
||
786 | * @param string $class_name |
||
787 | * @param string $type |
||
788 | * @param array $file_paths |
||
789 | * @return boolean |
||
790 | * @throws \EE_Error |
||
791 | */ |
||
792 | protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
||
828 | |||
829 | |||
830 | |||
831 | /** |
||
832 | * _create_object |
||
833 | * Attempts to instantiate the requested class via any of the |
||
834 | * commonly used instantiation methods employed throughout EE. |
||
835 | * The priority for instantiation is as follows: |
||
836 | * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
||
837 | * - model objects via their 'new_instance_from_db' method |
||
838 | * - model objects via their 'new_instance' method |
||
839 | * - "singleton" classes" via their 'instance' method |
||
840 | * - standard instantiable classes via their __constructor |
||
841 | * Prior to instantiation, if the classname exists in the dependency_map, |
||
842 | * then the constructor for the requested class will be examined to determine |
||
843 | * if any dependencies exist, and if they can be injected. |
||
844 | * If so, then those classes will be added to the array of arguments passed to the constructor |
||
845 | * |
||
846 | * @access protected |
||
847 | * @param string $class_name |
||
848 | * @param array $arguments |
||
849 | * @param string $type |
||
850 | * @param bool $from_db |
||
851 | * @return null | object |
||
852 | * @throws \EE_Error |
||
853 | */ |
||
854 | protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
||
921 | |||
922 | |||
923 | |||
924 | /** |
||
925 | * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
||
926 | * @param array $array |
||
927 | * @return bool |
||
928 | */ |
||
929 | protected function _array_is_numerically_and_sequentially_indexed(array $array) |
||
933 | |||
934 | |||
935 | |||
936 | /** |
||
937 | * getReflectionClass |
||
938 | * checks if a ReflectionClass object has already been generated for a class |
||
939 | * and returns that instead of creating a new one |
||
940 | * |
||
941 | * @access public |
||
942 | * @param string $class_name |
||
943 | * @return ReflectionClass |
||
944 | */ |
||
945 | View Code Duplication | public function get_ReflectionClass($class_name) |
|
955 | |||
956 | |||
957 | |||
958 | /** |
||
959 | * _resolve_dependencies |
||
960 | * examines the constructor for the requested class to determine |
||
961 | * if any dependencies exist, and if they can be injected. |
||
962 | * If so, then those classes will be added to the array of arguments passed to the constructor |
||
963 | * PLZ NOTE: this is achieved by type hinting the constructor params |
||
964 | * For example: |
||
965 | * if attempting to load a class "Foo" with the following constructor: |
||
966 | * __construct( Bar $bar_class, Fighter $grohl_class ) |
||
967 | * then $bar_class and $grohl_class will be added to the $arguments array, |
||
968 | * but only IF they are NOT already present in the incoming arguments array, |
||
969 | * and the correct classes can be loaded |
||
970 | * |
||
971 | * @access protected |
||
972 | * @param ReflectionClass $reflector |
||
973 | * @param string $class_name |
||
974 | * @param array $arguments |
||
975 | * @return array |
||
976 | * @throws \ReflectionException |
||
977 | */ |
||
978 | protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
||
1032 | |||
1033 | |||
1034 | |||
1035 | /** |
||
1036 | * @access protected |
||
1037 | * @param string $class_name |
||
1038 | * @param string $param_class |
||
1039 | * @param array $arguments |
||
1040 | * @param mixed $index |
||
1041 | * @return array |
||
1042 | */ |
||
1043 | protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
||
1085 | |||
1086 | |||
1087 | |||
1088 | /** |
||
1089 | * _set_cached_class |
||
1090 | * attempts to cache the instantiated class locally |
||
1091 | * in one of the following places, in the following order: |
||
1092 | * $this->{class_abbreviation} ie: $this->CART |
||
1093 | * $this->{$class_name} ie: $this->Some_Class |
||
1094 | * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
||
1095 | * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
||
1096 | * |
||
1097 | * @access protected |
||
1098 | * @param object $class_obj |
||
1099 | * @param string $class_name |
||
1100 | * @param string $class_prefix |
||
1101 | * @param bool $from_db |
||
1102 | * @return void |
||
1103 | */ |
||
1104 | protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
||
1121 | |||
1122 | |||
1123 | |||
1124 | /** |
||
1125 | * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
||
1126 | * |
||
1127 | * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
||
1128 | * in the EE_Dependency_Map::$_class_loaders array, |
||
1129 | * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
||
1130 | * @param array $arguments |
||
1131 | * @return object |
||
1132 | */ |
||
1133 | public static function factory($classname, $arguments = array()) |
||
1143 | |||
1144 | |||
1145 | |||
1146 | /** |
||
1147 | * Gets the addon by its name/slug (not classname. For that, just |
||
1148 | * use the classname as the property name on EE_Config::instance()->addons) |
||
1149 | * |
||
1150 | * @param string $name |
||
1151 | * @return EE_Addon |
||
1152 | */ |
||
1153 | public function get_addon_by_name($name) |
||
1162 | |||
1163 | |||
1164 | |||
1165 | /** |
||
1166 | * 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 |
||
1167 | * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
||
1168 | * |
||
1169 | * @return EE_Addon[] where the KEYS are the addon's name() |
||
1170 | */ |
||
1171 | public function get_addons_by_name() |
||
1179 | |||
1180 | |||
1181 | |||
1182 | /** |
||
1183 | * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
||
1184 | * a stale copy of it around |
||
1185 | * |
||
1186 | * @param string $model_name |
||
1187 | * @return \EEM_Base |
||
1188 | * @throws \EE_Error |
||
1189 | */ |
||
1190 | public function reset_model($model_name) |
||
1204 | |||
1205 | |||
1206 | |||
1207 | /** |
||
1208 | * Resets the registry. |
||
1209 | * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
||
1210 | * is used in a multisite install. Here is a list of things that are NOT reset. |
||
1211 | * - $_dependency_map |
||
1212 | * - $_class_abbreviations |
||
1213 | * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
||
1214 | * - $REQ: Still on the same request so no need to change. |
||
1215 | * - $CAP: There is no site specific state in the EE_Capability class. |
||
1216 | * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
||
1217 | * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
||
1218 | * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
||
1219 | * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
||
1220 | * switch or on the restore. |
||
1221 | * - $modules |
||
1222 | * - $shortcodes |
||
1223 | * - $widgets |
||
1224 | * |
||
1225 | * @param boolean $hard whether to reset data in the database too, or just refresh |
||
1226 | * the Registry to its state at the beginning of the request |
||
1227 | * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
||
1228 | * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
||
1229 | * currently reinstantiate the singletons at the moment) |
||
1230 | * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
||
1231 | * code instead can just change the model context to a different blog id if necessary |
||
1232 | * @return EE_Registry |
||
1233 | */ |
||
1234 | public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
||
1257 | |||
1258 | |||
1259 | |||
1260 | /** |
||
1261 | * if passed object implements ResettableInterface, then call it's reset() method |
||
1262 | * if passed object implements InterminableInterface, then return false, |
||
1263 | * to indicate that it should NOT be cleared from the Registry cache |
||
1264 | * |
||
1265 | * @param $object |
||
1266 | * @param bool $reset_models |
||
1267 | * @return bool returns true if cached object should be unset |
||
1268 | */ |
||
1269 | private static function _reset_and_unset_object($object, $reset_models) |
||
1289 | |||
1290 | |||
1291 | |||
1292 | /** |
||
1293 | * @override magic methods |
||
1294 | * @return void |
||
1295 | */ |
||
1296 | public final function __destruct() |
||
1299 | |||
1300 | |||
1301 | |||
1302 | /** |
||
1303 | * @param $a |
||
1304 | * @param $b |
||
1305 | */ |
||
1306 | public final function __call($a, $b) |
||
1309 | |||
1310 | |||
1311 | |||
1312 | /** |
||
1313 | * @param $a |
||
1314 | */ |
||
1315 | public final function __get($a) |
||
1318 | |||
1319 | |||
1320 | |||
1321 | /** |
||
1322 | * @param $a |
||
1323 | * @param $b |
||
1324 | */ |
||
1325 | public final function __set($a, $b) |
||
1328 | |||
1329 | |||
1330 | |||
1331 | /** |
||
1332 | * @param $a |
||
1333 | */ |
||
1334 | public final function __isset($a) |
||
1337 | |||
1338 | |||
1339 | |||
1340 | /** |
||
1341 | * @param $a |
||
1342 | */ |
||
1343 | public final function __unset($a) |
||
1346 | |||
1347 | |||
1348 | |||
1349 | /** |
||
1350 | * @return array |
||
1351 | */ |
||
1352 | public final function __sleep() |
||
1356 | |||
1357 | |||
1358 | |||
1359 | public final function __wakeup() |
||
1362 | |||
1363 | |||
1364 | |||
1365 | /** |
||
1366 | * @return string |
||
1367 | */ |
||
1368 | public final function __toString() |
||
1372 | |||
1373 | |||
1374 | |||
1375 | public final function __invoke() |
||
1378 | |||
1379 | |||
1380 | |||
1381 | public final static function __set_state($array = array()) |
||
1385 | |||
1386 | |||
1387 | |||
1388 | public final function __clone() |
||
1391 | |||
1392 | |||
1393 | |||
1394 | /** |
||
1395 | * @param $a |
||
1396 | * @param $b |
||
1397 | */ |
||
1398 | public final static function __callStatic($a, $b) |
||
1401 | |||
1402 | |||
1403 | |||
1404 | /** |
||
1405 | * Gets all the custom post type models defined |
||
1406 | * |
||
1407 | * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
||
1408 | */ |
||
1409 | public function cpt_models() |
||
1419 | |||
1420 | |||
1421 | |||
1422 | /** |
||
1423 | * @return \EE_Config |
||
1424 | */ |
||
1425 | public static function CFG() |
||
1429 | |||
1430 | |||
1431 | } |
||
1432 | // End of file EE_Registry.core.php |
||
1434 |
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):