Completed
Branch FET/11183/improvements-to-pue-... (232f50)
by
unknown
43:46 queued 26:36
created

EE_Dependency_Map::setRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
use EventEspresso\core\exceptions\InvalidDataTypeException;
3
use EventEspresso\core\exceptions\InvalidInterfaceException;
4
use EventEspresso\core\services\loaders\LoaderFactory;
5
use EventEspresso\core\services\loaders\LoaderInterface;
6
use EventEspresso\core\services\request\LegacyRequestInterface;
7
use EventEspresso\core\services\request\RequestInterface;
8
use EventEspresso\core\services\request\ResponseInterface;
9
10
if (! defined('EVENT_ESPRESSO_VERSION')) {
11
    exit('No direct script access allowed');
12
}
13
14
15
16
/**
17
 * Class EE_Dependency_Map
18
 * info about how to load classes required by other classes
19
 *
20
 * @package       Event Espresso
21
 * @subpackage    core
22
 * @author        Brent Christensen
23
 * @since         4.9.0
24
 */
25
class EE_Dependency_Map
26
{
27
28
    /**
29
     * This means that the requested class dependency is not present in the dependency map
30
     */
31
    const not_registered = 0;
32
33
    /**
34
     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
35
     */
36
    const load_new_object = 1;
37
38
    /**
39
     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
40
     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
41
     */
42
    const load_from_cache = 2;
43
44
    /**
45
     * When registering a dependency,
46
     * this indicates to keep any existing dependencies that already exist,
47
     * and simply discard any new dependencies declared in the incoming data
48
     */
49
    const KEEP_EXISTING_DEPENDENCIES = 0;
50
51
    /**
52
     * When registering a dependency,
53
     * this indicates to overwrite any existing dependencies that already exist using the incoming data
54
     */
55
    const OVERWRITE_DEPENDENCIES = 1;
56
57
58
59
    /**
60
     * @type EE_Dependency_Map $_instance
61
     */
62
    protected static $_instance;
63
64
    /**
65
     * @type RequestInterface $request
66
     */
67
    protected $request;
68
69
    /**
70
     * @type LegacyRequestInterface $legacy_request
71
     */
72
    protected $legacy_request;
73
74
    /**
75
     * @type ResponseInterface $response
76
     */
77
    protected $response;
78
79
    /**
80
     * @type LoaderInterface $loader
81
     */
82
    protected $loader;
83
84
    /**
85
     * @type array $_dependency_map
86
     */
87
    protected $_dependency_map = array();
88
89
    /**
90
     * @type array $_class_loaders
91
     */
92
    protected $_class_loaders = array();
93
94
    /**
95
     * @type array $_aliases
96
     */
97
    protected $_aliases = array();
98
99
100
101
    /**
102
     * EE_Dependency_Map constructor.
103
     */
104
    protected function __construct()
105
    {
106
        // add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
107
        do_action('EE_Dependency_Map____construct');
108
    }
109
110
111
112
    /**
113
     * @throws InvalidDataTypeException
114
     * @throws InvalidInterfaceException
115
     * @throws InvalidArgumentException
116
     */
117
    public function initialize()
118
    {
119
        $this->_register_core_dependencies();
120
        $this->_register_core_class_loaders();
121
        $this->_register_core_aliases();
122
    }
123
124
125
126
    /**
127
     * @singleton method used to instantiate class object
128
     * @return EE_Dependency_Map
129
     */
130
    public static function instance() {
131
        // check if class object is instantiated, and instantiated properly
132
        if (! self::$_instance instanceof EE_Dependency_Map) {
133
            self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/);
134
        }
135
        return self::$_instance;
136
    }
137
138
139
    /**
140
     * @param RequestInterface $request
141
     */
142
    public function setRequest(RequestInterface $request)
143
    {
144
        $this->request = $request;
145
    }
146
147
148
    /**
149
     * @param LegacyRequestInterface $legacy_request
150
     */
151
    public function setLegacyRequest(LegacyRequestInterface $legacy_request)
152
    {
153
        $this->legacy_request = $legacy_request;
154
    }
155
156
157
    /**
158
     * @param ResponseInterface $response
159
     */
160
    public function setResponse(ResponseInterface $response)
