Completed
Branch BUG-9625-better-us-phone-valid... (e0ce21)
by
unknown
631:18 queued 616:37
created

EE_Registry::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 1
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
		$class_abbreviation = isset( $class_abbreviations[ $class_name ] )
469
			? $class_abbreviations[ $class_name ]
470
			: '';
471
		// check if class has already been loaded, and return it if it has been
472
		if ( $class_abbreviation !== '' && ! is_null( $this->{$class_abbreviation} )
473
		) {
474
			return $this->{$class_abbreviation};
475
		} else if ( isset ( $this->{$class_name} ) ) {
476
			return $this->{$class_name};
477
		} else if ( isset ( $this->LIB->{$class_name} ) ) {
478
			return $this->LIB->{$class_name};
479
		} else if ( $class_prefix == 'addon' && isset ( $this->addons->{$class_name} ) ) {
480
			return $this->addons->{$class_name};
481
		}
482
483
		// assume all paths lead nowhere
484
		$path = FALSE;
485
		// make sure $file_paths is an array
486
		$file_paths = is_array( $file_paths ) ? $file_paths : array( $file_paths );
487
		// cycle thru paths
488
		foreach ( $file_paths as $key => $file_path ) {
489
			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
490
			$file_path = $file_path ? str_replace( array( '/', '\\' ), DS, $file_path ) : EE_CLASSES;
491
			// prep file type
492
			$type = ! empty( $type ) ? trim( $type, '.' ) . '.' : '';
493
			// build full file path
494
			$file_paths[ $key ] = rtrim( $file_path, DS ) . DS . $class_name . '.' . $type . 'php';
495
			//does the file exist and can be read ?
496
			if ( is_readable( $file_paths[ $key ] )) {
497
				$path = $file_paths[ $key ];
498
				break;
499
			}
500
		}
501
		// don't give up! you gotta...
502
		try {
503
			//does the file exist and can it be read ?
504 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...
505
				// so sorry, can't find the file
506
				throw new EE_Error (
507
					sprintf (
508
						__('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'),
509
						trim( $type, '.' ),
510
						$class_name,
511
						'<br />' . implode( ',<br />', $file_paths )
512
					)
513
				);
514
			}
515
			// get the file
516
			require_once( $path );
517
			// if the class isn't already declared somewhere
518 View Code Duplication
			if ( class_exists( $class_name, FALSE ) === FALSE ) {
519
				// so sorry, not a class
520
				throw new EE_Error(
521
					sprintf(
522
						__('The %s file %s does not appear to contain the %s Class.','event_espresso'),
523
						$type,
524
						$path,
525
						$class_name
526
					)
527
				);
528
			}
529
530
		} catch ( EE_Error $e ) {
531
			$e->get_error();
532
		}
533
534
535
		// don't give up! you gotta...
536
		try {
537
			// create reflection
538
			$reflector = new ReflectionClass( $class_name );
539
			// instantiate the class and add to the LIB array for tracking
540
			// EE_Base_Classes are instantiated via new_instance by default (models call them via new_instance_from_db)
541
			if ( $reflector->getConstructor() === NULL || $reflector->isAbstract() || $load_only ) {
542
//				$instantiation_mode = 0;
543
				// no constructor = static methods only... nothing to instantiate, loading file was enough
544
				return TRUE;
545
			} else if ( $from_db && method_exists( $class_name, 'new_instance_from_db' ) ) {
546
//				$instantiation_mode = 1;
547
				$class_obj =  call_user_func_array( array( $class_name, 'new_instance_from_db' ), $arguments );
548
			} else if ( method_exists( $class_name, 'new_instance' ) ) {
549
//				$instantiation_mode = 2;
550
				$class_obj =  call_user_func_array( array( $class_name, 'new_instance' ), $arguments );
551
			} else if ( method_exists( $class_name, 'instance' )) {
552
//				$instantiation_mode = 3;
553
				$class_obj =  call_user_func_array( array( $class_name, 'instance' ), $arguments );
554
			} else if ( $reflector->isInstantiable() ) {
555
//				$instantiation_mode = 4;
556
				$class_obj =  $reflector->newInstance( $arguments );
557
			} else if ( ! $load_only ) {
558
				// heh ? something's not right !
559
//				$instantiation_mode = 5;
560
				throw new EE_Error(
561
					sprintf(
562
						__('The %s file %s could not be instantiated.','event_espresso'),
563
						$type,
564
						$class_name
565
					)
566
				);
567
			}
568
569
		} catch ( EE_Error $e ) {
570
			$e->get_error();
571
		}
572
573
//	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>';
574
//	echo '<h4>$from_db : ' . $from_db . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
575
//	echo '<h4>$cache : ' . $cache . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
576
//	echo '<h4>$load_only : ' . $load_only . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
577
//	EEH_Debug_Tools::printr( $arguments, '$arguments  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
578
//	EEH_Debug_Tools::printr( $class_obj, '$class_obj  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
579
580
581
		if ( isset( $class_obj )) {
582
			// return newly instantiated class
583
			if ( $class_abbreviation !== '' ) {
584
				$this->{$class_abbreviation} = $class_obj;
585
			} else if ( EEH_Class_Tools::has_property( $this, $class_name )) {
586
				$this->{$class_name} = $class_obj;
587
			} else if ( $class_prefix == 'addon' && $cache  ) {
588
				$this->addons->{$class_name} = $class_obj;
589
			} else if ( !$from_db && $cache  ) {
590
				$this->LIB->{$class_name} = $class_obj;
591
			}
592
			return $class_obj;
593
		}
