Completed
Branch FET/11450/reserved-instance-in... (cfa977)
by
unknown
69:04 queued 55:58
created
core/EE_Dependency_Map.core.php 3 patches
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,5 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-use EventEspresso\core\exceptions\InvalidClassException;
4
-use EventEspresso\core\exceptions\InvalidDataTypeException;
5
-use EventEspresso\core\exceptions\InvalidInterfaceException;
6 3
 use EventEspresso\core\services\loaders\ClassInterfaceCache;
7 4
 use EventEspresso\core\services\loaders\LoaderFactory;
8 5
 use EventEspresso\core\services\loaders\LoaderInterface;
Please login to merge, or discard this patch.
Indentation   +816 added lines, -816 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 use EventEspresso\core\services\request\ResponseInterface;
12 12
 
13 13
 if (! defined('EVENT_ESPRESSO_VERSION')) {
14
-    exit('No direct script access allowed');
14
+	exit('No direct script access allowed');
15 15
 }
16 16
 
17 17
 
@@ -28,821 +28,821 @@  discard block
 block discarded – undo
28 28
 class EE_Dependency_Map
29 29
 {
30 30
 
31
-    /**
32
-     * This means that the requested class dependency is not present in the dependency map
33
-     */
34
-    const not_registered = 0;
35
-
36
-    /**
37
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
38
-     */
39
-    const load_new_object = 1;
40
-
41
-    /**
42
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
43
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
44
-     */
45
-    const load_from_cache = 2;
46
-
47
-    /**
48
-     * When registering a dependency,
49
-     * this indicates to keep any existing dependencies that already exist,
50
-     * and simply discard any new dependencies declared in the incoming data
51
-     */
52
-    const KEEP_EXISTING_DEPENDENCIES = 0;
53
-
54
-    /**
55
-     * When registering a dependency,
56
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
57
-     */
58
-    const OVERWRITE_DEPENDENCIES = 1;
59
-
60
-
61
-
62
-    /**
63
-     * @type EE_Dependency_Map $_instance
64
-     */
65
-    protected static $_instance;
66
-
67
-    /**
68
-     * @var ClassInterfaceCache $class_cache
69
-     */
70
-    private $class_cache;
71
-
72
-    /**
73
-     * @type RequestInterface $request
74
-     */
75
-    protected $request;
76
-
77
-    /**
78
-     * @type LegacyRequestInterface $legacy_request
79
-     */
80
-    protected $legacy_request;
81
-
82
-    /**
83
-     * @type ResponseInterface $response
84
-     */
85
-    protected $response;
86
-
87
-    /**
88
-     * @type LoaderInterface $loader
89
-     */
90
-    protected $loader;
91
-
92
-    /**
93
-     * @type array $_dependency_map
94
-     */
95
-    protected $_dependency_map = array();
96
-
97
-    /**
98
-     * @type array $_class_loaders
99
-     */
100
-    protected $_class_loaders = array();
101
-
102
-
103
-    /**
104
-     * EE_Dependency_Map constructor.
105
-     *
106
-     * @param ClassInterfaceCache $class_cache
107
-     */
108
-    protected function __construct(ClassInterfaceCache $class_cache)
109
-    {
110
-        $this->class_cache = $class_cache;
111
-        do_action('EE_Dependency_Map____construct', $this);
112
-    }
113
-
114
-
115
-    /**
116
-     * @return void
117
-     */
118
-    public function initialize()
119
-    {
120
-        $this->_register_core_dependencies();
121
-        $this->_register_core_class_loaders();
122
-        $this->_register_core_aliases();
123
-    }
124
-
125
-
126
-    /**
127
-     * @singleton method used to instantiate class object
128
-     * @param ClassInterfaceCache|null $class_cache
129
-     * @return EE_Dependency_Map
130
-     */
131
-    public static function instance(ClassInterfaceCache $class_cache = null) {
132
-        // check if class object is instantiated, and instantiated properly
133
-        if (
134
-            ! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map
135
-            && $class_cache instanceof ClassInterfaceCache
136
-        ) {
137
-            EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache);
138
-        }
139
-        return EE_Dependency_Map::$_instance;
140
-    }
141
-
142
-
143
-    /**
144
-     * @param RequestInterface $request
145
-     */
146
-    public function setRequest(RequestInterface $request)
147
-    {
148
-        $this->request = $request;
149
-    }
150
-
151
-
152
-    /**
153
-     * @param LegacyRequestInterface $legacy_request
154
-     */
155
-    public function setLegacyRequest(LegacyRequestInterface $legacy_request)
156
-    {
157
-        $this->legacy_request = $legacy_request;
158
-    }
159
-
160
-
161
-    /**
162
-     * @param ResponseInterface $response
163
-     */
164
-    public function setResponse(ResponseInterface $response)
165
-    {
166
-        $this->response = $response;
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     * @param LoaderInterface $loader
173
-     */
174
-    public function setLoader(LoaderInterface $loader)
175
-    {
176
-        $this->loader = $loader;
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     * @param string $class
183
-     * @param array  $dependencies
184
-     * @param int    $overwrite
185
-     * @return bool
186
-     */
187
-    public static function register_dependencies(
188
-        $class,
189
-        array $dependencies,
190
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
191
-    ) {
192
-        return EE_Dependency_Map::$_instance->registerDependencies($class, $dependencies, $overwrite);
193
-    }
194
-
195
-
196
-
197
-    /**
198
-     * Assigns an array of class names and corresponding load sources (new or cached)
199
-     * to the class specified by the first parameter.
200
-     * IMPORTANT !!!
201
-     * The order of elements in the incoming $dependencies array MUST match
202
-     * the order of the constructor parameters for the class in question.
203
-     * This is especially important when overriding any existing dependencies that are registered.
204
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
205
-     *
206
-     * @param string $class
207
-     * @param array  $dependencies
208
-     * @param int    $overwrite
209
-     * @return bool
210
-     */
211
-    public function registerDependencies(
212
-        $class,
213
-        array $dependencies,
214
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
215
-    ) {
216
-        $class = trim($class, '\\');
217
-        $registered = false;
218
-        if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) {
219
-            EE_Dependency_Map::$_instance->_dependency_map[ $class ] = array();
220
-        }
221
-        // we need to make sure that any aliases used when registering a dependency
222
-        // get resolved to the correct class name
223
-        foreach ($dependencies as $dependency => $load_source) {
224
-            $alias = EE_Dependency_Map::$_instance->get_alias($dependency);
225
-            if (
226
-                $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
227
-                || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ])
228
-            ) {
229
-                unset($dependencies[$dependency]);
230
-                $dependencies[$alias] = $load_source;
231
-                $registered = true;
232
-            }
233
-        }
234
-        // now add our two lists of dependencies together.
235
-        // using Union (+=) favours the arrays in precedence from left to right,
236
-        // so $dependencies is NOT overwritten because it is listed first
237
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
238
-        // Union is way faster than array_merge() but should be used with caution...
239
-        // especially with numerically indexed arrays
240
-        $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ];
241
-        // now we need to ensure that the resulting dependencies
242
-        // array only has the entries that are required for the class
243
-        // so first count how many dependencies were originally registered for the class
244
-        $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]);
245
-        // if that count is non-zero (meaning dependencies were already registered)
246
-        EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count
247
-            // then truncate the  final array to match that count
248
-            ? array_slice($dependencies, 0, $dependency_count)
249
-            // otherwise just take the incoming array because nothing previously existed
250
-            : $dependencies;
251
-        return $registered;
252
-    }
253
-
254
-
255
-
256
-    /**
257
-     * @param string $class_name
258
-     * @param string $loader
259
-     * @return bool
260
-     * @throws DomainException
261
-     */
262
-    public static function register_class_loader($class_name, $loader = 'load_core')
263
-    {
264
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
265
-            throw new DomainException(
266
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
267
-            );
268
-        }
269
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
270
-        if (
271
-            ! is_callable($loader)
272
-            && (
273
-                strpos($loader, 'load_') !== 0
274
-                || ! method_exists('EE_Registry', $loader)
275
-            )
276
-        ) {
277
-            throw new DomainException(
278
-                sprintf(
279
-                    esc_html__(
280
-                        '"%1$s" is not a valid loader method on EE_Registry.',
281
-                        'event_espresso'
282
-                    ),
283
-                    $loader
284
-                )
285
-            );
286
-        }
287
-        $class_name = EE_Dependency_Map::$_instance->get_alias($class_name);
288
-        if (! isset(EE_Dependency_Map::$_instance->_class_loaders[$class_name])) {
289
-            EE_Dependency_Map::$_instance->_class_loaders[$class_name] = $loader;
290
-            return true;
291
-        }
292
-        return false;
293
-    }
294
-
295
-
296
-
297
-    /**
298
-     * @return array
299
-     */
300
-    public function dependency_map()
301
-    {
302
-        return $this->_dependency_map;
303
-    }
304
-
305
-
306
-
307
-    /**
308
-     * returns TRUE if dependency map contains a listing for the provided class name
309
-     *
310
-     * @param string $class_name
311
-     * @return boolean
312
-     */
313
-    public function has($class_name = '')
314
-    {
315
-        // all legacy models have the same dependencies
316
-        if (strpos($class_name, 'EEM_') === 0) {
317
-            $class_name = 'LEGACY_MODELS';
318
-        }
319
-        return isset($this->_dependency_map[$class_name]) ? true : false;
320
-    }
321
-
322
-
323
-
324
-    /**
325
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
326
-     *
327
-     * @param string $class_name
328
-     * @param string $dependency
329
-     * @return bool
330
-     */
331
-    public function has_dependency_for_class($class_name = '', $dependency = '')
332
-    {
333
-        // all legacy models have the same dependencies
334
-        if (strpos($class_name, 'EEM_') === 0) {
335
-            $class_name = 'LEGACY_MODELS';
336
-        }
337
-        $dependency = $this->get_alias($dependency);
338
-        return isset($this->_dependency_map[$class_name][$dependency])
339
-            ? true
340
-            : false;
341
-    }
342
-
343
-
344
-
345
-    /**
346
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
347
-     *
348
-     * @param string $class_name
349
-     * @param string $dependency
350
-     * @return int
351
-     */
352
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
353
-    {
354
-        // all legacy models have the same dependencies
355
-        if (strpos($class_name, 'EEM_') === 0) {
356
-            $class_name = 'LEGACY_MODELS';
357
-        }
358
-        $dependency = $this->get_alias($dependency);
359
-        return $this->has_dependency_for_class($class_name, $dependency)
360
-            ? $this->_dependency_map[$class_name][$dependency]
361
-            : EE_Dependency_Map::not_registered;
362
-    }
363
-
364
-
365
-
366
-    /**
367
-     * @param string $class_name
368
-     * @return string | Closure
369
-     */
370
-    public function class_loader($class_name)
371
-    {
372
-        // all legacy models use load_model()
373
-        if(strpos($class_name, 'EEM_') === 0){
374
-            return 'load_model';
375
-        }
376
-        $class_name = $this->get_alias($class_name);
377
-        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * @return array
384
-     */
385
-    public function class_loaders()
386
-    {
387
-        return $this->_class_loaders;
388
-    }
389
-
390
-
391
-
392
-    /**
393
-     * adds an alias for a classname
394
-     *
395
-     * @param string $fqcn      the class name that should be used (concrete class to replace interface)
396
-     * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
397
-     * @param string $for_class the class that has the dependency (is type hinting for the interface)
398
-     */
399
-    public function add_alias($fqcn, $alias, $for_class = '')
400
-    {
401
-        $this->class_cache->addAlias($alias, $fqcn, $for_class);
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     * PLZ NOTE: a better name for this method would be is_alias()
408
-     * because it returns TRUE if the provided fully qualified name IS an alias
409
-     *
410
-     * @param string $fqn
411
-     * @param string $for_class
412
-     * @return bool
413
-     */
414
-    public function has_alias($fqn = '', $for_class = '')
415
-    {
416
-        return $this->class_cache->isAlias($fqn, $for_class);
417
-    }
418
-
419
-
420
-
421
-    /**
422
-     * PLZ NOTE: a better name for this method would be get_fqn_for_alias()
423
-     * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias
424
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
425
-     *  for example:
426
-     *      if the following two entries were added to the _aliases array:
427
-     *          array(
428
-     *              'interface_alias'           => 'some\namespace\interface'
429
-     *              'some\namespace\interface'  => 'some\namespace\classname'
430
-     *          )
431
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
432
-     *      to load an instance of 'some\namespace\classname'
433
-     *
434
-     * @param string $alias
435
-     * @param string $for_class
436
-     * @return string
437
-     */
438
-    public function get_alias($alias = '', $for_class = '')
439
-    {
440
-        return (string) $this->class_cache->getFqnForAlias($alias, $for_class);
441
-    }
442
-
443
-
444
-
445
-    /**
446
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
447
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
448
-     * This is done by using the following class constants:
449
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
450
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
451
-     */
452
-    protected function _register_core_dependencies()
453
-    {
454
-        $this->_dependency_map = array(
455
-            'EE_Request_Handler'                                                                                          => array(
456
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
457
-            ),
458
-            'EE_System'                                                                                                   => array(
459
-                'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
460
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
461
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
462
-                'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
463
-            ),
464
-            'EE_Session'                                                                                                  => array(
465
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
466
-                'EventEspresso\core\services\request\Request'             => EE_Dependency_Map::load_from_cache,
467
-                'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
468
-            ),
469
-            'EE_Cart'                                                                                                     => array(
470
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
471
-            ),
472
-            'EE_Front_Controller'                                                                                         => array(
473
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
474
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
475
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
476
-            ),
477
-            'EE_Messenger_Collection_Loader'                                                                              => array(
478
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
479
-            ),
480
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
481
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
482
-            ),
483
-            'EE_Message_Resource_Manager'                                                                                 => array(
484
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
485
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
486
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
487
-            ),
488
-            'EE_Message_Factory'                                                                                          => array(
489
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
490
-            ),
491
-            'EE_messages'                                                                                                 => array(
492
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
493
-            ),
494
-            'EE_Messages_Generator'                                                                                       => array(
495
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
496
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
497
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
498
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
499
-            ),
500
-            'EE_Messages_Processor'                                                                                       => array(
501
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
502
-            ),
503
-            'EE_Messages_Queue'                                                                                           => array(
504
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
505
-            ),
506
-            'EE_Messages_Template_Defaults'                                                                               => array(
507
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
508
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
509
-            ),
510
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
511
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
512
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
513
-            ),
514
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
515
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
516
-            ),
517
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
518
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
519
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
520
-            ),
521
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
522
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
523
-            ),
524
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
525
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
526
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
527
-            ),
528
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
529
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
530
-            ),
531
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
532
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
533
-            ),
534
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
535
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
536
-            ),
537
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
538
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
539
-            ),
540
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
541
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
542
-            ),
543
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
544
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
545
-            ),
546
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
547
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
548
-            ),
549
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
550
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
551
-            ),
552
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
553
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
554
-            ),
555
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
556
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
557
-            ),
558
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
559
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
560
-            ),
561
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
562
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
563
-            ),
564
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
565
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
566
-            ),
567
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
568
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
569
-            ),
570
-            'EE_Data_Migration_Class_Base'                                                                                => array(
571
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
572
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
573
-            ),
574
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
575
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
576
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
577
-            ),
578
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
579
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
581
-            ),
582
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
583
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
584
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
585
-            ),
586
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
587
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
588
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
589
-            ),
590
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
591
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
592
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
593
-            ),
594
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
595
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
596
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
597
-            ),
598
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
599
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
600
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
601
-            ),
602
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
603
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
604
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
605
-            ),
606
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
607
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
608
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
609
-            ),
610
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
611
-                'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
612
-                'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
613
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
614
-            ),
615
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
616
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
617
-            ),
618
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
619
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
620
-            ),
621
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
622
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
623
-            ),
624
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
625
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
626
-            ),
627
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
628
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
629
-            ),
630
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
631
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
632
-            ),
633
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
634
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
635
-            ),
636
-            'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
637
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
638
-            ),
639
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
640
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
641
-            ),
642
-            'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
643
-                'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
644
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
645
-            ),
646
-            'EventEspresso\core\domain\values\EmailAddress'                              => array(
647
-                null,
648
-                'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
649
-            ),
650
-            'EventEspresso\core\services\orm\ModelFieldFactory' => array(
651
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
652
-            ),
653
-            'LEGACY_MODELS'                                                   => array(
654
-                null,
655
-                'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
656
-            ),
657
-            'EE_Module_Request_Router' => array(
658
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
659
-            ),
660
-            'EE_Registration_Processor' => array(
661
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
662
-            ),
663
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array(
664
-                null,
665
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
666
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
667
-            ),
668
-        );
669
-    }
670
-
671
-
672
-    /**
673
-     * Registers how core classes are loaded.
674
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
675
-     *        'EE_Request_Handler' => 'load_core'
676
-     *        'EE_Messages_Queue'  => 'load_lib'
677
-     *        'EEH_Debug_Tools'    => 'load_helper'
678
-     * or, if greater control is required, by providing a custom closure. For example:
679
-     *        'Some_Class' => function () {
680
-     *            return new Some_Class();
681
-     *        },
682
-     * This is required for instantiating dependencies
683
-     * where an interface has been type hinted in a class constructor. For example:
684
-     *        'Required_Interface' => function () {
685
-     *            return new A_Class_That_Implements_Required_Interface();
686
-     *        },
687
-     *
688
-     */
689
-    protected function _register_core_class_loaders()
690
-    {
691
-        //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
692
-        //be used in a closure.
693
-        $request = &$this->request;
694
-        $response = &$this->response;
695
-        $legacy_request = &$this->legacy_request;
696
-        // $loader = &$this->loader;
697
-        $this->_class_loaders = array(
698
-            //load_core
699
-            'EE_Capabilities'          => 'load_core',
700
-            'EE_Encryption'            => 'load_core',
701
-            'EE_Front_Controller'      => 'load_core',
702
-            'EE_Module_Request_Router' => 'load_core',
703
-            'EE_Registry'              => 'load_core',
704
-            'EE_Request'               => function () use (&$legacy_request) {
705
-                return $legacy_request;
706
-            },
707
-            'EventEspresso\core\services\request\Request' => function () use (&$request) {
708
-                return $request;
709
-            },
710
-            'EventEspresso\core\services\request\Response' => function () use (&$response) {
711
-                return $response;
712
-            },
713
-            'EE_Request_Handler'       => 'load_core',
714
-            'EE_Session'               => 'load_core',
715
-            'EE_Cron_Tasks'            => 'load_core',
716
-            'EE_System'                => 'load_core',
717
-            'EE_Maintenance_Mode'      => 'load_core',
718
-            'EE_Register_CPTs'         => 'load_core',
719
-            'EE_Admin'                 => 'load_core',
720
-            //load_lib
721
-            'EE_Message_Resource_Manager'          => 'load_lib',
722
-            'EE_Message_Type_Collection'           => 'load_lib',
723
-            'EE_Message_Type_Collection_Loader'    => 'load_lib',
724
-            'EE_Messenger_Collection'              => 'load_lib',
725
-            'EE_Messenger_Collection_Loader'       => 'load_lib',
726
-            'EE_Messages_Processor'                => 'load_lib',
727
-            'EE_Message_Repository'                => 'load_lib',
728
-            'EE_Messages_Queue'                    => 'load_lib',
729
-            'EE_Messages_Data_Handler_Collection'  => 'load_lib',
730
-            'EE_Message_Template_Group_Collection' => 'load_lib',
731
-            'EE_Payment_Method_Manager'            => 'load_lib',
732
-            'EE_Messages_Generator'                => function () {
733
-                return EE_Registry::instance()->load_lib(
734
-                    'Messages_Generator',
735
-                    array(),
736
-                    false,
737
-                    false
738
-                );
739
-            },
740
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
741
-                return EE_Registry::instance()->load_lib(
742
-                    'Messages_Template_Defaults',
743
-                    $arguments,
744
-                    false,
745
-                    false
746
-                );
747
-            },
748
-            //load_model
749
-            // 'EEM_Attendee'                         => 'load_model',
750
-            // 'EEM_Message_Template_Group'           => 'load_model',
751
-            // 'EEM_Message_Template'                 => 'load_model',
752
-            //load_helper
753
-            'EEH_Parse_Shortcodes'                 => function () {
754
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
755
-                    return new EEH_Parse_Shortcodes();
756
-                }
757
-                return null;
758
-            },
759
-            'EE_Template_Config'                   => function () {
760
-                return EE_Config::instance()->template_settings;
761
-            },
762
-            'EE_Currency_Config'                   => function () {
763
-                return EE_Config::instance()->currency;
764
-            },
765
-            'EE_Registration_Config'                   => function () {
766
-                return EE_Config::instance()->registration;
767
-            },
768
-            'EventEspresso\core\services\loaders\Loader' => function () {
769
-                return LoaderFactory::getLoader();
770
-            },
771
-            'EE_Base' => 'load_core',
772
-        );
773
-    }
774
-
775
-
776
-
777
-
778
-    /**
779
-     * can be used for supplying alternate names for classes,
780
-     * or for connecting interface names to instantiable classes
781
-     */
782
-    protected function _register_core_aliases()
783
-    {
784
-        $aliases = array(
785
-            'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
786
-            'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
787
-            'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
788
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
789
-            'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
790
-            'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
791
-            'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
792
-            'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
793
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
794
-            'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
795
-            'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
796
-            'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
797
-            'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
798
-            'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
799
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
800
-            'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
801
-            'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
802
-            'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
803
-            'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
804
-            'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
805
-            'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
806
-            'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
807
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
808
-            'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
809
-            'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
810
-            'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
811
-            'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
812
-            'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
813
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
814
-            'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
815
-            'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
816
-            'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
817
-            'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
818
-            'NoticesContainerInterface'                                           => 'EventEspresso\core\services\notices\NoticesContainerInterface',
819
-            'EventEspresso\core\services\notices\NoticesContainerInterface'       => 'EventEspresso\core\services\notices\NoticesContainer',
820
-            'EventEspresso\core\services\request\RequestInterface'                => 'EventEspresso\core\services\request\Request',
821
-            'EventEspresso\core\services\request\ResponseInterface'               => 'EventEspresso\core\services\request\Response',
822
-            'EventEspresso\core\domain\DomainInterface'                           => 'EventEspresso\core\domain\Domain',
823
-        );
824
-        foreach ($aliases as $alias => $fqn) {
825
-            $this->class_cache->addAlias($fqn, $alias);
826
-        }
827
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
828
-            $this->class_cache->addAlias(
829
-                'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
830
-                'EventEspresso\core\services\notices\NoticeConverterInterface'
831
-            );
832
-        }
833
-    }
834
-
835
-
836
-
837
-    /**
838
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
839
-     * request Primarily used by unit tests.
840
-     */
841
-    public function reset()
842
-    {
843
-        $this->_register_core_class_loaders();
844
-        $this->_register_core_dependencies();
845
-    }
31
+	/**
32
+	 * This means that the requested class dependency is not present in the dependency map
33
+	 */
34
+	const not_registered = 0;
35
+
36
+	/**
37
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
38
+	 */
39
+	const load_new_object = 1;
40
+
41
+	/**
42
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
43
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
44
+	 */
45
+	const load_from_cache = 2;
46
+
47
+	/**
48
+	 * When registering a dependency,
49
+	 * this indicates to keep any existing dependencies that already exist,
50
+	 * and simply discard any new dependencies declared in the incoming data
51
+	 */
52
+	const KEEP_EXISTING_DEPENDENCIES = 0;
53
+
54
+	/**
55
+	 * When registering a dependency,
56
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
57
+	 */
58
+	const OVERWRITE_DEPENDENCIES = 1;
59
+
60
+
61
+
62
+	/**
63
+	 * @type EE_Dependency_Map $_instance
64
+	 */
65
+	protected static $_instance;
66
+
67
+	/**
68
+	 * @var ClassInterfaceCache $class_cache
69
+	 */
70
+	private $class_cache;
71
+
72
+	/**
73
+	 * @type RequestInterface $request
74
+	 */
75
+	protected $request;
76
+
77
+	/**
78
+	 * @type LegacyRequestInterface $legacy_request
79
+	 */
80
+	protected $legacy_request;
81
+
82
+	/**
83
+	 * @type ResponseInterface $response
84
+	 */
85
+	protected $response;
86
+
87
+	/**
88
+	 * @type LoaderInterface $loader
89
+	 */
90
+	protected $loader;
91
+
92
+	/**
93
+	 * @type array $_dependency_map
94
+	 */
95
+	protected $_dependency_map = array();
96
+
97
+	/**
98
+	 * @type array $_class_loaders
99
+	 */
100
+	protected $_class_loaders = array();
101
+
102
+
103
+	/**
104
+	 * EE_Dependency_Map constructor.
105
+	 *
106
+	 * @param ClassInterfaceCache $class_cache
107
+	 */
108
+	protected function __construct(ClassInterfaceCache $class_cache)
109
+	{
110
+		$this->class_cache = $class_cache;
111
+		do_action('EE_Dependency_Map____construct', $this);
112
+	}
113
+
114
+
115
+	/**
116
+	 * @return void
117
+	 */
118
+	public function initialize()
119
+	{
120
+		$this->_register_core_dependencies();
121
+		$this->_register_core_class_loaders();
122
+		$this->_register_core_aliases();
123
+	}
124
+
125
+
126
+	/**
127
+	 * @singleton method used to instantiate class object
128
+	 * @param ClassInterfaceCache|null $class_cache
129
+	 * @return EE_Dependency_Map
130
+	 */
131
+	public static function instance(ClassInterfaceCache $class_cache = null) {
132
+		// check if class object is instantiated, and instantiated properly
133
+		if (
134
+			! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map
135
+			&& $class_cache instanceof ClassInterfaceCache
136
+		) {
137
+			EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache);
138
+		}
139
+		return EE_Dependency_Map::$_instance;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @param RequestInterface $request
145
+	 */
146
+	public function setRequest(RequestInterface $request)
147
+	{
148
+		$this->request = $request;
149
+	}
150
+
151
+
152
+	/**
153
+	 * @param LegacyRequestInterface $legacy_request
154
+	 */
155
+	public function setLegacyRequest(LegacyRequestInterface $legacy_request)
156
+	{
157
+		$this->legacy_request = $legacy_request;
158
+	}
159
+
160
+
161
+	/**
162
+	 * @param ResponseInterface $response
163
+	 */
164
+	public function setResponse(ResponseInterface $response)
165
+	{
166
+		$this->response = $response;
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 * @param LoaderInterface $loader
173
+	 */
174
+	public function setLoader(LoaderInterface $loader)
175
+	{
176
+		$this->loader = $loader;
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 * @param string $class
183
+	 * @param array  $dependencies
184
+	 * @param int    $overwrite
185
+	 * @return bool
186
+	 */
187
+	public static function register_dependencies(
188
+		$class,
189
+		array $dependencies,
190
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
191
+	) {
192
+		return EE_Dependency_Map::$_instance->registerDependencies($class, $dependencies, $overwrite);
193
+	}
194
+
195
+
196
+
197
+	/**
198
+	 * Assigns an array of class names and corresponding load sources (new or cached)
199
+	 * to the class specified by the first parameter.
200
+	 * IMPORTANT !!!
201
+	 * The order of elements in the incoming $dependencies array MUST match
202
+	 * the order of the constructor parameters for the class in question.
203
+	 * This is especially important when overriding any existing dependencies that are registered.
204
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
205
+	 *
206
+	 * @param string $class
207
+	 * @param array  $dependencies
208
+	 * @param int    $overwrite
209
+	 * @return bool
210
+	 */
211
+	public function registerDependencies(
212
+		$class,
213
+		array $dependencies,
214
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
215
+	) {
216
+		$class = trim($class, '\\');
217
+		$registered = false;
218
+		if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) {
219
+			EE_Dependency_Map::$_instance->_dependency_map[ $class ] = array();
220
+		}
221
+		// we need to make sure that any aliases used when registering a dependency
222
+		// get resolved to the correct class name
223
+		foreach ($dependencies as $dependency => $load_source) {
224
+			$alias = EE_Dependency_Map::$_instance->get_alias($dependency);
225
+			if (
226
+				$overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
227
+				|| ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ])
228
+			) {
229
+				unset($dependencies[$dependency]);
230
+				$dependencies[$alias] = $load_source;
231
+				$registered = true;
232
+			}
233
+		}
234
+		// now add our two lists of dependencies together.
235
+		// using Union (+=) favours the arrays in precedence from left to right,
236
+		// so $dependencies is NOT overwritten because it is listed first
237
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
238
+		// Union is way faster than array_merge() but should be used with caution...
239
+		// especially with numerically indexed arrays
240
+		$dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ];
241
+		// now we need to ensure that the resulting dependencies
242
+		// array only has the entries that are required for the class
243
+		// so first count how many dependencies were originally registered for the class
244
+		$dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]);
245
+		// if that count is non-zero (meaning dependencies were already registered)
246
+		EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count
247
+			// then truncate the  final array to match that count
248
+			? array_slice($dependencies, 0, $dependency_count)
249
+			// otherwise just take the incoming array because nothing previously existed
250
+			: $dependencies;
251
+		return $registered;
252
+	}
253
+
254
+
255
+
256
+	/**
257
+	 * @param string $class_name
258
+	 * @param string $loader
259
+	 * @return bool
260
+	 * @throws DomainException
261
+	 */
262
+	public static function register_class_loader($class_name, $loader = 'load_core')
263
+	{
264
+		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
265
+			throw new DomainException(
266
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
267
+			);
268
+		}
269
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
270
+		if (
271
+			! is_callable($loader)
272
+			&& (
273
+				strpos($loader, 'load_') !== 0
274
+				|| ! method_exists('EE_Registry', $loader)
275
+			)
276
+		) {
277
+			throw new DomainException(
278
+				sprintf(
279
+					esc_html__(
280
+						'"%1$s" is not a valid loader method on EE_Registry.',
281
+						'event_espresso'
282
+					),
283
+					$loader
284
+				)
285
+			);
286
+		}
287
+		$class_name = EE_Dependency_Map::$_instance->get_alias($class_name);
288
+		if (! isset(EE_Dependency_Map::$_instance->_class_loaders[$class_name])) {
289
+			EE_Dependency_Map::$_instance->_class_loaders[$class_name] = $loader;
290
+			return true;
291
+		}
292
+		return false;
293
+	}
294
+
295
+
296
+
297
+	/**
298
+	 * @return array
299
+	 */
300
+	public function dependency_map()
301
+	{
302
+		return $this->_dependency_map;
303
+	}
304
+
305
+
306
+
307
+	/**
308
+	 * returns TRUE if dependency map contains a listing for the provided class name
309
+	 *
310
+	 * @param string $class_name
311
+	 * @return boolean
312
+	 */
313
+	public function has($class_name = '')
314
+	{
315
+		// all legacy models have the same dependencies
316
+		if (strpos($class_name, 'EEM_') === 0) {
317
+			$class_name = 'LEGACY_MODELS';
318
+		}
319
+		return isset($this->_dependency_map[$class_name]) ? true : false;
320
+	}
321
+
322
+
323
+
324
+	/**
325
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
326
+	 *
327
+	 * @param string $class_name
328
+	 * @param string $dependency
329
+	 * @return bool
330
+	 */
331
+	public function has_dependency_for_class($class_name = '', $dependency = '')
332
+	{
333
+		// all legacy models have the same dependencies
334
+		if (strpos($class_name, 'EEM_') === 0) {
335
+			$class_name = 'LEGACY_MODELS';
336
+		}
337
+		$dependency = $this->get_alias($dependency);
338
+		return isset($this->_dependency_map[$class_name][$dependency])
339
+			? true
340
+			: false;
341
+	}
342
+
343
+
344
+
345
+	/**
346
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
347
+	 *
348
+	 * @param string $class_name
349
+	 * @param string $dependency
350
+	 * @return int
351
+	 */
352
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
353
+	{
354
+		// all legacy models have the same dependencies
355
+		if (strpos($class_name, 'EEM_') === 0) {
356
+			$class_name = 'LEGACY_MODELS';
357
+		}
358
+		$dependency = $this->get_alias($dependency);
359
+		return $this->has_dependency_for_class($class_name, $dependency)
360
+			? $this->_dependency_map[$class_name][$dependency]
361
+			: EE_Dependency_Map::not_registered;
362
+	}
363
+
364
+
365
+
366
+	/**
367
+	 * @param string $class_name
368
+	 * @return string | Closure
369
+	 */
370
+	public function class_loader($class_name)
371
+	{
372
+		// all legacy models use load_model()
373
+		if(strpos($class_name, 'EEM_') === 0){
374
+			return 'load_model';
375
+		}
376
+		$class_name = $this->get_alias($class_name);
377
+		return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * @return array
384
+	 */
385
+	public function class_loaders()
386
+	{
387
+		return $this->_class_loaders;
388
+	}
389
+
390
+
391
+
392
+	/**
393
+	 * adds an alias for a classname
394
+	 *
395
+	 * @param string $fqcn      the class name that should be used (concrete class to replace interface)
396
+	 * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
397
+	 * @param string $for_class the class that has the dependency (is type hinting for the interface)
398
+	 */
399
+	public function add_alias($fqcn, $alias, $for_class = '')
400
+	{
401
+		$this->class_cache->addAlias($alias, $fqcn, $for_class);
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 * PLZ NOTE: a better name for this method would be is_alias()
408
+	 * because it returns TRUE if the provided fully qualified name IS an alias
409
+	 *
410
+	 * @param string $fqn
411
+	 * @param string $for_class
412
+	 * @return bool
413
+	 */
414
+	public function has_alias($fqn = '', $for_class = '')
415
+	{
416
+		return $this->class_cache->isAlias($fqn, $for_class);
417
+	}
418
+
419
+
420
+
421
+	/**
422
+	 * PLZ NOTE: a better name for this method would be get_fqn_for_alias()
423
+	 * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias
424
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
425
+	 *  for example:
426
+	 *      if the following two entries were added to the _aliases array:
427
+	 *          array(
428
+	 *              'interface_alias'           => 'some\namespace\interface'
429
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
430
+	 *          )
431
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
432
+	 *      to load an instance of 'some\namespace\classname'
433
+	 *
434
+	 * @param string $alias
435
+	 * @param string $for_class
436
+	 * @return string
437
+	 */
438
+	public function get_alias($alias = '', $for_class = '')
439
+	{
440
+		return (string) $this->class_cache->getFqnForAlias($alias, $for_class);
441
+	}
442
+
443
+
444
+
445
+	/**
446
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
447
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
448
+	 * This is done by using the following class constants:
449
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
450
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
451
+	 */
452
+	protected function _register_core_dependencies()
453
+	{
454
+		$this->_dependency_map = array(
455
+			'EE_Request_Handler'                                                                                          => array(
456
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
457
+			),
458
+			'EE_System'                                                                                                   => array(
459
+				'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
460
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
461
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
462
+				'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
463
+			),
464
+			'EE_Session'                                                                                                  => array(
465
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
466
+				'EventEspresso\core\services\request\Request'             => EE_Dependency_Map::load_from_cache,
467
+				'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
468
+			),
469
+			'EE_Cart'                                                                                                     => array(
470
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
471
+			),
472
+			'EE_Front_Controller'                                                                                         => array(
473
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
474
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
475
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
476
+			),
477
+			'EE_Messenger_Collection_Loader'                                                                              => array(
478
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
479
+			),
480
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
481
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
482
+			),
483
+			'EE_Message_Resource_Manager'                                                                                 => array(
484
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
485
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
486
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
487
+			),
488
+			'EE_Message_Factory'                                                                                          => array(
489
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
490
+			),
491
+			'EE_messages'                                                                                                 => array(
492
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
493
+			),
494
+			'EE_Messages_Generator'                                                                                       => array(
495
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
496
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
497
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
498
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
499
+			),
500
+			'EE_Messages_Processor'                                                                                       => array(
501
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
502
+			),
503
+			'EE_Messages_Queue'                                                                                           => array(
504
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
505
+			),
506
+			'EE_Messages_Template_Defaults'                                                                               => array(
507
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
508
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
509
+			),
510
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
511
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
512
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
513
+			),
514
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
515
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
516
+			),
517
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
518
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
519
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
520
+			),
521
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
522
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
523
+			),
524
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
525
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
526
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
527
+			),
528
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
529
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
530
+			),
531
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
532
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
533
+			),
534
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
535
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
536
+			),
537
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
538
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
539
+			),
540
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
541
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
542
+			),
543
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
544
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
545
+			),
546
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
547
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
548
+			),
549
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
550
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
551
+			),
552
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
553
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
554
+			),
555
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
556
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
557
+			),
558
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
559
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
560
+			),
561
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
562
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
563
+			),
564
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
565
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
566
+			),
567
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
568
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
569
+			),
570
+			'EE_Data_Migration_Class_Base'                                                                                => array(
571
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
572
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
573
+			),
574
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
575
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
576
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
577
+			),
578
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
579
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
581
+			),
582
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
583
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
584
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
585
+			),
586
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
587
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
588
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
589
+			),
590
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
591
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
592
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
593
+			),
594
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
595
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
596
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
597
+			),
598
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
599
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
600
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
601
+			),
602
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
603
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
604
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
605
+			),
606
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
607
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
608
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
609
+			),
610
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
611
+				'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
612
+				'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
613
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
614
+			),
615
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
616
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
617
+			),
618
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
619
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
620
+			),
621
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
622
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
623
+			),
624
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
625
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
626
+			),
627
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
628
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
629
+			),
630
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
631
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
632
+			),
633
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
634
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
635
+			),
636
+			'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
637
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
638
+			),
639
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
640
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
641
+			),
642
+			'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
643
+				'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
644
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
645
+			),
646
+			'EventEspresso\core\domain\values\EmailAddress'                              => array(
647
+				null,
648
+				'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
649
+			),
650
+			'EventEspresso\core\services\orm\ModelFieldFactory' => array(
651
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
652
+			),
653
+			'LEGACY_MODELS'                                                   => array(
654
+				null,
655
+				'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
656
+			),
657
+			'EE_Module_Request_Router' => array(
658
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
659
+			),
660
+			'EE_Registration_Processor' => array(
661
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
662
+			),
663
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array(
664
+				null,
665
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
666
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
667
+			),
668
+		);
669
+	}
670
+
671
+
672
+	/**
673
+	 * Registers how core classes are loaded.
674
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
675
+	 *        'EE_Request_Handler' => 'load_core'
676
+	 *        'EE_Messages_Queue'  => 'load_lib'
677
+	 *        'EEH_Debug_Tools'    => 'load_helper'
678
+	 * or, if greater control is required, by providing a custom closure. For example:
679
+	 *        'Some_Class' => function () {
680
+	 *            return new Some_Class();
681
+	 *        },
682
+	 * This is required for instantiating dependencies
683
+	 * where an interface has been type hinted in a class constructor. For example:
684
+	 *        'Required_Interface' => function () {
685
+	 *            return new A_Class_That_Implements_Required_Interface();
686
+	 *        },
687
+	 *
688
+	 */
689
+	protected function _register_core_class_loaders()
690
+	{
691
+		//for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
692
+		//be used in a closure.
693
+		$request = &$this->request;
694
+		$response = &$this->response;
695
+		$legacy_request = &$this->legacy_request;
696
+		// $loader = &$this->loader;
697
+		$this->_class_loaders = array(
698
+			//load_core
699
+			'EE_Capabilities'          => 'load_core',
700
+			'EE_Encryption'            => 'load_core',
701
+			'EE_Front_Controller'      => 'load_core',
702
+			'EE_Module_Request_Router' => 'load_core',
703
+			'EE_Registry'              => 'load_core',
704
+			'EE_Request'               => function () use (&$legacy_request) {
705
+				return $legacy_request;
706
+			},
707
+			'EventEspresso\core\services\request\Request' => function () use (&$request) {
708
+				return $request;
709
+			},
710
+			'EventEspresso\core\services\request\Response' => function () use (&$response) {
711
+				return $response;
712
+			},
713
+			'EE_Request_Handler'       => 'load_core',
714
+			'EE_Session'               => 'load_core',
715
+			'EE_Cron_Tasks'            => 'load_core',
716
+			'EE_System'                => 'load_core',
717
+			'EE_Maintenance_Mode'      => 'load_core',
718
+			'EE_Register_CPTs'         => 'load_core',
719
+			'EE_Admin'                 => 'load_core',
720
+			//load_lib
721
+			'EE_Message_Resource_Manager'          => 'load_lib',
722
+			'EE_Message_Type_Collection'           => 'load_lib',
723
+			'EE_Message_Type_Collection_Loader'    => 'load_lib',
724
+			'EE_Messenger_Collection'              => 'load_lib',
725
+			'EE_Messenger_Collection_Loader'       => 'load_lib',
726
+			'EE_Messages_Processor'                => 'load_lib',
727
+			'EE_Message_Repository'                => 'load_lib',
728
+			'EE_Messages_Queue'                    => 'load_lib',
729
+			'EE_Messages_Data_Handler_Collection'  => 'load_lib',
730
+			'EE_Message_Template_Group_Collection' => 'load_lib',
731
+			'EE_Payment_Method_Manager'            => 'load_lib',
732
+			'EE_Messages_Generator'                => function () {
733
+				return EE_Registry::instance()->load_lib(
734
+					'Messages_Generator',
735
+					array(),
736
+					false,
737
+					false
738
+				);
739
+			},
740
+			'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
741
+				return EE_Registry::instance()->load_lib(
742
+					'Messages_Template_Defaults',
743
+					$arguments,
744
+					false,
745
+					false
746
+				);
747
+			},
748
+			//load_model
749
+			// 'EEM_Attendee'                         => 'load_model',
750
+			// 'EEM_Message_Template_Group'           => 'load_model',
751
+			// 'EEM_Message_Template'                 => 'load_model',
752
+			//load_helper
753
+			'EEH_Parse_Shortcodes'                 => function () {
754
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
755
+					return new EEH_Parse_Shortcodes();
756
+				}
757
+				return null;
758
+			},
759
+			'EE_Template_Config'                   => function () {
760
+				return EE_Config::instance()->template_settings;
761
+			},
762
+			'EE_Currency_Config'                   => function () {
763
+				return EE_Config::instance()->currency;
764
+			},
765
+			'EE_Registration_Config'                   => function () {
766
+				return EE_Config::instance()->registration;
767
+			},
768
+			'EventEspresso\core\services\loaders\Loader' => function () {
769
+				return LoaderFactory::getLoader();
770
+			},
771
+			'EE_Base' => 'load_core',
772
+		);
773
+	}
774
+
775
+
776
+
777
+
778
+	/**
779
+	 * can be used for supplying alternate names for classes,
780
+	 * or for connecting interface names to instantiable classes
781
+	 */
782
+	protected function _register_core_aliases()
783
+	{
784
+		$aliases = array(
785
+			'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
786
+			'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
787
+			'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
788
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
789
+			'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
790
+			'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
791
+			'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
792
+			'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
793
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
794
+			'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
795
+			'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
796
+			'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
797
+			'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
798
+			'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
799
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
800
+			'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
801
+			'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
802
+			'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
803
+			'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
804
+			'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
805
+			'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
806
+			'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
807
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
808
+			'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
809
+			'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
810
+			'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
811
+			'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
812
+			'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
813
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
814
+			'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
815
+			'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
816
+			'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
817
+			'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
818
+			'NoticesContainerInterface'                                           => 'EventEspresso\core\services\notices\NoticesContainerInterface',
819
+			'EventEspresso\core\services\notices\NoticesContainerInterface'       => 'EventEspresso\core\services\notices\NoticesContainer',
820
+			'EventEspresso\core\services\request\RequestInterface'                => 'EventEspresso\core\services\request\Request',
821
+			'EventEspresso\core\services\request\ResponseInterface'               => 'EventEspresso\core\services\request\Response',
822
+			'EventEspresso\core\domain\DomainInterface'                           => 'EventEspresso\core\domain\Domain',
823
+		);
824
+		foreach ($aliases as $alias => $fqn) {
825
+			$this->class_cache->addAlias($fqn, $alias);
826
+		}
827
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
828
+			$this->class_cache->addAlias(
829
+				'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
830
+				'EventEspresso\core\services\notices\NoticeConverterInterface'
831
+			);
832
+		}
833
+	}
834
+
835
+
836
+
837
+	/**
838
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
839
+	 * request Primarily used by unit tests.
840
+	 */
841
+	public function reset()
842
+	{
843
+		$this->_register_core_class_loaders();
844
+		$this->_register_core_dependencies();
845
+	}
846 846
 
