Completed
Branch TASK-9118-extensions-page (04eaec)
by
unknown
856:31 queued 840:33
created

EE_Registry::load_dms()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2
/**
3
* EE_Registry Class
4
 *
5
 * Centralized Application Data Storage and Management
6
 *
7
 * @package				Event Espresso
8
 * @subpackage			core
9
 * @author					Brent Christensen
10
 */
11
final class EE_Registry {
12
13
	/**
14
	* 	EE_Registry Object
15
	* 	@var EE_Registry $_instance
16
	* 	@access 	private
17
	*/
18
	private static $_instance = NULL;
19
20
21
	/**
22
	* 	EE_Cart Object
23
	* 	@access 	public
24
	*	@var 	EE_Cart $CART
25
	*/
26
	public $CART = NULL;
27
28
	/**
29
	* 	EE_Config Object
30
	* 	@access 	public
31
	*	@var 	EE_Config $CFG
32
	*/
33
	public $CFG = NULL;
34
35
36
37
	/**
38
	 * EE_Network_Config Object
39
	 * @access public
40
	 * @var EE_Network_Config $NET_CFG
41
	 */
42
	public $NET_CFG = NULL;
43
44
45
46
	/**
47
	* 	StdClass object for storing library classes in
48
	* 	@public LIB
49
	*/
50
	public $LIB = NULL;
51
52
	/**
53
	 * 	EE_Request_Handler Object
54
	 * 	@access 	public
55
	 *	@var 	EE_Request_Handler	$REQ
56
	 */
57
	public $REQ = NULL;
58
59
	/**
60
	* 	EE_Session Object
61
	* 	@access 	public
62
	* 	@var 	EE_Session	 $SSN
63
	*/
64
	public $SSN = NULL;
65
66
67
68
	/**
69
	 * holds the ee capabilities object.
70
	 *
71
	 * @since 4.5.0
72
	 *
73
	 * @var EE_Capabilities
74
	 */
75
	public $CAP = NULL;
76
77
78
	/**
79
	 * 	$addons - StdClass object for holding addons which have registered themselves to work with EE core
80
	 * 	@access 	public
81
	 *	@var 	EE_Addon[]
82
	 */
83
	public $addons = NULL;
84
85
	/**
86
	 * 	$models
87
	 * 	@access 	public
88
	 *	@var 	EEM_Base[]   	$models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
89
	 */
90
	public $models = array();
91
92
	/**
93
	 * 	$modules
94
	 * 	@access 	public
95
	 *	@var 	EED_Module[] $modules
96
	 */
97
	public $modules = NULL;
98
99
	/**
100
	 * 	$shortcodes
101
	 * 	@access 	public
102
	 *	@var 	EES_Shortcode[]  $shortcodes
103
	 */
104
	public $shortcodes = NULL;
105
106
	/**
107
	 * 	$widgets
108
	 * 	@access 	public
109
	 *	@var 	WP_Widget[]  $widgets
110
	 */
111
	public $widgets = NULL;
112
113
114
115
116
	/**
117
	 * $non_abstract_db_models
118
	 * @access public
119
	 * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models
120
	 * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
121
	 * Keys are model "shortnames" (eg "Event") as used in model relations, and values are
122
	 * classnames (eg "EEM_Event")
123
	 */
124
	public $non_abstract_db_models = array();
125
126
127
128
129
	/**
130
	* 	$i18n_js_strings - internationalization for JS strings
131
	*  	usage:   EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' );
132
	*  	in js file:  var translatedString = eei18n.string_key;
133
	*
134
	* 	@access 	public
135
	*	@var 	array
136
	*/
137
	public static $i18n_js_strings = array();
138
139
	/**
140
	* 	$main_file - path to espresso.php
141
	*
142
	* 	@access 	public
143
	*	@var 	array
144
	*/
145
	public $main_file;
146
147
148
149
150
151
152
	/**
153
	 *@singleton method used to instantiate class object
154
	 *@access public
155
	 *@return EE_Registry instance
156
	 */
157 View Code Duplication
	public static function instance() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
		// check if class object is instantiated
159
		if ( self::$_instance === NULL  or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EE_Registry )) {
160
			self::$_instance = new self();
161
		}
162
		return self::$_instance;
163
	}
164
165
166
167
	/**
168
	 *private constructor to prevent direct creation
169
	 * @Constructor
170
	 * @access private
171
	 * @return EE_Registry
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
172
	 */