161
    {
162
        $this->response = $response;
163
    }
164
165
166
167
    /**
168
     * @param LoaderInterface $loader
169
     */
170
    public function setLoader(LoaderInterface $loader)
171
    {
172
        $this->loader = $loader;
173
    }
174
175
176
177
    /**
178
     * @param string $class
179
     * @param array  $dependencies
180
     * @param int    $overwrite
181
     * @return bool
182
     */
183
    public static function register_dependencies(
184
        $class,
185
        array $dependencies,
186
        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
187
    ) {
188
        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
189
    }
190
191
192
193
    /**
194
     * Assigns an array of class names and corresponding load sources (new or cached)
195
     * to the class specified by the first parameter.
196
     * IMPORTANT !!!
197
     * The order of elements in the incoming $dependencies array MUST match
198
     * the order of the constructor parameters for the class in question.
199
     * This is especially important when overriding any existing dependencies that are registered.
200
     * the third parameter controls whether any duplicate dependencies are overwritten or not.
201
     *
202
     * @param string $class
203
     * @param array  $dependencies
204
     * @param int    $overwrite
205
     * @return bool
206
     */
207
    public function registerDependencies(
208
        $class,
209
        array $dependencies,
210
        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
211
    ) {
212
        $class = trim($class, '\\');
213
        $registered = false;
214
        if (empty(self::$_instance->_dependency_map[ $class ])) {
215
            self::$_instance->_dependency_map[ $class ] = array();
216
        }
217
        // we need to make sure that any aliases used when registering a dependency
218
        // get resolved to the correct class name
219
        foreach ($dependencies as $dependency => $load_source) {
220
            $alias = self::$_instance->get_alias($dependency);
221
            if (
222
                $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
223
                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
224
            ) {
225
                unset($dependencies[$dependency]);
226
                $dependencies[$alias] = $load_source;
227
                $registered = true;
228
            }
229
        }
230
        // now add our two lists of dependencies together.
231
        // using Union (+=) favours the arrays in precedence from left to right,
232
        // so $dependencies is NOT overwritten because it is listed first
233
        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
234
        // Union is way faster than array_merge() but should be used with caution...
235
        // especially with numerically indexed arrays
236
        $dependencies += self::$_instance->_dependency_map[ $class ];
237
        // now we need to ensure that the resulting dependencies
238
        // array only has the entries that are required for the class
239
        // so first count how many dependencies were originally registered for the class
240
        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
241
        // if that count is non-zero (meaning dependencies were already registered)
242
        self::$_instance->_dependency_map[ $class ] = $dependency_count
243
            // then truncate the  final array to match that count
244
            ? array_slice($dependencies, 0, $dependency_count)
245
            // otherwise just take the incoming array because nothing previously existed
246
            : $dependencies;
247
        return $registered;
248
    }
249
250
251
252
    /**
253
     * @param string $class_name
254
     * @param string $loader
255
     * @return bool
256
     * @throws DomainException
257
     */
258
    public static function register_class_loader($class_name, $loader = 'load_core')
259
    {
260
        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
261
            throw new DomainException(
262
                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
263
            );
264
        }
265
        // check that loader is callable or method starts with "load_" and exists in EE_Registry
266
        if (
267
            ! is_callable($loader)
268
            && (
269
                strpos($loader, 'load_') !== 0
270
                || ! method_exists('EE_Registry', $loader)
271
            )
272
        ) {
273
            throw new DomainException(
274
                sprintf(
275
                    esc_html__(
276
                        '"%1$s" is not a valid loader method on EE_Registry.',
277
                        'event_espresso'
278
                    ),
279
                    $loader
280
                )
281
            );
282
        }
283
        $class_name = self::$_instance->get_alias($class_name);
284
        if (! isset(self::$_instance->_class_loaders[$class_name])) {
285
            self::$_instance->_class_loaders[$class_name] = $loader;
286
            return true;
287
        }
288
        return false;
289
    }
290
291
292
293
    /**
294
     * @return array
295
     */
296
    public function dependency_map()
297
    {
298
        return $this->_dependency_map;
299
    }