847 847
 
848 848
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 use EventEspresso\core\services\request\RequestInterface;
11 11
 use EventEspresso\core\services\request\ResponseInterface;
12 12
 
13
-if (! defined('EVENT_ESPRESSO_VERSION')) {
13
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
14 14
     exit('No direct script access allowed');
15 15
 }
16 16
 
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
     ) {
216 216
         $class = trim($class, '\\');
217 217
         $registered = false;
218
-        if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) {
219
-            EE_Dependency_Map::$_instance->_dependency_map[ $class ] = array();
218
+        if (empty(EE_Dependency_Map::$_instance->_dependency_map[$class])) {
219
+            EE_Dependency_Map::$_instance->_dependency_map[$class] = array();
220 220
         }
221 221
         // we need to make sure that any aliases used when registering a dependency
222 222
         // get resolved to the correct class name
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
             $alias = EE_Dependency_Map::$_instance->get_alias($dependency);
225 225
             if (
226 226
                 $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
227
-                || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ])
227
+                || ! isset(EE_Dependency_Map::$_instance->_dependency_map[$class][$alias])
228 228
             ) {
229 229
                 unset($dependencies[$dependency]);
230 230
                 $dependencies[$alias] = $load_source;
@@ -237,13 +237,13 @@  discard block
 block discarded – undo
237 237
         // ie: with A = B + C, entries in B take precedence over duplicate entries in C
238 238
         // Union is way faster than array_merge() but should be used with caution...
239 239
         // especially with numerically indexed arrays
240
-        $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ];
240
+        $dependencies += EE_Dependency_Map::$_instance->_dependency_map[$class];
241 241
         // now we need to ensure that the resulting dependencies
242 242
         // array only has the entries that are required for the class
243 243
         // so first count how many dependencies were originally registered for the class
244
-        $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]);
244
+        $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[$class]);
245 245
         // if that count is non-zero (meaning dependencies were already registered)
246
-        EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count
246
+        EE_Dependency_Map::$_instance->_dependency_map[$class] = $dependency_count
247 247
             // then truncate the  final array to match that count
248 248
             ? array_slice($dependencies, 0, $dependency_count)
249 249
             // otherwise just take the incoming array because nothing previously existed
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
      */
262 262
     public static function register_class_loader($class_name, $loader = 'load_core')
263 263
     {
264
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
264
+        if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
265 265
             throw new DomainException(
266 266
                 esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
267 267
             );
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
             );
286 286
         }
287 287
         $class_name = EE_Dependency_Map::$_instance->get_alias($class_name);
