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 |
||
27 | class EE_Registry implements ResettableInterface |
||
28 | { |
||
29 | |||
30 | /** |
||
31 | * @var EE_Registry $_instance |
||
32 | */ |
||
33 | private static $_instance; |
||
34 | |||
35 | /** |
||
36 | * @var EE_Dependency_Map $_dependency_map |
||
37 | */ |
||
38 | protected $_dependency_map; |
||
39 | |||
40 | /** |
||
41 | * @var Mirror |
||
42 | */ |
||
43 | private $mirror; |
||
44 | |||
45 | /** |
||
46 | * @var ClassInterfaceCache $class_cache |
||
47 | */ |
||
48 | private $class_cache; |
||
49 | |||
50 | /** |
||
51 | * @var array $_class_abbreviations |
||
52 | */ |
||
53 | protected $_class_abbreviations = array(); |
||
54 | |||
55 | /** |
||
56 | * @var CommandBusInterface $BUS |
||
57 | */ |
||
58 | public $BUS; |
||
59 | |||
60 | /** |
||
61 | * @var EE_Cart $CART |
||
62 | */ |
||
63 | public $CART; |
||
64 | |||
65 | /** |
||
66 | * @var EE_Config $CFG |
||
67 | */ |
||
68 | public $CFG; |
||
69 | |||
70 | /** |
||
71 | * @var EE_Network_Config $NET_CFG |
||
72 | */ |
||
73 | public $NET_CFG; |
||
74 | |||
75 | /** |
||
76 | * StdClass object for storing library classes in |
||
77 | * |
||
78 | * @var RegistryContainer $LIB |
||
79 | */ |
||
80 | public $LIB; |
||
81 | |||
82 | /** |
||
83 | * @var EE_Request_Handler $REQ |
||
84 | */ |
||
85 | public $REQ; |
||
86 | |||
87 | /** |
||
88 | * @var EE_Session $SSN |
||
89 | */ |
||
90 | public $SSN; |
||
91 | |||
92 | /** |
||
93 | * @since 4.5.0 |
||
94 | * @var EE_Capabilities $CAP |
||
95 | */ |
||
96 | public $CAP; |
||
97 | |||
98 | /** |
||
99 | * @since 4.9.0 |
||
100 | * @var EE_Message_Resource_Manager $MRM |
||
101 | */ |
||
102 | public $MRM; |
||
103 | |||
104 | /** |
||
105 | * @var Registry $AssetsRegistry |
||
106 | */ |
||
107 | public $AssetsRegistry; |
||
108 | |||
109 | /** |
||
110 | * StdClass object for holding addons which have registered themselves to work with EE core |
||
111 | * |
||
112 | * @var EE_Addon[] $addons |
||
113 | */ |
||
114 | public $addons; |
||
115 | |||
116 | /** |
||
117 | * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
||
118 | * |
||
119 | * @var EEM_Base[] $models |
||
120 | */ |
||
121 | public $models = array(); |
||
122 | |||
123 | /** |
||
124 | * @var EED_Module[] $modules |
||
125 | */ |
||
126 | public $modules; |
||
127 | |||
128 | /** |
||
129 | * @var EES_Shortcode[] $shortcodes |
||
130 | */ |
||
131 | public $shortcodes; |
||
132 | |||
133 | /** |
||
134 | * @var WP_Widget[] $widgets |
||
135 | */ |
||
136 | public $widgets; |
||
137 | |||
138 | /** |
||
139 | * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
||
140 | * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
||
141 | * Keys are model "short names" (eg "Event") as used in model relations, and values are |
||
142 | * classnames (eg "EEM_Event") |
||
143 | * |
||
144 | * @var array $non_abstract_db_models |
||
145 | */ |
||
146 | public $non_abstract_db_models = array(); |
||
147 | |||
148 | /** |
||
149 | * internationalization for JS strings |
||
150 | * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
||
151 | * in js file: var translatedString = eei18n.string_key; |
||
152 | * |
||
153 | * @var array $i18n_js_strings |
||
154 | */ |
||
155 | public static $i18n_js_strings = array(); |
||
156 | |||
157 | /** |
||
158 | * $main_file - path to espresso.php |
||
159 | * |
||
160 | * @var array $main_file |
||
161 | */ |
||
162 | public $main_file; |
||
163 | |||
164 | /** |
||
165 | * array of ReflectionClass objects where the key is the class name |
||
166 | * |
||
167 | * @deprecated $VID:$ |
||
168 | * @var ReflectionClass[] $_reflectors |
||
169 | */ |
||
170 | public $_reflectors; |
||
171 | |||
172 | /** |
||
173 | * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
||
174 | * |
||
175 | * @var boolean $_cache_on |
||
176 | */ |
||
177 | protected $_cache_on = true; |
||
178 | |||
179 | /** |
||
180 | * @var ObjectIdentifier |
||
181 | */ |
||
182 | private $object_identifier; |
||
183 | |||
184 | |||
185 | /** |
||
186 | * @singleton method used to instantiate class object |
||
187 | * @param EE_Dependency_Map|null $dependency_map |
||
188 | * @param Mirror|null $mirror |
||
189 | * @param ClassInterfaceCache|null $class_cache |
||
190 | * @param ObjectIdentifier|null $object_identifier |
||
191 | * @return EE_Registry instance |
||
192 | */ |
||
193 | public static function instance( |
||
216 | |||
217 | |||
218 | /** |
||
219 | * protected constructor to prevent direct creation |
||
220 | * |
||
221 | * @Constructor |
||
222 | * @param EE_Dependency_Map $dependency_map |
||
223 | * @param Mirror $mirror |
||
224 | * @param ClassInterfaceCache $class_cache |
||
225 | * @param ObjectIdentifier $object_identifier |
||
226 | */ |
||
227 | protected function __construct( |
||
245 | |||
246 | |||
247 | /** |
||
248 | * initialize |
||
249 | * |
||
250 | * @throws OutOfBoundsException |
||
251 | * @throws InvalidArgumentException |
||
252 | * @throws InvalidInterfaceException |
||
253 | * @throws InvalidDataTypeException |
||
254 | * @throws EE_Error |
||
255 | * @throws ReflectionException |
||
256 | */ |
||
257 | public function initialize() |
||
291 | |||
292 | |||
293 | /** |
||
294 | * @return void |
||
295 | */ |
||
296 | public function init() |
||
304 | |||
305 | |||
306 | /** |
||
307 | * localize_i18n_js_strings |
||
308 | * |
||
309 | * @return string |
||
310 | */ |
||
311 | public static function localize_i18n_js_strings() |
||
321 | |||
322 | |||
323 | /** |
||
324 | * @param mixed string | EED_Module $module |
||
325 | * @throws OutOfBoundsException |
||
326 | * @throws InvalidArgumentException |
||
327 | * @throws InvalidInterfaceException |
||
328 | * @throws InvalidDataTypeException |
||
329 | * @throws EE_Error |
||
330 | * @throws ReflectionException |
||
331 | */ |
||
332 | public function add_module($module) |
||
344 | |||
345 | |||
346 | /** |
||
347 | * @param string $module_name |
||
348 | * @return mixed EED_Module | NULL |
||
349 | */ |
||
350 | public function get_module($module_name = '') |
||
356 | |||
357 | |||
358 | /** |
||
359 | * loads core classes - must be singletons |
||
360 | * |
||
361 | * @param string $class_name - simple class name ie: session |
||
362 | * @param mixed $arguments |
||
363 | * @param bool $load_only |
||
364 | * @return mixed |
||
365 | * @throws InvalidInterfaceException |
||
366 | * @throws InvalidDataTypeException |
||
367 | * @throws EE_Error |
||
368 | * @throws ReflectionException |
||
369 | * @throws InvalidArgumentException |
||
370 | */ |
||
371 | public function load_core($class_name, $arguments = array(), $load_only = false) |
||
397 | |||
398 | |||
399 | /** |
||
400 | * loads service classes |
||
401 | * |
||
402 | * @param string $class_name - simple class name ie: session |
||
403 | * @param mixed $arguments |
||
404 | * @param bool $load_only |
||
405 | * @return mixed |
||
406 | * @throws InvalidInterfaceException |
||
407 | * @throws InvalidDataTypeException |
||
408 | * @throws EE_Error |
||
409 | * @throws ReflectionException |
||
410 | * @throws InvalidArgumentException |
||
411 | */ |
||
412 | public function load_service($class_name, $arguments = array(), $load_only = false) |
||
432 | |||
433 | |||
434 | /** |
||
435 | * loads data_migration_scripts |
||
436 | * |
||
437 | * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
||
438 | * @param mixed $arguments |
||
439 | * @return EE_Data_Migration_Script_Base|mixed |
||
440 | * @throws InvalidInterfaceException |
||
441 | * @throws InvalidDataTypeException |
||
442 | * @throws EE_Error |
||
443 | * @throws ReflectionException |
||
444 | * @throws InvalidArgumentException |
||
445 | */ |
||
446 | public function load_dms($class_name, $arguments = array()) |
||
459 | |||
460 | |||
461 | /** |
||
462 | * loads object creating classes - must be singletons |
||
463 | * |
||
464 | * @param string $class_name - simple class name ie: attendee |
||
465 | * @param mixed $arguments - an array of arguments to pass to the class |
||
466 | * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
||
467 | * instantiate |
||
468 | * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
||
469 | * set this to FALSE (ie. when instantiating model objects from client in a loop) |
||
470 | * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
||
471 | * (default) |
||
472 | * @return EE_Base_Class | bool |
||
473 | * @throws InvalidInterfaceException |
||
474 | * @throws InvalidDataTypeException |
||
475 | * @throws EE_Error |
||
476 | * @throws ReflectionException |
||
477 | * @throws InvalidArgumentException |
||
478 | */ |
||
479 | public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
||
500 | |||
501 | |||
502 | /** |
||
503 | * loads helper classes - must be singletons |
||
504 | * |
||
505 | * @param string $class_name - simple class name ie: price |
||
506 | * @param mixed $arguments |
||
507 | * @param bool $load_only |
||
508 | * @return EEH_Base | bool |
||
509 | * @throws InvalidInterfaceException |
||
510 | * @throws InvalidDataTypeException |
||
511 | * @throws EE_Error |
||
512 | * @throws ReflectionException |
||
513 | * @throws InvalidArgumentException |
||
514 | */ |
||
515 | public function load_helper($class_name, $arguments = array(), $load_only = true) |
||
531 | |||
532 | |||
533 | /** |
||
534 | * loads core classes - must be singletons |
||
535 | * |
||
536 | * @param string $class_name - simple class name ie: session |
||
537 | * @param mixed $arguments |
||
538 | * @param bool $load_only |
||
539 | * @param bool $cache whether to cache the object or not. |
||
540 | * @return mixed |
||
541 | * @throws InvalidInterfaceException |
||
542 | * @throws InvalidDataTypeException |
||
543 | * @throws EE_Error |
||
544 | * @throws ReflectionException |
||
545 | * @throws InvalidArgumentException |
||
546 | */ |
||
547 | public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
||
568 | |||
569 | |||
570 | /** |
||
571 | * loads model classes - must be singletons |
||
572 | * |
||
573 | * @param string $class_name - simple class name ie: price |
||
574 | * @param mixed $arguments |
||
575 | * @param bool $load_only |
||
576 | * @return EEM_Base | bool |
||
577 | * @throws InvalidInterfaceException |
||
578 | * @throws InvalidDataTypeException |
||
579 | * @throws EE_Error |
||
580 | * @throws ReflectionException |
||
581 | * @throws InvalidArgumentException |
||
582 | */ |
||
583 | public function load_model($class_name, $arguments = array(), $load_only = false) |
||
603 | |||
604 | |||
605 | /** |
||
606 | * loads model classes - must be singletons |
||
607 | * |
||
608 | * @param string $class_name - simple class name ie: price |
||
609 | * @param mixed $arguments |
||
610 | * @param bool $load_only |
||
611 | * @return mixed | bool |
||
612 | * @throws InvalidInterfaceException |
||
613 | * @throws InvalidDataTypeException |
||
614 | * @throws EE_Error |
||
615 | * @throws ReflectionException |
||
616 | * @throws InvalidArgumentException |
||
617 | */ |
||
618 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
||
638 | |||
639 | |||
640 | /** |
||
641 | * Determines if $model_name is the name of an actual EE model. |
||
642 | * |
||
643 | * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
||
644 | * @return boolean |
||
645 | */ |
||
646 | public function is_model_name($model_name) |
||
650 | |||
651 | |||
652 | /** |
||
653 | * generic class loader |
||
654 | * |
||
655 | * @param string $path_to_file - directory path to file location, not including filename |
||
656 | * @param string $file_name - file name ie: my_file.php, including extension |
||
657 | * @param string $type - file type - core? class? helper? model? |
||
658 | * @param mixed $arguments |
||
659 | * @param bool $load_only |
||
660 | * @return mixed |
||
661 | * @throws InvalidInterfaceException |
||
662 | * @throws InvalidDataTypeException |
||
663 | * @throws EE_Error |
||
664 | * @throws ReflectionException |
||
665 | * @throws InvalidArgumentException |
||
666 | */ |
||
667 | public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
||
681 | |||
682 | |||
683 | /** |
||
684 | * @param string $path_to_file - directory path to file location, not including filename |
||
685 | * @param string $class_name - full class name ie: My_Class |
||
686 | * @param string $type - file type - core? class? helper? model? |
||
687 | * @param mixed $arguments |
||
688 | * @param bool $load_only |
||
689 | * @return bool|EE_Addon|object |
||
690 | * @throws InvalidInterfaceException |
||
691 | * @throws InvalidDataTypeException |
||
692 | * @throws EE_Error |
||
693 | * @throws ReflectionException |
||
694 | * @throws InvalidArgumentException |
||
695 | */ |
||
696 | public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
||
710 | |||
711 | |||
712 | /** |
||
713 | * instantiates, caches, and automatically resolves dependencies |
||
714 | * for classes that use a Fully Qualified Class Name. |
||
715 | * if the class is not capable of being loaded using PSR-4 autoloading, |
||
716 | * then you need to use one of the existing load_*() methods |
||
717 | * which can resolve the classname and filepath from the passed arguments |
||
718 | * |
||
719 | * @param bool|string $class_name Fully Qualified Class Name |
||
720 | * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
||
721 | * @param bool $cache whether to cache the instantiated object for reuse |
||
722 | * @param bool $from_db some classes are instantiated from the db |
||
723 | * and thus call a different method to instantiate |
||
724 | * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
||
725 | * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
||
726 | * @return bool|null|mixed null = failure to load or instantiate class object. |
||
727 | * object = class loaded and instantiated successfully. |
||
728 | * bool = fail or success when $load_only is true |
||
729 | * @throws InvalidInterfaceException |
||
730 | * @throws InvalidDataTypeException |
||
731 | * @throws EE_Error |
||
732 | * @throws ReflectionException |
||
733 | * @throws InvalidArgumentException |
||
734 | */ |
||
735 | public function create( |
||
792 | |||
793 | |||
794 | /** |
||
795 | * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
||
796 | * |
||
797 | * @param string|object $class_name |
||
798 | * @param array $arguments |
||
799 | * @param int $attempt |
||
800 | * @return mixed |
||
801 | */ |
||
802 | private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) |
||
828 | |||
829 | |||
830 | /** |
||
831 | * instantiates, caches, and injects dependencies for classes |
||
832 | * |
||
833 | * @param array $file_paths an array of paths to folders to look in |
||
834 | * @param string $class_prefix EE or EEM or... ??? |
||
835 | * @param bool|string $class_name $class name |
||
836 | * @param string $type file type - core? class? helper? model? |
||
837 | * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
||
838 | * @param bool $from_db some classes are instantiated from the db |
||
839 | * and thus call a different method to instantiate |
||
840 | * @param bool $cache whether to cache the instantiated object for reuse |
||
841 | * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
||
842 | * @return bool|null|object null = failure to load or instantiate class object. |
||
843 | * object = class loaded and instantiated successfully. |
||
844 | * bool = fail or success when $load_only is true |
||
845 | * @throws EE_Error |
||
846 | * @throws ReflectionException |
||
847 | * @throws InvalidInterfaceException |
||
848 | * @throws InvalidDataTypeException |
||
849 | * @throws InvalidArgumentException |
||
850 | */ |
||
851 | protected function _load( |
||
919 | |||
920 | |||
921 | /** |
||
922 | * @param string $class_name |
||
923 | * @param string $default have to specify something, but not anything that will conflict |
||
924 | * @return mixed|string |
||
925 | */ |
||
926 | protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
||
932 | |||
933 | |||
934 | /** |
||
935 | * attempts to find a cached version of the requested class |
||
936 | * by looking in the following places: |
||
937 | * $this->{$class_abbreviation} ie: $this->CART |
||
938 | * $this->{$class_name} ie: $this->Some_Class |
||
939 | * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
||
940 | * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
||
941 | * |
||
942 | * @param string $class_name |
||
943 | * @param string $class_prefix |
||
944 | * @param array $arguments |
||
945 | * @return mixed |
||
946 | */ |
||
947 | protected function _get_cached_class( |
||
983 | |||
984 | |||
985 | /** |
||
986 | * removes a cached version of the requested class |
||
987 | * |
||
988 | * @param string $class_name |
||
989 | * @param boolean $addon |
||
990 | * @param array $arguments |
||
991 | * @return boolean |
||
992 | */ |
||
993 | public function clear_cached_class( |
||
1020 | |||
1021 | |||
1022 | /** |
||
1023 | * _set_cached_class |
||
1024 | * attempts to cache the instantiated class locally |
||
1025 | * in one of the following places, in the following order: |
||
1026 | * $this->{class_abbreviation} ie: $this->CART |
||
1027 | * $this->{$class_name} ie: $this->Some_Class |
||
1028 | * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
||
1029 | * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
||
1030 | * |
||
1031 | * @param object $class_obj |
||
1032 | * @param string $class_name |
||
1033 | * @param string $class_prefix |
||
1034 | * @param bool $from_db |
||
1035 | * @param array $arguments |
||
1036 | * @return void |
||
1037 | */ |
||
1038 | protected function _set_cached_class( |
||
1068 | |||
1069 | |||
1070 | /** |
||
1071 | * attempts to find a full valid filepath for the requested class. |
||
1072 | * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
||
1073 | * then returns that path if the target file has been found and is readable |
||
1074 | * |
||
1075 | * @param string $class_name |
||
1076 | * @param string $type |
||
1077 | * @param array $file_paths |
||
1078 | * @return string | bool |
||
1079 | */ |
||
1080 | protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
||
1105 | |||
1106 | |||
1107 | /** |
||
1108 | * basically just performs a require_once() |
||
1109 | * but with some error handling |
||
1110 | * |
||
1111 | * @param string $path |
||
1112 | * @param string $class_name |
||
1113 | * @param string $type |
||
1114 | * @param array $file_paths |
||
1115 | * @return bool |
||
1116 | * @throws EE_Error |
||
1117 | * @throws ReflectionException |
||
1118 | */ |
||
1119 | protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
||
1170 | |||
1171 | |||
1172 | /** |
||
1173 | * Some of our legacy classes that extended a parent class would simply use a require() statement |
||
1174 | * before their class declaration in order to ensure that the parent class was loaded. |
||
1175 | * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
||
1176 | * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
||
1177 | * |
||
1178 | * @param string $class_name |
||
1179 | */ |
||
1180 | protected function resolve_legacy_class_parent($class_name = '') |
||
1192 | |||
1193 | |||
1194 | /** |
||
1195 | * _create_object |
||
1196 | * Attempts to instantiate the requested class via any of the |
||
1197 | * commonly used instantiation methods employed throughout EE. |
||
1198 | * The priority for instantiation is as follows: |
||
1199 | * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
||
1200 | * - model objects via their 'new_instance_from_db' method |
||
1201 | * - model objects via their 'new_instance' method |
||
1202 | * - "singleton" classes" via their 'instance' method |
||
1203 | * - standard instantiable classes via their __constructor |
||
1204 | * Prior to instantiation, if the classname exists in the dependency_map, |
||
1205 | * then the constructor for the requested class will be examined to determine |
||
1206 | * if any dependencies exist, and if they can be injected. |
||
1207 | * If so, then those classes will be added to the array of arguments passed to the constructor |
||
1208 | * |
||
1209 | * @param string $class_name |
||
1210 | * @param array $arguments |
||
1211 | * @param string $type |
||
1212 | * @param bool $from_db |
||
1213 | * @return null|object|bool |
||
1214 | * @throws InvalidArgumentException |
||
1215 | * @throws InvalidInterfaceException |
||
1216 | * @throws EE_Error |
||
1217 | * @throws ReflectionException |
||
1218 | * @throws InvalidDataTypeException |
||
1219 | */ |
||
1220 | protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
||
1278 | |||
1279 | |||
1280 | /** |
||
1281 | * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
||
1282 | * @param array $array |
||
1283 | * @return bool |
||
1284 | */ |
||
1285 | protected function _array_is_numerically_and_sequentially_indexed(array $array) |
||
1291 | |||
1292 | |||
1293 | /** |
||
1294 | * _resolve_dependencies |
||
1295 | * examines the constructor for the requested class to determine |
||
1296 | * if any dependencies exist, and if they can be injected. |
||
1297 | * If so, then those classes will be added to the array of arguments passed to the constructor |
||
1298 | * PLZ NOTE: this is achieved by type hinting the constructor params |
||
1299 | * For example: |
||
1300 | * if attempting to load a class "Foo" with the following constructor: |
||
1301 | * __construct( Bar $bar_class, Fighter $grohl_class ) |
||
1302 | * then $bar_class and $grohl_class will be added to the $arguments array, |
||
1303 | * but only IF they are NOT already present in the incoming arguments array, |
||
1304 | * and the correct classes can be loaded |
||
1305 | * |
||
1306 | * @param ReflectionClass $reflector |
||
1307 | * @param string $class_name |
||
1308 | * @param array $arguments |
||
1309 | * @return array |
||
1310 | * @throws InvalidArgumentException |
||
1311 | * @throws InvalidDataTypeException |
||
1312 | * @throws InvalidInterfaceException |
||
1313 | * @throws ReflectionException |
||
1314 | */ |
||
1315 | protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array()) |
||
1375 | |||
1376 | |||
1377 | /** |
||
1378 | * @param string $class_name |
||
1379 | * @param string $param_class |
||
1380 | * @param array $arguments |
||
1381 | * @param mixed $index |
||
1382 | * @return array |
||
1383 | * @throws InvalidArgumentException |
||
1384 | * @throws InvalidInterfaceException |
||
1385 | * @throws InvalidDataTypeException |
||
1386 | */ |
||
1387 | protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
||
1432 | |||
1433 | |||
1434 | /** |
||
1435 | * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
||
1436 | * |
||
1437 | * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
||
1438 | * in the EE_Dependency_Map::$_class_loaders array, |
||
1439 | * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
||
1440 | * @param array $arguments |
||
1441 | * @return object |
||
1442 | */ |
||
1443 | public static function factory($classname, $arguments = array()) |
||
1454 | |||
1455 | |||
1456 | /** |
||
1457 | * Gets the addon by its class name |
||
1458 | * |
||
1459 | * @param string $class_name |
||
1460 | * @return EE_Addon |
||
1461 | */ |
||
1462 | public function getAddon($class_name) |
||
1467 | |||
1468 | |||
1469 | /** |
||
1470 | * removes the addon from the internal cache |
||
1471 | * |
||
1472 | * @param string $class_name |
||
1473 | * @return void |
||
1474 | */ |
||
1475 | public function removeAddon($class_name) |
||
1480 | |||
1481 | |||
1482 | /** |
||
1483 | * Gets the addon by its name/slug (not classname. For that, just |
||
1484 | * use the get_addon() method above |
||
1485 | * |
||
1486 | * @param string $name |
||
1487 | * @return EE_Addon |
||
1488 | */ |
||
1489 | public function get_addon_by_name($name) |
||
1498 | |||
1499 | |||
1500 | /** |
||
1501 | * Gets an array of all the registered addons, where the keys are their names. |
||
1502 | * (ie, what each returns for their name() function) |
||
1503 | * They're already available on EE_Registry::instance()->addons as properties, |
||
1504 | * where each property's name is the addon's classname, |
||
1505 | * So if you just want to get the addon by classname, |
||
1506 | * OR use the get_addon() method above. |
||
1507 | * PLEASE NOTE: |
||
1508 | * addons with Fully Qualified Class Names |
||
1509 | * have had the namespace separators converted to underscores, |
||
1510 | * so a classname like Fully\Qualified\ClassName |
||
1511 | * would have been converted to Fully_Qualified_ClassName |
||
1512 | * |
||
1513 | * @return EE_Addon[] where the KEYS are the addon's name() |
||
1514 | */ |
||
1515 | public function get_addons_by_name() |
||
1523 | |||
1524 | |||
1525 | /** |
||
1526 | * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
||
1527 | * a stale copy of it around |
||
1528 | * |
||
1529 | * @param string $model_name |
||
1530 | * @return \EEM_Base |
||
1531 | * @throws \EE_Error |
||
1532 | */ |
||
1533 | public function reset_model($model_name) |
||
1557 | |||
1558 | |||
1559 | /** |
||
1560 | * Resets the registry. |
||
1561 | * The criteria for what gets reset is based on what can be shared between sites on the same request when |
||
1562 | * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
||
1563 | * - $_dependency_map |
||
1564 | * - $_class_abbreviations |
||
1565 | * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
||
1566 | * - $REQ: Still on the same request so no need to change. |
||
1567 | * - $CAP: There is no site specific state in the EE_Capability class. |
||
1568 | * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
||
1569 | * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
||
1570 | * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
||
1571 | * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
||
1572 | * switch or on the restore. |
||
1573 | * - $modules |
||
1574 | * - $shortcodes |
||
1575 | * - $widgets |
||
1576 | * |
||
1577 | * @param boolean $hard [deprecated] |
||
1578 | * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
||
1579 | * or just reset without re-instantiating (handy to set to FALSE if you're not |
||
1580 | * sure if you CAN currently reinstantiate the singletons at the moment) |
||
1581 | * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
||
1582 | * client |
||
1583 | * code instead can just change the model context to a different blog id if |
||
1584 | * necessary |
||
1585 | * @return EE_Registry |
||
1586 | * @throws InvalidInterfaceException |
||
1587 | * @throws InvalidDataTypeException |
||
1588 | * @throws EE_Error |
||
1589 | * @throws ReflectionException |
||
1590 | * @throws InvalidArgumentException |
||
1591 | */ |
||
1592 | public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
||
1617 | |||
1618 | |||
1619 | /** |
||
1620 | * if passed object implements ResettableInterface, then call it's reset() method |
||
1621 | * if passed object implements InterminableInterface, then return false, |
||
1622 | * to indicate that it should NOT be cleared from the Registry cache |
||
1623 | * |
||
1624 | * @param $object |
||
1625 | * @param bool $reset_models |
||
1626 | * @return bool returns true if cached object should be unset |
||
1627 | */ |
||
1628 | private static function _reset_and_unset_object($object, $reset_models) |
||
1655 | |||
1656 | |||
1657 | /** |
||
1658 | * Gets all the custom post type models defined |
||
1659 | * |
||
1660 | * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
||
1661 | */ |
||
1662 | public function cpt_models() |
||
1672 | |||
1673 | |||
1674 | /** |
||
1675 | * @return \EE_Config |
||
1676 | */ |
||
1677 | public static function CFG() |
||
1681 | |||
1682 | |||
1683 | /** |
||
1684 | * @deprecated $VID:$ |
||
1685 | * @param string $class_name |
||
1686 | * @return ReflectionClass |
||
1687 | * @throws ReflectionException |
||
1688 | * @throws InvalidDataTypeException |
||
1689 | */ |
||
1690 | public function get_ReflectionClass($class_name) |
||
1694 | } |
||
1695 | // End of file EE_Registry.core.php |
||
1697 |