594
595
		return FALSE;
596
597
	}
598
599
600
601
602
	/**
603
	 *		@ override magic methods
604
	 *		@ return void
605
	 */
606
	final function __destruct() {}
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
607
608
609
610
	/**
611
	 * @param $a
612
	 * @param $b
613
	 */
614
	final function __call($a,$b) {}
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
615
616
617
618
	/**
619
	 * @param $a
620
	 */
621
	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...
622
623
624
625
	/**
626
	 * @param $a
627
	 * @param $b
628
	 */
629
	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...
630
631
632
633
	/**
634
	 * @param $a
635
	 */
636
	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...
637
638
639
640
	/**
641
	 * @param $a
642
	 */
643
	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...
644
645
646
647
	/**
648
	 * @return array
649
	 */
650
	final function __sleep() { return array(); }
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
651
	final function __wakeup() {}
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
652
653
654
655
	/**
656
	 * @return string
657
	 */
658
	final function __toString() { return ''; }
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
659
	final function __invoke() {}
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
660
	final function __set_state() {}
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
661
	final function __clone() {}
0 ignored issues
show
Coding Style introduced by
Unnecessary FINAL modifier in FINAL class
Loading history...
662
663
664
665
	/**
666
	 * @param $a
667
	 * @param $b
668
	 */
669
	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...
670
671
	/**
672
	 * Gets the addon by its name/slug (not classname. For that, just
673
	 * use the classname as the property name on EE_Config::instance()->addons)
674
	 * @param string $name
675
	 * @return EE_Addon
676
	 */
677
	public function get_addon_by_name( $name ){
678
		foreach($this->addons as $addon){
679
			if( $addon->name() == $name){
680
				return $addon;
681
			}
682
		}
683
		return NULL;
684
	}
685
	/**
686
	 * 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}
687
	 *
688
	 * @return EE_Addon[] where the KEYS are the addon's name()
689
	 */
690
	public function get_addons_by_name(){
691
		$addons = array();
692
		foreach($this->addons as $addon){
693
			$addons[ $addon->name() ] = $addon;
694
		}
695
		return $addons;
696
	}
697
698
699
700
	/**
701
	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
702
	 * a stale copy of it around
703
	 *
704
	 * @param string $model_name
705
	 * @return EEM_Base
706
	 * @throws EE_Error
707
	 */
708
	public function reset_model( $model_name ){
709
		$model = $this->load_model( $model_name );
710
		$model_class_name = get_class( $model );
711
		//get that model reset it and make sure we nuke the old reference to it
712
		if ( $model instanceof $model_class_name && is_callable( array( $model_class_name, 'reset' ))) {
713
			$this->LIB->{$model_class_name} = $model::reset();
714
		}else{
715
			throw new EE_Error( sprintf( __( 'Model %s does not have a method "reset"', 'event_espresso' ), $model_name ) );
716
		}
717
		return $this->LIB->{$model_class_name};
718
	}
719
720
	/**
721
	 * Resets the registry and everything in it (eventually, getting it to properly
722
	 * reset absolutely everything will probably be tricky. right now it just resets
723
	 * the config, data migration manager, and the models)
724
	 * @param boolean $hard whether to reset data in the database too, or just refresh
725
	 * the Registry to its state at the beginning of the request
726
	 * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too,
727
	 * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN
728
	 * currently reinstantiate the singletons at the moment)
729
	 * @return EE_Registry
730
	 */
731
	public static function reset( $hard = FALSE, $reinstantiate = TRUE ){
732
		$instance = self::instance();
733
		$instance->load_helper('Activation');
734
		EEH_Activation::reset();
735
		$instance->CFG = EE_Config::reset( $hard, $reinstantiate );
736
		$instance->LIB->EE_Data_Migration_Manager = EE_Data_Migration_Manager::reset();
737
		$instance->LIB = new stdClass();
738
		foreach( array_keys( $instance->non_abstract_db_models ) as $model_name ){
739
			$instance->reset_model( $model_name );
740
		}
741
		return $instance;
742
	}
743
744
	/**
745
	 * Gets all the custom post type models defined
746
	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
747
	 */
748
	public function cpt_models() {
749
		$cpt_models = array();
750
		foreach( $this->non_abstract_db_models as $shortname => $classname ) {
751
			if( is_subclass_of(  $classname, 'EEM_CPT_Base' ) ) {
752
				$cpt_models[ $shortname ] = $classname;
753
			}
754
		}
755
		return $cpt_models;
756
	}
757
758
759
760
	public static function CFG() {
761
		return self::instance()->CFG;
762
	}
763
764
765
}
766
// End of file EE_Registry.core.php
767
// Location: ./core/EE_Registry.core.php
768