300
301
302
303
    /**
304
     * returns TRUE if dependency map contains a listing for the provided class name
305
     *
306
     * @param string $class_name
307
     * @return boolean
308
     */
309
    public function has($class_name = '')
310
    {
311
        // all legacy models have the same dependencies
312
        if (strpos($class_name, 'EEM_') === 0) {
313
            $class_name = 'LEGACY_MODELS';
314
        }
315
        return isset($this->_dependency_map[$class_name]) ? true : false;
316
    }
317
318
319
320
    /**
321
     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
322
     *
323
     * @param string $class_name
324
     * @param string $dependency
325
     * @return bool
326
     */
327
    public function has_dependency_for_class($class_name = '', $dependency = '')
328
    {
329
        // all legacy models have the same dependencies
330
        if (strpos($class_name, 'EEM_') === 0) {
331
            $class_name = 'LEGACY_MODELS';
332
        }
333
        $dependency = $this->get_alias($dependency);
334
        return isset($this->_dependency_map[$class_name][$dependency])
335
            ? true
336
            : false;
337
    }
338
339
340
341
    /**
342
     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
343
     *
344
     * @param string $class_name
345
     * @param string $dependency
346
     * @return int
347
     */
348
    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
349
    {
350
        // all legacy models have the same dependencies
351
        if (strpos($class_name, 'EEM_') === 0) {
352
            $class_name = 'LEGACY_MODELS';
353
        }
354
        $dependency = $this->get_alias($dependency);
355
        return $this->has_dependency_for_class($class_name, $dependency)
356
            ? $this->_dependency_map[$class_name][$dependency]
357
            : EE_Dependency_Map::not_registered;
358
    }
359
360
361
362
    /**
363
     * @param string $class_name
364
     * @return string | Closure
365
     */
366
    public function class_loader($class_name)
367
    {
368
        // all legacy models use load_model()
369
        if(strpos($class_name, 'EEM_') === 0){
370
            return 'load_model';
371
        }
372
        $class_name = $this->get_alias($class_name);
373
        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
374
    }
375
376
377
378
    /**
379
     * @return array
380
     */
381
    public function class_loaders()
382
    {
383
        return $this->_class_loaders;
384
    }
385
386
387
388
    /**
389
     * adds an alias for a classname
390
     *
391
     * @param string $class_name the class name that should be used (concrete class to replace interface)
392
     * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
393
     * @param string $for_class  the class that has the dependency (is type hinting for the interface)
394
     */
395
    public function add_alias($class_name, $alias, $for_class = '')
396
    {
397
        if ($for_class !== '') {
398
            if (! isset($this->_aliases[$for_class])) {
399
                $this->_aliases[$for_class] = array();
400
            }
401
            $this->_aliases[$for_class][$class_name] = $alias;
402
        }
403
        $this->_aliases[$class_name] = $alias;
404
    }
405
406
407
408
    /**
409
     * returns TRUE if the provided class name has an alias
410
     *
411
     * @param string $class_name
412
     * @param string $for_class
413
     * @return bool
414
     */
415
    public function has_alias($class_name = '', $for_class = '')
416
    {
417
        return isset($this->_aliases[$for_class][$class_name])
418
               || (
419
                   isset($this->_aliases[$class_name])
420
                   && ! is_array($this->_aliases[$class_name])
421
               );
422
    }
423
424
425
426
    /**
427
     * returns alias for class name if one exists, otherwise returns the original classname
428
     * functions recursively, so that multiple aliases can be used to drill down to a classname
429
     *  for example:
430
     *      if the following two entries were added to the _aliases array:
431
     *          array(
432
     *              'interface_alias'           => 'some\namespace\interface'
433
     *              'some\namespace\interface'  => 'some\namespace\classname'
434
     *          )
435
     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
436
     *      to load an instance of 'some\namespace\classname'
437
     *
438
     * @param string $class_name
439
     * @param string $for_class
440
     * @return string
441
     */
442
    public function get_alias($class_name = '', $for_class = '')
443
    {
444
        if (! $this->has_alias($class_name, $for_class)) {
445
            return $class_name;
446
        }
447
        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
448
            return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
449
        }
450
        return $this->get_alias($this->_aliases[$class_name]);
451
    }