288
-        if (! isset(EE_Dependency_Map::$_instance->_class_loaders[$class_name])) {
288
+        if ( ! isset(EE_Dependency_Map::$_instance->_class_loaders[$class_name])) {
289 289
             EE_Dependency_Map::$_instance->_class_loaders[$class_name] = $loader;
290 290
             return true;
291 291
         }
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
     public function class_loader($class_name)
371 371
     {
372 372
         // all legacy models use load_model()
373
-        if(strpos($class_name, 'EEM_') === 0){
373
+        if (strpos($class_name, 'EEM_') === 0) {
374 374
             return 'load_model';
375 375
         }
376 376
         $class_name = $this->get_alias($class_name);
@@ -701,13 +701,13 @@  discard block
 block discarded – undo
701 701
             'EE_Front_Controller'      => 'load_core',
702 702
             'EE_Module_Request_Router' => 'load_core',
703 703
             'EE_Registry'              => 'load_core',
704
-            'EE_Request'               => function () use (&$legacy_request) {
704
+            'EE_Request'               => function() use (&$legacy_request) {
705 705
                 return $legacy_request;
706 706
             },
707
-            'EventEspresso\core\services\request\Request' => function () use (&$request) {
707
+            'EventEspresso\core\services\request\Request' => function() use (&$request) {
708 708
                 return $request;
709 709
             },
710
-            'EventEspresso\core\services\request\Response' => function () use (&$response) {
710
+            'EventEspresso\core\services\request\Response' => function() use (&$response) {
711 711
                 return $response;
712 712
             },
713 713
             'EE_Request_Handler'       => 'load_core',
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
             'EE_Messages_Data_Handler_Collection'  => 'load_lib',
730 730
             'EE_Message_Template_Group_Collection' => 'load_lib',
731 731
             'EE_Payment_Method_Manager'            => 'load_lib',
732
-            'EE_Messages_Generator'                => function () {
732
+            'EE_Messages_Generator'                => function() {
733 733
                 return EE_Registry::instance()->load_lib(
734 734
                     'Messages_Generator',
735 735
                     array(),
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
                     false
738 738
                 );
739 739
             },
740
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
740
+            'EE_Messages_Template_Defaults'        => function($arguments = array()) {
741 741
                 return EE_Registry::instance()->load_lib(
742 742
                     'Messages_Template_Defaults',
743 743
                     $arguments,
@@ -750,22 +750,22 @@  discard block
 block discarded – undo
750 750
             // 'EEM_Message_Template_Group'           => 'load_model',
751 751
             // 'EEM_Message_Template'                 => 'load_model',
752 752
             //load_helper
753
-            'EEH_Parse_Shortcodes'                 => function () {
753
+            'EEH_Parse_Shortcodes'                 => function() {
754 754
                 if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
755 755
                     return new EEH_Parse_Shortcodes();
756 756
                 }
757 757
                 return null;
758 758
             },
759
-            'EE_Template_Config'                   => function () {
759
+            'EE_Template_Config'                   => function() {
760 760
                 return EE_Config::instance()->template_settings;
761 761
             },
762
-            'EE_Currency_Config'                   => function () {
762
+            'EE_Currency_Config'                   => function() {
763 763
                 return EE_Config::instance()->currency;
764 764
             },
765
-            'EE_Registration_Config'                   => function () {
765
+            'EE_Registration_Config'                   => function() {
766 766
                 return EE_Config::instance()->registration;
767 767
             },
768
-            'EventEspresso\core\services\loaders\Loader' => function () {
768
+            'EventEspresso\core\services\loaders\Loader' => function() {
769 769
                 return LoaderFactory::getLoader();
770 770
             },
771 771
             'EE_Base' => 'load_core',
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
         foreach ($aliases as $alias => $fqn) {
825 825
             $this->class_cache->addAlias($fqn, $alias);
826 826
         }
827
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
827
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
828 828
             $this->class_cache->addAlias(
829 829
                 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
830 830
                 'EventEspresso\core\services\notices\NoticeConverterInterface'
Please login to merge, or discard this patch.
core/EE_Registry.core.php 3 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -306,6 +306,7 @@  discard block
 block discarded – undo
306 306
 
307 307
     /**
308 308
      * @param mixed string | EED_Module $module
309
+     * @param string $module
309 310
      * @throws EE_Error
310 311
      * @throws ReflectionException
311 312
      */
@@ -1274,7 +1275,7 @@  discard block
 block discarded – undo
1274 1275
      * @param string $class_name
1275 1276
      * @param string $param_class
1276 1277
      * @param array  $arguments
1277
-     * @param mixed  $index
1278
+     * @param integer  $index
1278 1279
      * @param array  $argument_keys
1279 1280
      * @return array
1280 1281
      * @throws EE_Error
Please login to merge, or discard this patch.
Indentation   +1603 added lines, -1603 removed lines patch added patch discarded remove patch
@@ -27,1609 +27,1609 @@
 block discarded – undo
27 27
 class EE_Registry implements ResettableInterface
28 28
 {
29 29
 
30
-    /**
31
-     * @var EE_Registry $_instance
32
-     */
33
-    private static $_instance;
34
-
35
-    /**
36
-     * @var EE_Dependency_Map $_dependency_map
37
-     */
38
-    protected $_dependency_map;
39
-
40
-    /**
41
-     * @var Mirror
42
-     */
43
-    private $mirror;
44
-
45
-    /**
46
-     * @var ClassInterfaceCache $class_cache
47
-     */
48
-    private $class_cache;
49
-
50
-    /**
51
-     * @var array $_class_abbreviations
52
-     */
53
-    protected $_class_abbreviations = array();
54
-
55
-    /**
56
-     * @var CommandBusInterface $BUS
57
-     */
58
-    public $BUS;
59
-
60
-    /**
61
-     * @var EE_Cart $CART
62
-     */
63
-    public $CART;
64
-
65
-    /**
66
-     * @var EE_Config $CFG
67
-     */
68
-    public $CFG;
69
-
70
-    /**
71
-     * @var EE_Network_Config $NET_CFG
72
-     */
73
-    public $NET_CFG;
74
-
75
-    /**
76
-     * StdClass object for storing library classes in
77
-     *
78
-     * @var StdClass $LIB
79
-     */
80
-    public $LIB;
81
-
82
-    /**
83
-     * @var EE_Request_Handler $REQ
84
-     */
85
-    public $REQ;
86
-
87
-    /**
88
-     * @var EE_Session $SSN
89
-     */
90
-    public $SSN;
91
-
92
-    /**
93
-     * @since 4.5.0
94
-     * @var EE_Capabilities $CAP
95
-     */
96
-    public $CAP;
97
-
98
-    /**
99
-     * @since 4.9.0
100
-     * @var EE_Message_Resource_Manager $MRM
101
-     */
102
-    public $MRM;
103
-
104
-
105
-    /**
106
-     * @var Registry $AssetsRegistry
107
-     */
108
-    public $AssetsRegistry;
109
-
110
-    /**
111
-     * StdClass object for holding addons which have registered themselves to work with EE core
112
-     *
113
-     * @var EE_Addon[] $addons
114
-     */
115
-    public $addons;
116
-
117
-    /**
118
-     * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
119
-     *
120
-     * @var EEM_Base[] $models
121
-     */
122
-    public $models = array();
123
-
124
-    /**
125
-     * @var EED_Module[] $modules
126
-     */
127
-    public $modules;
128
-
129
-    /**
130
-     * @var EES_Shortcode[] $shortcodes
131
-     */
132
-    public $shortcodes;
133
-
134
-    /**
135
-     * @var WP_Widget[] $widgets
136
-     */
137
-    public $widgets;
138
-
139
-    /**
140
-     * this is an array of all implemented model names (i.e. not the parent abstract models, or models
141
-     * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
142
-     * Keys are model "short names" (eg "Event") as used in model relations, and values are
143
-     * classnames (eg "EEM_Event")
144
-     *
145
-     * @var array $non_abstract_db_models
146
-     */
147
-    public $non_abstract_db_models = array();
148
-
149
-
150
-    /**
151
-     * internationalization for JS strings
152
-     *    usage:   EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' );
153
-     *    in js file:  var translatedString = eei18n.string_key;
154
-     *
155
-     * @var array $i18n_js_strings
156
-     */
157
-    public static $i18n_js_strings = array();
158
-
159
-
160
-    /**
161
-     * $main_file - path to espresso.php
162
-     *
163
-     * @var array $main_file
164
-     */
165
-    public $main_file;
166
-
167
-    /**
168
-     * array of ReflectionClass objects where the key is the class name
169
-     *
170
-     * @deprecated $VID:$
171
-     * @var ReflectionClass[] $_reflectors
172
-     */
173
-    public $_reflectors;
174
-
175
-    /**
176
-     * boolean flag to indicate whether or not to load/save dependencies from/to the cache
177
-     *
178
-     * @var boolean $_cache_on
179
-     */
180
-    protected $_cache_on = true;
181
-
182
-
183
-    /**
184
-     * @singleton method used to instantiate class object
185
-     * @param EE_Dependency_Map|null   $dependency_map
186
-     * @param Mirror|null              $mirror
187
-     * @param ClassInterfaceCache|null $class_cache
188
-     * @return EE_Registry instance
189
-     */
190
-    public static function instance(
191
-        EE_Dependency_Map $dependency_map = null,
192
-        Mirror $mirror = null,
193
-        ClassInterfaceCache $class_cache = null
194
-    ) {
195
-        // check if class object is instantiated
196
-        if (
197
-            ! EE_Registry::$_instance instanceof EE_Registry
198
-            && $dependency_map instanceof EE_Dependency_Map
199
-            && $mirror instanceof Mirror
200
-            && $class_cache instanceof ClassInterfaceCache
201
-        ) {
202
-            EE_Registry::$_instance = new self($dependency_map, $mirror, $class_cache);
203
-        }
204
-        return EE_Registry::$_instance;
205
-    }
206
-
207
-
208
-    /**
209
-     * protected constructor to prevent direct creation
210
-     *
211
-     * @Constructor
212
-     * @param  EE_Dependency_Map  $dependency_map
213
-     * @param Mirror              $mirror
214
-     * @param ClassInterfaceCache $class_cache
215
-     */
216
-    protected function __construct(EE_Dependency_Map $dependency_map, Mirror $mirror, ClassInterfaceCache $class_cache)
217
-    {
218
-        $this->_dependency_map = $dependency_map;
219
-        $this->mirror = $mirror;
220
-        $this->class_cache = $class_cache;
221
-        // $registry_container = new RegistryContainer();
222
-        $this->LIB = new RegistryContainer();
223
-        $this->addons = new RegistryContainer();
224
-        $this->modules = new RegistryContainer();
225
-        $this->shortcodes = new RegistryContainer();
226
-        $this->widgets = new RegistryContainer();
227
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
228
-    }
229
-
230
-
231
-
232
-    /**
233
-     * initialize
234
-     *
235
-     * @throws EE_Error
236
-     * @throws ReflectionException
237
-     */
238
-    public function initialize()
239
-    {
240
-        $this->_class_abbreviations = apply_filters(
241
-            'FHEE__EE_Registry____construct___class_abbreviations',
242
-            array(
243
-                'EE_Config'                                       => 'CFG',
244
-                'EE_Session'                                      => 'SSN',
245
-                'EE_Capabilities'                                 => 'CAP',
246
-                'EE_Cart'                                         => 'CART',
247
-                'EE_Network_Config'                               => 'NET_CFG',
248
-                'EE_Request_Handler'                              => 'REQ',
249
-                'EE_Message_Resource_Manager'                     => 'MRM',
250
-                'EventEspresso\core\services\commands\CommandBus' => 'BUS',
251
-                'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
252
-            )
253
-        );
254
-        $this->load_core('Base', array(), true);
255
-        // add our request and response objects to the cache
256
-        $request_loader = $this->_dependency_map->class_loader(
257
-            'EventEspresso\core\services\request\Request'
258
-        );
259
-        $this->_set_cached_class(
260
-            $request_loader(),
261
-            'EventEspresso\core\services\request\Request'
262
-        );
263
-        $response_loader = $this->_dependency_map->class_loader(
264
-            'EventEspresso\core\services\request\Response'
265
-        );
266
-        $this->_set_cached_class(
267
-            $response_loader(),
268
-            'EventEspresso\core\services\request\Response'
269
-        );
270
-        add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
271
-    }
272
-
273
-
274
-
275
-    /**
276
-     * @return void
277
-     */
278
-    public function init()
279
-    {
280
-        // Get current page protocol
281
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
282
-        // Output admin-ajax.php URL with same protocol as current page
283
-        self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
284
-        self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
285
-    }
286
-
287
-
288
-
289
-    /**
290
-     * localize_i18n_js_strings
291
-     *
292
-     * @return string
293
-     */
294
-    public static function localize_i18n_js_strings()
295
-    {
296
-        $i18n_js_strings = (array)self::$i18n_js_strings;
297
-        foreach ($i18n_js_strings as $key => $value) {
298
-            if (is_scalar($value)) {
299
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
300
-            }
301
-        }
302
-        return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
303
-    }
304
-
305
-
306
-
307
-    /**
308
-     * @param mixed string | EED_Module $module
309
-     * @throws EE_Error
310
-     * @throws ReflectionException
311
-     */
312
-    public function add_module($module)
313
-    {
314
-        if ($module instanceof EED_Module) {
315
-            $module_class = get_class($module);
316
-            $this->modules->{$module_class} = $module;
317
-        } else {
318
-            if ( ! class_exists('EE_Module_Request_Router', false)) {
319
-                $this->load_core('Module_Request_Router');
320
-            }
321
-            EE_Module_Request_Router::module_factory($module);
322
-        }
323
-    }
324
-
325
-
326
-
327
-    /**
328
-     * @param string $module_name
329
-     * @return mixed EED_Module | NULL
330
-     */
331
-    public function get_module($module_name = '')
332
-    {
333
-        return isset($this->modules->{$module_name})
334
-            ? $this->modules->{$module_name}
335
-            : null;
336
-    }
337
-
338
-
339
-
340
-    /**
341
-     * loads core classes - must be singletons
342
-     *
343
-     * @param string $class_name - simple class name ie: session
344
-     * @param mixed  $arguments
345
-     * @param bool   $load_only
346
-     * @return mixed
347
-     * @throws EE_Error
348
-     * @throws ReflectionException
349
-     */
350
-    public function load_core($class_name, $arguments = array(), $load_only = false)
351
-    {
352
-        $core_paths = apply_filters(
353
-            'FHEE__EE_Registry__load_core__core_paths',
354
-            array(
355
-                EE_CORE,
356
-                EE_ADMIN,
357
-                EE_CPTS,
358
-                EE_CORE . 'data_migration_scripts' . DS,
359
-                EE_CORE . 'capabilities' . DS,
360
-                EE_CORE . 'request_stack' . DS,
361
-                EE_CORE . 'middleware' . DS,
362
-            )
363
-        );
364
-        // retrieve instantiated class
365
-        return $this->_load(
366
-            $core_paths,
367
-            'EE_',
368
-            $class_name,
369
-            'core',
370
-            $arguments,
371
-            false,
372
-            true,
373
-            $load_only
374
-        );
375
-    }
376
-
377
-
378
-
379
-    /**
380
-     * loads service classes
381
-     *
382
-     * @param string $class_name - simple class name ie: session
383
-     * @param mixed  $arguments
384
-     * @param bool   $load_only
385
-     * @return mixed
386
-     * @throws EE_Error
387
-     * @throws ReflectionException
388
-     */
389
-    public function load_service($class_name, $arguments = array(), $load_only = false)
390
-    {
391
-        $service_paths = apply_filters(
392
-            'FHEE__EE_Registry__load_service__service_paths',
393
-            array(
394
-                EE_CORE . 'services' . DS,
395
-            )
396
-        );
397
-        // retrieve instantiated class
398
-        return $this->_load(
399
-            $service_paths,
400
-            'EE_',
401
-            $class_name,
402
-            'class',
403
-            $arguments,
404
-            false,
405
-            true,
406
-            $load_only
407
-        );
408
-    }
409
-
410
-
411
-
412
-    /**
413
-     * loads data_migration_scripts
414
-     *
415
-     * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
416
-     * @param mixed  $arguments
417
-     * @return EE_Data_Migration_Script_Base|mixed
418
-     * @throws EE_Error
419
-     * @throws ReflectionException
420
-     */
421
-    public function load_dms($class_name, $arguments = array())
422
-    {
423
-        // retrieve instantiated class
424
-        return $this->_load(
425
-            EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(),
426
-            'EE_DMS_',
427
-            $class_name,
428
-            'dms',
429
-            $arguments,
430
-            false,
431
-            false
432
-        );
433
-    }
434
-
435
-
436
-
437
-    /**
438
-     * loads object creating classes - must be singletons
439
-     *
440
-     * @param string $class_name - simple class name ie: attendee
441
-     * @param mixed  $arguments  - an array of arguments to pass to the class
442
-     * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to
443
-     *                           instantiate
444
-     * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then
445
-     *                           set this to FALSE (ie. when instantiating model objects from client in a loop)
446
-     * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate
447
-     *                           (default)
448
-     * @return EE_Base_Class | bool
449
-     * @throws EE_Error
450
-     * @throws ReflectionException
451
-     */
452
-    public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
453
-    {
454
-        $paths = apply_filters(
455
-            'FHEE__EE_Registry__load_class__paths', array(
456
-            EE_CORE,
457
-            EE_CLASSES,
458
-            EE_BUSINESS,
459
-        )
460
-        );
461
-        // retrieve instantiated class
462
-        return $this->_load(
463
-            $paths,
464
-            'EE_',
465
-            $class_name,
466
-            'class',
467
-            $arguments,
468
-            $from_db,
469
-            $cache,
470
-            $load_only
471
-        );
472
-    }
473
-
474
-
475
-
476
-    /**
477
-     * loads helper classes - must be singletons
478
-     *
479
-     * @param string $class_name - simple class name ie: price
480
-     * @param mixed  $arguments
481
-     * @param bool   $load_only
482
-     * @return EEH_Base | bool
483
-     * @throws EE_Error
484
-     * @throws ReflectionException
485
-     */
486
-    public function load_helper($class_name, $arguments = array(), $load_only = true)
487
-    {
488
-        // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
489
-        $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
490
-        // retrieve instantiated class
491
-        return $this->_load(
492
-            $helper_paths,
493
-            'EEH_',
494
-            $class_name,
495
-            'helper',
496
-            $arguments,
497
-            false,
498
-            true,
499
-            $load_only
500
-        );
501
-    }
502
-
503
-
504
-
505
-    /**
506
-     * loads core classes - must be singletons
507
-     *
508
-     * @param string $class_name - simple class name ie: session
509
-     * @param mixed  $arguments
510
-     * @param bool   $load_only
511
-     * @param bool   $cache      whether to cache the object or not.
512
-     * @return mixed
513
-     * @throws EE_Error
514
-     * @throws ReflectionException
515
-     */
516
-    public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
517
-    {
518
-        $paths = array(
519
-            EE_LIBRARIES,
520
-            EE_LIBRARIES . 'messages' . DS,
521
-            EE_LIBRARIES . 'shortcodes' . DS,
522
-            EE_LIBRARIES . 'qtips' . DS,
523
-            EE_LIBRARIES . 'payment_methods' . DS,
524
-        );
525
-        // retrieve instantiated class
526
-        return $this->_load(
527
-            $paths,
528
-            'EE_',
529
-            $class_name,
530
-            'lib',
531
-            $arguments,
532
-            false,
533
-            $cache,
534
-            $load_only
535
-        );
536
-    }
537
-
538
-
539
-
540
-    /**
541
-     * loads model classes - must be singletons
542
-     *
543
-     * @param string $class_name - simple class name ie: price
544
-     * @param mixed  $arguments
545
-     * @param bool   $load_only
546
-     * @return EEM_Base | bool
547
-     * @throws EE_Error
548
-     * @throws ReflectionException
549
-     */
550
-    public function load_model($class_name, $arguments = array(), $load_only = false)
551
-    {
552
-        $paths = apply_filters(
553
-            'FHEE__EE_Registry__load_model__paths', array(
554
-            EE_MODELS,
555
-            EE_CORE,
556
-        )
557
-        );
558
-        // retrieve instantiated class
559
-        return $this->_load(
560
-            $paths,
561
-            'EEM_',
562
-            $class_name,
563
-            'model',
564
-            $arguments,
565
-            false,
566
-            true,
567
-            $load_only
568
-        );
569
-    }
570
-
571
-
572
-
573
-    /**
574
-     * loads model classes - must be singletons
575
-     *
576
-     * @param string $class_name - simple class name ie: price
577
-     * @param mixed  $arguments
578
-     * @param bool   $load_only
579
-     * @return mixed | bool
580
-     * @throws EE_Error
581
-     * @throws ReflectionException
582
-     */
583
-    public function load_model_class($class_name, $arguments = array(), $load_only = true)
584
-    {
585
-        $paths = array(
586
-            EE_MODELS . 'fields' . DS,
587
-            EE_MODELS . 'helpers' . DS,
588
-            EE_MODELS . 'relations' . DS,
589
-            EE_MODELS . 'strategies' . DS,
590
-        );
591
-        // retrieve instantiated class
592
-        return $this->_load(
593
-            $paths,
594
-            'EE_',
595
-            $class_name,
596
-            '',
597
-            $arguments,
598
-            false,
599
-            true,
600
-            $load_only
601
-        );
602
-    }
603
-
604
-
605
-
606
-    /**
607
-     * Determines if $model_name is the name of an actual EE model.
608
-     *
609
-     * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
610
-     * @return boolean
611
-     */
612
-    public function is_model_name($model_name)
613
-    {
614
-        return isset($this->models[$model_name]);
615
-    }
616
-
617
-
618
-
619
-    /**
620
-     * generic class loader
621
-     *
622
-     * @param string $path_to_file - directory path to file location, not including filename
623
-     * @param string $file_name    - file name  ie:  my_file.php, including extension
624
-     * @param string $type         - file type - core? class? helper? model?
625
-     * @param mixed  $arguments
626
-     * @param bool   $load_only
627
-     * @return mixed
628
-     * @throws EE_Error
629
-     * @throws ReflectionException
630
-     */
631
-    public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
632
-    {
633
-        // retrieve instantiated class
634
-        return $this->_load(
635
-            $path_to_file,
636
-            '',
637
-            $file_name,
638
-            $type,
639
-            $arguments,
640
-            false,
641
-            true,
642
-            $load_only
643
-        );
644
-    }
645
-
646
-
647
-
648
-    /**
649
-     * @param string $path_to_file - directory path to file location, not including filename
650
-     * @param string $class_name   - full class name  ie:  My_Class
651
-     * @param string $type         - file type - core? class? helper? model?
652
-     * @param mixed  $arguments
653
-     * @param bool   $load_only
654
-     * @return bool|EE_Addon|object
655
-     * @throws EE_Error
656
-     * @throws ReflectionException
657
-     */
658
-    public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
659
-    {
660
-        // retrieve instantiated class
661
-        return $this->_load(
662
-            $path_to_file,
663
-            'addon',
664
-            $class_name,
665
-            $type,
666
-            $arguments,
667
-            false,
668
-            true,
669
-            $load_only
670
-        );
671
-    }
672
-
673
-
674
-    /**
675
-     * instantiates, caches, and automatically resolves dependencies
676
-     * for classes that use a Fully Qualified Class Name.
677
-     * if the class is not capable of being loaded using PSR-4 autoloading,
678
-     * then you need to use one of the existing load_*() methods
679
-     * which can resolve the classname and filepath from the passed arguments
680
-     *
681
-     * @param bool|string $class_name   Fully Qualified Class Name
682
-     * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
683
-     * @param bool        $cache        whether to cache the instantiated object for reuse
684
-     * @param bool        $from_db      some classes are instantiated from the db
685
-     *                                  and thus call a different method to instantiate
686
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
687
-     * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
688
-     * @return bool|null|mixed          null = failure to load or instantiate class object.
689
-     *                                  object = class loaded and instantiated successfully.
690
-     *                                  bool = fail or success when $load_only is true
691
-     * @throws InvalidInterfaceException
692
-     * @throws InvalidDataTypeException
693
-     * @throws InvalidClassException
694
-     * @throws EE_Error
695
-     * @throws ReflectionException
696
-     */
697
-    public function create(
698
-        $class_name = false,
699
-        $arguments = array(),
700
-        $cache = false,
701
-        $from_db = false,
702
-        $load_only = false,
703
-        $addon = false
704
-    ) {
705
-        $class_name = ltrim($class_name, '\\');
706
-        $class_name = $this->class_cache->getFqnForAlias($class_name);
707
-        $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
708
-        // if a non-FQCN was passed, then verifyClassExists() might return an object
709
-        // or it could return null if the class just could not be found anywhere
710
-        if ($class_exists instanceof $class_name || $class_exists === null){
711
-            // either way, return the results
712
-            return $class_exists;
713
-        }
714
-        $class_name = $class_exists;
715
-        // if we're only loading the class and it already exists, then let's just return true immediately
716
-        if ($load_only) {
717
-            return true;
718
-        }
719
-        $addon = $addon
720
-            ? 'addon'
721
-            : '';
722
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
723
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
724
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
725
-        if ($this->_cache_on && $cache && ! $load_only) {
726
-            // return object if it's already cached
727
-            $cached_class = $this->_get_cached_class($class_name, $addon);
728
-            if ($cached_class !== null) {
729
-                return $cached_class;
730
-            }
731
-        }
732
-        // obtain the loader method from the dependency map
733
-        $loader = $this->_dependency_map->class_loader($class_name);
734
-        // instantiate the requested object
735
-        if ($loader instanceof Closure) {
736
-            $class_obj = $loader($arguments);
737
-        } else if ($loader && method_exists($this, $loader)) {
738
-            $class_obj = $this->{$loader}($class_name, $arguments);
739
-        } else {
740
-            $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
741
-        }
742
-        if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) {
743
-            // save it for later... kinda like gum  { : $
744
-            $this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
745
-        }
746
-        $this->_cache_on = true;
747
-        return $class_obj;
748
-    }
749
-
750
-
751
-
752
-    /**
753
-     * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
754
-     *
755
-     * @param string $class_name
756
-     * @param array  $arguments
757
-     * @param int    $attempt
758
-     * @return mixed
759
-     */
760
-    private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) {
761
-        if (is_object($class_name) || class_exists($class_name)) {
762
-            return $class_name;
763
-        }
764
-        switch ($attempt) {
765
-            case 1:
766
-                // if it's a FQCN then maybe the class is registered with a preceding \
767
-                $class_name = strpos($class_name, '\\') !== false
768
-                    ? '\\' . ltrim($class_name, '\\')
769
-                    : $class_name;
770
-                break;
771
-            case 2:
772
-                //
773
-                $loader = $this->_dependency_map->class_loader($class_name);
774
-                if ($loader && method_exists($this, $loader)) {
775
-                    return $this->{$loader}($class_name, $arguments);
776
-                }
777
-                break;
778
-            case 3:
779
-            default;
780
-                return null;
781
-        }
782
-        $attempt++;
783
-        return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
784
-    }
785
-
786
-
787
-
788
-    /**
789
-     * instantiates, caches, and injects dependencies for classes
790
-     *
791
-     * @param array       $file_paths   an array of paths to folders to look in
792
-     * @param string      $class_prefix EE  or EEM or... ???
793
-     * @param bool|string $class_name   $class name
794
-     * @param string      $type         file type - core? class? helper? model?
795
-     * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
796
-     * @param bool        $from_db      some classes are instantiated from the db
797
-     *                                  and thus call a different method to instantiate
798
-     * @param bool        $cache        whether to cache the instantiated object for reuse
799
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
800
-     * @return bool|null|object null = failure to load or instantiate class object.
801
-     *                                  object = class loaded and instantiated successfully.
802
-     *                                  bool = fail or success when $load_only is true
803
-     * @throws EE_Error
804
-     * @throws ReflectionException
805
-     * @throws InvalidInterfaceException
806
-     * @throws InvalidDataTypeException
807
-     * @throws InvalidClassException
808
-     */
809
-    protected function _load(
810
-        $file_paths = array(),
811
-        $class_prefix = 'EE_',
812
-        $class_name = false,
813
-        $type = 'class',
814
-        $arguments = array(),
815
-        $from_db = false,
816
-        $cache = true,
817
-        $load_only = false
818
-    ) {
819
-        $class_name = ltrim($class_name, '\\');
820
-        // strip php file extension
821
-        $class_name = str_replace('.php', '', trim($class_name));
822
-        // does the class have a prefix ?
823
-        if (! empty($class_prefix) && $class_prefix !== 'addon') {
824
-            // make sure $class_prefix is uppercase
825
-            $class_prefix = strtoupper(trim($class_prefix));
826
-            // add class prefix ONCE!!!
827
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
828
-        }
829
-        $class_name = $this->class_cache->getFqnForAlias($class_name);
830
-        $class_exists = class_exists($class_name, false);
831
-        // if we're only loading the class and it already exists, then let's just return true immediately
832
-        if ($load_only && $class_exists) {
833
-            return true;
834
-        }
835
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
836
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
837
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
838
-        if ($this->_cache_on && $cache && ! $load_only) {
839
-            // return object if it's already cached
840
-            $cached_class = $this->_get_cached_class($class_name, $class_prefix);
841
-            if ($cached_class !== null) {
842
-                return $cached_class;
843
-            }
844
-        }
845
-        // if the class doesn't already exist.. then we need to try and find the file and load it
846
-        if (! $class_exists) {
847
-            // get full path to file
848
-            $path = $this->_resolve_path($class_name, $type, $file_paths);
849
-            // load the file
850
-            $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
851
-            // if loading failed, or we are only loading a file but NOT instantiating an object
852
-            if (! $loaded || $load_only) {
853
-                // return boolean if only loading, or null if an object was expected
854
-                return $load_only
855
-                    ? $loaded
856
-                    : null;
857
-            }
858
-        }
859
-        // instantiate the requested object
860
-        $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
861
-        if ($this->_cache_on && $cache) {
862
-            // save it for later... kinda like gum  { : $
863
-            $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
864
-        }
865
-        $this->_cache_on = true;
866
-        return $class_obj;
867
-    }
868
-
869
-
870
-
871
-    /**
872
-     * @param string $class_name
873
-     * @param string $default have to specify something, but not anything that will conflict
874
-     * @return mixed|string
875
-     */
876
-    protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
877
-    {
878
-        return isset($this->_class_abbreviations[$class_name])
879
-            ? $this->_class_abbreviations[$class_name]
880
-            : $default;
881
-    }
882
-
883
-    /**
884
-     * attempts to find a cached version of the requested class
885
-     * by looking in the following places:
886
-     *        $this->{$class_abbreviation}            ie:    $this->CART
887
-     *        $this->{$class_name}                        ie:    $this->Some_Class
888
-     *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
889
-     *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
890
-     *
891
-     * @param string $class_name
892
-     * @param string $class_prefix
893
-     * @return mixed
894
-     */
895
-    protected function _get_cached_class($class_name, $class_prefix = '')
896
-    {
897
-        if ($class_name === 'EE_Registry') {
898
-            return $this;
899
-        }
900
-        $class_abbreviation = $this->get_class_abbreviation($class_name);
901
-        $class_name = str_replace('\\', '_', $class_name);
902
-        // check if class has already been loaded, and return it if it has been
903
-        if (isset($this->{$class_abbreviation})) {
904
-            return $this->{$class_abbreviation};
905
-        }
906
-        if (isset ($this->{$class_name})) {
907
-            return $this->{$class_name};
908
-        }
909
-        if (isset ($this->LIB->{$class_name})) {
910
-            return $this->LIB->{$class_name};
911
-        }
912
-        if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
913
-            return $this->addons->{$class_name};
914
-        }
915
-        return null;
916
-    }
917
-
918
-
919
-
920
-    /**
921
-     * removes a cached version of the requested class
922
-     *
923
-     * @param string  $class_name
924
-     * @param boolean $addon
925
-     * @return boolean
926
-     */
927
-    public function clear_cached_class($class_name, $addon = false)
928
-    {
929
-        $class_abbreviation = $this->get_class_abbreviation($class_name);
930
-        $class_name = str_replace('\\', '_', $class_name);
931
-        // check if class has already been loaded, and return it if it has been
932
-        if (isset($this->{$class_abbreviation})) {
933
-            $this->{$class_abbreviation} = null;
934
-            return true;
935
-        }
936
-        if (isset($this->{$class_name})) {
937
-            $this->{$class_name} = null;
938
-            return true;
939
-        }
940
-        if (isset($this->LIB->{$class_name})) {
941
-            unset($this->LIB->{$class_name});
942
-            return true;
943
-        }
944
-        if ($addon && isset($this->addons->{$class_name})) {
945
-            unset($this->addons->{$class_name});
946
-            return true;
947
-        }
948
-        return false;
949
-    }
950
-
951
-
952
-
953
-    /**
954
-     * attempts to find a full valid filepath for the requested class.
955
-     * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
956
-     * then returns that path if the target file has been found and is readable
957
-     *
958
-     * @param string $class_name
959
-     * @param string $type
960
-     * @param array  $file_paths
961
-     * @return string | bool
962
-     */
963
-    protected function _resolve_path($class_name, $type = '', $file_paths = array())
964
-    {
965
-        // make sure $file_paths is an array
966
-        $file_paths = is_array($file_paths)
967
-            ? $file_paths
968
-            : array($file_paths);
969
-        // cycle thru paths
970
-        foreach ($file_paths as $key => $file_path) {
971
-            // convert all separators to proper DS, if no filepath, then use EE_CLASSES
972
-            $file_path = $file_path
973
-                ? str_replace(array('/', '\\'), DS, $file_path)
974
-                : EE_CLASSES;
975
-            // prep file type
976
-            $type = ! empty($type)
977
-                ? trim($type, '.') . '.'
978
-                : '';
979
-            // build full file path
980
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
981
-            //does the file exist and can be read ?
982
-            if (is_readable($file_paths[$key])) {
983
-                return $file_paths[$key];
984
-            }
985
-        }
986
-        return false;
987
-    }
988
-
989
-
990
-
991
-    /**
992
-     * basically just performs a require_once()
993
-     * but with some error handling
994
-     *
995
-     * @param  string $path
996
-     * @param  string $class_name
997
-     * @param  string $type
998
-     * @param  array  $file_paths
999
-     * @return bool
1000
-     * @throws EE_Error
1001
-     * @throws ReflectionException
1002
-     */
1003
-    protected function _require_file($path, $class_name, $type = '', $file_paths = array())
1004
-    {
1005
-        $this->resolve_legacy_class_parent($class_name);
1006
-        // don't give up! you gotta...
1007
-        try {
1008
-            //does the file exist and can it be read ?
1009
-            if (! $path) {
1010
-                // just in case the file has already been autoloaded,
1011
-                // but discrepancies in the naming schema are preventing it from
1012
-                // being loaded via one of the EE_Registry::load_*() methods,
1013
-                // then let's try one last hail mary before throwing an exception
1014
-                // and call class_exists() again, but with autoloading turned ON
1015
-                if(class_exists($class_name)) {
1016
-                    return true;
1017
-                }
1018
-                // so sorry, can't find the file
1019
-                throw new EE_Error (
1020
-                    sprintf(
1021
-                        esc_html__(
1022
-                            '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',
1023
-                            'event_espresso'
1024
-                        ),
1025
-                        trim($type, '.'),
1026
-                        $class_name,
1027
-                        '<br />' . implode(',<br />', $file_paths)
1028
-                    )
1029
-                );
1030
-            }
1031
-            // get the file
1032
-            require_once($path);
1033
-            // if the class isn't already declared somewhere
1034
-            if (class_exists($class_name, false) === false) {
1035
-                // so sorry, not a class
1036
-                throw new EE_Error(
1037
-                    sprintf(
1038
-                        esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
1039
-                        $type,
1040
-                        $path,
1041
-                        $class_name
1042
-                    )
1043
-                );
1044
-            }
1045
-        } catch (EE_Error $e) {
1046
-            $e->get_error();
1047
-            return false;
1048
-        }
1049
-        return true;
1050
-    }
1051
-
1052
-
1053
-
1054
-    /**
1055
-     * Some of our legacy classes that extended a parent class would simply use a require() statement
1056
-     * before their class declaration in order to ensure that the parent class was loaded.
1057
-     * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class,
1058
-     * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist.
1059
-     *
1060
-     * @param string $class_name
1061
-     */
1062
-    protected function resolve_legacy_class_parent($class_name = '')
1063
-    {
1064
-        try {
1065
-            $legacy_parent_class_map = array(
1066
-                'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php'
1067
-            );
1068
-            if(isset($legacy_parent_class_map[$class_name])) {
1069
-                require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name];
1070
-            }
1071
-        } catch (Exception $exception) {
1072
-        }
1073
-    }
1074
-
1075
-
1076
-    /**
1077
-     * _create_object
1078
-     * Attempts to instantiate the requested class via any of the
1079
-     * commonly used instantiation methods employed throughout EE.
1080
-     * The priority for instantiation is as follows:
1081
-     *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
1082
-     *        - model objects via their 'new_instance_from_db' method
1083
-     *        - model objects via their 'new_instance' method
1084
-     *        - "singleton" classes" via their 'instance' method
1085
-     *    - standard instantiable classes via their __constructor
1086
-     * Prior to instantiation, if the classname exists in the dependency_map,
1087
-     * then the constructor for the requested class will be examined to determine
1088
-     * if any dependencies exist, and if they can be injected.
1089
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1090
-     *
1091
-     * @param string $class_name
1092
-     * @param array  $arguments
1093
-     * @param string $type
1094
-     * @param bool   $from_db
1095
-     * @return null|object
1096
-     * @throws EE_Error
1097
-     * @throws ReflectionException
1098
-     * @throws InvalidDataTypeException
1099
-     */
1100
-    protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
1101
-    {
1102
-        // create reflection
1103
-        $reflector = $this->mirror->getReflectionClass($class_name);
1104
-        // make sure arguments are an array
1105
-        $arguments = is_array($arguments)
1106
-            ? $arguments
1107
-            : array($arguments);
1108
-        // and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1109
-        // else wrap it in an additional array so that it doesn't get split into multiple parameters
1110
-        $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1111
-            ? $arguments
1112
-            : array($arguments);
1113
-        // attempt to inject dependencies ?
1114
-        if ($this->_dependency_map->has($class_name)) {
1115
-            $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1116
-        }
1117
-        // instantiate the class if possible
1118
-        if ($reflector->isAbstract()) {
1119
-            // nothing to instantiate, loading file was enough
1120
-            // does not throw an exception so $instantiation_mode is unused
1121
-            // $instantiation_mode = "1) no constructor abstract class";
1122
-            return true;
1123
-        }
1124
-        if (
1125
-            empty($arguments)
1126
-            && $this->mirror->getConstructorFromReflection($reflector) === null
1127
-            && $reflector->isInstantiable()
1128
-        ) {
1129
-            // no constructor = static methods only... nothing to instantiate, loading file was enough
1130
-            // $instantiation_mode = "2) no constructor but instantiable";
1131
-            return $reflector->newInstance();
1132
-        }
1133
-        if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1134
-            // $instantiation_mode = "3) new_instance_from_db()";
1135
-            return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1136
-        }
1137
-        if (method_exists($class_name, 'new_instance')) {
1138
-            // $instantiation_mode = "4) new_instance()";
1139
-            return call_user_func_array(array($class_name, 'new_instance'), $arguments);
1140
-        }
1141
-        if (method_exists($class_name, 'instance')) {
1142
-            // $instantiation_mode = "5) instance()";
1143
-            return call_user_func_array(array($class_name, 'instance'), $arguments);
1144
-        }
1145
-        if ($reflector->isInstantiable()) {
1146
-            // $instantiation_mode = "6) constructor";
1147
-            return $reflector->newInstanceArgs($arguments);
1148
-        }
1149
-        // heh ? something's not right !
1150
-        throw new EE_Error(
1151
-            sprintf(
1152
-                __('The %s file %s could not be instantiated.', 'event_espresso'),
1153
-                $type,
1154
-                $class_name
1155
-            )
1156
-        );
1157
-    }
1158
-
1159
-
1160
-
1161
-    /**
1162
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1163
-     * @param array $array
1164
-     * @return bool
1165
-     */
1166
-    protected function _array_is_numerically_and_sequentially_indexed(array $array)
1167
-    {
1168
-        return ! empty($array)
1169
-            ? array_keys($array) === range(0, count($array) - 1)
1170
-            : true;
1171
-    }
1172
-
1173
-
1174
-    /**
1175
-     * _resolve_dependencies
1176
-     * examines the constructor for the requested class to determine
1177
-     * if any dependencies exist, and if they can be injected.
1178
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1179
-     * PLZ NOTE: this is achieved by type hinting the constructor params
1180
-     * For example:
1181
-     *        if attempting to load a class "Foo" with the following constructor:
1182
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
1183
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
1184
-     *        but only IF they are NOT already present in the incoming arguments array,
1185
-     *        and the correct classes can be loaded
1186
-     *
1187
-     * @param ReflectionClass $reflector
1188
-     * @param string          $class_name
1189
-     * @param array           $arguments
1190
-     * @return array
1191
-     * @throws EE_Error
1192
-     * @throws InvalidArgumentException
1193
-     * @throws InvalidDataTypeException
1194
-     * @throws InvalidInterfaceException
1195
-     * @throws ReflectionException
1196
-     * @throws InvalidClassException
1197
-     */
1198
-    protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array())
1199
-    {
1200
-        // let's examine the constructor
1201
-        $constructor = $this->mirror->getConstructorFromReflection($reflector);
1202
-        // whu? huh? nothing?
1203
-        if (! $constructor) {
1204
-            return $arguments;
1205
-        }
1206
-        // get constructor parameters
1207
-        $params = $this->mirror->getParametersFromReflection($reflector);
1208
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1209
-        $argument_keys = array_keys($arguments);
1210
-        // now loop thru all of the constructors expected parameters
1211
-        foreach ($params as $index => $param) {
1212
-            // is this a dependency for a specific class ?
1213
-            $param_class = $this->mirror->getParameterClassName($param, $class_name, $index);
1214
-            // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1215
-            $param_class = $this->class_cache->isAlias($param_class, $class_name)
1216
-                ? $this->class_cache->getFqnForAlias($param_class, $class_name)
1217
-                : $param_class;
1218
-            if (
1219
-                // param is not even a class
1220
-                $param_class === null
1221
-                // and something already exists in the incoming arguments for this param
1222
-                && array_key_exists($index, $argument_keys)
1223
-                && array_key_exists($argument_keys[$index], $arguments)
1224
-            ) {
1225
-                // so let's skip this argument and move on to the next
1226
-                continue;
1227
-            }
1228
-            if (
1229
-                // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1230
-                $param_class !== null
1231
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1232
-                && $arguments[$argument_keys[$index]] instanceof $param_class
1233
-            ) {
1234
-                // skip this argument and move on to the next
1235
-                continue;
1236
-            }
1237
-            if (
1238
-                // parameter is type hinted as a class, and should be injected
1239
-                $param_class !== null
1240
-                && $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1241
-            ) {
1242
-                $arguments = $this->_resolve_dependency(
1243
-                    $class_name,
1244
-                    $param_class,
1245
-                    $arguments,
1246
-                    $index,
1247
-                    $argument_keys
1248
-                );
1249
-            } else {
1250
-                try {
1251
-                    $arguments[$index] = $this->mirror->getParameterDefaultValue(
1252
-                        $param,
1253
-                        $class_name,
1254
-                        $index
1255
-                    );
1256
-                } catch (ReflectionException $e) {
1257
-                    throw new ReflectionException(
1258
-                        sprintf(
1259
-                            esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'),
1260
-                            $e->getMessage(),
1261
-                            $param->getName(),
1262
-                            $class_name
1263
-                        )
1264
-                    );
1265
-                }
1266
-            }
1267
-        }
1268
-        return $arguments;
1269
-    }
1270
-
1271
-
1272
-
1273
-    /**
1274
-     * @param string $class_name
1275
-     * @param string $param_class
1276
-     * @param array  $arguments
1277
-     * @param mixed  $index
1278
-     * @param array  $argument_keys
1279
-     * @return array
1280
-     * @throws EE_Error
1281
-     * @throws ReflectionException
1282
-     * @throws InvalidArgumentException
1283
-     * @throws InvalidInterfaceException
1284
-     * @throws InvalidDataTypeException
1285
-     */
1286
-    protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys)
1287
-    {
1288
-        $dependency = null;
1289
-        // should dependency be loaded from cache ?
1290
-        $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1291
-            $class_name,
1292
-            $param_class
1293
-        );
1294
-        $cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1295
-        // we might have a dependency...
1296
-        // let's MAYBE try and find it in our cache if that's what's been requested
1297
-        $cached_class = $cache_on
1298
-            ? $this->_get_cached_class($param_class)
1299
-            : null;
1300
-        // and grab it if it exists
1301
-        if ($cached_class instanceof $param_class) {
1302
-            $dependency = $cached_class;
1303
-        } else if ($param_class !== $class_name) {
1304
-            // obtain the loader method from the dependency map
1305
-            $loader = $this->_dependency_map->class_loader($param_class);
1306
-            // is loader a custom closure ?
1307
-            if ($loader instanceof Closure) {
1308
-                $dependency = $loader($arguments);
1309
-            } else {
1310
-                // set the cache on property for the recursive loading call
1311
-                $this->_cache_on = $cache_on;
1312
-                // if not, then let's try and load it via the registry
1313
-                if ($loader && method_exists($this, $loader)) {
1314
-                    $dependency = $this->{$loader}($param_class);
1315
-                } else {
1316
-                    $dependency = LoaderFactory::getLoader()->load(
1317
-                        $param_class,
1318
-                        array(),
1319
-                        $cache_on
1320
-                    );
1321
-                }
1322
-            }
1323
-        }
1324
-        // did we successfully find the correct dependency ?
1325
-        if ($dependency instanceof $param_class) {
1326
-            // then let's inject it into the incoming array of arguments at the correct location
1327
-            $arguments[$index] = $dependency;
1328
-        }
1329
-        return $arguments;
1330
-    }
1331
-
1332
-
1333
-
1334
-    /**
1335
-     * _set_cached_class
1336
-     * attempts to cache the instantiated class locally
1337
-     * in one of the following places, in the following order:
1338
-     *        $this->{class_abbreviation}   ie:    $this->CART
1339
-     *        $this->{$class_name}          ie:    $this->Some_Class
1340
-     *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1341
-     *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1342
-     *
1343
-     * @param object $class_obj
1344
-     * @param string $class_name
1345
-     * @param string $class_prefix
1346
-     * @param bool   $from_db
1347
-     * @return void
1348
-     */
1349
-    protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1350
-    {
1351
-        if ($class_name === 'EE_Registry' || empty($class_obj)) {
1352
-            return;
1353
-        }
1354
-        // return newly instantiated class
1355
-        $class_abbreviation = $this->get_class_abbreviation($class_name, '');
1356
-        if ($class_abbreviation) {
1357
-            $this->{$class_abbreviation} = $class_obj;
1358
-            return;
1359
-        }
1360
-        $class_name = str_replace('\\', '_', $class_name);
1361
-        if (property_exists($this, $class_name)) {
1362
-            $this->{$class_name} = $class_obj;
1363
-            return;
1364
-        }
1365
-        if ($class_prefix === 'addon') {
1366
-            $this->addons->{$class_name} = $class_obj;
1367
-            return;
1368
-        }
1369
-        if (! $from_db) {
1370
-            $this->LIB->{$class_name} = $class_obj;
1371
-        }
1372
-    }
1373
-
1374
-
1375
-
1376
-    /**
1377
-     * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1378
-     *
1379
-     * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1380
-     *                          in the EE_Dependency_Map::$_class_loaders array,
1381
-     *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1382
-     * @param array  $arguments
1383
-     * @return object
1384
-     */
1385
-    public static function factory($classname, $arguments = array())
1386
-    {
1387
-        $loader = self::instance()->_dependency_map->class_loader($classname);
1388
-        if ($loader instanceof Closure) {
1389
-            return $loader($arguments);
1390
-        }
1391
-        if (method_exists(self::instance(), $loader)) {
1392
-            return self::instance()->{$loader}($classname, $arguments);
1393
-        }
1394
-        return null;
1395
-    }
1396
-
1397
-
1398
-
1399
-    /**
1400
-     * Gets the addon by its class name
1401
-     *
1402
-     * @param string $class_name
1403
-     * @return EE_Addon
1404
-     */
1405
-    public function getAddon($class_name)
1406
-    {
1407
-        $class_name = str_replace('\\', '_', $class_name);
1408
-        return $this->addons->{$class_name};
1409
-    }
1410
-
1411
-
1412
-    /**
1413
-     * removes the addon from the internal cache
1414
-     *
1415
-     * @param string $class_name
1416
-     * @return void
1417
-     */
1418
-    public function removeAddon($class_name)
1419
-    {
1420
-        $class_name = str_replace('\\', '_', $class_name);
1421
-        unset($this->addons->{$class_name});
1422
-    }
1423
-
1424
-
1425
-
1426
-    /**
1427
-     * Gets the addon by its name/slug (not classname. For that, just
1428
-     * use the get_addon() method above
1429
-     *
1430
-     * @param string $name
1431
-     * @return EE_Addon
1432
-     */
1433
-    public function get_addon_by_name($name)
1434
-    {
1435
-        foreach ($this->addons as $addon) {
1436
-            if ($addon->name() === $name) {
1437
-                return $addon;
1438
-            }
1439
-        }
1440
-        return null;
1441
-    }
1442
-
1443
-
1444
-
1445
-    /**
1446
-     * Gets an array of all the registered addons, where the keys are their names.
1447
-     * (ie, what each returns for their name() function)
1448
-     * They're already available on EE_Registry::instance()->addons as properties,
1449
-     * where each property's name is the addon's classname,
1450
-     * So if you just want to get the addon by classname,
1451
-     * OR use the get_addon() method above.
1452
-     * PLEASE  NOTE:
1453
-     * addons with Fully Qualified Class Names
1454
-     * have had the namespace separators converted to underscores,
1455
-     * so a classname like Fully\Qualified\ClassName
1456
-     * would have been converted to Fully_Qualified_ClassName
1457
-     *
1458
-     * @return EE_Addon[] where the KEYS are the addon's name()
1459
-     */
1460
-    public function get_addons_by_name()
1461
-    {
1462
-        $addons = array();
1463
-        foreach ($this->addons as $addon) {
1464
-            $addons[$addon->name()] = $addon;
1465
-        }
1466
-        return $addons;
1467
-    }
1468
-
1469
-
1470
-    /**
1471
-     * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1472
-     * a stale copy of it around
1473
-     *
1474
-     * @param string $model_name
1475
-     * @return \EEM_Base
1476
-     * @throws \EE_Error
1477
-     */
1478
-    public function reset_model($model_name)
1479
-    {
1480
-        $model_class_name = strpos($model_name, 'EEM_') !== 0
1481
-            ? "EEM_{$model_name}"
1482
-            : $model_name;
1483
-        if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1484
-            return null;
1485
-        }
1486
-        //get that model reset it and make sure we nuke the old reference to it
1487
-        if ($this->LIB->{$model_class_name} instanceof $model_class_name
1488
-            && is_callable(
1489
-                array($model_class_name, 'reset')
1490
-            )) {
1491
-            $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1492
-        } else {
1493
-            throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1494
-        }
1495
-        return $this->LIB->{$model_class_name};
1496
-    }
1497
-
1498
-
1499
-
1500
-    /**
1501
-     * Resets the registry.
1502
-     * The criteria for what gets reset is based on what can be shared between sites on the same request when
1503
-     * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1504
-     * - $_dependency_map
1505
-     * - $_class_abbreviations
1506
-     * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1507
-     * - $REQ:  Still on the same request so no need to change.
1508
-     * - $CAP: There is no site specific state in the EE_Capability class.
1509
-     * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1510
-     * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1511
-     * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1512
-     *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1513
-     *             switch or on the restore.
1514
-     * - $modules
1515
-     * - $shortcodes
1516
-     * - $widgets
1517
-     *
1518
-     * @param boolean $hard             [deprecated]
1519
-     * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1520
-     *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1521
-     *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1522
-     * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1523
-     *                                  client
1524
-     *                                  code instead can just change the model context to a different blog id if
1525
-     *                                  necessary
1526
-     * @return EE_Registry
1527
-     * @throws EE_Error
1528
-     * @throws ReflectionException
1529
-     */
1530
-    public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1531
-    {
1532
-        $instance = self::instance();
1533
-        $instance->_cache_on = true;
1534
-        // reset some "special" classes
1535
-        EEH_Activation::reset();
1536
-        $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1537
-        $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1538
-        $instance->CART = null;
1539
-        $instance->MRM = null;
1540
-        $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1541
-        //messages reset
1542
-        EED_Messages::reset();
1543
-        //handle of objects cached on LIB
1544
-        foreach (array('LIB', 'modules') as $cache) {
1545
-            foreach ($instance->{$cache} as $class_name => $class) {
1546
-                if (self::_reset_and_unset_object($class, $reset_models)) {
1547
-                    unset($instance->{$cache}->{$class_name});
1548
-                }
1549
-            }
1550
-        }
1551
-        return $instance;
1552
-    }
1553
-
1554
-
1555
-
1556
-    /**
1557
-     * if passed object implements ResettableInterface, then call it's reset() method
1558
-     * if passed object implements InterminableInterface, then return false,
1559
-     * to indicate that it should NOT be cleared from the Registry cache
1560
-     *
1561
-     * @param      $object
1562
-     * @param bool $reset_models
1563
-     * @return bool returns true if cached object should be unset
1564
-     */
1565
-    private static function _reset_and_unset_object($object, $reset_models)
1566
-    {
1567
-        if (! is_object($object)) {
1568
-            // don't unset anything that's not an object
1569
-            return false;
1570
-        }
1571
-        if ($object instanceof EED_Module) {
1572
-            $object::reset();
1573
-            // don't unset modules
1574
-            return false;
1575
-        }
1576
-        if ($object instanceof ResettableInterface) {
1577
-            if ($object instanceof EEM_Base) {
1578
-                if ($reset_models) {
1579
-                    $object->reset();
1580
-                    return true;
1581
-                }
1582
-                return false;
1583
-            }
1584
-            $object->reset();
1585
-            return true;
1586
-        }
1587
-        if (! $object instanceof InterminableInterface) {
1588
-            return true;
1589
-        }
1590
-        return false;
1591
-    }
1592
-
1593
-
1594
-
1595
-    /**
1596
-     * Gets all the custom post type models defined
1597
-     *
1598
-     * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1599
-     */
1600
-    public function cpt_models()
1601
-    {
1602
-        $cpt_models = array();
1603
-        foreach ($this->non_abstract_db_models as $short_name => $classname) {
1604
-            if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1605
-                $cpt_models[$short_name] = $classname;
1606
-            }
1607
-        }
1608
-        return $cpt_models;
1609
-    }
1610
-
1611
-
1612
-
1613
-    /**
1614
-     * @return \EE_Config
1615
-     */
1616
-    public static function CFG()
1617
-    {
1618
-        return self::instance()->CFG;
1619
-    }
1620
-
1621
-
1622
-    /**
1623
-     * @deprecated $VID:$
1624
-     * @param string $class_name
1625
-     * @return ReflectionClass
1626
-     * @throws ReflectionException
1627
-     * @throws InvalidDataTypeException
1628
-     */
1629
-    public function get_ReflectionClass($class_name)
1630
-    {
1631
-        return $this->mirror->getReflectionClass($class_name);
1632
-    }
30
+	/**
31
+	 * @var EE_Registry $_instance
32
+	 */
33
+	private static $_instance;
34
+
35
+	/**
36
+	 * @var EE_Dependency_Map $_dependency_map
37
+	 */
38
+	protected $_dependency_map;
39
+
40
+	/**
41
+	 * @var Mirror
42
+	 */
43
+	private $mirror;
44
+
45
+	/**
46
+	 * @var ClassInterfaceCache $class_cache
47
+	 */
48
+	private $class_cache;
49
+
50
+	/**
51
+	 * @var array $_class_abbreviations
52
+	 */
53
+	protected $_class_abbreviations = array();
54
+
55
+	/**
56
+	 * @var CommandBusInterface $BUS
57
+	 */
58
+	public $BUS;
59
+
60
+	/**
61
+	 * @var EE_Cart $CART
62
+	 */
63
+	public $CART;
64
+
65
+	/**
66
+	 * @var EE_Config $CFG
67
+	 */
68
+	public $CFG;
69
+
70
+	/**
71
+	 * @var EE_Network_Config $NET_CFG
72
+	 */
73
+	public $NET_CFG;
74
+
75
+	/**
76
+	 * StdClass object for storing library classes in
77
+	 *
78
+	 * @var StdClass $LIB
79
+	 */
80
+	public $LIB;
81
+
82
+	/**
83
+	 * @var EE_Request_Handler $REQ
84
+	 */
85
+	public $REQ;
86
+
87
+	/**
88
+	 * @var EE_Session $SSN
89
+	 */
90
+	public $SSN;
91
+
92
+	/**
93
+	 * @since 4.5.0
94
+	 * @var EE_Capabilities $CAP
95
+	 */
96
+	public $CAP;
97
+
98
+	/**
99
+	 * @since 4.9.0
100
+	 * @var EE_Message_Resource_Manager $MRM
101
+	 */
102
+	public $MRM;
103
+
104
+
105
+	/**
106
+	 * @var Registry $AssetsRegistry
107
+	 */
108
+	public $AssetsRegistry;
109
+
110
+	/**
111
+	 * StdClass object for holding addons which have registered themselves to work with EE core
112
+	 *
113
+	 * @var EE_Addon[] $addons
114
+	 */
115
+	public $addons;
116
+
117
+	/**
118
+	 * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
119
+	 *
120
+	 * @var EEM_Base[] $models
121
+	 */
122
+	public $models = array();
123
+
124
+	/**
125
+	 * @var EED_Module[] $modules
126
+	 */
127
+	public $modules;
128
+
129
+	/**
130
+	 * @var EES_Shortcode[] $shortcodes
131
+	 */
132
+	public $shortcodes;
133
+
134
+	/**
135
+	 * @var WP_Widget[] $widgets
136
+	 */
137
+	public $widgets;
138
+
139
+	/**
140
+	 * this is an array of all implemented model names (i.e. not the parent abstract models, or models
141
+	 * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
142
+	 * Keys are model "short names" (eg "Event") as used in model relations, and values are
143
+	 * classnames (eg "EEM_Event")
144
+	 *
145
+	 * @var array $non_abstract_db_models
146
+	 */
147
+	public $non_abstract_db_models = array();
148
+
149
+
150
+	/**
151
+	 * internationalization for JS strings
152
+	 *    usage:   EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' );
153
+	 *    in js file:  var translatedString = eei18n.string_key;
154
+	 *
155
+	 * @var array $i18n_js_strings
156
+	 */
157
+	public static $i18n_js_strings = array();
158
+
159
+
160
+	/**
161
+	 * $main_file - path to espresso.php
162
+	 *
163
+	 * @var array $main_file
164
+	 */
165
+	public $main_file;
166
+
167
+	/**
168
+	 * array of ReflectionClass objects where the key is the class name
169
+	 *
170
+	 * @deprecated $VID:$
171
+	 * @var ReflectionClass[] $_reflectors
172
+	 */
173
+	public $_reflectors;
174
+
175
+	/**
176
+	 * boolean flag to indicate whether or not to load/save dependencies from/to the cache
177
+	 *
178
+	 * @var boolean $_cache_on
179
+	 */
180
+	protected $_cache_on = true;
181
+
182
+
183
+	/**
184
+	 * @singleton method used to instantiate class object
185
+	 * @param EE_Dependency_Map|null   $dependency_map
186
+	 * @param Mirror|null              $mirror
187
+	 * @param ClassInterfaceCache|null $class_cache
188
+	 * @return EE_Registry instance
189
+	 */
190
+	public static function instance(
191
+		EE_Dependency_Map $dependency_map = null,
192
+		Mirror $mirror = null,
193
+		ClassInterfaceCache $class_cache = null
194
+	) {
195
+		// check if class object is instantiated
196
+		if (
197
+			! EE_Registry::$_instance instanceof EE_Registry
198
+			&& $dependency_map instanceof EE_Dependency_Map
199
+			&& $mirror instanceof Mirror
200
+			&& $class_cache instanceof ClassInterfaceCache
201
+		) {
202
+			EE_Registry::$_instance = new self($dependency_map, $mirror, $class_cache);
203
+		}
204
+		return EE_Registry::$_instance;
205
+	}
206
+
207
+
208
+	/**
209
+	 * protected constructor to prevent direct creation
210
+	 *
211
+	 * @Constructor
212
+	 * @param  EE_Dependency_Map  $dependency_map
213
+	 * @param Mirror              $mirror
214
+	 * @param ClassInterfaceCache $class_cache
215
+	 */
216
+	protected function __construct(EE_Dependency_Map $dependency_map, Mirror $mirror, ClassInterfaceCache $class_cache)
217
+	{
218
+		$this->_dependency_map = $dependency_map;
219
+		$this->mirror = $mirror;
220
+		$this->class_cache = $class_cache;
221
+		// $registry_container = new RegistryContainer();
222
+		$this->LIB = new RegistryContainer();
223
+		$this->addons = new RegistryContainer();
224
+		$this->modules = new RegistryContainer();
225
+		$this->shortcodes = new RegistryContainer();
226
+		$this->widgets = new RegistryContainer();
227
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 * initialize
234
+	 *
235
+	 * @throws EE_Error
236
+	 * @throws ReflectionException
237
+	 */
238
+	public function initialize()
239
+	{
240
+		$this->_class_abbreviations = apply_filters(
241
+			'FHEE__EE_Registry____construct___class_abbreviations',
242
+			array(
243
+				'EE_Config'                                       => 'CFG',
244
+				'EE_Session'                                      => 'SSN',
245
+				'EE_Capabilities'                                 => 'CAP',
246
+				'EE_Cart'                                         => 'CART',
247
+				'EE_Network_Config'                               => 'NET_CFG',
248
+				'EE_Request_Handler'                              => 'REQ',
249
+				'EE_Message_Resource_Manager'                     => 'MRM',
250
+				'EventEspresso\core\services\commands\CommandBus' => 'BUS',
251
+				'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
252
+			)
253
+		);
254
+		$this->load_core('Base', array(), true);
255
+		// add our request and response objects to the cache
256
+		$request_loader = $this->_dependency_map->class_loader(
257
+			'EventEspresso\core\services\request\Request'
258
+		);
259
+		$this->_set_cached_class(
260
+			$request_loader(),
261
+			'EventEspresso\core\services\request\Request'
262
+		);
263
+		$response_loader = $this->_dependency_map->class_loader(
264
+			'EventEspresso\core\services\request\Response'
265
+		);
266
+		$this->_set_cached_class(
267
+			$response_loader(),
268
+			'EventEspresso\core\services\request\Response'
269
+		);
270
+		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * @return void
277
+	 */
278
+	public function init()
279
+	{
280
+		// Get current page protocol
281
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
282
+		// Output admin-ajax.php URL with same protocol as current page
283
+		self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
284
+		self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
285
+	}
286
+
287
+
288
+
289
+	/**
290
+	 * localize_i18n_js_strings
291
+	 *
292
+	 * @return string
293
+	 */
294
+	public static function localize_i18n_js_strings()
295
+	{
296
+		$i18n_js_strings = (array)self::$i18n_js_strings;
297
+		foreach ($i18n_js_strings as $key => $value) {
298
+			if (is_scalar($value)) {
299
+				$i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
300
+			}
301
+		}
302
+		return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
303
+	}
304
+
305
+
306
+
307
+	/**
308
+	 * @param mixed string | EED_Module $module
309
+	 * @throws EE_Error
310
+	 * @throws ReflectionException
311
+	 */
312
+	public function add_module($module)
313
+	{
314
+		if ($module instanceof EED_Module) {
315
+			$module_class = get_class($module);
316
+			$this->modules->{$module_class} = $module;
317
+		} else {
318
+			if ( ! class_exists('EE_Module_Request_Router', false)) {
319
+				$this->load_core('Module_Request_Router');
320
+			}
321
+			EE_Module_Request_Router::module_factory($module);
322
+		}
323
+	}
324
+
325
+
326
+
327
+	/**
328
+	 * @param string $module_name
329
+	 * @return mixed EED_Module | NULL
330
+	 */
331
+	public function get_module($module_name = '')
332
+	{
333
+		return isset($this->modules->{$module_name})
334
+			? $this->modules->{$module_name}
335
+			: null;
336
+	}
337
+
338
+
339
+
340
+	/**
341
+	 * loads core classes - must be singletons
342
+	 *
343
+	 * @param string $class_name - simple class name ie: session
344
+	 * @param mixed  $arguments
345
+	 * @param bool   $load_only
346
+	 * @return mixed
347
+	 * @throws EE_Error
348
+	 * @throws ReflectionException
349
+	 */
350
+	public function load_core($class_name, $arguments = array(), $load_only = false)
351
+	{
352
+		$core_paths = apply_filters(
353
+			'FHEE__EE_Registry__load_core__core_paths',
354
+			array(
355
+				EE_CORE,
356
+				EE_ADMIN,
357
+				EE_CPTS,
358
+				EE_CORE . 'data_migration_scripts' . DS,
359
+				EE_CORE . 'capabilities' . DS,
360
+				EE_CORE . 'request_stack' . DS,
361
+				EE_CORE . 'middleware' . DS,
362
+			)
363
+		);
364
+		// retrieve instantiated class
365
+		return $this->_load(
366
+			$core_paths,
367
+			'EE_',
368
+			$class_name,
369
+			'core',
370
+			$arguments,
371
+			false,
372
+			true,
373
+			$load_only
374
+		);
375
+	}
376
+
377
+
378
+
379
+	/**
380
+	 * loads service classes
381
+	 *
382
+	 * @param string $class_name - simple class name ie: session
383
+	 * @param mixed  $arguments
384
+	 * @param bool   $load_only
385
+	 * @return mixed
386
+	 * @throws EE_Error
387
+	 * @throws ReflectionException
388
+	 */
389
+	public function load_service($class_name, $arguments = array(), $load_only = false)
390
+	{
391
+		$service_paths = apply_filters(
392
+			'FHEE__EE_Registry__load_service__service_paths',
393
+			array(
394
+				EE_CORE . 'services' . DS,
395
+			)
396
+		);
397
+		// retrieve instantiated class
398
+		return $this->_load(
399
+			$service_paths,
400
+			'EE_',
401
+			$class_name,
402
+			'class',
403
+			$arguments,
404
+			false,
405
+			true,
406
+			$load_only
407
+		);
408
+	}
409
+
410
+
411
+
412
+	/**
413
+	 * loads data_migration_scripts
414
+	 *
415
+	 * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
416
+	 * @param mixed  $arguments
417
+	 * @return EE_Data_Migration_Script_Base|mixed
418
+	 * @throws EE_Error
419
+	 * @throws ReflectionException
420
+	 */
421
+	public function load_dms($class_name, $arguments = array())
422
+	{
423
+		// retrieve instantiated class
424
+		return $this->_load(
425
+			EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(),
426
+			'EE_DMS_',
427
+			$class_name,
428
+			'dms',
429
+			$arguments,
430
+			false,
431
+			false
432
+		);
433
+	}
434
+
435
+
436
+
437
+	/**
438
+	 * loads object creating classes - must be singletons
439
+	 *
440
+	 * @param string $class_name - simple class name ie: attendee
441
+	 * @param mixed  $arguments  - an array of arguments to pass to the class
442
+	 * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to
443
+	 *                           instantiate
444
+	 * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then
445
+	 *                           set this to FALSE (ie. when instantiating model objects from client in a loop)
446
+	 * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate
447
+	 *                           (default)
448
+	 * @return EE_Base_Class | bool
449
+	 * @throws EE_Error
450
+	 * @throws ReflectionException
451
+	 */
452
+	public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
453
+	{
454
+		$paths = apply_filters(
455
+			'FHEE__EE_Registry__load_class__paths', array(
456
+			EE_CORE,
457
+			EE_CLASSES,
458
+			EE_BUSINESS,
459
+		)
460
+		);
461
+		// retrieve instantiated class
462
+		return $this->_load(
463
+			$paths,
464
+			'EE_',
465
+			$class_name,
466
+			'class',
467
+			$arguments,
468
+			$from_db,
469
+			$cache,
470
+			$load_only
471
+		);
472
+	}
473
+
474
+
475
+
476
+	/**
477
+	 * loads helper classes - must be singletons
478
+	 *
479
+	 * @param string $class_name - simple class name ie: price
480
+	 * @param mixed  $arguments
481
+	 * @param bool   $load_only
482
+	 * @return EEH_Base | bool
483
+	 * @throws EE_Error
484
+	 * @throws ReflectionException
485
+	 */
486
+	public function load_helper($class_name, $arguments = array(), $load_only = true)
487
+	{
488
+		// todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
489
+		$helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
490
+		// retrieve instantiated class
491
+		return $this->_load(
492
+			$helper_paths,
493
+			'EEH_',
494
+			$class_name,
495
+			'helper',
496
+			$arguments,
497
+			false,
498
+			true,
499
+			$load_only
500
+		);
501
+	}
502
+
503
+
504
+
505
+	/**
506
+	 * loads core classes - must be singletons
507
+	 *
508
+	 * @param string $class_name - simple class name ie: session
509
+	 * @param mixed  $arguments
510
+	 * @param bool   $load_only
511
+	 * @param bool   $cache      whether to cache the object or not.
512
+	 * @return mixed
513
+	 * @throws EE_Error
514
+	 * @throws ReflectionException
515
+	 */
516
+	public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
517
+	{
518
+		$paths = array(
519
+			EE_LIBRARIES,
520
+			EE_LIBRARIES . 'messages' . DS,
521
+			EE_LIBRARIES . 'shortcodes' . DS,
522
+			EE_LIBRARIES . 'qtips' . DS,
523
+			EE_LIBRARIES . 'payment_methods' . DS,
524
+		);
525
+		// retrieve instantiated class
526
+		return $this->_load(
527
+			$paths,
528
+			'EE_',
529
+			$class_name,
530
+			'lib',
531
+			$arguments,
532
+			false,
533
+			$cache,
534
+			$load_only
535
+		);
536
+	}
537
+
538
+
539
+
540
+	/**
541
+	 * loads model classes - must be singletons
542
+	 *
543
+	 * @param string $class_name - simple class name ie: price
544
+	 * @param mixed  $arguments
545
+	 * @param bool   $load_only
546
+	 * @return EEM_Base | bool
547
+	 * @throws EE_Error
548
+	 * @throws ReflectionException
549
+	 */
550
+	public function load_model($class_name, $arguments = array(), $load_only = false)
551
+	{
552
+		$paths = apply_filters(
553
+			'FHEE__EE_Registry__load_model__paths', array(
554
+			EE_MODELS,
555
+			EE_CORE,
556
+		)
557
+		);
558
+		// retrieve instantiated class
559
+		return $this->_load(
560
+			$paths,
561
+			'EEM_',
562
+			$class_name,
563
+			'model',
564
+			$arguments,
565
+			false,
566
+			true,
567
+			$load_only
568
+		);
569
+	}
570
+
571
+
572
+
573
+	/**
574
+	 * loads model classes - must be singletons
575
+	 *
576
+	 * @param string $class_name - simple class name ie: price
577
+	 * @param mixed  $arguments
578
+	 * @param bool   $load_only
579
+	 * @return mixed | bool
580
+	 * @throws EE_Error
581
+	 * @throws ReflectionException
582
+	 */
583
+	public function load_model_class($class_name, $arguments = array(), $load_only = true)
584
+	{
585
+		$paths = array(
586
+			EE_MODELS . 'fields' . DS,
587
+			EE_MODELS . 'helpers' . DS,
588
+			EE_MODELS . 'relations' . DS,
589
+			EE_MODELS . 'strategies' . DS,
590
+		);
591
+		// retrieve instantiated class
592
+		return $this->_load(
593
+			$paths,
594
+			'EE_',
595
+			$class_name,
596
+			'',
597
+			$arguments,
598
+			false,
599
+			true,
600
+			$load_only
601
+		);
602
+	}
603
+
604
+
605
+
606
+	/**
607
+	 * Determines if $model_name is the name of an actual EE model.
608
+	 *
609
+	 * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
610
+	 * @return boolean
611
+	 */
612
+	public function is_model_name($model_name)
613
+	{
614
+		return isset($this->models[$model_name]);
615
+	}
616
+
617
+
618
+
619
+	/**
620
+	 * generic class loader
621
+	 *
622
+	 * @param string $path_to_file - directory path to file location, not including filename
623
+	 * @param string $file_name    - file name  ie:  my_file.php, including extension
624
+	 * @param string $type         - file type - core? class? helper? model?
625
+	 * @param mixed  $arguments
626
+	 * @param bool   $load_only
627
+	 * @return mixed
628
+	 * @throws EE_Error
629
+	 * @throws ReflectionException
630
+	 */
631
+	public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
632
+	{
633
+		// retrieve instantiated class
634
+		return $this->_load(
635
+			$path_to_file,
636
+			'',
637
+			$file_name,
638
+			$type,
639
+			$arguments,
640
+			false,
641
+			true,
642
+			$load_only
643
+		);
644
+	}
645
+
646
+
647
+
648
+	/**
649
+	 * @param string $path_to_file - directory path to file location, not including filename
650
+	 * @param string $class_name   - full class name  ie:  My_Class
651
+	 * @param string $type         - file type - core? class? helper? model?
652
+	 * @param mixed  $arguments
653
+	 * @param bool   $load_only
654
+	 * @return bool|EE_Addon|object
655
+	 * @throws EE_Error
656
+	 * @throws ReflectionException
657
+	 */
658
+	public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
659
+	{
660
+		// retrieve instantiated class
661
+		return $this->_load(
662
+			$path_to_file,
663
+			'addon',
664
+			$class_name,
665
+			$type,
666
+			$arguments,
667
+			false,
668
+			true,
669
+			$load_only
670
+		);
671
+	}
672
+
673
+
674
+	/**
675
+	 * instantiates, caches, and automatically resolves dependencies
676
+	 * for classes that use a Fully Qualified Class Name.
677
+	 * if the class is not capable of being loaded using PSR-4 autoloading,
678
+	 * then you need to use one of the existing load_*() methods
679
+	 * which can resolve the classname and filepath from the passed arguments
680
+	 *
681
+	 * @param bool|string $class_name   Fully Qualified Class Name
682
+	 * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
683
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
684
+	 * @param bool        $from_db      some classes are instantiated from the db
685
+	 *                                  and thus call a different method to instantiate
686
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
687
+	 * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
688
+	 * @return bool|null|mixed          null = failure to load or instantiate class object.
689
+	 *                                  object = class loaded and instantiated successfully.
690
+	 *                                  bool = fail or success when $load_only is true
691
+	 * @throws InvalidInterfaceException
692
+	 * @throws InvalidDataTypeException
693
+	 * @throws InvalidClassException
694
+	 * @throws EE_Error
695
+	 * @throws ReflectionException
696
+	 */
697
+	public function create(
698
+		$class_name = false,
699
+		$arguments = array(),
700
+		$cache = false,
701
+		$from_db = false,
702
+		$load_only = false,
703
+		$addon = false
704
+	) {
705
+		$class_name = ltrim($class_name, '\\');
706
+		$class_name = $this->class_cache->getFqnForAlias($class_name);
707
+		$class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
708
+		// if a non-FQCN was passed, then verifyClassExists() might return an object
709
+		// or it could return null if the class just could not be found anywhere
710
+		if ($class_exists instanceof $class_name || $class_exists === null){
711
+			// either way, return the results
712
+			return $class_exists;
713
+		}
714
+		$class_name = $class_exists;
715
+		// if we're only loading the class and it already exists, then let's just return true immediately
716
+		if ($load_only) {
717
+			return true;
718
+		}
719
+		$addon = $addon
720
+			? 'addon'
721
+			: '';
722
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
723
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
724
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
725
+		if ($this->_cache_on && $cache && ! $load_only) {
726
+			// return object if it's already cached
727
+			$cached_class = $this->_get_cached_class($class_name, $addon);
728
+			if ($cached_class !== null) {
729
+				return $cached_class;
730
+			}
731
+		}
732
+		// obtain the loader method from the dependency map
733
+		$loader = $this->_dependency_map->class_loader($class_name);
734
+		// instantiate the requested object
735
+		if ($loader instanceof Closure) {
736
+			$class_obj = $loader($arguments);
737
+		} else if ($loader && method_exists($this, $loader)) {
738
+			$class_obj = $this->{$loader}($class_name, $arguments);
739
+		} else {
740
+			$class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
741
+		}
742
+		if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) {
743
+			// save it for later... kinda like gum  { : $
744
+			$this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
745
+		}
746
+		$this->_cache_on = true;
747
+		return $class_obj;
748
+	}
749
+
750
+
751
+
752
+	/**
753
+	 * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
754
+	 *
755
+	 * @param string $class_name
756
+	 * @param array  $arguments
757
+	 * @param int    $attempt
758
+	 * @return mixed
759
+	 */
760
+	private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) {
761
+		if (is_object($class_name) || class_exists($class_name)) {
762
+			return $class_name;
763
+		}
764
+		switch ($attempt) {
765
+			case 1:
766
+				// if it's a FQCN then maybe the class is registered with a preceding \
767
+				$class_name = strpos($class_name, '\\') !== false
768
+					? '\\' . ltrim($class_name, '\\')
769
+					: $class_name;
770
+				break;
771
+			case 2:
772
+				//
773
+				$loader = $this->_dependency_map->class_loader($class_name);
774
+				if ($loader && method_exists($this, $loader)) {
775
+					return $this->{$loader}($class_name, $arguments);
776
+				}
777
+				break;
778
+			case 3:
779
+			default;
780
+				return null;
781
+		}
782
+		$attempt++;
783
+		return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
784
+	}
785
+
786
+
787
+
788
+	/**
789
+	 * instantiates, caches, and injects dependencies for classes
790
+	 *
791
+	 * @param array       $file_paths   an array of paths to folders to look in
792
+	 * @param string      $class_prefix EE  or EEM or... ???
793
+	 * @param bool|string $class_name   $class name
794
+	 * @param string      $type         file type - core? class? helper? model?
795
+	 * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
796
+	 * @param bool        $from_db      some classes are instantiated from the db
797
+	 *                                  and thus call a different method to instantiate
798
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
799
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
800
+	 * @return bool|null|object null = failure to load or instantiate class object.
801
+	 *                                  object = class loaded and instantiated successfully.
802
+	 *                                  bool = fail or success when $load_only is true
803
+	 * @throws EE_Error
804
+	 * @throws ReflectionException
805
+	 * @throws InvalidInterfaceException
806
+	 * @throws InvalidDataTypeException
807
+	 * @throws InvalidClassException
808
+	 */
809
+	protected function _load(
810
+		$file_paths = array(),
811
+		$class_prefix = 'EE_',
812
+		$class_name = false,
813
+		$type = 'class',
814
+		$arguments = array(),
815
+		$from_db = false,
816
+		$cache = true,
817
+		$load_only = false
818
+	) {
819
+		$class_name = ltrim($class_name, '\\');
820
+		// strip php file extension
821
+		$class_name = str_replace('.php', '', trim($class_name));
822
+		// does the class have a prefix ?
823
+		if (! empty($class_prefix) && $class_prefix !== 'addon') {
824
+			// make sure $class_prefix is uppercase
825
+			$class_prefix = strtoupper(trim($class_prefix));
826
+			// add class prefix ONCE!!!
827
+			$class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
828
+		}
829
+		$class_name = $this->class_cache->getFqnForAlias($class_name);
830
+		$class_exists = class_exists($class_name, false);
831
+		// if we're only loading the class and it already exists, then let's just return true immediately
832
+		if ($load_only && $class_exists) {
833
+			return true;
834
+		}
835
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
836
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
837
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
838
+		if ($this->_cache_on && $cache && ! $load_only) {
839
+			// return object if it's already cached
840
+			$cached_class = $this->_get_cached_class($class_name, $class_prefix);
841
+			if ($cached_class !== null) {
842
+				return $cached_class;
843
+			}
844
+		}
845
+		// if the class doesn't already exist.. then we need to try and find the file and load it
846
+		if (! $class_exists) {
847
+			// get full path to file
848
+			$path = $this->_resolve_path($class_name, $type, $file_paths);
849
+			// load the file
850
+			$loaded = $this->_require_file($path, $class_name, $type, $file_paths);
851
+			// if loading failed, or we are only loading a file but NOT instantiating an object
852
+			if (! $loaded || $load_only) {
853
+				// return boolean if only loading, or null if an object was expected
854
+				return $load_only
855
+					? $loaded
856
+					: null;
857
+			}
858
+		}
859
+		// instantiate the requested object
860
+		$class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
861
+		if ($this->_cache_on && $cache) {
862
+			// save it for later... kinda like gum  { : $
863
+			$this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
864
+		}
865
+		$this->_cache_on = true;
866
+		return $class_obj;
867
+	}
868
+
869
+
870
+
871
+	/**
872
+	 * @param string $class_name
873
+	 * @param string $default have to specify something, but not anything that will conflict
874
+	 * @return mixed|string
875
+	 */
876
+	protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
877
+	{
878
+		return isset($this->_class_abbreviations[$class_name])
879
+			? $this->_class_abbreviations[$class_name]
880
+			: $default;
881
+	}
882
+
883
+	/**
884
+	 * attempts to find a cached version of the requested class
885
+	 * by looking in the following places:
886
+	 *        $this->{$class_abbreviation}            ie:    $this->CART
887
+	 *        $this->{$class_name}                        ie:    $this->Some_Class
888
+	 *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
889
+	 *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
890
+	 *
891
+	 * @param string $class_name
892
+	 * @param string $class_prefix
893
+	 * @return mixed
894
+	 */
895
+	protected function _get_cached_class($class_name, $class_prefix = '')
896
+	{
897
+		if ($class_name === 'EE_Registry') {
898
+			return $this;
899
+		}
900
+		$class_abbreviation = $this->get_class_abbreviation($class_name);
901
+		$class_name = str_replace('\\', '_', $class_name);
902
+		// check if class has already been loaded, and return it if it has been
903
+		if (isset($this->{$class_abbreviation})) {
904
+			return $this->{$class_abbreviation};
905
+		}
906
+		if (isset ($this->{$class_name})) {
907
+			return $this->{$class_name};
908
+		}
909
+		if (isset ($this->LIB->{$class_name})) {
910
+			return $this->LIB->{$class_name};
911
+		}
912
+		if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
913
+			return $this->addons->{$class_name};
914
+		}
915
+		return null;
916
+	}
917
+
918
+
919
+
920
+	/**
921
+	 * removes a cached version of the requested class
922
+	 *
923
+	 * @param string  $class_name
924
+	 * @param boolean $addon
925
+	 * @return boolean
926
+	 */
927
+	public function clear_cached_class($class_name, $addon = false)
928
+	{
929
+		$class_abbreviation = $this->get_class_abbreviation($class_name);
930
+		$class_name = str_replace('\\', '_', $class_name);
931
+		// check if class has already been loaded, and return it if it has been
932
+		if (isset($this->{$class_abbreviation})) {
933
+			$this->{$class_abbreviation} = null;
934
+			return true;
935
+		}
936
+		if (isset($this->{$class_name})) {
937
+			$this->{$class_name} = null;
938
+			return true;
939
+		}
940
+		if (isset($this->LIB->{$class_name})) {
941
+			unset($this->LIB->{$class_name});
942
+			return true;
943
+		}
944
+		if ($addon && isset($this->addons->{$class_name})) {
945
+			unset($this->addons->{$class_name});
946
+			return true;
947
+		}
948
+		return false;
949
+	}
950
+
951
+
952
+
953
+	/**
954
+	 * attempts to find a full valid filepath for the requested class.
955
+	 * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
956
+	 * then returns that path if the target file has been found and is readable
957
+	 *
958
+	 * @param string $class_name
959
+	 * @param string $type
960
+	 * @param array  $file_paths
961
+	 * @return string | bool
962
+	 */
963
+	protected function _resolve_path($class_name, $type = '', $file_paths = array())
964
+	{
965
+		// make sure $file_paths is an array
966
+		$file_paths = is_array($file_paths)
967
+			? $file_paths
968
+			: array($file_paths);
969
+		// cycle thru paths
970
+		foreach ($file_paths as $key => $file_path) {
971
+			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
972
+			$file_path = $file_path
973
+				? str_replace(array('/', '\\'), DS, $file_path)
974
+				: EE_CLASSES;
975
+			// prep file type
976
+			$type = ! empty($type)
977
+				? trim($type, '.') . '.'
978
+				: '';
979
+			// build full file path
980
+			$file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
981
+			//does the file exist and can be read ?
982
+			if (is_readable($file_paths[$key])) {
983
+				return $file_paths[$key];
984
+			}
985
+		}
986
+		return false;
987
+	}
988
+
989
+
990
+
991
+	/**
992
+	 * basically just performs a require_once()
993
+	 * but with some error handling
994
+	 *
995
+	 * @param  string $path
996
+	 * @param  string $class_name
997
+	 * @param  string $type
998
+	 * @param  array  $file_paths
999
+	 * @return bool
1000
+	 * @throws EE_Error
1001
+	 * @throws ReflectionException
1002
+	 */
1003
+	protected function _require_file($path, $class_name, $type = '', $file_paths = array())
1004
+	{
1005
+		$this->resolve_legacy_class_parent($class_name);
1006
+		// don't give up! you gotta...
1007
+		try {
1008
+			//does the file exist and can it be read ?
1009
+			if (! $path) {
1010
+				// just in case the file has already been autoloaded,
1011
+				// but discrepancies in the naming schema are preventing it from
1012
+				// being loaded via one of the EE_Registry::load_*() methods,
1013
+				// then let's try one last hail mary before throwing an exception
1014
+				// and call class_exists() again, but with autoloading turned ON
1015
+				if(class_exists($class_name)) {
1016
+					return true;
1017
+				}
1018
+				// so sorry, can't find the file
1019
+				throw new EE_Error (
1020
+					sprintf(
1021
+						esc_html__(
1022
+							'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',
1023
+							'event_espresso'
1024
+						),
1025
+						trim($type, '.'),
1026
+						$class_name,
1027
+						'<br />' . implode(',<br />', $file_paths)
1028
+					)
1029
+				);
1030
+			}
1031
+			// get the file
1032
+			require_once($path);
1033
+			// if the class isn't already declared somewhere
1034
+			if (class_exists($class_name, false) === false) {
1035
+				// so sorry, not a class
1036
+				throw new EE_Error(
1037
+					sprintf(
1038
+						esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
1039
+						$type,
1040
+						$path,
1041
+						$class_name
1042
+					)
1043
+				);
1044
+			}
1045
+		} catch (EE_Error $e) {
1046
+			$e->get_error();
1047
+			return false;
1048
+		}
1049
+		return true;
1050
+	}
1051
+
1052
+
1053
+
1054
+	/**
1055
+	 * Some of our legacy classes that extended a parent class would simply use a require() statement
1056
+	 * before their class declaration in order to ensure that the parent class was loaded.
1057
+	 * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class,
1058
+	 * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist.
1059
+	 *
1060
+	 * @param string $class_name
1061
+	 */
1062
+	protected function resolve_legacy_class_parent($class_name = '')
1063
+	{
1064
+		try {
1065
+			$legacy_parent_class_map = array(
1066
+				'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php'
1067
+			);
1068
+			if(isset($legacy_parent_class_map[$class_name])) {
1069
+				require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name];
1070
+			}
1071
+		} catch (Exception $exception) {
1072
+		}
1073
+	}
1074
+
1075
+
1076
+	/**
1077
+	 * _create_object
1078
+	 * Attempts to instantiate the requested class via any of the
1079
+	 * commonly used instantiation methods employed throughout EE.
1080
+	 * The priority for instantiation is as follows:
1081
+	 *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
1082
+	 *        - model objects via their 'new_instance_from_db' method
1083
+	 *        - model objects via their 'new_instance' method
1084
+	 *        - "singleton" classes" via their 'instance' method
1085
+	 *    - standard instantiable classes via their __constructor
1086
+	 * Prior to instantiation, if the classname exists in the dependency_map,
1087
+	 * then the constructor for the requested class will be examined to determine
1088
+	 * if any dependencies exist, and if they can be injected.
1089
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1090
+	 *
1091
+	 * @param string $class_name
1092
+	 * @param array  $arguments
1093
+	 * @param string $type
1094
+	 * @param bool   $from_db
1095
+	 * @return null|object
1096
+	 * @throws EE_Error
1097
+	 * @throws ReflectionException
1098
+	 * @throws InvalidDataTypeException
1099
+	 */
1100
+	protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
1101
+	{
1102
+		// create reflection
1103
+		$reflector = $this->mirror->getReflectionClass($class_name);
1104
+		// make sure arguments are an array
1105
+		$arguments = is_array($arguments)
1106
+			? $arguments
1107
+			: array($arguments);
1108
+		// and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1109
+		// else wrap it in an additional array so that it doesn't get split into multiple parameters
1110
+		$arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1111
+			? $arguments
1112
+			: array($arguments);
1113
+		// attempt to inject dependencies ?
1114
+		if ($this->_dependency_map->has($class_name)) {
1115
+			$arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1116
+		}
1117
+		// instantiate the class if possible
1118
+		if ($reflector->isAbstract()) {
1119
+			// nothing to instantiate, loading file was enough
1120
+			// does not throw an exception so $instantiation_mode is unused
1121
+			// $instantiation_mode = "1) no constructor abstract class";
1122
+			return true;
1123
+		}
1124
+		if (
1125
+			empty($arguments)
1126
+			&& $this->mirror->getConstructorFromReflection($reflector) === null
1127
+			&& $reflector->isInstantiable()
1128
+		) {
1129
+			// no constructor = static methods only... nothing to instantiate, loading file was enough
1130
+			// $instantiation_mode = "2) no constructor but instantiable";
1131
+			return $reflector->newInstance();
1132
+		}
1133
+		if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1134
+			// $instantiation_mode = "3) new_instance_from_db()";
1135
+			return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1136
+		}
1137
+		if (method_exists($class_name, 'new_instance')) {
1138
+			// $instantiation_mode = "4) new_instance()";
1139
+			return call_user_func_array(array($class_name, 'new_instance'), $arguments);
1140
+		}
1141
+		if (method_exists($class_name, 'instance')) {
1142
+			// $instantiation_mode = "5) instance()";
1143
+			return call_user_func_array(array($class_name, 'instance'), $arguments);
1144
+		}
1145
+		if ($reflector->isInstantiable()) {
1146
+			// $instantiation_mode = "6) constructor";
1147
+			return $reflector->newInstanceArgs($arguments);
1148
+		}
1149
+		// heh ? something's not right !
1150
+		throw new EE_Error(
1151
+			sprintf(
1152
+				__('The %s file %s could not be instantiated.', 'event_espresso'),
1153
+				$type,
1154
+				$class_name
1155
+			)
1156
+		);
1157
+	}
1158
+
1159
+
1160
+
1161
+	/**
1162
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1163
+	 * @param array $array
1164
+	 * @return bool
1165
+	 */
1166
+	protected function _array_is_numerically_and_sequentially_indexed(array $array)
1167
+	{
1168
+		return ! empty($array)
1169
+			? array_keys($array) === range(0, count($array) - 1)
1170
+			: true;
1171
+	}
1172
+
1173
+
1174
+	/**
1175
+	 * _resolve_dependencies
1176
+	 * examines the constructor for the requested class to determine
1177
+	 * if any dependencies exist, and if they can be injected.
1178
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1179
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
1180
+	 * For example:
1181
+	 *        if attempting to load a class "Foo" with the following constructor:
1182
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
1183
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
1184
+	 *        but only IF they are NOT already present in the incoming arguments array,
1185
+	 *        and the correct classes can be loaded
1186
+	 *
1187
+	 * @param ReflectionClass $reflector
1188
+	 * @param string          $class_name
1189
+	 * @param array           $arguments
1190
+	 * @return array
1191
+	 * @throws EE_Error
1192
+	 * @throws InvalidArgumentException
1193
+	 * @throws InvalidDataTypeException
1194
+	 * @throws InvalidInterfaceException
1195
+	 * @throws ReflectionException
1196
+	 * @throws InvalidClassException
1197
+	 */
1198
+	protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array())
1199
+	{
1200
+		// let's examine the constructor
1201
+		$constructor = $this->mirror->getConstructorFromReflection($reflector);
1202
+		// whu? huh? nothing?
1203
+		if (! $constructor) {
1204
+			return $arguments;
1205
+		}
1206
+		// get constructor parameters
1207
+		$params = $this->mirror->getParametersFromReflection($reflector);
1208
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1209
+		$argument_keys = array_keys($arguments);
1210
+		// now loop thru all of the constructors expected parameters
1211
+		foreach ($params as $index => $param) {
1212
+			// is this a dependency for a specific class ?
1213
+			$param_class = $this->mirror->getParameterClassName($param, $class_name, $index);
1214
+			// BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1215
+			$param_class = $this->class_cache->isAlias($param_class, $class_name)
1216
+				? $this->class_cache->getFqnForAlias($param_class, $class_name)
1217
+				: $param_class;
1218
+			if (
1219
+				// param is not even a class
1220
+				$param_class === null
1221
+				// and something already exists in the incoming arguments for this param
1222
+				&& array_key_exists($index, $argument_keys)
1223
+				&& array_key_exists($argument_keys[$index], $arguments)
1224
+			) {
1225
+				// so let's skip this argument and move on to the next
1226
+				continue;
1227
+			}
1228
+			if (
1229
+				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1230
+				$param_class !== null
1231
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1232
+				&& $arguments[$argument_keys[$index]] instanceof $param_class
1233
+			) {
1234
+				// skip this argument and move on to the next
1235
+				continue;
1236
+			}
1237
+			if (
1238
+				// parameter is type hinted as a class, and should be injected
1239
+				$param_class !== null
1240
+				&& $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1241
+			) {
1242
+				$arguments = $this->_resolve_dependency(
1243
+					$class_name,
1244
+					$param_class,
1245
+					$arguments,
1246
+					$index,
1247
+					$argument_keys
1248
+				);
1249
+			} else {
1250
+				try {
1251
+					$arguments[$index] = $this->mirror->getParameterDefaultValue(
1252
+						$param,
1253
+						$class_name,
1254
+						$index
1255
+					);
1256
+				} catch (ReflectionException $e) {
1257
+					throw new ReflectionException(
1258
+						sprintf(
1259
+							esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'),
1260
+							$e->getMessage(),
1261
+							$param->getName(),
1262
+							$class_name
1263
+						)
1264
+					);
1265
+				}
1266
+			}
1267
+		}
1268
+		return $arguments;
1269
+	}
1270
+
1271
+
1272
+
1273
+	/**
1274
+	 * @param string $class_name
1275
+	 * @param string $param_class
1276
+	 * @param array  $arguments
1277
+	 * @param mixed  $index
1278
+	 * @param array  $argument_keys
1279
+	 * @return array
1280
+	 * @throws EE_Error
1281
+	 * @throws ReflectionException
1282
+	 * @throws InvalidArgumentException
1283
+	 * @throws InvalidInterfaceException
1284
+	 * @throws InvalidDataTypeException
1285
+	 */
1286
+	protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys)
1287
+	{
1288
+		$dependency = null;
1289
+		// should dependency be loaded from cache ?
1290
+		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1291
+			$class_name,
1292
+			$param_class
1293
+		);
1294
+		$cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1295
+		// we might have a dependency...
1296
+		// let's MAYBE try and find it in our cache if that's what's been requested
1297
+		$cached_class = $cache_on
1298
+			? $this->_get_cached_class($param_class)
1299
+			: null;
1300
+		// and grab it if it exists
1301
+		if ($cached_class instanceof $param_class) {
1302
+			$dependency = $cached_class;
1303
+		} else if ($param_class !== $class_name) {
1304
+			// obtain the loader method from the dependency map
1305
+			$loader = $this->_dependency_map->class_loader($param_class);
1306
+			// is loader a custom closure ?
1307
+			if ($loader instanceof Closure) {
1308
+				$dependency = $loader($arguments);
1309
+			} else {
1310
+				// set the cache on property for the recursive loading call
1311
+				$this->_cache_on = $cache_on;
1312
+				// if not, then let's try and load it via the registry
1313
+				if ($loader && method_exists($this, $loader)) {
1314
+					$dependency = $this->{$loader}($param_class);
1315
+				} else {
1316
+					$dependency = LoaderFactory::getLoader()->load(
1317
+						$param_class,
1318
+						array(),
1319
+						$cache_on
1320
+					);
1321
+				}
1322
+			}
1323
+		}
1324
+		// did we successfully find the correct dependency ?
1325
+		if ($dependency instanceof $param_class) {
1326
+			// then let's inject it into the incoming array of arguments at the correct location
1327
+			$arguments[$index] = $dependency;
1328
+		}
1329
+		return $arguments;
1330
+	}
1331
+
1332
+
1333
+
1334
+	/**
1335
+	 * _set_cached_class
1336
+	 * attempts to cache the instantiated class locally
1337
+	 * in one of the following places, in the following order:
1338
+	 *        $this->{class_abbreviation}   ie:    $this->CART
1339
+	 *        $this->{$class_name}          ie:    $this->Some_Class
1340
+	 *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1341
+	 *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1342
+	 *
1343
+	 * @param object $class_obj
1344
+	 * @param string $class_name
1345
+	 * @param string $class_prefix
1346
+	 * @param bool   $from_db
1347
+	 * @return void
1348
+	 */
1349
+	protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1350
+	{
1351
+		if ($class_name === 'EE_Registry' || empty($class_obj)) {
1352
+			return;
1353
+		}
1354
+		// return newly instantiated class
1355
+		$class_abbreviation = $this->get_class_abbreviation($class_name, '');
1356
+		if ($class_abbreviation) {
1357
+			$this->{$class_abbreviation} = $class_obj;
1358
+			return;
1359
+		}
1360
+		$class_name = str_replace('\\', '_', $class_name);
1361
+		if (property_exists($this, $class_name)) {
1362
+			$this->{$class_name} = $class_obj;
1363
+			return;
1364
+		}
1365
+		if ($class_prefix === 'addon') {
1366
+			$this->addons->{$class_name} = $class_obj;
1367
+			return;
1368
+		}
1369
+		if (! $from_db) {
1370
+			$this->LIB->{$class_name} = $class_obj;
1371
+		}
1372
+	}
1373
+
1374
+
1375
+
1376
+	/**
1377
+	 * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1378
+	 *
1379
+	 * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1380
+	 *                          in the EE_Dependency_Map::$_class_loaders array,
1381
+	 *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1382
+	 * @param array  $arguments
1383
+	 * @return object
1384
+	 */
1385
+	public static function factory($classname, $arguments = array())
1386
+	{
1387
+		$loader = self::instance()->_dependency_map->class_loader($classname);
1388
+		if ($loader instanceof Closure) {
1389
+			return $loader($arguments);
1390
+		}
1391
+		if (method_exists(self::instance(), $loader)) {
1392
+			return self::instance()->{$loader}($classname, $arguments);
1393
+		}
1394
+		return null;
1395
+	}
1396
+
1397
+
1398
+
1399
+	/**
1400
+	 * Gets the addon by its class name
1401
+	 *
1402
+	 * @param string $class_name
1403
+	 * @return EE_Addon
1404
+	 */
1405
+	public function getAddon($class_name)
1406
+	{
1407
+		$class_name = str_replace('\\', '_', $class_name);
1408
+		return $this->addons->{$class_name};
1409
+	}
1410
+
1411
+
1412
+	/**
1413
+	 * removes the addon from the internal cache
1414
+	 *
1415
+	 * @param string $class_name
1416
+	 * @return void
1417
+	 */
1418
+	public function removeAddon($class_name)
1419
+	{
1420
+		$class_name = str_replace('\\', '_', $class_name);
1421
+		unset($this->addons->{$class_name});
1422
+	}
1423
+
1424
+
1425
+
1426
+	/**
1427
+	 * Gets the addon by its name/slug (not classname. For that, just
1428
+	 * use the get_addon() method above
1429
+	 *
1430
+	 * @param string $name
1431
+	 * @return EE_Addon
1432
+	 */
1433
+	public function get_addon_by_name($name)
1434
+	{
1435
+		foreach ($this->addons as $addon) {
1436
+			if ($addon->name() === $name) {
1437
+				return $addon;
1438
+			}
1439
+		}
1440
+		return null;
1441
+	}
1442
+
1443
+
1444
+
1445
+	/**
1446
+	 * Gets an array of all the registered addons, where the keys are their names.
1447
+	 * (ie, what each returns for their name() function)
1448
+	 * They're already available on EE_Registry::instance()->addons as properties,
1449
+	 * where each property's name is the addon's classname,
1450
+	 * So if you just want to get the addon by classname,
1451
+	 * OR use the get_addon() method above.
1452
+	 * PLEASE  NOTE:
1453
+	 * addons with Fully Qualified Class Names
1454
+	 * have had the namespace separators converted to underscores,
1455
+	 * so a classname like Fully\Qualified\ClassName
1456
+	 * would have been converted to Fully_Qualified_ClassName
1457
+	 *
1458
+	 * @return EE_Addon[] where the KEYS are the addon's name()
1459
+	 */
1460
+	public function get_addons_by_name()
1461
+	{
1462
+		$addons = array();
1463
+		foreach ($this->addons as $addon) {
1464
+			$addons[$addon->name()] = $addon;
1465
+		}
1466
+		return $addons;
1467
+	}
1468
+
1469
+
1470
+	/**
1471
+	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1472
+	 * a stale copy of it around
1473
+	 *
1474
+	 * @param string $model_name
1475
+	 * @return \EEM_Base
1476
+	 * @throws \EE_Error
1477
+	 */
1478
+	public function reset_model($model_name)
1479
+	{
1480
+		$model_class_name = strpos($model_name, 'EEM_') !== 0
1481
+			? "EEM_{$model_name}"
1482
+			: $model_name;
1483
+		if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1484
+			return null;
1485
+		}
1486
+		//get that model reset it and make sure we nuke the old reference to it
1487
+		if ($this->LIB->{$model_class_name} instanceof $model_class_name
1488
+			&& is_callable(
1489
+				array($model_class_name, 'reset')
1490
+			)) {
1491
+			$this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1492
+		} else {
1493
+			throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1494
+		}
1495
+		return $this->LIB->{$model_class_name};
1496
+	}
1497
+
1498
+
1499
+
1500
+	/**
1501
+	 * Resets the registry.
1502
+	 * The criteria for what gets reset is based on what can be shared between sites on the same request when
1503
+	 * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1504
+	 * - $_dependency_map
1505
+	 * - $_class_abbreviations
1506
+	 * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1507
+	 * - $REQ:  Still on the same request so no need to change.
1508
+	 * - $CAP: There is no site specific state in the EE_Capability class.
1509
+	 * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1510
+	 * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1511
+	 * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1512
+	 *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1513
+	 *             switch or on the restore.
1514
+	 * - $modules
1515
+	 * - $shortcodes
1516
+	 * - $widgets
1517
+	 *
1518
+	 * @param boolean $hard             [deprecated]
1519
+	 * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1520
+	 *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1521
+	 *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1522
+	 * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1523
+	 *                                  client
1524
+	 *                                  code instead can just change the model context to a different blog id if
1525
+	 *                                  necessary
1526
+	 * @return EE_Registry
1527
+	 * @throws EE_Error
1528
+	 * @throws ReflectionException
1529
+	 */
1530
+	public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1531
+	{
1532
+		$instance = self::instance();
1533
+		$instance->_cache_on = true;
1534
+		// reset some "special" classes
1535
+		EEH_Activation::reset();
1536
+		$hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1537
+		$instance->CFG = EE_Config::reset($hard, $reinstantiate);
1538
+		$instance->CART = null;
1539
+		$instance->MRM = null;
1540
+		$instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1541
+		//messages reset
1542
+		EED_Messages::reset();
1543
+		//handle of objects cached on LIB
1544
+		foreach (array('LIB', 'modules') as $cache) {
1545
+			foreach ($instance->{$cache} as $class_name => $class) {
1546
+				if (self::_reset_and_unset_object($class, $reset_models)) {
1547
+					unset($instance->{$cache}->{$class_name});
1548
+				}
1549
+			}
1550
+		}
1551
+		return $instance;
1552
+	}
1553
+
1554
+
1555
+
1556
+	/**
1557
+	 * if passed object implements ResettableInterface, then call it's reset() method
1558
+	 * if passed object implements InterminableInterface, then return false,
1559
+	 * to indicate that it should NOT be cleared from the Registry cache
1560
+	 *
1561
+	 * @param      $object
1562
+	 * @param bool $reset_models
1563
+	 * @return bool returns true if cached object should be unset
1564
+	 */
1565
+	private static function _reset_and_unset_object($object, $reset_models)
1566
+	{
1567
+		if (! is_object($object)) {
1568
+			// don't unset anything that's not an object
1569
+			return false;
1570
+		}
1571
+		if ($object instanceof EED_Module) {
1572
+			$object::reset();
1573
+			// don't unset modules
1574
+			return false;
1575
+		}
1576
+		if ($object instanceof ResettableInterface) {
1577
+			if ($object instanceof EEM_Base) {
1578
+				if ($reset_models) {
1579
+					$object->reset();
1580
+					return true;
1581
+				}
1582
+				return false;
1583
+			}
1584
+			$object->reset();
1585
+			return true;
1586
+		}
1587
+		if (! $object instanceof InterminableInterface) {
1588
+			return true;
1589
+		}
1590
+		return false;
1591
+	}
1592
+
1593
+
1594
+
1595
+	/**
1596
+	 * Gets all the custom post type models defined
1597
+	 *
1598
+	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1599
+	 */
1600
+	public function cpt_models()
1601
+	{
1602
+		$cpt_models = array();
1603
+		foreach ($this->non_abstract_db_models as $short_name => $classname) {
1604
+			if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1605
+				$cpt_models[$short_name] = $classname;
1606
+			}
1607
+		}
1608
+		return $cpt_models;
1609
+	}
1610
+
1611
+
1612
+
1613
+	/**
1614
+	 * @return \EE_Config
1615
+	 */
1616
+	public static function CFG()
1617
+	{
1618
+		return self::instance()->CFG;
1619
+	}
1620
+
1621
+
1622
+	/**
1623
+	 * @deprecated $VID:$
1624
+	 * @param string $class_name
1625
+	 * @return ReflectionClass
1626
+	 * @throws ReflectionException
1627
+	 * @throws InvalidDataTypeException
1628
+	 */
1629
+	public function get_ReflectionClass($class_name)
1630
+	{
1631
+		return $this->mirror->getReflectionClass($class_name);
1632
+	}
1633 1633
 }