173
	private function __construct() {
174
		$this->load_core( 'Base' );
175
		// class library
176
		$this->LIB = new StdClass();
177
		$this->addons = new StdClass();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \StdClass() of type object<stdClass> is incompatible with the declared type array<integer,object<EE_Addon>> of property $addons.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
178
		$this->modules = new StdClass();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \StdClass() of type object<stdClass> is incompatible with the declared type array<integer,object<EED_Module>> of property $modules.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
179
		$this->shortcodes = new StdClass();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \StdClass() of type object<stdClass> is incompatible with the declared type array<integer,object<EES_Shortcode>> of property $shortcodes.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
180
		$this->widgets = new StdClass();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \StdClass() of type object<stdClass> is incompatible with the declared type array<integer,object<WP_Widget>> of property $widgets.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
181
		add_action( 'AHEE__EE_System__set_hooks_for_core', array( $this, 'init' ));
182
	}
183
184
185
186
	/**
187
	 * 	init
188
	 *
189
	 *  @access 	public
190
	 *  @return 	void
191
	 */
192
	public function init() {
193
		// Get current page protocol
194
		$protocol = isset( $_SERVER['HTTPS'] ) ? 'https://' : 'http://';
195
		// Output admin-ajax.php URL with same protocol as current page
196
		self::$i18n_js_strings['ajax_url'] = admin_url( 'admin-ajax.php', $protocol );
197
		self::$i18n_js_strings['wp_debug'] = defined( 'WP_DEBUG' ) ? WP_DEBUG : FALSE;
198
	}
199
200
201
202
	/**
203
	 * localize_i18n_js_strings
204
	 *
205
	 * @return string
206
	 */
207
	public static function localize_i18n_js_strings() {
208
		$i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
209
		foreach ( $i18n_js_strings as $key => $value ) {
210
			if ( is_scalar( $value ) ) {
211
				$i18n_js_strings[ $key ] = html_entity_decode( (string)$value, ENT_QUOTES, 'UTF-8' );
212
			}
213
		}
214
215
		return "/* <![CDATA[ */ var eei18n = " . wp_json_encode( $i18n_js_strings ) . '; /* ]]> */';
216
	}
217
218
219
220
	/**
221
	 * @param mixed string | EED_Module $module
222
	 */
223
	public function add_module( $module ) {
224
		if ( $module instanceof EED_Module ) {
225
			$module_class = get_class( $module );
226
			$this->modules->{$module_class} = $module;
227
		} else {
228
			if ( ! class_exists( 'EE_Module_Request_Router' )) {
229
				$this->load_core( 'Module_Request_Router' );
230
			}
231
			$this->modules->{$module} = EE_Module_Request_Router::module_factory( $module );
232
		}
233
	}
234
235
236
237
	/**
238
	 * @param string $module_name
239
	 * @return mixed EED_Module | NULL
240
	 */
241
	public function get_module( $module_name = '' ) {
242
		return isset( $this->modules->{$module_name} ) ? $this->modules->{$module_name} : NULL;
243
	}
244
245
246
	/**
247
	 *    loads core classes - must be singletons
248
	 *
249
	 * @access    public
250
	 * @param string $class_name - simple class name ie: session
251
	 * @param mixed  $arguments
252
	 * @param bool   $load_only
253
	 * @return mixed
254
	 */
255
	public function load_core ( $class_name, $arguments = array(), $load_only = FALSE ) {
256
		$core_paths = apply_filters(
257
			'FHEE__EE_Registry__load_core__core_paths',
258
			array(
259
				EE_CORE,
260
				EE_ADMIN,
261
				EE_CPTS,
262
				EE_CORE . 'data_migration_scripts' . DS
263
			)
264
		);
265
		// retrieve instantiated class
266
		return $this->_load( $core_paths, 'EE_' , $class_name, 'core', $arguments, FALSE, TRUE, $load_only );
267
	}
268
269
270
271
	/**
272
	 *    loads data_migration_scripts
273
	 *
274
	 * @access    public
275
	 * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
276
	 * @param mixed  $arguments
277
	 * @return EE_Data_Migration_Script_Base
278
	 */