452
453
454
455
    /**
456
     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
457
     * if one exists, or whether a new object should be generated every time the requested class is loaded.
458
     * This is done by using the following class constants:
459
     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
460
     *        EE_Dependency_Map::load_new_object - generates a new object every time
461
     */
462
    protected function _register_core_dependencies()
463
    {
464
        $this->_dependency_map = array(
465
            'EE_Request_Handler'                                                                                          => array(
466
                'EE_Request' => EE_Dependency_Map::load_from_cache,
467
            ),
468
            'EE_System'                                                                                                   => array(
469
                'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
470
                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
471
                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
472
                'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
473
            ),
474
            'EE_Session'                                                                                                  => array(
475
                'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
476
                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
477
                'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
478
                'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
479
            ),
480
            'EE_Cart'                                                                                                     => array(
481
                'EE_Session' => EE_Dependency_Map::load_from_cache,
482
            ),
483
            'EE_Front_Controller'                                                                                         => array(
484
                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
485
                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
486
                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
487
            ),
488
            'EE_Messenger_Collection_Loader'                                                                              => array(
489
                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
490
            ),
491
            'EE_Message_Type_Collection_Loader'                                                                           => array(
492
                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
493
            ),
494
            'EE_Message_Resource_Manager'                                                                                 => array(
495
                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
496
                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
497
                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
498
            ),
499
            'EE_Message_Factory'                                                                                          => array(
500
                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
501
            ),
502
            'EE_messages'                                                                                                 => array(
503
                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
504
            ),
505
            'EE_Messages_Generator'                                                                                       => array(
506
                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
507
                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
508
                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
509
                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
510
            ),
511
            'EE_Messages_Processor'                                                                                       => array(
512
                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
513
            ),
514
            'EE_Messages_Queue'                                                                                           => array(
515
                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
516
            ),
517
            'EE_Messages_Template_Defaults'                                                                               => array(
518
                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
519
                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
520
            ),
521
            'EE_Message_To_Generate_From_Request'                                                                         => array(
522
                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
523
                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
524
            ),
525
            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
526
                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
527
            ),
528
            'EventEspresso\services\commands\CommandHandler'                                                              => array(
529
                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
530
                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
531
            ),
532
            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
533
                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
534
            ),
535
            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
536
                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
537
                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
538
            ),
539
            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
540
                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
541
            ),
542
            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
543
                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
544
            ),
545
            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
546
                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
547
            ),
548
            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
549
                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
550
            ),
551
            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
552
                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
553
            ),
554
            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
555
                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
556
            ),
557
            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
558
                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
559
            ),
560
            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
561
                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
562
            ),
563
            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
564
                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
565
            ),
566
            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
567
                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
568
            ),
569
            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
570
                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
571
            ),
572
            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
573
                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
574
            ),
575
            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
576
                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
577
            ),
578
            'EventEspresso\core\services\database\TableManager'                                                           => array(
579
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
            ),
581
            'EE_Data_Migration_Class_Base'                                                                                => array(
582
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
583
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
584
            ),
585
            'EE_DMS_Core_4_1_0'                                                                                           => array(
586
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
587
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
588
            ),
589
            'EE_DMS_Core_4_2_0'                                                                                           => array(
590
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
591
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
592
            ),
593
            'EE_DMS_Core_4_3_0'                                                                                           => array(
594
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
595
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
596
            ),
597
            'EE_DMS_Core_4_4_0'                                                                                           => array(
598
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
599
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
600
            ),
601
            'EE_DMS_Core_4_5_0'                                                                                           => array(
602
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
603
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
604
            ),
605
            'EE_DMS_Core_4_6_0'                                                                                           => array(
606
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
607
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
608
            ),
609
            'EE_DMS_Core_4_7_0'                                                                                           => array(
610
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
611
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
612
            ),
613
            'EE_DMS_Core_4_8_0'                                                                                           => array(
614
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
615
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
616
            ),
617
            'EE_DMS_Core_4_9_0'                                                                                           => array(
618
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
619
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
620
            ),
621
            'EventEspresso\core\services\assets\Registry'                                                                 => array(
622
                'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
623
                'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
624
                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
625
            ),
626
            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
627
                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
628
            ),
629
            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
630
                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
