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 |
||
16 | class EE_Registry |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * EE_Registry Object |
||
21 | * |
||
22 | * @var EE_Registry $_instance |
||
23 | * @access private |
||
24 | */ |
||
25 | private static $_instance = null; |
||
26 | |||
27 | /** |
||
28 | * @var EE_Dependency_Map $_dependency_map |
||
29 | * @access protected |
||
30 | */ |
||
31 | protected $_dependency_map = null; |
||
32 | |||
33 | /** |
||
34 | * @var array $_class_abbreviations |
||
35 | * @access protected |
||
36 | */ |
||
37 | protected $_class_abbreviations = array(); |
||
38 | |||
39 | /** |
||
40 | * @access public |
||
41 | * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
||
42 | */ |
||
43 | public $BUS; |
||
44 | |||
45 | /** |
||
46 | * EE_Cart Object |
||
47 | * |
||
48 | * @access public |
||
49 | * @var EE_Cart $CART |
||
50 | */ |
||
51 | public $CART = null; |
||
52 | |||
53 | /** |
||
54 | * EE_Config Object |
||
55 | * |
||
56 | * @access public |
||
57 | * @var EE_Config $CFG |
||
58 | */ |
||
59 | public $CFG = null; |
||
60 | |||
61 | /** |
||
62 | * EE_Network_Config Object |
||
63 | * |
||
64 | * @access public |
||
65 | * @var EE_Network_Config $NET_CFG |
||
66 | */ |
||
67 | public $NET_CFG = null; |
||
68 | |||
69 | /** |
||
70 | * StdClass object for storing library classes in |
||
71 | * |
||
72 | * @public LIB |
||
73 | * @var StdClass $LIB |
||
74 | */ |
||
75 | public $LIB = null; |
||
76 | |||
77 | /** |
||
78 | * EE_Request_Handler Object |
||
79 | * |
||
80 | * @access public |
||
81 | * @var EE_Request_Handler $REQ |
||
82 | */ |
||
83 | public $REQ = null; |
||
84 | |||
85 | /** |
||
86 | * EE_Session Object |
||
87 | * |
||
88 | * @access public |
||
89 | * @var EE_Session $SSN |
||
90 | */ |
||
91 | public $SSN = null; |
||
92 | |||
93 | /** |
||
94 | * holds the ee capabilities object. |
||
95 | * |
||
96 | * @since 4.5.0 |
||
97 | * @var EE_Capabilities |
||
98 | */ |
||
99 | public $CAP = null; |
||
100 | |||
101 | /** |
||
102 | * holds the EE_Message_Resource_Manager object. |
||
103 | * |
||
104 | * @since 4.9.0 |
||
105 | * @var EE_Message_Resource_Manager |
||
106 | */ |
||
107 | public $MRM = null; |
||
108 | |||
109 | |||
110 | /** |
||
111 | * Holds the Assets Registry instance |
||
112 | * @var Registry |
||
113 | */ |
||
114 | public $AssetsRegistry = null; |
||
115 | |||
116 | /** |
||
117 | * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
||
118 | * |
||
119 | * @access public |
||
120 | * @var EE_Addon[] |
||
121 | */ |
||
122 | public $addons = null; |
||
123 | |||
124 | /** |
||
125 | * $models |
||
126 | * @access public |
||
127 | * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
||
128 | */ |
||
129 | public $models = array(); |
||
130 | |||
131 | /** |
||
132 | * $modules |
||
133 | * @access public |
||
134 | * @var EED_Module[] $modules |
||
135 | */ |
||
136 | public $modules = null; |
||
137 | |||
138 | /** |
||
139 | * $shortcodes |
||
140 | * @access public |
||
141 | * @var EES_Shortcode[] $shortcodes |
||
142 | */ |
||
143 | public $shortcodes = null; |
||
144 | |||
145 | /** |
||
146 | * $widgets |
||
147 | * @access public |
||
148 | * @var WP_Widget[] $widgets |
||
149 | */ |
||
150 | public $widgets = null; |
||
151 | |||
152 | /** |
||
153 | * $non_abstract_db_models |
||
154 | * @access public |
||
155 | * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
||
156 | * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
||
157 | * Keys are model "short names" (eg "Event") as used in model relations, and values are |
||
158 | * classnames (eg "EEM_Event") |
||
159 | */ |
||
160 | public $non_abstract_db_models = array(); |
||
161 | |||
162 | |||
163 | /** |
||
164 | * $i18n_js_strings - internationalization for JS strings |
||
165 | * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
||
166 | * in js file: var translatedString = eei18n.string_key; |
||
167 | * |
||
168 | * @access public |
||
169 | * @var array |
||
170 | */ |
||
171 | public static $i18n_js_strings = array(); |
||
172 | |||
173 | |||
174 | /** |
||
175 | * $main_file - path to espresso.php |
||
176 | * |
||
177 | * @access public |
||
178 | * @var array |
||
179 | */ |
||
180 | public $main_file; |
||
181 | |||
182 | /** |
||
183 | * array of ReflectionClass objects where the key is the class name |
||
184 | * |
||
185 | * @access public |
||
186 | * @var ReflectionClass[] |
||
187 | */ |
||
188 | public $_reflectors; |
||
189 | |||
190 | /** |
||
191 | * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
||
192 | * |
||
193 | * @access protected |
||
194 | * @var boolean $_cache_on |
||
195 | */ |
||
196 | protected $_cache_on = true; |
||
197 | |||
198 | |||
199 | |||
200 | /** |
||
201 | * @singleton method used to instantiate class object |
||
202 | * @access public |
||
203 | * @param \EE_Dependency_Map $dependency_map |
||
204 | * @return \EE_Registry instance |
||
205 | */ |
||
206 | public static function instance(\EE_Dependency_Map $dependency_map = null) |
||
207 | { |
||
208 | // check if class object is instantiated |
||
209 | if ( ! self::$_instance instanceof EE_Registry) { |
||
210 | self::$_instance = new EE_Registry($dependency_map); |
||
|
|||
211 | } |
||
212 | return self::$_instance; |
||
213 | } |
||
214 | |||
215 | |||
216 | |||
217 | /** |
||
218 | *protected constructor to prevent direct creation |
||
219 | * |
||
220 | * @Constructor |
||
221 | * @access protected |
||
222 | * @param \EE_Dependency_Map $dependency_map |
||
223 | */ |
||
224 | protected function __construct(\EE_Dependency_Map $dependency_map) |
||
225 | { |
||
226 | $this->_dependency_map = $dependency_map; |
||
227 | $this->LIB = new stdClass(); |
||
228 | $this->addons = new stdClass(); |
||
229 | $this->modules = new stdClass(); |
||
230 | $this->shortcodes = new stdClass(); |
||
231 | $this->widgets = new stdClass(); |
||
232 | add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
||
233 | } |
||
234 | |||
235 | |||
236 | |||
237 | /** |
||
238 | * initialize |
||
239 | */ |
||
240 | public function initialize() |
||
241 | { |
||
242 | $this->_class_abbreviations = apply_filters( |
||
243 | 'FHEE__EE_Registry____construct___class_abbreviations', |
||
244 | array( |
||
245 | 'EE_Config' => 'CFG', |
||
246 | 'EE_Session' => 'SSN', |
||
247 | 'EE_Capabilities' => 'CAP', |
||
248 | 'EE_Cart' => 'CART', |
||
249 | 'EE_Network_Config' => 'NET_CFG', |
||
250 | 'EE_Request_Handler' => 'REQ', |
||
251 | 'EE_Message_Resource_Manager' => 'MRM', |
||
252 | 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
||
253 | 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
||
254 | ) |
||
255 | ); |
||
256 | $this->load_core('Base', array(), true); |
||
257 | // add our request and response objects to the cache |
||
258 | $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
||
259 | $this->_set_cached_class( |
||
260 | $request_loader(), |
||
261 | 'EE_Request' |
||
262 | ); |
||
263 | $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
||
264 | $this->_set_cached_class( |
||
265 | $response_loader(), |
||
266 | 'EE_Response' |
||
267 | ); |
||
268 | add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
||
269 | } |
||
270 | |||
271 | |||
272 | |||
273 | /** |
||
274 | * init |
||
275 | * |
||
276 | * @access public |
||
277 | * @return void |
||
278 | */ |
||
279 | public function init() |
||
287 | |||
288 | |||
289 | |||
290 | /** |
||
291 | * localize_i18n_js_strings |
||
292 | * |
||
293 | * @return string |
||
294 | */ |
||
295 | public static function localize_i18n_js_strings() |
||
305 | |||
306 | |||
307 | |||
308 | /** |
||
309 | * @param mixed string | EED_Module $module |
||
310 | */ |
||
311 | public function add_module($module) |
||
323 | |||
324 | |||
325 | |||
326 | /** |
||
327 | * @param string $module_name |
||
328 | * @return mixed EED_Module | NULL |
||
329 | */ |
||
330 | public function get_module($module_name = '') |
||
334 | |||
335 | |||
336 | |||
337 | /** |
||
338 | * loads core classes - must be singletons |
||
339 | * |
||
340 | * @access public |
||
341 | * @param string $class_name - simple class name ie: session |
||
342 | * @param mixed $arguments |
||
343 | * @param bool $load_only |
||
344 | * @return mixed |
||
345 | */ |
||
346 | public function load_core($class_name, $arguments = array(), $load_only = false) |
||
362 | |||
363 | |||
364 | |||
365 | /** |
||
366 | * loads service classes |
||
367 | * |
||
368 | * @access public |
||
369 | * @param string $class_name - simple class name ie: session |
||
370 | * @param mixed $arguments |
||
371 | * @param bool $load_only |
||
372 | * @return mixed |
||
373 | */ |
||
374 | public function load_service($class_name, $arguments = array(), $load_only = false) |
||
385 | |||
386 | |||
387 | |||
388 | /** |
||
389 | * loads data_migration_scripts |
||
390 | * |
||
391 | * @access public |
||
392 | * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
||
393 | * @param mixed $arguments |
||
394 | * @return EE_Data_Migration_Script_Base|mixed |
||
395 | */ |
||
396 | public function load_dms($class_name, $arguments = array()) |
||
401 | |||
402 | |||
403 | |||
404 | /** |
||
405 | * loads object creating classes - must be singletons |
||
406 | * |
||
407 | * @param string $class_name - simple class name ie: attendee |
||
408 | * @param mixed $arguments - an array of arguments to pass to the class |
||
409 | * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
||
410 | * @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) |
||
411 | * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
||
412 | * @return EE_Base_Class | bool |
||
413 | */ |
||
414 | public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
||
424 | |||
425 | |||
426 | |||
427 | /** |
||
428 | * loads helper classes - must be singletons |
||
429 | * |
||
430 | * @param string $class_name - simple class name ie: price |
||
431 | * @param mixed $arguments |
||
432 | * @param bool $load_only |
||
433 | * @return EEH_Base | bool |
||
434 | */ |
||
435 | public function load_helper($class_name, $arguments = array(), $load_only = true) |
||
442 | |||
443 | |||
444 | |||
445 | /** |
||
446 | * loads core classes - must be singletons |
||
447 | * |
||
448 | * @access public |
||
449 | * @param string $class_name - simple class name ie: session |
||
450 | * @param mixed $arguments |
||
451 | * @param bool $load_only |
||
452 | * @param bool $cache whether to cache the object or not. |
||
453 | * @return mixed |
||
454 | */ |
||
455 | public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
||
467 | |||
468 | |||
469 | |||
470 | /** |
||
471 | * loads model classes - must be singletons |
||
472 | * |
||
473 | * @param string $class_name - simple class name ie: price |
||
474 | * @param mixed $arguments |
||
475 | * @param bool $load_only |
||
476 | * @return EEM_Base | bool |
||
477 | */ |
||
478 | public function load_model($class_name, $arguments = array(), $load_only = false) |
||
487 | |||
488 | |||
489 | |||
490 | /** |
||
491 | * loads model classes - must be singletons |
||
492 | * |
||
493 | * @param string $class_name - simple class name ie: price |
||
494 | * @param mixed $arguments |
||
495 | * @param bool $load_only |
||
496 | * @return mixed | bool |
||
497 | */ |
||
498 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
||
509 | |||
510 | |||
511 | |||
512 | /** |
||
513 | * Determines if $model_name is the name of an actual EE model. |
||
514 | * |
||
515 | * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
||
516 | * @return boolean |
||
517 | */ |
||
518 | public function is_model_name($model_name) |
||
522 | |||
523 | |||
524 | |||
525 | /** |
||
526 | * generic class loader |
||
527 | * |
||
528 | * @param string $path_to_file - directory path to file location, not including filename |
||
529 | * @param string $file_name - file name ie: my_file.php, including extension |
||
530 | * @param string $type - file type - core? class? helper? model? |
||
531 | * @param mixed $arguments |
||
532 | * @param bool $load_only |
||
533 | * @return mixed |
||
534 | */ |
||
535 | public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
||
540 | |||
541 | |||
542 | |||
543 | /** |
||
544 | * load_addon |
||
545 | * |
||
546 | * @param string $path_to_file - directory path to file location, not including filename |
||
547 | * @param string $class_name - full class name ie: My_Class |
||
548 | * @param string $type - file type - core? class? helper? model? |
||
549 | * @param mixed $arguments |
||
550 | * @param bool $load_only |
||
551 | * @return EE_Addon |
||
552 | */ |
||
553 | public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
||
558 | |||
559 | |||
560 | |||
561 | /** |
||
562 | * instantiates, caches, and automatically resolves dependencies |
||
563 | * for classes that use a Fully Qualified Class Name. |
||
564 | * if the class is not capable of being loaded using PSR-4 autoloading, |
||
565 | * then you need to use one of the existing load_*() methods |
||
566 | * which can resolve the classname and filepath from the passed arguments |
||
567 | * |
||
568 | * @param bool|string $class_name Fully Qualified Class Name |
||
569 | * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
||
570 | * @param bool $cache whether to cache the instantiated object for reuse |
||
571 | * @param bool $from_db some classes are instantiated from the db |
||
572 | * and thus call a different method to instantiate |
||
573 | * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
||
574 | * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
||
575 | * @return mixed null = failure to load or instantiate class object. |
||
576 | * object = class loaded and instantiated successfully. |
||
577 | * bool = fail or success when $load_only is true |
||
578 | * @throws EE_Error |
||
579 | */ |
||
580 | public function create( |
||
623 | |||
624 | |||
625 | |||
626 | /** |
||
627 | * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
||
628 | * |
||
629 | * @param string $class_name |
||
630 | * @param int $attempt |
||
631 | * @return mixed |
||
632 | */ |
||
633 | private function loadOrVerifyClassExists($class_name, $attempt = 1) { |
||
658 | |||
659 | |||
660 | |||
661 | /** |
||
662 | * instantiates, caches, and injects dependencies for classes |
||
663 | * |
||
664 | * @param array $file_paths an array of paths to folders to look in |
||
665 | * @param string $class_prefix EE or EEM or... ??? |
||
666 | * @param bool|string $class_name $class name |
||
667 | * @param string $type file type - core? class? helper? model? |
||
668 | * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
||
669 | * @param bool $from_db some classes are instantiated from the db |
||
670 | * and thus call a different method to instantiate |
||
671 | * @param bool $cache whether to cache the instantiated object for reuse |
||
672 | * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
||
673 | * @return bool|null|object null = failure to load or instantiate class object. |
||
674 | * object = class loaded and instantiated successfully. |
||
675 | * bool = fail or success when $load_only is true |
||
676 | * @throws EE_Error |
||
677 | */ |
||
678 | protected function _load( |
||
735 | |||
736 | |||
737 | |||
738 | |||
739 | /** |
||
740 | * _get_cached_class |
||
741 | * attempts to find a cached version of the requested class |
||
742 | * by looking in the following places: |
||
743 | * $this->{$class_abbreviation} ie: $this->CART |
||
744 | * $this->{$class_name} ie: $this->Some_Class |
||
745 | * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
||
746 | * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
||
747 | * |
||
748 | * @access protected |
||
749 | * @param string $class_name |
||
750 | * @param string $class_prefix |
||
751 | * @return mixed |
||
752 | */ |
||
753 | protected function _get_cached_class($class_name, $class_prefix = '') |
||
775 | |||
776 | |||
777 | |||
778 | /** |
||
779 | * removes a cached version of the requested class |
||
780 | * |
||
781 | * @param string $class_name |
||
782 | * @param boolean $addon |
||
783 | * @return boolean |
||
784 | */ |
||
785 | public function clear_cached_class($class_name, $addon = false) |
||
811 | |||
812 | |||
813 | /** |
||
814 | * _resolve_path |
||
815 | * attempts to find a full valid filepath for the requested class. |
||
816 | * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
||
817 | * then returns that path if the target file has been found and is readable |
||
818 | * |
||
819 | * @access protected |
||
820 | * @param string $class_name |
||
821 | * @param string $type |
||
822 | * @param array $file_paths |
||
823 | * @return string | bool |
||
824 | */ |
||
825 | protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
||
844 | |||
845 | |||
846 | |||
847 | /** |
||
848 | * _require_file |
||
849 | * basically just performs a require_once() |
||
850 | * but with some error handling |
||
851 | * |
||
852 | * @access protected |
||
853 | * @param string $path |
||
854 | * @param string $class_name |
||
855 | * @param string $type |
||
856 | * @param array $file_paths |
||
857 | * @return boolean |
||
858 | * @throws \EE_Error |
||
859 | */ |
||
860 | protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
||
896 | |||
897 | |||
898 | |||
899 | /** |
||
900 | * _create_object |
||
901 | * Attempts to instantiate the requested class via any of the |
||
902 | * commonly used instantiation methods employed throughout EE. |
||
903 | * The priority for instantiation is as follows: |
||
904 | * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
||
905 | * - model objects via their 'new_instance_from_db' method |
||
906 | * - model objects via their 'new_instance' method |
||
907 | * - "singleton" classes" via their 'instance' method |
||
908 | * - standard instantiable classes via their __constructor |
||
909 | * Prior to instantiation, if the classname exists in the dependency_map, |
||
910 | * then the constructor for the requested class will be examined to determine |
||
911 | * if any dependencies exist, and if they can be injected. |
||
912 | * If so, then those classes will be added to the array of arguments passed to the constructor |
||
913 | * |
||
914 | * @access protected |
||
915 | * @param string $class_name |
||
916 | * @param array $arguments |
||
917 | * @param string $type |
||
918 | * @param bool $from_db |
||
919 | * @return null | object |
||
920 | * @throws \EE_Error |
||
921 | */ |
||
922 | protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
||
989 | |||
990 | |||
991 | |||
992 | /** |
||
993 | * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
||
994 | * @param array $array |
||
995 | * @return bool |
||
996 | */ |
||
997 | protected function _array_is_numerically_and_sequentially_indexed(array $array) |
||
1001 | |||
1002 | |||
1003 | |||
1004 | /** |
||
1005 | * getReflectionClass |
||
1006 | * checks if a ReflectionClass object has already been generated for a class |
||
1007 | * and returns that instead of creating a new one |
||
1008 | * |
||
1009 | * @access public |
||
1010 | * @param string $class_name |
||
1011 | * @return ReflectionClass |
||
1012 | */ |
||
1013 | View Code Duplication | public function get_ReflectionClass($class_name) |
|
1023 | |||
1024 | |||
1025 | |||
1026 | /** |
||
1027 | * _resolve_dependencies |
||
1028 | * examines the constructor for the requested class to determine |
||
1029 | * if any dependencies exist, and if they can be injected. |
||
1030 | * If so, then those classes will be added to the array of arguments passed to the constructor |
||
1031 | * PLZ NOTE: this is achieved by type hinting the constructor params |
||
1032 | * For example: |
||
1033 | * if attempting to load a class "Foo" with the following constructor: |
||
1034 | * __construct( Bar $bar_class, Fighter $grohl_class ) |
||
1035 | * then $bar_class and $grohl_class will be added to the $arguments array, |
||
1036 | * but only IF they are NOT already present in the incoming arguments array, |
||
1037 | * and the correct classes can be loaded |
||
1038 | * |
||
1039 | * @access protected |
||
1040 | * @param ReflectionClass $reflector |
||
1041 | * @param string $class_name |
||
1042 | * @param array $arguments |
||
1043 | * @return array |
||
1044 | * @throws \ReflectionException |
||
1045 | */ |
||
1046 | protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
||
1106 | |||
1107 | |||
1108 | |||
1109 | /** |
||
1110 | * @access protected |
||
1111 | * @param string $class_name |
||
1112 | * @param string $param_class |
||
1113 | * @param array $arguments |
||
1114 | * @param mixed $index |
||
1115 | * @return array |
||
1116 | */ |
||
1117 | protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
||
1159 | |||
1160 | |||
1161 | |||
1162 | /** |
||
1163 | * _set_cached_class |
||
1164 | * attempts to cache the instantiated class locally |
||
1165 | * in one of the following places, in the following order: |
||
1166 | * $this->{class_abbreviation} ie: $this->CART |
||
1167 | * $this->{$class_name} ie: $this->Some_Class |
||
1168 | * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
||
1169 | * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
||
1170 | * |
||
1171 | * @access protected |
||
1172 | * @param object $class_obj |
||
1173 | * @param string $class_name |
||
1174 | * @param string $class_prefix |
||
1175 | * @param bool $from_db |
||
1176 | * @return void |
||
1177 | */ |
||
1178 | protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
||
1202 | |||
1203 | |||
1204 | |||
1205 | /** |
||
1206 | * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
||
1207 | * |
||
1208 | * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
||
1209 | * in the EE_Dependency_Map::$_class_loaders array, |
||
1210 | * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
||
1211 | * @param array $arguments |
||
1212 | * @return object |
||
1213 | */ |
||
1214 | public static function factory($classname, $arguments = array()) |
||
1225 | |||
1226 | |||
1227 | |||
1228 | /** |
||
1229 | * Gets the addon by its name/slug (not classname. For that, just |
||
1230 | * use the classname as the property name on EE_Config::instance()->addons) |
||
1231 | * |
||
1232 | * @param string $name |
||
1233 | * @return EE_Addon |
||
1234 | */ |
||
1235 | public function get_addon_by_name($name) |
||
1244 | |||
1245 | |||
1246 | |||
1247 | /** |
||
1248 | * 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 |
||
1249 | * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
||
1250 | * |
||
1251 | * @return EE_Addon[] where the KEYS are the addon's name() |
||
1252 | */ |
||
1253 | public function get_addons_by_name() |
||
1261 | |||
1262 | |||
1263 | |||
1264 | /** |
||
1265 | * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
||
1266 | * a stale copy of it around |
||
1267 | * |
||
1268 | * @param string $model_name |
||
1269 | * @return \EEM_Base |
||
1270 | * @throws \EE_Error |
||
1271 | */ |
||
1272 | public function reset_model($model_name) |
||
1286 | |||
1287 | |||
1288 | |||
1289 | /** |
||
1290 | * Resets the registry. |
||
1291 | * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
||
1292 | * is used in a multisite install. Here is a list of things that are NOT reset. |
||
1293 | * - $_dependency_map |
||
1294 | * - $_class_abbreviations |
||
1295 | * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
||
1296 | * - $REQ: Still on the same request so no need to change. |
||
1297 | * - $CAP: There is no site specific state in the EE_Capability class. |
||
1298 | * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
||
1299 | * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
||
1300 | * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
||
1301 | * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
||
1302 | * switch or on the restore. |
||
1303 | * - $modules |
||
1304 | * - $shortcodes |
||
1305 | * - $widgets |
||
1306 | * |
||
1307 | * @param boolean $hard whether to reset data in the database too, or just refresh |
||
1308 | * the Registry to its state at the beginning of the request |
||
1309 | * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
||
1310 | * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
||
1311 | * currently reinstantiate the singletons at the moment) |
||
1312 | * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
||
1313 | * code instead can just change the model context to a different blog id if necessary |
||
1314 | * @return EE_Registry |
||
1315 | */ |
||
1316 | public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
||
1337 | |||
1338 | |||
1339 | |||
1340 | /** |
||
1341 | * @override magic methods |
||
1342 | * @return void |
||
1343 | */ |
||
1344 | public final function __destruct() |
||
1347 | |||
1348 | |||
1349 | |||
1350 | /** |
||
1351 | * @param $a |
||
1352 | * @param $b |
||
1353 | */ |
||
1354 | public final function __call($a, $b) |
||
1357 | |||
1358 | |||
1359 | |||
1360 | /** |
||
1361 | * @param $a |
||
1362 | */ |
||
1363 | public final function __get($a) |
||
1366 | |||
1367 | |||
1368 | |||
1369 | /** |
||
1370 | * @param $a |
||
1371 | * @param $b |
||
1372 | */ |
||
1373 | public final function __set($a, $b) |
||
1376 | |||
1377 | |||
1378 | |||
1379 | /** |
||
1380 | * @param $a |
||
1381 | */ |
||
1382 | public final function __isset($a) |
||
1385 | |||
1386 | |||
1387 | |||
1388 | /** |
||
1389 | * @param $a |
||
1390 | */ |
||
1391 | public final function __unset($a) |
||
1394 | |||
1395 | |||
1396 | |||
1397 | /** |
||
1398 | * @return array |
||
1399 | */ |
||
1400 | public final function __sleep() |
||
1404 | |||
1405 | |||
1406 | |||
1407 | public final function __wakeup() |
||
1410 | |||
1411 | |||
1412 | |||
1413 | /** |
||
1414 | * @return string |
||
1415 | */ |
||
1416 | public final function __toString() |
||
1420 | |||
1421 | |||
1422 | |||
1423 | public final function __invoke() |
||
1426 | |||
1427 | |||
1428 | |||
1429 | public final static function __set_state($array = array()) |
||
1433 | |||
1434 | |||
1435 | |||
1436 | public final function __clone() |
||
1439 | |||
1440 | |||
1441 | |||
1442 | /** |
||
1443 | * @param $a |
||
1444 | * @param $b |
||
1445 | */ |
||
1446 | public final static function __callStatic($a, $b) |
||
1449 | |||
1450 | |||
1451 | |||
1452 | /** |
||
1453 | * Gets all the custom post type models defined |
||
1454 | * |
||
1455 | * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
||
1456 | */ |
||
1457 | public function cpt_models() |
||
1467 | |||
1468 | |||
1469 | |||
1470 | /** |
||
1471 | * @return \EE_Config |
||
1472 | */ |
||
1473 | public static function CFG() |
||
1477 | |||
1478 | |||
1479 | } |
||
1480 | // End of file EE_Registry.core.php |
||
1482 |
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):