1634 1634
 // End of file EE_Registry.core.php
1635 1635
 // Location: ./core/EE_Registry.core.php
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -293,13 +293,13 @@  discard block
 block discarded – undo
293 293
      */
294 294
     public static function localize_i18n_js_strings()
295 295
     {
296
-        $i18n_js_strings = (array)self::$i18n_js_strings;
296
+        $i18n_js_strings = (array) self::$i18n_js_strings;
297 297
         foreach ($i18n_js_strings as $key => $value) {
298 298
             if (is_scalar($value)) {
299
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
299
+                $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
300 300
             }
301 301
         }
302
-        return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
302
+        return '/* <![CDATA[ */ var eei18n = '.wp_json_encode($i18n_js_strings).'; /* ]]> */';
303 303
     }
304 304
 
305 305
 
@@ -355,10 +355,10 @@  discard block
 block discarded – undo
355 355
                 EE_CORE,
356 356
                 EE_ADMIN,
357 357
                 EE_CPTS,
358
-                EE_CORE . 'data_migration_scripts' . DS,
359
-                EE_CORE . 'capabilities' . DS,
360
-                EE_CORE . 'request_stack' . DS,
361
-                EE_CORE . 'middleware' . DS,
358
+                EE_CORE.'data_migration_scripts'.DS,
359
+                EE_CORE.'capabilities'.DS,
360
+                EE_CORE.'request_stack'.DS,
361
+                EE_CORE.'middleware'.DS,
362 362
             )
