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 |
||
| 20 | class EE_Registry implements ResettableInterface |
||
| 21 | { |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var EE_Registry $_instance |
||
| 25 | */ |
||
| 26 | private static $_instance; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var EE_Dependency_Map $_dependency_map |
||
| 30 | */ |
||
| 31 | protected $_dependency_map; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var array $_class_abbreviations |
||
| 35 | */ |
||
| 36 | protected $_class_abbreviations = array(); |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var CommandBusInterface $BUS |
||
| 40 | */ |
||
| 41 | public $BUS; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var EE_Cart $CART |
||
| 45 | */ |
||
| 46 | public $CART; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var EE_Config $CFG |
||
| 50 | */ |
||
| 51 | public $CFG; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var EE_Network_Config $NET_CFG |
||
| 55 | */ |
||
| 56 | public $NET_CFG; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * StdClass object for storing library classes in |
||
| 60 | * |
||
| 61 | * @var StdClass $LIB |
||
| 62 | */ |
||
| 63 | public $LIB; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var EE_Request_Handler $REQ |
||
| 67 | */ |
||
| 68 | public $REQ; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var EE_Session $SSN |
||
| 72 | */ |
||
| 73 | public $SSN; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @since 4.5.0 |
||
| 77 | * @var EE_Capabilities $CAP |
||
| 78 | */ |
||
| 79 | public $CAP; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @since 4.9.0 |
||
| 83 | * @var EE_Message_Resource_Manager $MRM |
||
| 84 | */ |
||
| 85 | public $MRM; |
||
| 86 | |||
| 87 | |||
| 88 | /** |
||
| 89 | * @var Registry $AssetsRegistry |
||
| 90 | */ |
||
| 91 | public $AssetsRegistry; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * StdClass object for holding addons which have registered themselves to work with EE core |
||
| 95 | * |
||
| 96 | * @var EE_Addon[] $addons |
||
| 97 | */ |
||
| 98 | public $addons; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
||
| 102 | * |
||
| 103 | * @var EEM_Base[] $models |
||
| 104 | */ |
||
| 105 | public $models = array(); |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @var EED_Module[] $modules |
||
| 109 | */ |
||
| 110 | public $modules; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @var EES_Shortcode[] $shortcodes |
||
| 114 | */ |
||
| 115 | public $shortcodes; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @var WP_Widget[] $widgets |
||
| 119 | */ |
||
| 120 | public $widgets; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
||
| 124 | * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
||
| 125 | * Keys are model "short names" (eg "Event") as used in model relations, and values are |
||
| 126 | * classnames (eg "EEM_Event") |
||
| 127 | * |
||
| 128 | * @var array $non_abstract_db_models |
||
| 129 | */ |
||
| 130 | public $non_abstract_db_models = array(); |
||
| 131 | |||
| 132 | |||
| 133 | /** |
||
| 134 | * internationalization for JS strings |
||
| 135 | * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
||
| 136 | * in js file: var translatedString = eei18n.string_key; |
||
| 137 | * |
||
| 138 | * @var array $i18n_js_strings |
||
| 139 | */ |
||
| 140 | public static $i18n_js_strings = array(); |
||
| 141 | |||
| 142 | |||
| 143 | /** |
||
| 144 | * $main_file - path to espresso.php |
||
| 145 | * |
||
| 146 | * @var array $main_file |
||
| 147 | */ |
||
| 148 | public $main_file; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * array of ReflectionClass objects where the key is the class name |
||
| 152 | * |
||
| 153 | * @var ReflectionClass[] $_reflectors |
||
| 154 | */ |
||
| 155 | public $_reflectors; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
||
| 159 | * |
||
| 160 | * @var boolean $_cache_on |
||
| 161 | */ |
||
| 162 | protected $_cache_on = true; |
||
| 163 | |||
| 164 | |||
| 165 | |||
| 166 | /** |
||
| 167 | * @singleton method used to instantiate class object |
||
| 168 | * @param EE_Dependency_Map $dependency_map |
||
| 169 | * @return EE_Registry instance |
||
| 170 | */ |
||
| 171 | public static function instance(EE_Dependency_Map $dependency_map = null) |
||
| 179 | |||
| 180 | |||
| 181 | |||
| 182 | /** |
||
| 183 | * protected constructor to prevent direct creation |
||
| 184 | * |
||
| 185 | * @Constructor |
||
| 186 | * @param EE_Dependency_Map $dependency_map |
||
| 187 | */ |
||
| 188 | protected function __construct(EE_Dependency_Map $dependency_map) |
||
| 198 | |||
| 199 | |||
| 200 | |||
| 201 | /** |
||
| 202 | * initialize |
||
| 203 | * |
||
| 204 | * @throws EE_Error |
||
| 205 | * @throws ReflectionException |
||
| 206 | */ |
||
| 207 | public function initialize() |
||
| 237 | |||
| 238 | |||
| 239 | |||
| 240 | /** |
||
| 241 | * @return void |
||
| 242 | */ |
||
| 243 | public function init() |
||
| 251 | |||
| 252 | |||
| 253 | |||
| 254 | /** |
||
| 255 | * localize_i18n_js_strings |
||
| 256 | * |
||
| 257 | * @return string |
||
| 258 | */ |
||
| 259 | public static function localize_i18n_js_strings() |
||
| 269 | |||
| 270 | |||
| 271 | |||
| 272 | /** |
||
| 273 | * @param $module |
||
| 274 | * @throws EE_Error |
||
| 275 | * @throws ReflectionException |
||
| 276 | */ |
||
| 277 | public function add_module($module) |
||
| 289 | |||
| 290 | |||
| 291 | |||
| 292 | /** |
||
| 293 | * @param string $module_name |
||
| 294 | * @return mixed EED_Module | NULL |
||
| 295 | */ |
||
| 296 | public function get_module($module_name = '') |
||
| 302 | |||
| 303 | |||
| 304 | |||
| 305 | /** |
||
| 306 | * loads core classes - must be singletons |
||
| 307 | * |
||
| 308 | * @param string $class_name - simple class name ie: session |
||
| 309 | * @param mixed $arguments |
||
| 310 | * @param bool $load_only |
||
| 311 | * @return mixed |
||
| 312 | * @throws EE_Error |
||
| 313 | * @throws ReflectionException |
||
| 314 | */ |
||
| 315 | public function load_core($class_name, $arguments = array(), $load_only = false) |
||
| 340 | |||
| 341 | |||
| 342 | |||
| 343 | /** |
||
| 344 | * loads service classes |
||
| 345 | * |
||
| 346 | * @param string $class_name - simple class name ie: session |
||
| 347 | * @param mixed $arguments |
||
| 348 | * @param bool $load_only |
||
| 349 | * @return mixed |
||
| 350 | * @throws EE_Error |
||
| 351 | * @throws ReflectionException |
||
| 352 | */ |
||
| 353 | public function load_service($class_name, $arguments = array(), $load_only = false) |
||
| 373 | |||
| 374 | |||
| 375 | |||
| 376 | /** |
||
| 377 | * loads data_migration_scripts |
||
| 378 | * |
||
| 379 | * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
||
| 380 | * @param mixed $arguments |
||
| 381 | * @return EE_Data_Migration_Script_Base|mixed |
||
| 382 | * @throws EE_Error |
||
| 383 | * @throws ReflectionException |
||
| 384 | */ |
||
| 385 | public function load_dms($class_name, $arguments = array()) |
||
| 398 | |||
| 399 | |||
| 400 | |||
| 401 | /** |
||
| 402 | * loads object creating classes - must be singletons |
||
| 403 | * |
||
| 404 | * @param string $class_name - simple class name ie: attendee |
||
| 405 | * @param mixed $arguments - an array of arguments to pass to the class |
||
| 406 | * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
||
| 407 | * instantiate |
||
| 408 | * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
||
| 409 | * set this to FALSE (ie. when instantiating model objects from client in a loop) |
||
| 410 | * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
||
| 411 | * (default) |
||
| 412 | * @return EE_Base_Class | bool |
||
| 413 | * @throws EE_Error |
||
| 414 | * @throws ReflectionException |
||
| 415 | */ |
||
| 416 | public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
||
| 437 | |||
| 438 | |||
| 439 | |||
| 440 | /** |
||
| 441 | * loads helper classes - must be singletons |
||
| 442 | * |
||
| 443 | * @param string $class_name - simple class name ie: price |
||
| 444 | * @param mixed $arguments |
||
| 445 | * @param bool $load_only |
||
| 446 | * @return EEH_Base | bool |
||
| 447 | * @throws EE_Error |
||
| 448 | * @throws ReflectionException |
||
| 449 | */ |
||
| 450 | public function load_helper($class_name, $arguments = array(), $load_only = true) |
||
| 466 | |||
| 467 | |||
| 468 | |||
| 469 | /** |
||
| 470 | * loads core classes - must be singletons |
||
| 471 | * |
||
| 472 | * @param string $class_name - simple class name ie: session |
||
| 473 | * @param mixed $arguments |
||
| 474 | * @param bool $load_only |
||
| 475 | * @param bool $cache whether to cache the object or not. |
||
| 476 | * @return mixed |
||
| 477 | * @throws EE_Error |
||
| 478 | * @throws ReflectionException |
||
| 479 | */ |
||
| 480 | public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
||
| 501 | |||
| 502 | |||
| 503 | |||
| 504 | /** |
||
| 505 | * loads model classes - must be singletons |
||
| 506 | * |
||
| 507 | * @param string $class_name - simple class name ie: price |
||
| 508 | * @param mixed $arguments |
||
| 509 | * @param bool $load_only |
||
| 510 | * @return EEM_Base | bool |
||
| 511 | * @throws EE_Error |
||
| 512 | * @throws ReflectionException |
||
| 513 | */ |
||
| 514 | public function load_model($class_name, $arguments = array(), $load_only = false) |
||
| 534 | |||
| 535 | |||
| 536 | |||
| 537 | /** |
||
| 538 | * loads model classes - must be singletons |
||
| 539 | * |
||
| 540 | * @param string $class_name - simple class name ie: price |
||
| 541 | * @param mixed $arguments |
||
| 542 | * @param bool $load_only |
||
| 543 | * @return mixed | bool |
||
| 544 | * @throws EE_Error |
||
| 545 | * @throws ReflectionException |
||
| 546 | */ |
||
| 547 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
||
| 567 | |||
| 568 | |||
| 569 | |||
| 570 | /** |
||
| 571 | * Determines if $model_name is the name of an actual EE model. |
||
| 572 | * |
||
| 573 | * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
||
| 574 | * @return boolean |
||
| 575 | */ |
||
| 576 | public function is_model_name($model_name) |
||
| 580 | |||
| 581 | |||
| 582 | |||
| 583 | /** |
||
| 584 | * generic class loader |
||
| 585 | * |
||
| 586 | * @param string $path_to_file - directory path to file location, not including filename |
||
| 587 | * @param string $file_name - file name ie: my_file.php, including extension |
||
| 588 | * @param string $type - file type - core? class? helper? model? |
||
| 589 | * @param mixed $arguments |
||
| 590 | * @param bool $load_only |
||
| 591 | * @return mixed |
||
| 592 | * @throws EE_Error |
||
| 593 | * @throws ReflectionException |
||
| 594 | */ |
||
| 595 | public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
||
| 609 | |||
| 610 | |||
| 611 | |||
| 612 | /** |
||
| 613 | * @param string $path_to_file - directory path to file location, not including filename |
||
| 614 | * @param string $class_name - full class name ie: My_Class |
||
| 615 | * @param string $type - file type - core? class? helper? model? |
||
| 616 | * @param mixed $arguments |
||
| 617 | * @param bool $load_only |
||
| 618 | * @return bool|EE_Addon|object |
||
| 619 | * @throws EE_Error |
||
| 620 | * @throws ReflectionException |
||
| 621 | */ |
||
| 622 | public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
||
| 636 | |||
| 637 | |||
| 638 | |||
| 639 | /** |
||
| 640 | * instantiates, caches, and automatically resolves dependencies |
||
| 641 | * for classes that use a Fully Qualified Class Name. |
||
| 642 | * if the class is not capable of being loaded using PSR-4 autoloading, |
||
| 643 | * then you need to use one of the existing load_*() methods |
||
| 644 | * which can resolve the classname and filepath from the passed arguments |
||
| 645 | * |
||
| 646 | * @param bool|string $class_name Fully Qualified Class Name |
||
| 647 | * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
||
| 648 | * @param bool $cache whether to cache the instantiated object for reuse |
||
| 649 | * @param bool $from_db some classes are instantiated from the db |
||
| 650 | * and thus call a different method to instantiate |
||
| 651 | * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
||
| 652 | * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
||
| 653 | * @return bool|null|object null = failure to load or instantiate class object. |
||
| 654 | * object = class loaded and instantiated successfully. |
||
| 655 | * bool = fail or success when $load_only is true |
||
| 656 | * @throws EE_Error |
||
| 657 | * @throws ReflectionException |
||
| 658 | */ |
||
| 659 | public function create( |
||
| 705 | |||
| 706 | |||
| 707 | |||
| 708 | /** |
||
| 709 | * instantiates, caches, and injects dependencies for classes |
||
| 710 | * |
||
| 711 | * @param array $file_paths an array of paths to folders to look in |
||
| 712 | * @param string $class_prefix EE or EEM or... ??? |
||
| 713 | * @param bool|string $class_name $class name |
||
| 714 | * @param string $type file type - core? class? helper? model? |
||
| 715 | * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
||
| 716 | * @param bool $from_db some classes are instantiated from the db |
||
| 717 | * and thus call a different method to instantiate |
||
| 718 | * @param bool $cache whether to cache the instantiated object for reuse |
||
| 719 | * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
||
| 720 | * @return bool|null|object null = failure to load or instantiate class object. |
||
| 721 | * object = class loaded and instantiated successfully. |
||
| 722 | * bool = fail or success when $load_only is true |
||
| 723 | * @throws EE_Error |
||
| 724 | * @throws ReflectionException |
||
| 725 | */ |
||
| 726 | protected function _load( |
||
| 785 | |||
| 786 | |||
| 787 | |||
| 788 | /** |
||
| 789 | * attempts to find a cached version of the requested class |
||
| 790 | * by looking in the following places: |
||
| 791 | * $this->{$class_abbreviation} ie: $this->CART |
||
| 792 | * $this->{$class_name} ie: $this->Some_Class |
||
| 793 | * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
||
| 794 | * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
||
| 795 | * |
||
| 796 | * @param string $class_name |
||
| 797 | * @param string $class_prefix |
||
| 798 | * @return mixed |
||
| 799 | */ |
||
| 800 | protected function _get_cached_class($class_name, $class_prefix = '') |
||
| 825 | |||
| 826 | |||
| 827 | |||
| 828 | /** |
||
| 829 | * removes a cached version of the requested class |
||
| 830 | * |
||
| 831 | * @param string $class_name |
||
| 832 | * @param boolean $addon |
||
| 833 | * @return boolean |
||
| 834 | */ |
||
| 835 | public function clear_cached_class($class_name, $addon = false) |
||
| 861 | |||
| 862 | |||
| 863 | |||
| 864 | /** |
||
| 865 | * attempts to find a full valid filepath for the requested class. |
||
| 866 | * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
||
| 867 | * then returns that path if the target file has been found and is readable |
||
| 868 | * |
||
| 869 | * @param string $class_name |
||
| 870 | * @param string $type |
||
| 871 | * @param array $file_paths |
||
| 872 | * @return string | bool |
||
| 873 | */ |
||
| 874 | protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
||
| 899 | |||
| 900 | |||
| 901 | |||
| 902 | /** |
||
| 903 | * basically just performs a require_once() |
||
| 904 | * but with some error handling |
||
| 905 | * |
||
| 906 | * @param string $path |
||
| 907 | * @param string $class_name |
||
| 908 | * @param string $type |
||
| 909 | * @param array $file_paths |
||
| 910 | * @return bool |
||
| 911 | * @throws EE_Error |
||
| 912 | * @throws ReflectionException |
||
| 913 | */ |
||
| 914 | protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
||
| 953 | |||
| 954 | |||
| 955 | |||
| 956 | /** |
||
| 957 | * _create_object |
||
| 958 | * Attempts to instantiate the requested class via any of the |
||
| 959 | * commonly used instantiation methods employed throughout EE. |
||
| 960 | * The priority for instantiation is as follows: |
||
| 961 | * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
||
| 962 | * - model objects via their 'new_instance_from_db' method |
||
| 963 | * - model objects via their 'new_instance' method |
||
| 964 | * - "singleton" classes" via their 'instance' method |
||
| 965 | * - standard instantiable classes via their __constructor |
||
| 966 | * Prior to instantiation, if the classname exists in the dependency_map, |
||
| 967 | * then the constructor for the requested class will be examined to determine |
||
| 968 | * if any dependencies exist, and if they can be injected. |
||
| 969 | * If so, then those classes will be added to the array of arguments passed to the constructor |
||
| 970 | * |
||
| 971 | * @param string $class_name |
||
| 972 | * @param array $arguments |
||
| 973 | * @param string $type |
||
| 974 | * @param bool $from_db |
||
| 975 | * @return null|object |
||
| 976 | * @throws EE_Error |
||
| 977 | * @throws ReflectionException |
||
| 978 | */ |
||
| 979 | protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
||
| 1051 | |||
| 1052 | |||
| 1053 | |||
| 1054 | /** |
||
| 1055 | * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
||
| 1056 | * @param array $array |
||
| 1057 | * @return bool |
||
| 1058 | */ |
||
| 1059 | protected function _array_is_numerically_and_sequentially_indexed(array $array) |
||
| 1065 | |||
| 1066 | |||
| 1067 | |||
| 1068 | /** |
||
| 1069 | * getReflectionClass |
||
| 1070 | * checks if a ReflectionClass object has already been generated for a class |
||
| 1071 | * and returns that instead of creating a new one |
||
| 1072 | * |
||
| 1073 | * @param string $class_name |
||
| 1074 | * @return ReflectionClass |
||
| 1075 | * @throws ReflectionException |
||
| 1076 | */ |
||
| 1077 | View Code Duplication | public function get_ReflectionClass($class_name) |
|
| 1087 | |||
| 1088 | |||
| 1089 | |||
| 1090 | /** |
||
| 1091 | * _resolve_dependencies |
||
| 1092 | * examines the constructor for the requested class to determine |
||
| 1093 | * if any dependencies exist, and if they can be injected. |
||
| 1094 | * If so, then those classes will be added to the array of arguments passed to the constructor |
||
| 1095 | * PLZ NOTE: this is achieved by type hinting the constructor params |
||
| 1096 | * For example: |
||
| 1097 | * if attempting to load a class "Foo" with the following constructor: |
||
| 1098 | * __construct( Bar $bar_class, Fighter $grohl_class ) |
||
| 1099 | * then $bar_class and $grohl_class will be added to the $arguments array, |
||
| 1100 | * but only IF they are NOT already present in the incoming arguments array, |
||
| 1101 | * and the correct classes can be loaded |
||
| 1102 | * |
||
| 1103 | * @param ReflectionClass $reflector |
||
| 1104 | * @param string $class_name |
||
| 1105 | * @param array $arguments |
||
| 1106 | * @return array |
||
| 1107 | * @throws EE_Error |
||
| 1108 | * @throws ReflectionException |
||
| 1109 | */ |
||
| 1110 | protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
||
| 1172 | |||
| 1173 | |||
| 1174 | |||
| 1175 | /** |
||
| 1176 | * @param string $class_name |
||
| 1177 | * @param string $param_class |
||
| 1178 | * @param array $arguments |
||
| 1179 | * @param mixed $index |
||
| 1180 | * @return array |
||
| 1181 | * @throws EE_Error |
||
| 1182 | * @throws ReflectionException |
||
| 1183 | */ |
||
| 1184 | protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
||
| 1226 | |||
| 1227 | |||
| 1228 | |||
| 1229 | /** |
||
| 1230 | * _set_cached_class |
||
| 1231 | * attempts to cache the instantiated class locally |
||
| 1232 | * in one of the following places, in the following order: |
||
| 1233 | * $this->{class_abbreviation} ie: $this->CART |
||
| 1234 | * $this->{$class_name} ie: $this->Some_Class |
||
| 1235 | * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
||
| 1236 | * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
||
| 1237 | * |
||
| 1238 | * @param object $class_obj |
||
| 1239 | * @param string $class_name |
||
| 1240 | * @param string $class_prefix |
||
| 1241 | * @param bool $from_db |
||
| 1242 | * @return void |
||
| 1243 | */ |
||
| 1244 | protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
||
| 1268 | |||
| 1269 | |||
| 1270 | |||
| 1271 | /** |
||
| 1272 | * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
||
| 1273 | * |
||
| 1274 | * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
||
| 1275 | * in the EE_Dependency_Map::$_class_loaders array, |
||
| 1276 | * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
||
| 1277 | * @param array $arguments |
||
| 1278 | * @return object |
||
| 1279 | */ |
||
| 1280 | public static function factory($classname, $arguments = array()) |
||
| 1291 | |||
| 1292 | |||
| 1293 | |||
| 1294 | /** |
||
| 1295 | * Gets the addon by its name/slug (not classname. For that, just |
||
| 1296 | * use the classname as the property name on EE_Config::instance()->addons) |
||
| 1297 | * |
||
| 1298 | * @param string $name |
||
| 1299 | * @return EE_Addon |
||
| 1300 | */ |
||
| 1301 | public function get_addon_by_name($name) |
||
| 1310 | |||
| 1311 | |||
| 1312 | |||
| 1313 | /** |
||
| 1314 | * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their |
||
| 1315 | * name() function) They're already available on EE_Config::instance()->addons as properties, where each property's |
||
| 1316 | * name is the addon's classname. So if you just want to get the addon by classname, use |
||
| 1317 | * EE_Config::instance()->addons->{classname} |
||
| 1318 | * |
||
| 1319 | * @return EE_Addon[] where the KEYS are the addon's name() |
||
| 1320 | */ |
||
| 1321 | public function get_addons_by_name() |
||
| 1329 | |||
| 1330 | |||
| 1331 | |||
| 1332 | /** |
||
| 1333 | * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
||
| 1334 | * a stale copy of it around |
||
| 1335 | * |
||
| 1336 | * @param string $model_name |
||
| 1337 | * @return \EEM_Base |
||
| 1338 | * @throws \EE_Error |
||
| 1339 | */ |
||
| 1340 | public function reset_model($model_name) |
||
| 1359 | |||
| 1360 | |||
| 1361 | |||
| 1362 | /** |
||
| 1363 | * Resets the registry. |
||
| 1364 | * The criteria for what gets reset is based on what can be shared between sites on the same request when |
||
| 1365 | * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
||
| 1366 | * - $_dependency_map |
||
| 1367 | * - $_class_abbreviations |
||
| 1368 | * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
||
| 1369 | * - $REQ: Still on the same request so no need to change. |
||
| 1370 | * - $CAP: There is no site specific state in the EE_Capability class. |
||
| 1371 | * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
||
| 1372 | * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
||
| 1373 | * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
||
| 1374 | * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
||
| 1375 | * switch or on the restore. |
||
| 1376 | * - $modules |
||
| 1377 | * - $shortcodes |
||
| 1378 | * - $widgets |
||
| 1379 | * |
||
| 1380 | * @param boolean $hard whether to reset data in the database too, or just refresh |
||
| 1381 | * the Registry to its state at the beginning of the request |
||
| 1382 | * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
||
| 1383 | * or just reset without re-instantiating (handy to set to FALSE if you're not |
||
| 1384 | * sure if you CAN currently reinstantiate the singletons at the moment) |
||
| 1385 | * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
||
| 1386 | * client |
||
| 1387 | * code instead can just change the model context to a different blog id if |
||
| 1388 | * necessary |
||
| 1389 | * @return EE_Registry |
||
| 1390 | * @throws EE_Error |
||
| 1391 | * @throws ReflectionException |
||
| 1392 | */ |
||
| 1393 | public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
||
| 1415 | |||
| 1416 | |||
| 1417 | |||
| 1418 | /** |
||
| 1419 | * if passed object implements ResettableInterface, then call it's reset() method |
||
| 1420 | * if passed object implements InterminableInterface, then return false, |
||
| 1421 | * to indicate that it should NOT be cleared from the Registry cache |
||
| 1422 | * |
||
| 1423 | * @param $object |
||
| 1424 | * @param bool $reset_models |
||
| 1425 | * @return bool returns true if cached object should be unset |
||
| 1426 | */ |
||
| 1427 | private static function _reset_and_unset_object($object, $reset_models) |
||
| 1454 | |||
| 1455 | |||
| 1456 | |||
| 1457 | /** |
||
| 1458 | * Gets all the custom post type models defined |
||
| 1459 | * |
||
| 1460 | * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
||
| 1461 | */ |
||
| 1462 | public function cpt_models() |
||
| 1472 | |||
| 1473 | |||
| 1474 | |||
| 1475 | /** |
||
| 1476 | * @return \EE_Config |
||
| 1477 | */ |
||
| 1478 | public static function CFG() |
||
| 1482 | |||
| 1483 | |||
| 1484 | } |
||
| 1485 | // End of file EE_Registry.core.php |
||
| 1487 |
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):