279
	public function load_dms ( $class_name, $arguments = array() ) {
280
		// retrieve instantiated class
281
		return $this->_load( EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_' , $class_name, 'dms', $arguments, FALSE, FALSE, FALSE );
282
	}
283
284
285
286
	/**
287
	 *	loads object creating classes - must be singletons
288
	 *
289
	 *	@param string $class_name - simple class name ie: attendee
290
	 *	@param mixed  $arguments - an array of arguments to pass to the class
291
	 *	@param bool   $from_db    - some classes are instantiated from the db and thus call a different method to instantiate
292
	 *	@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)
293
	 *	@param bool   $load_only      whether or not to just load the file and NOT instantiate, or load AND instantiate (default)
294
	 *	@return EE_Base_Class
295
	 */
296
	public function load_class ( $class_name, $arguments = array(), $from_db = FALSE, $cache = TRUE, $load_only = FALSE ) {
297
		$paths = apply_filters('FHEE__EE_Registry__load_class__paths',array(
298
			EE_CORE,
299
			EE_CLASSES,
300
			EE_BUSINESS
301
		));
302
		// retrieve instantiated class
303
		return $this->_load( $paths, 'EE_' , $class_name, 'class', $arguments, $from_db, $cache, $load_only );
304
	}
305
306
307
308
309
	/**
310
	 *    loads helper classes - must be singletons
311
	 *
312
	 * @param string $class_name - simple class name ie: price
313
	 * @param mixed  $arguments
314
	 * @param bool   $load_only
315
	 * @return EEH_Base
316
	 */
317
	public function load_helper ( $class_name, $arguments = array(), $load_only = TRUE ) {
318
		$helper_paths = apply_filters( 'FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS ) );
319
		// retrieve instantiated class
320
		return $this->_load( $helper_paths, 'EEH_', $class_name, 'helper', $arguments, FALSE, TRUE, $load_only );
321
	}
322
323
324
325
	/**
326
	 *    loads core classes - must be singletons
327
	 *
328
	 * @access    public
329
	 * @param string $class_name - simple class name ie: session
330
	 * @param mixed  $arguments
331
	 * @param bool   $load_only
332
	 * @return mixed
333
	 */
334
	public function load_lib ( $class_name, $arguments = array(), $load_only = FALSE ) {
335
		$paths = array(
336
			EE_LIBRARIES,
337
			EE_LIBRARIES . 'messages' . DS,
338
			EE_LIBRARIES . 'shortcodes' . DS,
339
			EE_LIBRARIES . 'qtips' . DS,
340
			EE_LIBRARIES . 'payment_methods' . DS,
341
		);
342
		// retrieve instantiated class
343
		return $this->_load( $paths, 'EE_' , $class_name, 'lib', $arguments, FALSE, TRUE, $load_only );
344
	}
345
346
347
348
	/**
349
	 *    loads model classes - must be singletons
350
	 *
351
	 * @param string $class_name - simple class name ie: price
352
	 * @param mixed  $arguments
353
	 * @param bool   $load_only
354
	 * @return EEM_Base
355
	 */
356
	public function load_model ( $class_name, $arguments = array(), $load_only = FALSE ) {
357
		$paths = apply_filters('FHEE__EE_Registry__load_model__paths',array(
358
			EE_MODELS,
359
			EE_CORE
360
		));
361
		// retrieve instantiated class
362
		return $this->_load( $paths, 'EEM_' , $class_name, 'model', $arguments, FALSE, TRUE, $load_only );
363
	}
364
365
366
367
	/**
368
	 *    loads model classes - must be singletons
369
	 *
370
	 * @param string $class_name - simple class name ie: price
371
	 * @param mixed  $arguments
372
	 * @param bool   $load_only
373
	 * @return mixed
374
	 */
375
	public function load_model_class ( $class_name, $arguments = array(), $load_only = TRUE ) {
376
		$paths = array(
377
			EE_MODELS . 'fields' . DS,
378
			EE_MODELS . 'helpers' . DS,
379
			EE_MODELS . 'relations' . DS,
380
			EE_MODELS . 'strategies' . DS
381
		);
382
		// retrieve instantiated class
383
		return $this->_load( $paths, 'EE_' , $class_name, '', $arguments, FALSE, TRUE, $load_only );
384
	}
385
386
387
388
389
390
	/**
391
	 * Determines if $model_name is the name of an actual EE model.
392
	 * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
393
	 * @return boolean
394
	 */
395
	public function is_model_name( $model_name ){
396
		return isset( $this->models[ $model_name ] ) ? TRUE : FALSE;
397
	}
398
399
400
401
	/**
402
	 *    generic class loader
403
	 *
404
	 * @param string $path_to_file - directory path to file location, not including filename
405
	 * @param string $file_name   - file name  ie:  my_file.php, including extension
406
	 * @param string $type         - file type - core? class? helper? model?
407
	 * @param mixed  $arguments
408
	 * @param bool   $load_only
409
	 * @return mixed
410
	 */
411
	public function load_file ( $path_to_file, $file_name, $type = '', $arguments = array(), $load_only = TRUE ) {
412
		// retrieve instantiated class
413
		return $this->_load( $path_to_file, '', $file_name, $type, $arguments, FALSE, TRUE, $load_only );
0 ignored issues
show
Documentation introduced by
$path_to_file is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
414
	}
415
416
417
418
	/**
419
	 *    load_addon
420
	 *
421
	 * @param string $path_to_file - directory path to file location, not including filename
422
	 * @param string $class_name   - full class name  ie:  My_Class
423
	 * @param string $type         - file type - core? class? helper? model?
424
	 * @param mixed  $arguments
425
	 * @param bool   $load_only
426
	 * @return EE_Addon
427
	 */
428
	public function load_addon ( $path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = FALSE ) {
429
		// retrieve instantiated class
430
		return $this->_load( $path_to_file, 'addon', $class_name, $type, $arguments, FALSE, TRUE, $load_only );
0 ignored issues
show
Documentation introduced by
$path_to_file is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
431
	}
432
433
434
	/**
435
	 *    loads and tracks classes
436
	 *
437
	 * @param array       $file_paths
438
	 * @param string      $class_prefix - EE  or EEM or... ???
439
	 * @param bool|string $class_name   - $class name
440
	 * @param string      $type         - file type - core? class? helper? model?
441
	 * @param mixed  $arguments    - an argument or array of arguments to pass to the class upon instantiation
442
	 * @param bool        $from_db      - some classes are instantiated from the db and thus call a different method to instantiate
443
	 * @param bool        $cache
444
	 * @param bool        $load_only
445
	 * @internal param string $file_path - file path including file name
446
	 * @return bool | object
447
	 */
448
	private function _load ( $file_paths = array(), $class_prefix = 'EE_', $class_name = FALSE, $type = 'class', $arguments = array(), $from_db = FALSE, $cache = TRUE, $load_only = FALSE ) {
449
		// strip php file extension
450
		$class_name = str_replace( '.php', '', trim( $class_name ));
451
		// does the class have a prefix ?
452
		if ( ! empty( $class_prefix ) && $class_prefix != 'addon' ) {
453
			// make sure $class_prefix is uppercase
454
			$class_prefix = strtoupper( trim( $class_prefix ));
455
			// add class prefix ONCE!!!
456
			$class_name = $class_prefix . str_replace( $class_prefix, '', $class_name );
457
		}
458
459
		$class_abbreviations = array(
460
			'EE_Cart' => 'CART',
461
			'EE_Config' => 'CFG',
462
			'EE_Network_Config' => 'NET_CFG',
463
			'EE_Request_Handler' => 'REQ',
464
			'EE_Session' => 'SSN',
465
			'EE_Capabilities' => 'CAP'
466
		);
467
468
		// check if class has already been loaded, and return it if it has been
469
		if ( isset( $class_abbreviations[ $class_name ] ) && ! is_null( $this->$class_abbreviations[ $class_name ] )) {
470
			return $this->$class_abbreviations[ $class_name ];
471
		} else if ( isset ( $this->{$class_name} )) {
472
			return $this->{$class_name};
473
		} else if ( isset ( $this->LIB->$class_name )) {
474
			return $this->LIB->$class_name;
475
		} else if ( $class_prefix == 'addon' && isset ( $this->addons->$class_name )) {
476
			return $this->addons->$class_name;
477
		}
478
479
		// assume all paths lead nowhere
480
		$path = FALSE;
481
		// make sure $file_paths is an array
482
		$file_paths = is_array( $file_paths ) ? $file_paths : array( $file_paths );
483
		// cycle thru paths
484
		foreach ( $file_paths as $key => $file_path ) {
485
			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
486
			$file_path = $file_path ? str_replace( array( '/', '\\' ), DS, $file_path ) : EE_CLASSES;
487
			// prep file type
488
			$type = ! empty( $type ) ? trim( $type, '.' ) . '.' : '';
489
			// build full file path
490
			$file_paths[ $key ] = rtrim( $file_path, DS ) . DS . $class_name . '.' . $type . 'php';
491
			//does the file exist and can be read ?
492
			if ( is_readable( $file_paths[ $key ] )) {
493
				$path = $file_paths[ $key ];
494
				break;
495
			}
496
		}
497
		// don't give up! you gotta...
498
		try {
499
			//does the file exist and can it be read ?
500 View Code Duplication
			if ( ! $path ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $path of type string|false is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
501
				// so sorry, can't find the file
502
				throw new EE_Error (
503
					sprintf (
504
						__('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s','event_espresso'),
505
						trim( $type, '.' ),
506
						$class_name,
507
						'<br />' . implode( ',<br />', $file_paths )
508
					)
509
				);
510
			}
511
			// get the file
512
			require_once( $path );
513
			// if the class isn't already declared somewhere
514 View Code Duplication
			if ( class_exists( $class_name, FALSE ) === FALSE ) {
515
				// so sorry, not a class
516
				throw new EE_Error(
517
					sprintf(
518
						__('The %s file %s does not appear to contain the %s Class.','event_espresso'),
519
						$type,
520
						$path,
521
						$class_name
522
					)
523
				);
524
			}
525
526
		} catch ( EE_Error $e ) {
527
			$e->get_error();
528
		}
529
530
531
		// don't give up! you gotta...
532
		try {
533
			// create reflection
534
			$reflector = new ReflectionClass( $class_name );
535
			// instantiate the class and add to the LIB array for tracking
536
			// EE_Base_Classes are instantiated via new_instance by default (models call them via new_instance_from_db)
537
			if ( $reflector->getConstructor() === NULL || $reflector->isAbstract() || $load_only ) {
538
//				$instantiation_mode = 0;
539
				// no constructor = static methods only... nothing to instantiate, loading file was enough
540
				return TRUE;
541
			} else if ( $from_db && method_exists( $class_name, 'new_instance_from_db' ) ) {
542
//				$instantiation_mode = 1;
543
				$class_obj =  call_user_func_array( array( $class_name, 'new_instance_from_db' ), $arguments );
544
			} else if ( method_exists( $class_name, 'new_instance' ) ) {
545
//				$instantiation_mode = 2;
546
				$class_obj =  call_user_func_array( array( $class_name, 'new_instance' ), $arguments );
547
			} else if ( method_exists( $class_name, 'instance' )) {
548
//				$instantiation_mode = 3;
549
				$class_obj =  call_user_func_array( array( $class_name, 'instance' ), $arguments );
550
			} else if ( $reflector->isInstantiable() ) {
551
//				$instantiation_mode = 4;
552
				$class_obj =  $reflector->newInstance( $arguments );
553
			} else if ( ! $load_only ) {
554
				// heh ? something's not right !
555
//				$instantiation_mode = 5;
556
				throw new EE_Error(
557
					sprintf(
558
						__('The %s file %s could not be instantiated.','event_espresso'),
559
						$type,
560
						$class_name
561
					)
562
				);
563
			}
564
565
		} catch ( EE_Error $e ) {
566
			$e->get_error();
567
		}
568
569
//	echo '<h4>$class_name : ' . $class_name . '  <br /><span style="font-size:10px;font-weight:normal;">$instantiation_mode : ' . $instantiation_mode . '<br/>' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
570
//	echo '<h4>$from_db : ' . $from_db . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
571
//	echo '<h4>$cache : ' . $cache . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
572
//	echo '<h4>$load_only : ' . $load_only . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
573
//	EEH_Debug_Tools::printr( $arguments, '$arguments  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
574
//	EEH_Debug_Tools::printr( $class_obj, '$class_obj  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
575
576
577
		if ( isset( $class_obj )) {
578
			// return newly instantiated class
579
			if ( isset( $class_abbreviations[ $class_name ] )) {
580
				$this->$class_abbreviations[ $class_name ] = $class_obj;
581
			} else if ( EEH_Class_Tools::has_property( $this, $class_name )) {
582
				$this->{$class_name} = $class_obj;
583
			} else if ( $class_prefix == 'addon' && $cache  ) {
584
				$this->addons->$class_name = $class_obj;
585
			} else if ( !$from_db && $cache  ) {
586
				$this->LIB->$class_name = $class_obj;
587
			}
588
			return $class_obj;
589
		}
590
591
		return FALSE;
592
593
	}
594
595
596
597
598
	/**
599
	 *		@ override magic methods
600
	 *		@ return void
601
	 */
602
	final function __destruct() {}
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
603
604
605
606
	/**
607
	 * @param $a
608
	 * @param $b
609
	 */
610
	final function __call($a,$b) {}
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
611
612
613
614
	/**
615
	 * @param $a
616
	 */
617
	final function __get($a) {}
0 ignored issues
show
Unused Code introduced by
The parameter $a is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
618
619
620
621
	/**
622
	 * @param $a
623
	 * @param $b
624
	 */
625
	final function __set($a,$b) {}
0 ignored issues
show
Unused Code introduced by
The parameter $a is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $b is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
626
627
628
629
	/**
630
	 * @param $a
631
	 */
632
	final function __isset($a) {}
0 ignored issues
show
Unused Code introduced by
The parameter $a is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
633
634
635
636
	/**
637
	 * @param $a
638
	 */
639
	final function __unset($a) {}
0 ignored issues
show
Unused Code introduced by
The parameter $a is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
640
641
642
643
	/**
644
	 * @return array
645
	 */
646
	final function __sleep() { return array(); }
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
647
	final function __wakeup() {}
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
648
649
650
651
	/**
652
	 * @return string
653
	 */
654
	final function __toString() { return ''; }
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
655
	final function __invoke() {}
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
656
	final function __set_state() {}
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
657
	final function __clone() {}
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
658
659
660
661
	/**
662
	 * @param $a
663
	 * @param $b
664
	 */
665
	final static function __callStatic($a,$b) {}
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
Unused Code introduced by
The parameter $a is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $b is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
666
667
	/**
668
	 * Gets the addon by its name/slug (not classname. For that, just
669
	 * use the classname as the property name on EE_Config::instance()->addons)
670
	 * @param string $name
671
	 * @return EE_Addon
672
	 */
673
	public function get_addon_by_name( $name ){
674
		foreach($this->addons as $addon){
675
			if( $addon->name() == $name){
676
				return $addon;
677
			}
678
		}
679
		return NULL;
680
	}
681
	/**
682
	 * 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 the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname}
683
	 *
684
	 * @return EE_Addon[] where the KEYS are the addon's name()
685
	 */
686
	public function get_addons_by_name(){
687
		$addons = array();
688
		foreach($this->addons as $addon){
689
			$addons[ $addon->name() ] = $addon;
690
		}
691
		return $addons;
692
	}
693
694
695
696
	/**
697
	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
698
	 * a stale copy of it around
699
	 *
700
	 * @param string $model_name
701
	 * @return EEM_Base
702
	 * @throws EE_Error
703
	 */
704
	public function reset_model( $model_name ){
705
		$model = $this->load_model( $model_name );
706
		$model_class_name = get_class( $model );
707
		//get that model reset it and make sure we nuke the old reference to it
708
		if ( $model instanceof $model_class_name && is_callable( array( $model_class_name, 'reset' ))) {
709
			$this->LIB->$model_class_name = $model::reset();
710
		}else{
711
			throw new EE_Error( sprintf( __( 'Model %s does not have a method "reset"', 'event_espresso' ), $model_name ) );
712
		}
713
		return $this->LIB->$model_class_name;
714
	}
715
716
	/**
717
	 * Resets the registry and everything in it (eventually, getting it to properly
718
	 * reset absolutely everything will probably be tricky. right now it just resets
719
	 * the config, data migration manager, and the models)
720
	 * @param boolean $hard whether to reset data in the database too, or just refresh
721
	 * the Registry to its state at the beginning of the request
722
	 * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too,
723
	 * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN
724
	 * currently reinstantiate the singletons at the moment)
725
	 * @return EE_Registry
726
	 */
727
	public static function reset( $hard = FALSE, $reinstantiate = TRUE ){
728
		$instance = self::instance();
729
		$instance->load_helper('Activation');
730
		EEH_Activation::reset();
731
		$instance->CFG = EE_Config::reset( $hard, $reinstantiate );
732
		$instance->LIB->EE_Data_Migration_Manager = EE_Data_Migration_Manager::reset();
733
		$instance->LIB = new stdClass();
734
		foreach( array_keys( $instance->non_abstract_db_models ) as $model_name ){
735
			$instance->reset_model( $model_name );
736
		}
737
		return $instance;
738
	}
739
740
	/**
741
	 * Gets all the custom post type models defined
742
	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
743
	 */
744
	public function cpt_models() {
745
		$cpt_models = array();
746
		foreach( $this->non_abstract_db_models as $shortname => $classname ) {
747
			if( is_subclass_of(  $classname, 'EEM_CPT_Base' ) ) {
748
				$cpt_models[ $shortname ] = $classname;
749
			}
750
		}
751
		return $cpt_models;
752
	}
753
754
755
}
756
// End of file EE_Registry.core.php
757
// Location: ./core/EE_Registry.core.php
758