631
            ),
632
            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
633
                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
634
            ),
635
            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
636
                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
637
            ),
638
            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
639
                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
640
            ),
641
            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
642
                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
643
            ),
644
            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
645
                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
646
            ),
647
            'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
648
                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
649
            ),
650
            'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
651
                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
652
            ),
653
            'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
654
                'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
655
                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
656
            ),
657
            'EventEspresso\core\domain\values\EmailAddress'                              => array(
658
                null,
659
                'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
660
            ),
661
            'EventEspresso\core\services\orm\ModelFieldFactory' => array(
662
                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
663
            ),
664
            'LEGACY_MODELS'                                                   => array(
665
                null,
666
                'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
667
            ),
668
            'EE_Module_Request_Router' => array(
669
                'EE_Request' => EE_Dependency_Map::load_from_cache,
670
            ),
671
            'EE_Registration_Processor' => array(
672
                'EE_Request' => EE_Dependency_Map::load_from_cache,
673
            ),
674
            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array(
675
                null,
676
                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
677
                'EE_Request' => EE_Dependency_Map::load_from_cache,
678
            ),
679
            'EventEspresso\core\services\licensing\LicenseService' => array(
680
                'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache,
681
                'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache
682
            ),
683
			'EE_Admin_Transactions_List_Table' => array(
684
                null,
685
                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
686
			),
687
            'EventEspresso\core\domain\services\pue\Stats' => array(
688
                'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
689
                'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache,
690
                'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache
691
            ),
692
            'EventEspresso\core\domain\services\pue\Config' => array(
693
                'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
694
                'EE_Config' => EE_Dependency_Map::load_from_cache
695
            ),
696
            'EventEspresso\core\domain\services\pue\StatsGatherer' => array(
697
                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
698
                'EEM_Event' => EE_Dependency_Map::load_from_cache,
699
                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
700
                'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
701
                'EEM_Registration' => EE_Dependency_Map::load_from_cache,
702
                'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
703
                'EE_Config' => EE_Dependency_Map::load_from_cache
704
            )
705
        );
706
    }
707
708
709
710
    /**
711
     * Registers how core classes are loaded.
712
     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
713
     *        'EE_Request_Handler' => 'load_core'
714
     *        'EE_Messages_Queue'  => 'load_lib'
715
     *        'EEH_Debug_Tools'    => 'load_helper'
716
     * or, if greater control is required, by providing a custom closure. For example:
717
     *        'Some_Class' => function () {
718
     *            return new Some_Class();
719
     *        },
720
     * This is required for instantiating dependencies
721
     * where an interface has been type hinted in a class constructor. For example:
722
     *        'Required_Interface' => function () {
723
     *            return new A_Class_That_Implements_Required_Interface();
724
     *        },
725
     *
726
     * @throws InvalidInterfaceException
727
     * @throws InvalidDataTypeException
728
     * @throws InvalidArgumentException
729
     */
730
    protected function _register_core_class_loaders()