363 363
         );
364 364
         // retrieve instantiated class
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
         $service_paths = apply_filters(
392 392
             'FHEE__EE_Registry__load_service__service_paths',
393 393
             array(
394
-                EE_CORE . 'services' . DS,
394
+                EE_CORE.'services'.DS,
395 395
             )
396 396
         );
397 397
         // retrieve instantiated class
@@ -517,10 +517,10 @@  discard block
 block discarded – undo
517 517
     {
518 518
         $paths = array(
519 519
             EE_LIBRARIES,
520
-            EE_LIBRARIES . 'messages' . DS,
521
-            EE_LIBRARIES . 'shortcodes' . DS,
522
-            EE_LIBRARIES . 'qtips' . DS,
523
-            EE_LIBRARIES . 'payment_methods' . DS,
520
+            EE_LIBRARIES.'messages'.DS,
521
+            EE_LIBRARIES.'shortcodes'.DS,
522
+            EE_LIBRARIES.'qtips'.DS,
523
+            EE_LIBRARIES.'payment_methods'.DS,
524 524
         );
525 525
         // retrieve instantiated class
526 526
         return $this->_load(
@@ -583,10 +583,10 @@  discard block
 block discarded – undo
583 583
     public function load_model_class($class_name, $arguments = array(), $load_only = true)
584 584
     {
585 585
         $paths = array(
586
-            EE_MODELS . 'fields' . DS,
587
-            EE_MODELS . 'helpers' . DS,
588
-            EE_MODELS . 'relations' . DS,
589
-            EE_MODELS . 'strategies' . DS,
586
+            EE_MODELS.'fields'.DS,
587
+            EE_MODELS.'helpers'.DS,
588
+            EE_MODELS.'relations'.DS,
589
+            EE_MODELS.'strategies'.DS,
590 590
         );
591 591
         // retrieve instantiated class
592 592
         return $this->_load(
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
         $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
708 708
         // if a non-FQCN was passed, then verifyClassExists() might return an object
709 709
         // or it could return null if the class just could not be found anywhere
710
-        if ($class_exists instanceof $class_name || $class_exists === null){
710
+        if ($class_exists instanceof $class_name || $class_exists === null) {
711 711
             // either way, return the results
712 712
             return $class_exists;
713 713
         }
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
             case 1:
766 766
                 // if it's a FQCN then maybe the class is registered with a preceding \
767 767
                 $class_name = strpos($class_name, '\\') !== false
768
-                    ? '\\' . ltrim($class_name, '\\')
768
+                    ? '\\'.ltrim($class_name, '\\')
769 769
                     : $class_name;
770 770
                 break;
771 771
             case 2:
@@ -820,11 +820,11 @@  discard block
 block discarded – undo
820 820
         // strip php file extension
821 821
         $class_name = str_replace('.php', '', trim($class_name));
822 822
         // does the class have a prefix ?
823
-        if (! empty($class_prefix) && $class_prefix !== 'addon') {
823
+        if ( ! empty($class_prefix) && $class_prefix !== 'addon') {
824 824
             // make sure $class_prefix is uppercase
825 825
             $class_prefix = strtoupper(trim($class_prefix));
826 826
             // add class prefix ONCE!!!
827
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
827
+            $class_name = $class_prefix.str_replace($class_prefix, '', $class_name);
828 828
         }
829 829
         $class_name = $this->class_cache->getFqnForAlias($class_name);
830 830
         $class_exists = class_exists($class_name, false);
@@ -843,13 +843,13 @@  discard block
 block discarded – undo
843 843
             }
844 844
         }
845 845
         // if the class doesn't already exist.. then we need to try and find the file and load it
846
-        if (! $class_exists) {
846
+        if ( ! $class_exists) {
847 847
             // get full path to file
848 848
             $path = $this->_resolve_path($class_name, $type, $file_paths);
849 849
             // load the file
850 850
             $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
851 851
             // if loading failed, or we are only loading a file but NOT instantiating an object
852
-            if (! $loaded || $load_only) {
852
+            if ( ! $loaded || $load_only) {
853 853
                 // return boolean if only loading, or null if an object was expected
854 854
                 return $load_only
855 855
                     ? $loaded
@@ -974,10 +974,10 @@  discard block
 block discarded – undo
974 974
                 : EE_CLASSES;
975 975
             // prep file type
976 976
             $type = ! empty($type)
977
-                ? trim($type, '.') . '.'
977
+                ? trim($type, '.').'.'
978 978
                 : '';
979 979
             // build full file path
980
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
980
+            $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php';
981 981
             //does the file exist and can be read ?
982 982
             if (is_readable($file_paths[$key])) {
983 983
                 return $file_paths[$key];
@@ -1006,17 +1006,17 @@  discard block
 block discarded – undo
1006 1006
         // don't give up! you gotta...
1007 1007
         try {
1008 1008
             //does the file exist and can it be read ?
1009
-            if (! $path) {
1009
+            if ( ! $path) {
1010 1010
                 // just in case the file has already been autoloaded,
1011 1011
                 // but discrepancies in the naming schema are preventing it from
1012 1012
                 // being loaded via one of the EE_Registry::load_*() methods,
1013 1013
                 // then let's try one last hail mary before throwing an exception
1014 1014
                 // and call class_exists() again, but with autoloading turned ON
1015
-                if(class_exists($class_name)) {
1015
+                if (class_exists($class_name)) {
1016 1016
                     return true;
1017 1017
                 }
1018 1018
                 // so sorry, can't find the file
1019
-                throw new EE_Error (
1019
+                throw new EE_Error(
1020 1020
                     sprintf(
1021 1021
                         esc_html__(
1022 1022
                             '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',
@@ -1024,7 +1024,7 @@  discard block
 block discarded – undo
1024 1024
                         ),
1025 1025
                         trim($type, '.'),
1026 1026
                         $class_name,
1027
-                        '<br />' . implode(',<br />', $file_paths)
1027
+                        '<br />'.implode(',<br />', $file_paths)
1028 1028
                     )
1029 1029
                 );
1030 1030
             }
@@ -1065,8 +1065,8 @@  discard block
 block discarded – undo
1065 1065
             $legacy_parent_class_map = array(
1066 1066
                 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php'
1067 1067
             );
1068
-            if(isset($legacy_parent_class_map[$class_name])) {
1069
-                require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name];
1068
+            if (isset($legacy_parent_class_map[$class_name])) {
1069
+                require_once EE_PLUGIN_DIR_PATH.$legacy_parent_class_map[$class_name];
1070 1070
             }
1071 1071
         } catch (Exception $exception) {
1072 1072
         }
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
         // let's examine the constructor
1201 1201
         $constructor = $this->mirror->getConstructorFromReflection($reflector);
1202 1202
         // whu? huh? nothing?
1203
-        if (! $constructor) {
1203
+        if ( ! $constructor) {
1204 1204
             return $arguments;
1205 1205
         }
1206 1206
         // get constructor parameters
@@ -1366,7 +1366,7 @@  discard block
 block discarded – undo
1366 1366
             $this->addons->{$class_name} = $class_obj;
1367 1367
             return;
1368 1368
         }
1369
-        if (! $from_db) {
1369
+        if ( ! $from_db) {
1370 1370
             $this->LIB->{$class_name} = $class_obj;
1371 1371
         }
1372 1372
     }
@@ -1480,7 +1480,7 @@  discard block
 block discarded – undo
1480 1480
         $model_class_name = strpos($model_name, 'EEM_') !== 0
1481 1481
             ? "EEM_{$model_name}"
1482 1482
             : $model_name;
1483
-        if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1483
+        if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1484 1484
             return null;
1485 1485
         }
1486 1486
         //get that model reset it and make sure we nuke the old reference to it
@@ -1533,7 +1533,7 @@  discard block
 block discarded – undo
1533 1533
         $instance->_cache_on = true;
1534 1534
         // reset some "special" classes
1535 1535
         EEH_Activation::reset();
1536
-        $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1536
+        $hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard);
1537 1537
         $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1538 1538
         $instance->CART = null;
1539 1539
         $instance->MRM = null;
@@ -1564,7 +1564,7 @@  discard block
 block discarded – undo
1564 1564
      */
1565 1565
     private static function _reset_and_unset_object($object, $reset_models)
1566 1566
     {
1567
-        if (! is_object($object)) {
1567
+        if ( ! is_object($object)) {
1568 1568
             // don't unset anything that's not an object
1569 1569
             return false;
1570 1570
         }
@@ -1584,7 +1584,7 @@  discard block
 block discarded – undo
1584 1584
             $object->reset();
1585 1585
             return true;
1586 1586
         }
1587
-        if (! $object instanceof InterminableInterface) {
1587
+        if ( ! $object instanceof InterminableInterface) {
1588 1588
             return true;
1589 1589
         }
1590 1590
         return false;
Please login to merge, or discard this patch.
core/services/loaders/CachingLoader.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -174,7 +174,7 @@
 block discarded – undo
174 174
     /**
175 175
      * generates an identifier for a class
176 176
      *
177
-     * @param FullyQualifiedName|string $fqcn
177
+     * @param string $fqcn
178 178
      * @param array                     $arguments
179 179
      * @return string
180 180
      */
Please login to merge, or discard this patch.
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -23,196 +23,196 @@
 block discarded – undo
23 23
 class CachingLoader extends CachingLoaderDecorator
24 24
 {
25 25
 
26
-    /**
27
-     * @var CollectionInterface $cache
28
-     */
29
-    protected $cache;
30
-
31
-    /**
32
-     * @var string $identifier
33
-     */
34
-    protected $identifier;
35
-
36
-    /**
37
-     * @var ClassInterfaceCache $class_cache
38
-     */
39
-    private $class_cache;
40
-
41
-
42
-    /**
43
-     * CachingLoader constructor.
44
-     *
45
-     * @param LoaderDecoratorInterface $loader
46
-     * @param CollectionInterface      $cache
47
-     * @param ClassInterfaceCache      $class_cache
48
-     * @param string                   $identifier
49
-     * @throws InvalidDataTypeException
50
-     */
51
-    public function __construct(
52
-        LoaderDecoratorInterface $loader,
53
-        CollectionInterface $cache,
54
-        ClassInterfaceCache $class_cache,
55
-        $identifier = ''
56
-    ) {
57
-        parent::__construct($loader);
58
-        $this->cache = $cache;
59
-        $this->class_cache = $class_cache;
60
-        $this->setIdentifier($identifier);
61
-        if ($this->identifier !== '') {
62
-            // to only clear this cache, and assuming an identifier has been set, simply do the following:
63
-            // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER');
64
-            // where "IDENTIFIER" = the string that was set during construction
65
-            add_action(
66
-                "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}",
67
-                array($this, 'reset')
68
-            );
69
-        }
70
-        // to clear ALL caches, simply do the following:
71
-        // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache');
72
-        add_action(
73
-            'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache',
74
-            array($this, 'reset')
75
-        );
76
-    }
77
-
78
-
79
-
80
-    /**
81
-     * @return string
82
-     */
83
-    public function identifier()
84
-    {
85
-        return $this->identifier;
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * @param string $identifier
92
-     * @throws InvalidDataTypeException
93
-     */
94
-    private function setIdentifier($identifier)
95
-    {
96
-        if (! is_string($identifier)) {
97
-            throw new InvalidDataTypeException('$identifier', $identifier, 'string');
98
-        }
99
-        $this->identifier = $identifier;
100
-    }
101
-
102
-
103
-    /**
104
-     * @param FullyQualifiedName|string $fqcn
105
-     * @param mixed  $object
106
-     * @return bool
107
-     * @throws InvalidArgumentException
108
-     */
109
-    public function share($fqcn, $object)
110
-    {
111
-        if ($object instanceof $fqcn) {
112
-            return $this->cache->add($object, md5($fqcn));
113
-        }
114
-        throw new InvalidArgumentException(
115
-            sprintf(
116
-                esc_html__(
117
-                    'The supplied class name "%1$s" must match the class of the supplied object.',
118
-                    'event_espresso'
119
-                ),
120
-                $fqcn
121
-            )
122
-        );
123
-    }
124
-
125
-
126
-    /**
127
-     * @param FullyQualifiedName|string $fqcn
128
-     * @param array  $arguments
129
-     * @param bool   $shared
130
-     * @param array  $interfaces
131
-     * @return mixed
132
-     */
133
-    public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array())
134
-    {
135
-        $fqcn = ltrim($fqcn, '\\');
136
-        // caching can be turned off via the following code:
137
-        // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
138
-        if(
139
-            apply_filters(
140
-                'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
141
-                false,
142
-                $this
143
-            )
144
-        ){
145
-            // even though $shared might be true, caching could be bypassed for whatever reason,
146
-            // so we don't want the core loader to cache anything, therefore caching is turned off
147
-            return $this->loader->load($fqcn, $arguments, false);
148
-        }
149
-
150
-        $identifier = $this->getCacheIdentifier($fqcn, $arguments);
151
-        if ($this->cache->has($identifier)) {
152
-            return $this->cache->get($identifier);
153
-        }
154
-        $object = $this->loader->load($fqcn, $arguments, $shared);
155
-        if ($object instanceof $fqcn) {
156
-            $this->cache->add($object, $identifier);
157
-        }
158
-        return $object;
159
-    }
160
-
161
-
162
-
163
-    /**
164
-     * empties cache and calls reset() on loader if method exists
165
-     */
166
-    public function reset()
167
-    {
168
-        $this->cache->trashAndDetachAll();
169
-        $this->loader->reset();
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * generates an identifier for a class
176
-     *
177
-     * @param FullyQualifiedName|string $fqcn
178
-     * @param array                     $arguments
179
-     * @return string
180
-     */
181
-    protected function getCacheIdentifier($fqcn, array $arguments)
182
-    {
183
-        return $this->class_cache->hasInterface($fqcn, 'EventEspresso\core\interfaces\ReservedInstanceInterface')
184
-            ? md5($fqcn)
185
-            : md5($fqcn . $this->getCacheIdentifierForArgument($arguments));
186
-    }
187
-
188
-
189
-
190
-    /**
191
-     * build a string representation of a class' arguments
192
-     * (mostly because Closures can't be serialized)
193
-     *
194
-     * @param array $arguments
195
-     * @return string
196
-     */
197
-    protected function getCacheIdentifierForArgument(array $arguments)
198
-    {
199
-        $identifier = '';
200
-        foreach ($arguments as $argument) {
201
-            switch (true) {
202
-                case is_object($argument) :
203
-                case $argument instanceof Closure :
204
-                    $identifier .= spl_object_hash($argument);
205
-                    break;
206
-                case is_array($argument) :
207
-                    $identifier .= $this->getCacheIdentifierForArgument($argument);
208
-                    break;
209
-                default :
210
-                    $identifier .= $argument;
211
-                    break;
212
-            }
213
-        }
214
-        return $identifier;
215
-    }
26
+	/**
27
+	 * @var CollectionInterface $cache
28
+	 */
29
+	protected $cache;
30
+
31
+	/**
32
+	 * @var string $identifier
33
+	 */
34
+	protected $identifier;
35
+
36
+	/**
37
+	 * @var ClassInterfaceCache $class_cache
38
+	 */
39
+	private $class_cache;
40
+
41
+
42
+	/**
43
+	 * CachingLoader constructor.
44
+	 *
45
+	 * @param LoaderDecoratorInterface $loader
46
+	 * @param CollectionInterface      $cache
47
+	 * @param ClassInterfaceCache      $class_cache
48
+	 * @param string                   $identifier
49
+	 * @throws InvalidDataTypeException
50
+	 */
51
+	public function __construct(
52
+		LoaderDecoratorInterface $loader,
53
+		CollectionInterface $cache,
54
+		ClassInterfaceCache $class_cache,
55
+		$identifier = ''
56
+	) {
57
+		parent::__construct($loader);
58
+		$this->cache = $cache;
59
+		$this->class_cache = $class_cache;
60
+		$this->setIdentifier($identifier);
61
+		if ($this->identifier !== '') {
62
+			// to only clear this cache, and assuming an identifier has been set, simply do the following:
63
+			// do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER');
64
+			// where "IDENTIFIER" = the string that was set during construction
65
+			add_action(
66
+				"AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}",
67
+				array($this, 'reset')
68
+			);
69
+		}
70
+		// to clear ALL caches, simply do the following:
71
+		// do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache');
72
+		add_action(
73
+			'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache',
74
+			array($this, 'reset')
75
+		);
76
+	}
77
+
78
+
79
+
80
+	/**
81
+	 * @return string
82
+	 */
83
+	public function identifier()
84
+	{
85
+		return $this->identifier;
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * @param string $identifier
92
+	 * @throws InvalidDataTypeException
93
+	 */
94
+	private function setIdentifier($identifier)
95
+	{
96
+		if (! is_string($identifier)) {
97
+			throw new InvalidDataTypeException('$identifier', $identifier, 'string');
98
+		}
99
+		$this->identifier = $identifier;
100
+	}
101
+
102
+
103
+	/**
104
+	 * @param FullyQualifiedName|string $fqcn
105
+	 * @param mixed  $object
106
+	 * @return bool
107
+	 * @throws InvalidArgumentException
108
+	 */
109
+	public function share($fqcn, $object)
110
+	{
111
+		if ($object instanceof $fqcn) {
112
+			return $this->cache->add($object, md5($fqcn));
113
+		}
114
+		throw new InvalidArgumentException(
115
+			sprintf(
116
+				esc_html__(
117
+					'The supplied class name "%1$s" must match the class of the supplied object.',
118
+					'event_espresso'
119
+				),
120
+				$fqcn
121
+			)
122
+		);
123
+	}
124
+
125
+
126
+	/**
127
+	 * @param FullyQualifiedName|string $fqcn
128
+	 * @param array  $arguments
129
+	 * @param bool   $shared
130
+	 * @param array  $interfaces
131
+	 * @return mixed
132
+	 */
133
+	public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array())
134
+	{
135
+		$fqcn = ltrim($fqcn, '\\');
136
+		// caching can be turned off via the following code:
137
+		// add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
138
+		if(
139
+			apply_filters(
140
+				'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
141
+				false,
142
+				$this
143
+			)
144
+		){
145
+			// even though $shared might be true, caching could be bypassed for whatever reason,
146
+			// so we don't want the core loader to cache anything, therefore caching is turned off
147
+			return $this->loader->load($fqcn, $arguments, false);
148
+		}
149
+
150
+		$identifier = $this->getCacheIdentifier($fqcn, $arguments);
151
+		if ($this->cache->has($identifier)) {
152
+			return $this->cache->get($identifier);
153
+		}
154
+		$object = $this->loader->load($fqcn, $arguments, $shared);
155
+		if ($object instanceof $fqcn) {
156
+			$this->cache->add($object, $identifier);
157
+		}
158
+		return $object;
159
+	}
160
+
161
+
162
+
163
+	/**
164
+	 * empties cache and calls reset() on loader if method exists
165
+	 */
166
+	public function reset()
167
+	{
168
+		$this->cache->trashAndDetachAll();
169
+		$this->loader->reset();
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * generates an identifier for a class
176
+	 *
177
+	 * @param FullyQualifiedName|string $fqcn
178
+	 * @param array                     $arguments
179
+	 * @return string
180
+	 */
181
+	protected function getCacheIdentifier($fqcn, array $arguments)
182
+	{
183
+		return $this->class_cache->hasInterface($fqcn, 'EventEspresso\core\interfaces\ReservedInstanceInterface')
184
+			? md5($fqcn)
185
+			: md5($fqcn . $this->getCacheIdentifierForArgument($arguments));
186
+	}
187
+
188
+
189
+
190
+	/**
191
+	 * build a string representation of a class' arguments
192
+	 * (mostly because Closures can't be serialized)
193
+	 *
194
+	 * @param array $arguments
195
+	 * @return string
196
+	 */
197
+	protected function getCacheIdentifierForArgument(array $arguments)
198
+	{
199
+		$identifier = '';
200
+		foreach ($arguments as $argument) {
201
+			switch (true) {
202
+				case is_object($argument) :
203
+				case $argument instanceof Closure :
204
+					$identifier .= spl_object_hash($argument);
205
+					break;
206
+				case is_array($argument) :
207
+					$identifier .= $this->getCacheIdentifierForArgument($argument);
208
+					break;
209
+				default :
210
+					$identifier .= $argument;
211
+					break;
212
+			}
213
+		}
214
+		return $identifier;
215
+	}
216 216
 
217 217
 
218 218
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      */
94 94
     private function setIdentifier($identifier)
95 95
     {
96
-        if (! is_string($identifier)) {
96
+        if ( ! is_string($identifier)) {
97 97
             throw new InvalidDataTypeException('$identifier', $identifier, 'string');
98 98
         }
99 99
         $this->identifier = $identifier;
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
         $fqcn = ltrim($fqcn, '\\');
136 136
         // caching can be turned off via the following code:
137 137
         // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
138
-        if(
138
+        if (
139 139
             apply_filters(
140 140
                 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
141 141
                 false,
142 142
                 $this
143 143
             )
144
-        ){
144
+        ) {
145 145
             // even though $shared might be true, caching could be bypassed for whatever reason,
146 146
             // so we don't want the core loader to cache anything, therefore caching is turned off
147 147
             return $this->loader->load($fqcn, $arguments, false);
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
     {
183 183
         return $this->class_cache->hasInterface($fqcn, 'EventEspresso\core\interfaces\ReservedInstanceInterface')
184 184
             ? md5($fqcn)
185
-            : md5($fqcn . $this->getCacheIdentifierForArgument($arguments));
185
+            : md5($fqcn.$this->getCacheIdentifierForArgument($arguments));
186 186
     }
187 187
 
188 188
 
Please login to merge, or discard this patch.
core/services/loaders/Loader.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@
 block discarded – undo
101 101
 
102 102
 
103 103
     /**
104
-     * @param FullyQualifiedName|string $fqcn
104
+     * @param string $fqcn
105 105
      * @param array                     $arguments
106 106
      * @return mixed
107 107
      */
Please login to merge, or discard this patch.
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -19,118 +19,118 @@
 block discarded – undo
19 19
 class Loader implements LoaderInterface
20 20
 {
21 21
 
22
-    /**
23
-     * @var LoaderDecoratorInterface $new_loader
24
-     */
25
-    private $new_loader;
26
-
27
-    /**
28
-     * @var LoaderDecoratorInterface $shared_loader
29
-     */
30
-    private $shared_loader;
31
-
32
-    /**
33
-     * @var ClassInterfaceCache $class_cache
34
-     */
35
-    private $class_cache;
36
-
37
-
38
-    /**
39
-     * Loader constructor.
40
-     *
41
-     * @param LoaderDecoratorInterface        $new_loader
42
-     * @param CachingLoaderDecoratorInterface $shared_loader
43
-     * @param ClassInterfaceCache             $class_cache
44
-     */
45
-    public function __construct(
46
-        LoaderDecoratorInterface $new_loader,
47
-        CachingLoaderDecoratorInterface $shared_loader,
48
-        ClassInterfaceCache $class_cache
49
-    ) {
50
-        $this->new_loader    = $new_loader;
51
-        $this->shared_loader = $shared_loader;
52
-        $this->class_cache   = $class_cache;
53
-    }
54
-
55
-
56
-    /**
57
-     * @return LoaderDecoratorInterface
58
-     */
59
-    public function getNewLoader()
60
-    {
61
-        return $this->new_loader;
62
-    }
63
-
64
-
65
-    /**
66
-     * @return CachingLoaderDecoratorInterface
67
-     */
68
-    public function getSharedLoader()
69
-    {
70
-        return $this->shared_loader;
71
-    }
72
-
73
-
74
-    /**
75
-     * @param FullyQualifiedName|string $fqcn
76
-     * @param array                     $arguments
77
-     * @param bool                      $shared
78
-     * @return mixed
79
-     */
80
-    public function load($fqcn, array $arguments = array(), $shared = true)
81
-    {
82
-        $fqcn = $this->class_cache->getFqn($fqcn);
83
-        if ($this->class_cache->hasInterface($fqcn, 'EventEspresso\core\interfaces\ReservedInstanceInterface')) {
84
-            $shared = true;
85
-        }
86
-        return $shared
87
-            ? $this->getSharedLoader()->load($fqcn, $arguments, $shared)
88
-            : $this->getNewLoader()->load($fqcn, $arguments, $shared);
89
-    }
90
-
91
-
92
-    /**
93
-     * @param FullyQualifiedName|string $fqcn
94
-     * @param array                     $arguments
95
-     * @return mixed
96
-     */
97
-    public function getNew($fqcn, array $arguments = array())
98
-    {
99
-        return $this->load($fqcn, $arguments, false);
100
-    }
101
-
102
-
103
-    /**
104
-     * @param FullyQualifiedName|string $fqcn
105
-     * @param array                     $arguments
106
-     * @return mixed
107
-     */
108
-    public function getShared($fqcn, array $arguments = array())
109
-    {
110
-        return $this->load($fqcn, $arguments);
111
-    }
112
-
113
-
114
-    /**
115
-     * @param FullyQualifiedName|string $fqcn
116
-     * @param mixed                     $object
117
-     * @return bool
118
-     * @throws InvalidArgumentException
119
-     */
120
-    public function share($fqcn, $object)
121
-    {
122
-        $fqcn = $this->class_cache->getFqn($fqcn);
123
-        return $this->getSharedLoader()->share($fqcn, $object);
124
-    }
125
-
126
-
127
-    /**
128
-     * calls reset() on loaders if that method exists
129
-     */
130
-    public function reset()
131
-    {
132
-        $this->shared_loader->reset();
133
-    }
22
+	/**
23
+	 * @var LoaderDecoratorInterface $new_loader
24
+	 */
25
+	private $new_loader;
26
+
27
+	/**
28
+	 * @var LoaderDecoratorInterface $shared_loader
29
+	 */
30
+	private $shared_loader;
31
+
32
+	/**
33
+	 * @var ClassInterfaceCache $class_cache
34
+	 */
35
+	private $class_cache;
36
+
37
+
38
+	/**
39
+	 * Loader constructor.
40
+	 *
41
+	 * @param LoaderDecoratorInterface        $new_loader
42
+	 * @param CachingLoaderDecoratorInterface $shared_loader
43
+	 * @param ClassInterfaceCache             $class_cache
44
+	 */
45
+	public function __construct(
46
+		LoaderDecoratorInterface $new_loader,
47
+		CachingLoaderDecoratorInterface $shared_loader,
48
+		ClassInterfaceCache $class_cache
49
+	) {
50
+		$this->new_loader    = $new_loader;
51
+		$this->shared_loader = $shared_loader;
52
+		$this->class_cache   = $class_cache;
53
+	}
54
+
55
+
56
+	/**
57
+	 * @return LoaderDecoratorInterface
58
+	 */
59
+	public function getNewLoader()
60
+	{
61
+		return $this->new_loader;
62
+	}
63
+
64
+
65
+	/**
66
+	 * @return CachingLoaderDecoratorInterface
67
+	 */
68
+	public function getSharedLoader()
69
+	{
70
+		return $this->shared_loader;
71
+	}
72
+
73
+
74
+	/**
75
+	 * @param FullyQualifiedName|string $fqcn
76
+	 * @param array                     $arguments
77
+	 * @param bool                      $shared
78
+	 * @return mixed
79
+	 */
80
+	public function load($fqcn, array $arguments = array(), $shared = true)
81
+	{
82
+		$fqcn = $this->class_cache->getFqn($fqcn);
83
+		if ($this->class_cache->hasInterface($fqcn, 'EventEspresso\core\interfaces\ReservedInstanceInterface')) {
84
+			$shared = true;
85
+		}
86
+		return $shared
87
+			? $this->getSharedLoader()->load($fqcn, $arguments, $shared)
88
+			: $this->getNewLoader()->load($fqcn, $arguments, $shared);
89
+	}
90
+
91
+
92
+	/**
93
+	 * @param FullyQualifiedName|string $fqcn
94
+	 * @param array                     $arguments
95
+	 * @return mixed
96
+	 */
97
+	public function getNew($fqcn, array $arguments = array())
98
+	{
99
+		return $this->load($fqcn, $arguments, false);
100
+	}
101
+
102
+
103
+	/**
104
+	 * @param FullyQualifiedName|string $fqcn
105
+	 * @param array                     $arguments
106
+	 * @return mixed
107
+	 */
108
+	public function getShared($fqcn, array $arguments = array())
109
+	{
110
+		return $this->load($fqcn, $arguments);
111
+	}
112
+
113
+
114
+	/**
115
+	 * @param FullyQualifiedName|string $fqcn
116
+	 * @param mixed                     $object
117
+	 * @return bool
118
+	 * @throws InvalidArgumentException
119
+	 */
120
+	public function share($fqcn, $object)
121
+	{
122
+		$fqcn = $this->class_cache->getFqn($fqcn);
123
+		return $this->getSharedLoader()->share($fqcn, $object);
124
+	}
125
+
126
+
127
+	/**
128
+	 * calls reset() on loaders if that method exists
129
+	 */
130
+	public function reset()
131
+	{
132
+		$this->shared_loader->reset();
133
+	}
134 134
 }
135 135
 // End of file Loader.php
136 136
 // Location: EventEspresso\core\services\loaders/Loader.php
Please login to merge, or discard this patch.
core/services/loaders/CoreLoader.php 1 patch
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -34,112 +34,112 @@
 block discarded – undo
34 34
 class CoreLoader implements LoaderDecoratorInterface
35 35
 {
36 36
 
37
-    /**
38
-     * @var EE_Registry|CoffeeShop $generator
39
-     */
40
-    private $generator;
41
-
42
-
43
-
44
-    /**
45
-     * CoreLoader constructor.
46
-     *
47
-     * @param EE_Registry|CoffeeShop $generator
48
-     * @throws InvalidArgumentException
49
-     */
50
-    public function __construct($generator)
51
-    {
52
-        if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
53
-            throw new InvalidArgumentException(
54
-                esc_html__(
55
-                    'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
56
-                    'event_espresso'
57
-                )
58
-            );
59
-        }
60
-        $this->generator = $generator;
61
-    }
62
-
63
-
64
-    /**
65
-     * Calls the appropriate loading method from the installed generator;
66
-     * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method
67
-     * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(),
68
-     * but NOT to the class being instantiated.
69
-     * This is done by adding the parameters to the $arguments array as follows:
70
-     *  array(
71
-     *      'EE_Registry::create(from_db)'   => true, // boolean value, default = false
72
-     *      'EE_Registry::create(load_only)' => true, // boolean value, default = false
73
-     *      'EE_Registry::create(addon)'     => true, // boolean value, default = false
74
-     *  )
75
-     *
76
-     * @param string $fqcn
77
-     * @param array  $arguments
78
-     * @param bool   $shared
79
-     * @return mixed
80
-     * @throws OutOfBoundsException
81
-     * @throws ServiceExistsException
82
-     * @throws InstantiationException
83
-     * @throws InvalidIdentifierException
84
-     * @throws InvalidDataTypeException
85
-     * @throws InvalidClassException
86
-     * @throws EE_Error
87
-     * @throws ServiceNotFoundException
88
-     * @throws ReflectionException
89
-     * @throws InvalidInterfaceException
90
-     */
91
-    public function load($fqcn, $arguments = array(), $shared = true)
92
-    {
93
-        $shared = filter_var($shared, FILTER_VALIDATE_BOOLEAN);
94
-        if($this->generator instanceof EE_Registry) {
95
-            // check if additional EE_Registry::create() arguments have been passed
96
-            // from_db
97
-            $from_db = isset($arguments['EE_Registry::create(from_db)'])
98
-                ? filter_var($arguments['EE_Registry::create(from_db)'], FILTER_VALIDATE_BOOLEAN)
99
-                : false;
100
-            // load_only
101
-            $load_only = isset($arguments['EE_Registry::create(load_only)'])
102
-                ? filter_var($arguments['EE_Registry::create(load_only)'], FILTER_VALIDATE_BOOLEAN)
103
-                : false;
104
-            // addon
105
-            $addon = isset($arguments['EE_Registry::create(addon)'])
106
-                ? filter_var($arguments['EE_Registry::create(addon)'], FILTER_VALIDATE_BOOLEAN)
107
-                : false;
108
-            unset(
109
-                $arguments['EE_Registry::create(from_db)'],
110
-                $arguments['EE_Registry::create(load_only)'],
111
-                $arguments['EE_Registry::create(addon)']
112
-            );
113
-            // addons need to be cached on EE_Registry
114
-            $shared = $addon ? true : $shared;
115
-            return $this->generator->create(
116
-                $fqcn,
117
-                $arguments,
118
-                $shared,
119
-                $from_db,
120
-                $load_only,
121
-                $addon
122
-            );
123
-        }
124
-        return $this->generator->brew(
125
-            $fqcn,
126
-            $arguments,
127
-            $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW
128
-        );
129
-
130
-    }
131
-
132
-
133
-
134
-    /**
135
-     * calls reset() on generator if method exists
136
-     */
137
-    public function reset()
138
-    {
139
-        if ($this->generator instanceof ResettableInterface) {
140
-            $this->generator->reset();
141
-        }
142
-    }
37
+	/**
38
+	 * @var EE_Registry|CoffeeShop $generator
39
+	 */
40
+	private $generator;
41
+
42
+
43
+
44
+	/**
45
+	 * CoreLoader constructor.
46
+	 *
47
+	 * @param EE_Registry|CoffeeShop $generator
48
+	 * @throws InvalidArgumentException
49
+	 */
50
+	public function __construct($generator)
51
+	{
52
+		if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
53
+			throw new InvalidArgumentException(
54
+				esc_html__(
55
+					'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
56
+					'event_espresso'
57
+				)
58
+			);
59
+		}
60
+		$this->generator = $generator;
61
+	}
62
+
63
+
64
+	/**
65
+	 * Calls the appropriate loading method from the installed generator;
66
+	 * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method
67
+	 * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(),
68
+	 * but NOT to the class being instantiated.
69
+	 * This is done by adding the parameters to the $arguments array as follows:
70
+	 *  array(
71
+	 *      'EE_Registry::create(from_db)'   => true, // boolean value, default = false
72
+	 *      'EE_Registry::create(load_only)' => true, // boolean value, default = false
73
+	 *      'EE_Registry::create(addon)'     => true, // boolean value, default = false
74
+	 *  )
75
+	 *
76
+	 * @param string $fqcn
77
+	 * @param array  $arguments
78
+	 * @param bool   $shared
79
+	 * @return mixed
80
+	 * @throws OutOfBoundsException
81
+	 * @throws ServiceExistsException
82
+	 * @throws InstantiationException
83
+	 * @throws InvalidIdentifierException
84
+	 * @throws InvalidDataTypeException
85
+	 * @throws InvalidClassException
86
+	 * @throws EE_Error
87
+	 * @throws ServiceNotFoundException
88
+	 * @throws ReflectionException
89
+	 * @throws InvalidInterfaceException
90
+	 */
91
+	public function load($fqcn, $arguments = array(), $shared = true)
92
+	{
93
+		$shared = filter_var($shared, FILTER_VALIDATE_BOOLEAN);
94
+		if($this->generator instanceof EE_Registry) {
95
+			// check if additional EE_Registry::create() arguments have been passed
96
+			// from_db
97
+			$from_db = isset($arguments['EE_Registry::create(from_db)'])
98
+				? filter_var($arguments['EE_Registry::create(from_db)'], FILTER_VALIDATE_BOOLEAN)
99
+				: false;
100
+			// load_only
101
+			$load_only = isset($arguments['EE_Registry::create(load_only)'])
102
+				? filter_var($arguments['EE_Registry::create(load_only)'], FILTER_VALIDATE_BOOLEAN)
103
+				: false;
104
+			// addon
105
+			$addon = isset($arguments['EE_Registry::create(addon)'])
106
+				? filter_var($arguments['EE_Registry::create(addon)'], FILTER_VALIDATE_BOOLEAN)
107
+				: false;
108
+			unset(
109
+				$arguments['EE_Registry::create(from_db)'],
110
+				$arguments['EE_Registry::create(load_only)'],
111
+				$arguments['EE_Registry::create(addon)']
112
+			);
113
+			// addons need to be cached on EE_Registry
114
+			$shared = $addon ? true : $shared;
115
+			return $this->generator->create(
116
+				$fqcn,
117
+				$arguments,
118
+				$shared,
119
+				$from_db,
120
+				$load_only,
121
+				$addon
122
+			);
123
+		}
124
+		return $this->generator->brew(
125
+			$fqcn,
126
+			$arguments,
127
+			$shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW
128
+		);
129
+
130
+	}
131
+
132
+
133
+
134
+	/**
135
+	 * calls reset() on generator if method exists
136
+	 */
137
+	public function reset()
138
+	{
139
+		if ($this->generator instanceof ResettableInterface) {
140
+			$this->generator->reset();
141
+		}
142
+	}
143 143
 
144 144
 }
145 145
 // End of file CoreLoader.php
Please login to merge, or discard this patch.
core/services/loaders/LoaderInterface.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -12,51 +12,51 @@
 block discarded – undo
12 12
 interface LoaderInterface
13 13
 {
14 14
 
15
-    /**
16
-     * Can be for instantiating a new instance of a class,
17
-     * or for getting a shared instance of a class (default)
18
-     *
19
-     * @param FullyQualifiedName|string $fqcn
20
-     * @param array                     $arguments
21
-     * @param bool                      $shared
22
-     * @return mixed
23
-     */
24
-    public function load($fqcn, array $arguments = array(), $shared = true);
25
-
26
-
27
-    /**
28
-     * Used for instantiating a new instance of a class
29
-     *
30
-     * @param FullyQualifiedName|string $fqcn
31
-     * @param array                     $arguments
32
-     * @return mixed
33
-     */
34
-    public function getNew($fqcn, array $arguments = array());
35
-
36
-
37
-    /**
38
-     * Used for getting a shared instance of a class
39
-     *
40
-     * @param FullyQualifiedName|string $fqcn
41
-     * @param array                     $arguments
42
-     * @return mixed
43
-     */
44
-    public function getShared($fqcn, array $arguments = array());
45
-
46
-
47
-    /**
48
-     * @param FullyQualifiedName|string $fqcn
49
-     * @param mixed                     $object
50
-     * @return bool
51
-     * @throws InvalidArgumentException
52
-     */
53
-    public function share($fqcn, $object);
54
-
55
-
56
-    /**
57
-     * calls reset() on loader if method exists
58
-     */
59
-    public function reset();
15
+	/**
16
+	 * Can be for instantiating a new instance of a class,
17
+	 * or for getting a shared instance of a class (default)
18
+	 *
19
+	 * @param FullyQualifiedName|string $fqcn
20
+	 * @param array                     $arguments
21
+	 * @param bool                      $shared
22
+	 * @return mixed
23
+	 */
24
+	public function load($fqcn, array $arguments = array(), $shared = true);
25
+
26
+
27
+	/**
28
+	 * Used for instantiating a new instance of a class
29
+	 *
30
+	 * @param FullyQualifiedName|string $fqcn
31
+	 * @param array                     $arguments
32
+	 * @return mixed
33
+	 */
34
+	public function getNew($fqcn, array $arguments = array());
35
+
36
+
37
+	/**
38
+	 * Used for getting a shared instance of a class
39
+	 *
40
+	 * @param FullyQualifiedName|string $fqcn
41
+	 * @param array                     $arguments
42
+	 * @return mixed
43
+	 */
44
+	public function getShared($fqcn, array $arguments = array());
45
+
46
+
47
+	/**
48
+	 * @param FullyQualifiedName|string $fqcn
49
+	 * @param mixed                     $object
50
+	 * @return bool
51
+	 * @throws InvalidArgumentException
52
+	 */
53
+	public function share($fqcn, $object);
54
+
55
+
56
+	/**
57
+	 * calls reset() on loader if method exists
58
+	 */
59
+	public function reset();
60 60
 }
61 61
 // End of file LoaderInterface.php
62 62
 // Location: core/services/loaders/LoaderInterface.php
Please login to merge, or discard this patch.
core/services/loaders/LoaderFactory.php 2 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -80,38 +80,38 @@
 block discarded – undo
80 80
 class LoaderFactory
81 81
 {
82 82
 
83
-    /**
84
-     * @var LoaderInterface $loader ;
85
-     */
86
-    private static $loader;
83
+	/**
84
+	 * @var LoaderInterface $loader ;
85
+	 */
86
+	private static $loader;
87 87
 
88 88
 
89
-    /**
90
-     * @param EE_Registry|CoffeeShop   $generator   provided during very first instantiation in
91
-     *                                              BootstrapDependencyInjectionContainer::buildLoader()
92
-     *                                              otherwise can be left null
93
-     * @param ClassInterfaceCache|null $class_cache also provided during first instantiation
94
-     * @return LoaderInterface
95
-     * @throws InvalidArgumentException
96
-     * @throws InvalidDataTypeException
97
-     * @throws InvalidInterfaceException
98
-     */
99
-    public static function getLoader($generator = null, ClassInterfaceCache $class_cache = null)
100
-    {
101
-        if (! LoaderFactory::$loader instanceof LoaderInterface && $generator !== null && $class_cache !== null) {
102
-            $core_loader = new CoreLoader($generator);
103
-            LoaderFactory::$loader = new Loader(
104
-                $core_loader,
105
-                new CachingLoader(
106
-                    $core_loader,
107
-                    new LooseCollection(''),
108
-                    $class_cache
109
-                ),
110
-                $class_cache
111
-            );
112
-        }
113
-        return LoaderFactory::$loader;
114
-    }
89
+	/**
90
+	 * @param EE_Registry|CoffeeShop   $generator   provided during very first instantiation in
91
+	 *                                              BootstrapDependencyInjectionContainer::buildLoader()
92
+	 *                                              otherwise can be left null
93
+	 * @param ClassInterfaceCache|null $class_cache also provided during first instantiation
94
+	 * @return LoaderInterface
95
+	 * @throws InvalidArgumentException
96
+	 * @throws InvalidDataTypeException
97
+	 * @throws InvalidInterfaceException
98
+	 */
99
+	public static function getLoader($generator = null, ClassInterfaceCache $class_cache = null)
100
+	{
101
+		if (! LoaderFactory::$loader instanceof LoaderInterface && $generator !== null && $class_cache !== null) {
102
+			$core_loader = new CoreLoader($generator);
103
+			LoaderFactory::$loader = new Loader(
104
+				$core_loader,
105
+				new CachingLoader(
106
+					$core_loader,
107
+					new LooseCollection(''),
108
+					$class_cache
109
+				),
110
+				$class_cache
111
+			);
112
+		}
113
+		return LoaderFactory::$loader;
114
+	}
115 115
 
116 116
 
117 117
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@
 block discarded – undo
98 98
      */
99 99
     public static function getLoader($generator = null, ClassInterfaceCache $class_cache = null)
100 100
     {
101
-        if (! LoaderFactory::$loader instanceof LoaderInterface && $generator !== null && $class_cache !== null) {
101
+        if ( ! LoaderFactory::$loader instanceof LoaderInterface && $generator !== null && $class_cache !== null) {
102 102
             $core_loader = new CoreLoader($generator);
103 103
             LoaderFactory::$loader = new Loader(
104 104
                 $core_loader,
Please login to merge, or discard this patch.
core/services/loaders/ClassInterfaceCache.php 2 patches
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -20,159 +20,159 @@
 block discarded – undo
20 20
 class ClassInterfaceCache
21 21
 {
22 22
 
23
-    /**
24
-     * array of interfaces indexed by FQCNs where values are arrays of interface FQNs
25
-     *
26
-     * @var string[][] $interfaces
27
-     */
28
-    private $interfaces = array();
29
-
30
-    /**
31
-     * @type string[][] $aliases
32
-     */
33
-    protected $aliases = array();
34
-
35
-
36
-
37
-    /**
38
-     * @param string $fqn
39
-     * @return string
40
-     */
41
-    public function getFqn($fqn)
42
-    {
43
-        return $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn;
44
-    }
45
-
46
-
47
-
48
-    /**
49
-     * @param string $fqn
50
-     * @return array
51
-     */
52
-    public function getInterfaces($fqn)
53
-    {
54
-        $fqn = $this->getFqn($fqn);
55
-        // have we already seen this FQCN ?
56
-        if (! array_key_exists($fqn, $this->interfaces)) {
57
-            $this->interfaces[ $fqn ] = array();
58
-            if (class_exists($fqn)) {
59
-                $this->interfaces[ $fqn ] = class_implements($fqn, false);
60
-                $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
61
-                    ? $this->interfaces[ $fqn ]
62
-                    : array();
63
-            }
64
-        }
65
-        return $this->interfaces[ $fqn ];
66
-    }
67
-
68
-
69
-    /**
70
-     * @param string $fqn
71
-     * @param string $interface
72
-     * @return bool
73
-     */
74
-    public function hasInterface($fqn, $interface)
75
-    {
76
-        $fqn = $this->getFqn($fqn);
77
-        $interfaces = $this->getInterfaces($fqn);
78
-        return in_array($interface, $interfaces, true);
79
-    }
80
-
81
-
82
-    /**
83
-     * adds an alias for a classname
84
-     *
85
-     * @param string $fqn       the class name that should be used (concrete class to replace interface)
86
-     * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
87
-     * @param string $for_class the class that has the dependency (is type hinting for the interface)
88
-     */
89
-    public function addAlias($fqn, $alias, $for_class = '')
90
-    {
91
-        $fqn = $this->getFqn($fqn);
92
-        $alias = $this->getFqn($alias);
93
-        if ($for_class !== '') {
94
-            if (! isset($this->aliases[ $for_class ])) {
95
-                $this->aliases[ $for_class ] = array();
96
-            }
97
-            $this->aliases[ $for_class ][ $alias ] = $fqn;
98
-        }
99
-        $this->aliases[ $alias ] = $fqn;
100
-    }
101
-
102
-
103
-    /**
104
-     * returns TRUE if the provided FQN is an alias
105
-     *
106
-     * @param string $fqn
107
-     * @param string $for_class
108
-     * @return bool
109
-     */
110
-    public function isAlias($fqn = '', $for_class = '')
111
-    {
112
-        $fqn = $this->getFqn($fqn);
113
-        if ($this->isAliasForClass($fqn, $for_class)) {
114
-            return true;
115
-        }
116
-        if($this->isDirectAlias($fqn)) {
117
-            return true;
118
-        }
119
-        return false;
120
-    }
121
-
122
-
123
-    /**
124
-     * returns TRUE if the provided FQN is an alias
125
-     *
126
-     * @param string $fqn
127
-     * @return bool
128
-     */
129
-    protected function isDirectAlias($fqn = '')
130
-    {
131
-        return isset($this->aliases[ (string) $fqn ]);
132
-    }
133
-
134
-
135
-    /**
136
-     * returns TRUE if the provided FQN is an alias for the specified class
137
-     *
138
-     * @param string $fqn
139
-     * @param string $for_class
140
-     * @return bool
141
-     */
142
-    protected function isAliasForClass($fqn = '', $for_class = '')
143
-    {
144
-        return (
145
-            $for_class !== ''
146
-            && isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
147
-        );
148
-    }
149
-
150
-
151
-    /**
152
-     * returns FQN for provided alias if one exists, otherwise returns the original FQN
153
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
154
-     *  for example:
155
-     *      if the following two entries were added to the aliases array:
156
-     *          array(
157
-     *              'interface_alias'           => 'some\namespace\interface'
158
-     *              'some\namespace\interface'  => 'some\namespace\classname'
159
-     *          )
160
-     *      then one could use Loader::getNew( 'interface_alias' )
161
-     *      to load an instance of 'some\namespace\classname'
162
-     *
163
-     * @param string $alias
164
-     * @param string $for_class
165
-     * @return string
166
-     */
167
-    public function getFqnForAlias($alias = '', $for_class = '')
168
-    {
169
-        $alias = $this->getFqn($alias);
170
-        if ($this->isAliasForClass($alias, $for_class)) {
171
-            return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
172
-        }
173
-        if ($this->isDirectAlias($alias)) {
174
-            return $this->getFqnForAlias($this->aliases[ (string) $alias ], '');
175
-        }
176
-        return $alias;
177
-    }
23
+	/**
24
+	 * array of interfaces indexed by FQCNs where values are arrays of interface FQNs
25
+	 *
26
+	 * @var string[][] $interfaces
27
+	 */
28
+	private $interfaces = array();
29
+
30
+	/**
31
+	 * @type string[][] $aliases
32
+	 */
33
+	protected $aliases = array();
34
+
35
+
36
+
37
+	/**
38
+	 * @param string $fqn
39
+	 * @return string
40
+	 */
41
+	public function getFqn($fqn)
42
+	{
43
+		return $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn;
44
+	}
45
+
46
+
47
+
48
+	/**
49
+	 * @param string $fqn
50
+	 * @return array
51
+	 */
52
+	public function getInterfaces($fqn)
53
+	{
54
+		$fqn = $this->getFqn($fqn);
55
+		// have we already seen this FQCN ?
56
+		if (! array_key_exists($fqn, $this->interfaces)) {
57
+			$this->interfaces[ $fqn ] = array();
58
+			if (class_exists($fqn)) {
59
+				$this->interfaces[ $fqn ] = class_implements($fqn, false);
60
+				$this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
61
+					? $this->interfaces[ $fqn ]
62
+					: array();
63
+			}
64
+		}
65
+		return $this->interfaces[ $fqn ];
66
+	}
67
+
68
+
69
+	/**
70
+	 * @param string $fqn
71
+	 * @param string $interface
72
+	 * @return bool
73
+	 */
74
+	public function hasInterface($fqn, $interface)
75
+	{
76
+		$fqn = $this->getFqn($fqn);
77
+		$interfaces = $this->getInterfaces($fqn);
78
+		return in_array($interface, $interfaces, true);
79
+	}
80
+
81
+
82
+	/**
83
+	 * adds an alias for a classname
84
+	 *
85
+	 * @param string $fqn       the class name that should be used (concrete class to replace interface)
86
+	 * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
87
+	 * @param string $for_class the class that has the dependency (is type hinting for the interface)
88
+	 */
89
+	public function addAlias($fqn, $alias, $for_class = '')
90
+	{
91
+		$fqn = $this->getFqn($fqn);
92
+		$alias = $this->getFqn($alias);
93
+		if ($for_class !== '') {
94
+			if (! isset($this->aliases[ $for_class ])) {
95
+				$this->aliases[ $for_class ] = array();
96
+			}
97
+			$this->aliases[ $for_class ][ $alias ] = $fqn;
98
+		}
99
+		$this->aliases[ $alias ] = $fqn;
100
+	}
101
+
102
+
103
+	/**
104
+	 * returns TRUE if the provided FQN is an alias
105
+	 *
106
+	 * @param string $fqn
107
+	 * @param string $for_class
108
+	 * @return bool
109
+	 */
110
+	public function isAlias($fqn = '', $for_class = '')
111
+	{
112
+		$fqn = $this->getFqn($fqn);
113
+		if ($this->isAliasForClass($fqn, $for_class)) {
114
+			return true;
115
+		}
116
+		if($this->isDirectAlias($fqn)) {
117
+			return true;
118
+		}
119
+		return false;
120
+	}
121
+
122
+
123
+	/**
124
+	 * returns TRUE if the provided FQN is an alias
125
+	 *
126
+	 * @param string $fqn
127
+	 * @return bool
128
+	 */
129
+	protected function isDirectAlias($fqn = '')
130
+	{
131
+		return isset($this->aliases[ (string) $fqn ]);
132
+	}
133
+
134
+
135
+	/**
136
+	 * returns TRUE if the provided FQN is an alias for the specified class
137
+	 *
138
+	 * @param string $fqn
139
+	 * @param string $for_class
140
+	 * @return bool
141
+	 */
142
+	protected function isAliasForClass($fqn = '', $for_class = '')
143
+	{
144
+		return (
145
+			$for_class !== ''
146
+			&& isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
147
+		);
148
+	}
149
+
150
+
151
+	/**
152
+	 * returns FQN for provided alias if one exists, otherwise returns the original FQN
153
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
154
+	 *  for example:
155
+	 *      if the following two entries were added to the aliases array:
156
+	 *          array(
157
+	 *              'interface_alias'           => 'some\namespace\interface'
158
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
159
+	 *          )
160
+	 *      then one could use Loader::getNew( 'interface_alias' )
161
+	 *      to load an instance of 'some\namespace\classname'
162
+	 *
163
+	 * @param string $alias
164
+	 * @param string $for_class
165
+	 * @return string
166
+	 */
167
+	public function getFqnForAlias($alias = '', $for_class = '')
168
+	{
169
+		$alias = $this->getFqn($alias);
170
+		if ($this->isAliasForClass($alias, $for_class)) {
171
+			return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
172
+		}
173
+		if ($this->isDirectAlias($alias)) {
174
+			return $this->getFqnForAlias($this->aliases[ (string) $alias ], '');
175
+		}
176
+		return $alias;
177
+	}
178 178
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -53,16 +53,16 @@  discard block
 block discarded – undo
53 53
     {
54 54
         $fqn = $this->getFqn($fqn);
55 55
         // have we already seen this FQCN ?
56
-        if (! array_key_exists($fqn, $this->interfaces)) {
57
-            $this->interfaces[ $fqn ] = array();
56
+        if ( ! array_key_exists($fqn, $this->interfaces)) {
57
+            $this->interfaces[$fqn] = array();
58 58
             if (class_exists($fqn)) {
59
-                $this->interfaces[ $fqn ] = class_implements($fqn, false);
60
-                $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
61
-                    ? $this->interfaces[ $fqn ]
59
+                $this->interfaces[$fqn] = class_implements($fqn, false);
60
+                $this->interfaces[$fqn] = $this->interfaces[$fqn] !== false
61
+                    ? $this->interfaces[$fqn]
62 62
                     : array();
63 63
             }
64 64
         }
65
-        return $this->interfaces[ $fqn ];
65
+        return $this->interfaces[$fqn];
66 66
     }
67 67
 
68 68
 
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
         $fqn = $this->getFqn($fqn);
92 92
         $alias = $this->getFqn($alias);
93 93
         if ($for_class !== '') {
94
-            if (! isset($this->aliases[ $for_class ])) {
95
-                $this->aliases[ $for_class ] = array();
94
+            if ( ! isset($this->aliases[$for_class])) {
95
+                $this->aliases[$for_class] = array();
96 96
             }
97
-            $this->aliases[ $for_class ][ $alias ] = $fqn;
97
+            $this->aliases[$for_class][$alias] = $fqn;
98 98
         }
99
-        $this->aliases[ $alias ] = $fqn;
99
+        $this->aliases[$alias] = $fqn;
100 100
     }
101 101
 
102 102
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
         if ($this->isAliasForClass($fqn, $for_class)) {
114 114
             return true;
115 115
         }
116
-        if($this->isDirectAlias($fqn)) {
116
+        if ($this->isDirectAlias($fqn)) {
117 117
             return true;
118 118
         }
119 119
         return false;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      */
129 129
     protected function isDirectAlias($fqn = '')
130 130
     {
131
-        return isset($this->aliases[ (string) $fqn ]);
131
+        return isset($this->aliases[(string) $fqn]);
132 132
     }
133 133
 
134 134
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
     {
144 144
         return (
145 145
             $for_class !== ''
146
-            && isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
146
+            && isset($this->aliases[(string) $for_class][(string) $fqn])
147 147
         );
148 148
     }
149 149
 
@@ -168,10 +168,10 @@  discard block
 block discarded – undo
168 168
     {
169 169
         $alias = $this->getFqn($alias);
170 170
         if ($this->isAliasForClass($alias, $for_class)) {
171
-            return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
171
+            return $this->getFqnForAlias($this->aliases[(string) $for_class][(string) $alias], $for_class);
172 172
         }
173 173
         if ($this->isDirectAlias($alias)) {
174
-            return $this->getFqnForAlias($this->aliases[ (string) $alias ], '');
174
+            return $this->getFqnForAlias($this->aliases[(string) $alias], '');
175 175
         }
176 176
         return $alias;
177 177
     }
Please login to merge, or discard this patch.
core/services/request/Response.php 1 patch
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -20,130 +20,130 @@
 block discarded – undo
20 20
 class Response implements ResponseInterface, ReservedInstanceInterface
21 21
 {
22 22
 
23
-    /**
24
-     * @var array $notice
25
-     */
26
-    protected $notice = array();
23
+	/**
24
+	 * @var array $notice
25
+	 */
26
+	protected $notice = array();
27 27
 
28
-    /**
29
-     * rendered output to be returned to WP
30
-     *
31
-     * @var string $output
32
-     */
33
-    protected $output = '';
28
+	/**
29
+	 * rendered output to be returned to WP
30
+	 *
31
+	 * @var string $output
32
+	 */
33
+	protected $output = '';
34 34
 
35
-    /**
36
-     * @var bool
37
-     */
38
-    protected $request_terminated = false;
35
+	/**
36
+	 * @var bool
37
+	 */
38
+	protected $request_terminated = false;
39 39
 
40
-    /**
41
-     * @var bool $deactivate_plugin
42
-     */
43
-    protected $deactivate_plugin = false;
40
+	/**
41
+	 * @var bool $deactivate_plugin
42
+	 */
43
+	protected $deactivate_plugin = false;
44 44
 
45 45
 
46
-    /**
47
-     * EE_Response constructor.
48
-     */
49
-    public function __construct()
50
-    {
51
-        $this->terminateRequest(false);
52
-    }
46
+	/**
47
+	 * EE_Response constructor.
48
+	 */
49
+	public function __construct()
50
+	{
51
+		$this->terminateRequest(false);
52
+	}
53 53
 
54 54
 
55 55
 
56
-    /**
57
-     * @param $key
58
-     * @param $value
59
-     * @return    void
60
-     */
61
-    public function setNotice($key, $value)
62
-    {
63
-        $this->notice[ $key ] = $value;
64
-    }
56
+	/**
57
+	 * @param $key
58
+	 * @param $value
59
+	 * @return    void
60
+	 */
61
+	public function setNotice($key, $value)
62
+	{
63
+		$this->notice[ $key ] = $value;
64
+	}
65 65
 
66 66
 
67 67
 
68
-    /**
69
-     * @param $key
70
-     * @return    mixed
71
-     */
72
-    public function getNotice($key)
73
-    {
74
-        return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null;
75
-    }
68
+	/**
69
+	 * @param $key
70
+	 * @return    mixed
71
+	 */
72
+	public function getNotice($key)
73
+	{
74
+		return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null;
75
+	}
76 76
 
77 77
 
78 78
 
79
-    /**
80
-     * @return array
81
-     */
82
-    public function getNotices()
83
-    {
84
-        return $this->notice;
85
-    }
79
+	/**
80
+	 * @return array
81
+	 */
82
+	public function getNotices()
83
+	{
84
+		return $this->notice;
85
+	}
86 86
 
87 87
 
88 88
 
89
-    /**
90
-     * @param string $string
91
-     * @param bool   $append
92
-     */
93
-    public function addOutput($string, $append = true)
94
-    {
95
-        $this->output = $append ? $this->output . $string : $string . $this->output;
96
-    }
89
+	/**
90
+	 * @param string $string
91
+	 * @param bool   $append
92
+	 */
93
+	public function addOutput($string, $append = true)
94
+	{
95
+		$this->output = $append ? $this->output . $string : $string . $this->output;
96
+	}
97 97
 
98 98
 
99 99
 
100
-    /**
101
-     * @return string
102
-     */
103
-    public function getOutput()
104
-    {
105
-        return $this->output;
106
-    }
100
+	/**
101
+	 * @return string
102
+	 */
103
+	public function getOutput()
104
+	{
105
+		return $this->output;
106
+	}
107 107
 
108 108
 
109 109
 
110
-    /**
111
-     * @return boolean
112
-     */
113
-    public function requestTerminated()
114
-    {
115
-        return $this->request_terminated;
116
-    }
110
+	/**
111
+	 * @return boolean
112
+	 */
113
+	public function requestTerminated()
114
+	{
115
+		return $this->request_terminated;
116
+	}
117 117
 
118 118
 
119 119
 
120
-    /**
121
-     * @param boolean $request_terminated
122
-     */
123
-    public function terminateRequest($request_terminated = true)
124
-    {
125
-        $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN);
126
-    }
120
+	/**
121
+	 * @param boolean $request_terminated
122
+	 */
123
+	public function terminateRequest($request_terminated = true)
124
+	{
125
+		$this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN);
126
+	}
127 127
 
128 128
 
129 129
 
130
-    /**
131
-     * @return boolean
132
-     */
133
-    public function pluginDeactivated()
134
-    {
135
-        return $this->deactivate_plugin;
136
-    }
130
+	/**
131
+	 * @return boolean
132
+	 */
133
+	public function pluginDeactivated()
134
+	{
135
+		return $this->deactivate_plugin;
136
+	}
137 137
 
138 138
 
139 139
 
140
-    /**
141
-     * sets $deactivate_plugin to true
142
-     */
143
-    public function deactivatePlugin()
144
-    {
145
-        $this->deactivate_plugin = true;
146
-    }
140
+	/**
141
+	 * sets $deactivate_plugin to true
142
+	 */
143
+	public function deactivatePlugin()
144
+	{
145
+		$this->deactivate_plugin = true;
146
+	}
147 147
 
148 148
 
149 149
 }
Please login to merge, or discard this patch.