731
    {
732
        //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
733
        //be used in a closure.
734
        $request = &$this->request;
735
        $response = &$this->response;
736
        $legacy_request = &$this->legacy_request;
737
        // $loader = &$this->loader;
738
        $this->_class_loaders = array(
739
            //load_core
740
            'EE_Capabilities'          => 'load_core',
741
            'EE_Encryption'            => 'load_core',
742
            'EE_Front_Controller'      => 'load_core',
743
            'EE_Module_Request_Router' => 'load_core',
744
            'EE_Registry'              => 'load_core',
745
            'EE_Request'               => function () use (&$legacy_request) {
746
                return $legacy_request;
747
            },
748
            'EventEspresso\core\services\request\Request' => function () use (&$request) {
749
                return $request;
750
            },
751
            'EventEspresso\core\services\request\Response' => function () use (&$response) {
752
                return $response;
753
            },
754
            'EE_Request_Handler'       => 'load_core',
755
            'EE_Session'               => 'load_core',
756
            'EE_Cron_Tasks'            => 'load_core',
757
            'EE_System'                => 'load_core',
758
            'EE_Maintenance_Mode'      => 'load_core',
759
            'EE_Register_CPTs'         => 'load_core',
760
            'EE_Admin'                 => 'load_core',
761
            //load_lib
762
            'EE_Message_Resource_Manager'          => 'load_lib',
763
            'EE_Message_Type_Collection'           => 'load_lib',
764
            'EE_Message_Type_Collection_Loader'    => 'load_lib',
765
            'EE_Messenger_Collection'              => 'load_lib',
766
            'EE_Messenger_Collection_Loader'       => 'load_lib',
767
            'EE_Messages_Processor'                => 'load_lib',
768
            'EE_Message_Repository'                => 'load_lib',
769
            'EE_Messages_Queue'                    => 'load_lib',
770
            'EE_Messages_Data_Handler_Collection'  => 'load_lib',
771
            'EE_Message_Template_Group_Collection' => 'load_lib',
772
            'EE_Payment_Method_Manager'            => 'load_lib',
773
            'EE_Messages_Generator'                => function () {
774
                return EE_Registry::instance()->load_lib(
775
                    'Messages_Generator',
776
                    array(),
777
                    false,
778
                    false
779
                );
780
            },
781
            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
782
                return EE_Registry::instance()->load_lib(
783
                    'Messages_Template_Defaults',
784
                    $arguments,
785
                    false,
786
                    false
787
                );
788
            },
789
            //load_helper
790
            'EEH_Parse_Shortcodes'                 => function () {
791
                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
792
                    return new EEH_Parse_Shortcodes();
793
                }
794
                return null;
795
            },
796
            'EE_Template_Config'                   => function () {
797
                return EE_Config::instance()->template_settings;
798
            },
799
            'EE_Currency_Config'                   => function () {
800
                return EE_Config::instance()->currency;
801
            },
802
            'EE_Registration_Config'                   => function () {
803
                return EE_Config::instance()->registration;
804
            },
805
            'EventEspresso\core\services\loaders\Loader' => function () {
806
                return LoaderFactory::getLoader();
807
            },
808
            'EE_Network_Config' => function() {
809
                return EE_Network_Config::instance();
810
            },
811
            'EE_Config' => function () {
812
                return EE_Config::instance();
813
            }
814
        );
815
    }
816
817
818
819
    /**
820
     * can be used for supplying alternate names for classes,
821
     * or for connecting interface names to instantiable classes
822
     */
823
    protected function _register_core_aliases()
824
    {
825
        $this->_aliases = array(
826
            'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
827
            'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
828
            'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
829
            'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
830
            'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
831
            'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
832
            'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
833
            'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
834
            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
835
            'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
836
            'CreateRegCodeCommandHandler'                                                  => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
837
            'CreateRegUrlLinkCommandHandler'                                               => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
838
            'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
839
            'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
840
            'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
841
            'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
842
            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
843
            'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
844
            'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
845
            'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
846
            'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
847
            'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
848
            'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
849
            'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
850
            'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
851
            'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
852
            'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
853
            'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
854
            'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
855
            'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
856
            'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
857
            'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
858
            'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
859
            'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
860
            'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
861
            'NoticesContainerInterface'                                           => 'EventEspresso\core\services\notices\NoticesContainerInterface',
862
            'EventEspresso\core\services\notices\NoticesContainerInterface'       => 'EventEspresso\core\services\notices\NoticesContainer',
863
            'EventEspresso\core\services\request\RequestInterface'                => 'EventEspresso\core\services\request\Request',
864
            'EventEspresso\core\services\request\ResponseInterface'               => 'EventEspresso\core\services\request\Response',
865
            'EventEspresso\core\domain\DomainInterface'                           => 'EventEspresso\core\domain\Domain',
866
        );
867
        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
868
            $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices';
869
        }
870
    }
871
872
873
874
    /**
875
     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
876
     * request Primarily used by unit tests.
877
     *
878
     * @throws InvalidDataTypeException
879
     * @throws InvalidInterfaceException
880
     * @throws InvalidArgumentException
881
     */
882
    public function reset()
883
    {
884
        $this->_register_core_class_loaders();
885
        $this->_register_core_dependencies();
886
    }
887
888
889
}
890
// End of file EE_Dependency_Map.core.php
891
// Location: /EE_Dependency_Map.core.php
892