Completed
Branch BUG-10626-dst-unit-test (cc62a6)
by
unknown
37:15 queued 23:58
created

EE_Dependency_Map   B

Complexity

Total Complexity 44

Size/Duplication

Total Lines 737
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 737
rs 8
c 0
b 0
f 0
wmc 44
lcom 1
cbo 3

20 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A initialize() 0 6 1
A instance() 0 8 2
A setLoader() 0 4 1
A register_dependencies() 0 7 1
B registerDependencies() 0 42 6
A dependency_map() 0 4 1
A has() 0 4 2
A loading_strategy_for_class_dependency() 0 7 2
A _register_core_class_loaders() 0 71 2
A has_dependency_for_class() 0 7 2
C register_class_loader() 0 32 7
A class_loader() 0 5 2
A class_loaders() 0 4 1
A add_alias() 0 10 3
A has_alias() 0 8 3
A get_alias() 0 10 4
B _register_core_dependencies() 0 187 1
B _register_core_aliases() 0 40 1
A reset() 0 5 1

How to fix   Complexity   

Complex Class

Complex classes like EE_Dependency_Map often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use EE_Dependency_Map, and based on these observations, apply Extract Interface, too.

1
<?php
2
use EventEspresso\core\exceptions\InvalidDataTypeException;
3
use EventEspresso\core\exceptions\InvalidInterfaceException;
4
use EventEspresso\core\services\loaders\LoaderInterface;
5
6
if (! defined('EVENT_ESPRESSO_VERSION')) {
7
    exit('No direct script access allowed');
8
}
9
10
11
12
/**
13
 * Class EE_Dependency_Map
14
 * info about how to load classes required by other classes
15
 *
16
 * @package       Event Espresso
17
 * @subpackage    core
18
 * @author        Brent Christensen
19
 * @since         4.9.0
20
 */
21
class EE_Dependency_Map
22
{
23
24
    /**
25
     * This means that the requested class dependency is not present in the dependency map
26
     */
27
    const not_registered = 0;
28
29
    /**
30
     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
31
     */
32
    const load_new_object = 1;
33
34
    /**
35
     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
36
     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
37
     */
38
    const load_from_cache = 2;
39
40
    /**
41
     * When registering a dependency,
42
     * this indicates to keep any existing dependencies that already exist,
43
     * and simply discard any new dependencies declared in the incoming data
44
     */
45
    const KEEP_EXISTING_DEPENDENCIES = 0;
46
47
    /**
48
     * When registering a dependency,
49
     * this indicates to overwrite any existing dependencies that already exist using the incoming data
50
     */
51
    const OVERWRITE_DEPENDENCIES = 1;
52
53
54
55
    /**
56
     * @type EE_Dependency_Map $_instance
57
     */
58
    protected static $_instance;
59
60
    /**
61
     * @type EE_Request $request
62
     */
63
    protected $_request;
64
65
    /**
66
     * @type EE_Response $response
67
     */
68
    protected $_response;
69
70
    /**
71
     * @type LoaderInterface $loader
72
     */
73
    protected $loader;
74
75
    /**
76
     * @type array $_dependency_map
77
     */
78
    protected $_dependency_map = array();
79
80
    /**
81
     * @type array $_class_loaders
82
     */
83
    protected $_class_loaders = array();
84
85
    /**
86
     * @type array $_aliases
87
     */
88
    protected $_aliases = array();
89
90
91
92
    /**
93
     * EE_Dependency_Map constructor.
94
     *
95
     * @param EE_Request  $request
96
     * @param EE_Response $response
97
     */
98
    protected function __construct(EE_Request $request, EE_Response $response)
99
    {
100
        $this->_request = $request;
101
        $this->_response = $response;
102
        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
103
        do_action('EE_Dependency_Map____construct');
104
    }
105
106
107
108
    /**
109
     * @throws InvalidDataTypeException
110
     * @throws InvalidInterfaceException
111
     * @throws InvalidArgumentException
112
     */
113
    public function initialize()
114
    {
115
        $this->_register_core_dependencies();
116
        $this->_register_core_class_loaders();
117
        $this->_register_core_aliases();
118
    }
119
120
121
122
    /**
123
     * @singleton method used to instantiate class object
124
     * @access    public
125
     * @param EE_Request  $request
126
     * @param EE_Response $response
127
     * @return EE_Dependency_Map
128
     */
129
    public static function instance(EE_Request $request = null, EE_Response $response = null)
130
    {
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);
0 ignored issues
show
Bug introduced by
It seems like $request defined by parameter $request on line 129 can be null; however, EE_Dependency_Map::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
Bug introduced by
It seems like $response defined by parameter $response on line 129 can be null; however, EE_Dependency_Map::__construct() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
134
        }
135
        return self::$_instance;
136
    }
137
138
139
140
    /**
141
     * @param LoaderInterface $loader
142
     */
143
    public function setLoader(LoaderInterface $loader)
144
    {
145
        $this->loader = $loader;
146
    }
147
148
149
150
    /**
151
     * @param string $class
152
     * @param array  $dependencies
153
     * @param int    $overwrite
154
     * @return bool
155
     */
156
    public static function register_dependencies(
157
        $class,
158
        array $dependencies,
159
        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
160
    ) {
161
        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
162
    }
163
164
165
166
    /**
167
     * Assigns an array of class names and corresponding load sources (new or cached)
168
     * to the class specified by the first parameter.
169
     * IMPORTANT !!!
170
     * The order of elements in the incoming $dependencies array MUST match
171
     * the order of the constructor parameters for the class in question.
172
     * This is especially important when overriding any existing dependencies that are registered.
173
     * the third parameter controls whether any duplicate dependencies are overwritten or not.
174
     *
175
     * @param string $class
176
     * @param array  $dependencies
177
     * @param int    $overwrite
178
     * @return bool
179
     */
180
    public function registerDependencies(
181
        $class,
182
        array $dependencies,
183
        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
184
    ) {
185
        $class = trim($class, '\\');
186
        $registered = false;
187
        if (empty(self::$_instance->_dependency_map[ $class ])) {
188
            self::$_instance->_dependency_map[ $class ] = array();
189
        }
190
        // we need to make sure that any aliases used when registering a dependency
191
        // get resolved to the correct class name
192
        foreach ((array)$dependencies as $dependency => $load_source) {
193
            $alias = self::$_instance->get_alias($dependency);
194
            if (
195
                $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
196
                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
197
            ) {
198
                unset($dependencies[$dependency]);
199
                $dependencies[$alias] = $load_source;
200
                $registered = true;
201
            }
202
        }
203
        // now add our two lists of dependencies together.
204
        // using Union (+=) favours the arrays in precedence from left to right,
205
        // so $dependencies is NOT overwritten because it is listed first
206
        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
207
        // Union is way faster than array_merge() but should be used with caution...
208
        // especially with numerically indexed arrays
209
        $dependencies += self::$_instance->_dependency_map[ $class ];
210
        // now we need to ensure that the resulting dependencies
211
        // array only has the entries that are required for the class
212
        // so first count how many dependencies were originally registered for the class
213
        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
214
        // if that count is non-zero (meaning dependencies were already registered)
215
        self::$_instance->_dependency_map[ $class ] = $dependency_count
216
            // then truncate the  final array to match that count
217
            ? array_slice($dependencies, 0, $dependency_count)
218
            // otherwise just take the incoming array because nothing previously existed
219
            : $dependencies;
220
        return $registered;
221
    }
222
223
224
225
    /**
226
     * @param string $class_name
227
     * @param string $loader
228
     * @return bool
229
     * @throws DomainException
230
     */
231
    public static function register_class_loader($class_name, $loader = 'load_core')
232
    {
233
        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
234
            throw new DomainException(
235
                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
236
            );
237
        }
238
        // check that loader is callable or method starts with "load_" and exists in EE_Registry
239
        if (
240
            ! is_callable($loader)
241
            && (
242
                strpos($loader, 'load_') !== 0
243
                || ! method_exists('EE_Registry', $loader)
244
            )
245
        ) {
246
            throw new DomainException(
247
                sprintf(
248
                    esc_html__(
249
                        '"%1$s" is not a valid loader method on EE_Registry.',
250
                        'event_espresso'
251
                    ),
252
                    $loader
253
                )
254
            );
255
        }
256
        $class_name = self::$_instance->get_alias($class_name);
257
        if (! isset(self::$_instance->_class_loaders[$class_name])) {
258
            self::$_instance->_class_loaders[$class_name] = $loader;
259
            return true;
260
        }
261
        return false;
262
    }
263
264
265
266
    /**
267
     * @return array
268
     */
269
    public function dependency_map()
270
    {
271
        return $this->_dependency_map;
272
    }
273
274
275
276
    /**
277
     * returns TRUE if dependency map contains a listing for the provided class name
278
     *
279
     * @param string $class_name
280
     * @return boolean
281
     */
282
    public function has($class_name = '')
283
    {
284
        return isset($this->_dependency_map[$class_name]) ? true : false;
285
    }
286
287
288
289
    /**
290
     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
291
     *
292
     * @param string $class_name
293
     * @param string $dependency
294
     * @return bool
295
     */
296
    public function has_dependency_for_class($class_name = '', $dependency = '')
297
    {
298
        $dependency = $this->get_alias($dependency);
299
        return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency])
300
            ? true
301
            : false;
302
    }
303
304
305
306
    /**
307
     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
308
     *
309
     * @param string $class_name
310
     * @param string $dependency
311
     * @return int
312
     */
313
    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
314
    {
315
        $dependency = $this->get_alias($dependency);
316
        return $this->has_dependency_for_class($class_name, $dependency)
317
            ? $this->_dependency_map[$class_name][$dependency]
318
            : EE_Dependency_Map::not_registered;
319
    }
320
321
322
323
    /**
324
     * @param string $class_name
325
     * @return string | Closure
326
     */
327
    public function class_loader($class_name)
328
    {
329
        $class_name = $this->get_alias($class_name);
330
        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
331
    }
332
333
334
335
    /**
336
     * @return array
337
     */
338
    public function class_loaders()
339
    {
340
        return $this->_class_loaders;
341
    }
342
343
344
345
    /**
346
     * adds an alias for a classname
347
     *
348
     * @param string $class_name the class name that should be used (concrete class to replace interface)
349
     * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
350
     * @param string $for_class  the class that has the dependency (is type hinting for the interface)
351
     */
352
    public function add_alias($class_name, $alias, $for_class = '')
353
    {
354
        if ($for_class !== '') {
355
            if (! isset($this->_aliases[$for_class])) {
356
                $this->_aliases[$for_class] = array();
357
            }
358
            $this->_aliases[$for_class][$class_name] = $alias;
359
        }
360
        $this->_aliases[$class_name] = $alias;
361
    }
362
363
364
365
    /**
366
     * returns TRUE if the provided class name has an alias
367
     *
368
     * @param string $class_name
369
     * @param string $for_class
370
     * @return bool
371
     */
372
    public function has_alias($class_name = '', $for_class = '')
373
    {
374
        return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])
375
               || (
376
                   isset($this->_aliases[$class_name])
377
                   && ! is_array($this->_aliases[$class_name])
378
               );
379
    }
380
381
382
383
    /**
384
     * returns alias for class name if one exists, otherwise returns the original classname
385
     * functions recursively, so that multiple aliases can be used to drill down to a classname
386
     *  for example:
387
     *      if the following two entries were added to the _aliases array:
388
     *          array(
389
     *              'interface_alias'           => 'some\namespace\interface'
390
     *              'some\namespace\interface'  => 'some\namespace\classname'
391
     *          )
392
     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
393
     *      to load an instance of 'some\namespace\classname'
394
     *
395
     * @param string $class_name
396
     * @param string $for_class
397
     * @return string
398
     */
399
    public function get_alias($class_name = '', $for_class = '')
400
    {
401
        if (! $this->has_alias($class_name, $for_class)) {
402
            return $class_name;
403
        }
404
        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
405
            return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
406
        }
407
        return $this->get_alias($this->_aliases[$class_name]);
408
    }
409
410
411
412
    /**
413
     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
414
     * if one exists, or whether a new object should be generated every time the requested class is loaded.
415
     * This is done by using the following class constants:
416
     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
417
     *        EE_Dependency_Map::load_new_object - generates a new object every time
418
     */
419
    protected function _register_core_dependencies()
420
    {
421
        $this->_dependency_map = array(
422
            'EE_Request_Handler'                                                                                          => array(
423
                'EE_Request' => EE_Dependency_Map::load_from_cache,
424
            ),
425
            'EE_System'                                                                                                   => array(
426
                'EE_Registry' => EE_Dependency_Map::load_from_cache,
427
            ),
428
            'EE_Session'                                                                                                  => array(
429
                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
430
                'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
431
            ),
432
            'EE_Cart'                                                                                                     => array(
433
                'EE_Session' => EE_Dependency_Map::load_from_cache,
434
            ),
435
            'EE_Front_Controller'                                                                                         => array(
436
                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
437
                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
438
                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
439
            ),
440
            'EE_Messenger_Collection_Loader'                                                                              => array(
441
                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
442
            ),
443
            'EE_Message_Type_Collection_Loader'                                                                           => array(
444
                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
445
            ),
446
            'EE_Message_Resource_Manager'                                                                                 => array(
447
                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
448
                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
449
                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
450
            ),
451
            'EE_Message_Factory'                                                                                          => array(
452
                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
453
            ),
454
            'EE_messages'                                                                                                 => array(
455
                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
456
            ),
457
            'EE_Messages_Generator'                                                                                       => array(
458
                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
459
                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
460
                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
461
                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
462
            ),
463
            'EE_Messages_Processor'                                                                                       => array(
464
                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
465
            ),
466
            'EE_Messages_Queue'                                                                                           => array(
467
                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
468
            ),
469
            'EE_Messages_Template_Defaults'                                                                               => array(
470
                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
471
                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
472
            ),
473
            'EE_Message_To_Generate_From_Request'                                                                         => array(
474
                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
475
                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
476
            ),
477
            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
478
                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
479
            ),
480
            'EventEspresso\services\commands\CommandHandler'                                                              => array(
481
                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
482
                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
483
            ),
484
            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
485
                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
486
            ),
487
            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
488
                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
489
                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
490
            ),
491
            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
492
                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
493
            ),
494
            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
495
                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
496
            ),
497
            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
498
                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
499
            ),
500
            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
501
                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
502
            ),
503
            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
504
                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
505
            ),
506
            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
507
                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
508
            ),
509
            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
510
                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
511
            ),
512
            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
513
                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
514
            ),
515
            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
516
                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
517
            ),
518
            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
519
                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
520
            ),
521
            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
522
                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
523
            ),
524
            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
525
                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
526
            ),
527
            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
528
                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
529
            ),
530
            'EventEspresso\core\services\database\TableManager'                                                           => array(
531
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
532
            ),
533
            'EE_Data_Migration_Class_Base'                                                                                => array(
534
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
535
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
536
            ),
537
            'EE_DMS_Core_4_1_0'                                                                                           => array(
538
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
539
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
540
            ),
541
            'EE_DMS_Core_4_2_0'                                                                                           => array(
542
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
543
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
544
            ),
545
            'EE_DMS_Core_4_3_0'                                                                                           => array(
546
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
547
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
548
            ),
549
            'EE_DMS_Core_4_4_0'                                                                                           => array(
550
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
551
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
552
            ),
553
            'EE_DMS_Core_4_5_0'                                                                                           => array(
554
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
555
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
556
            ),
557
            'EE_DMS_Core_4_6_0'                                                                                           => array(
558
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
559
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
560
            ),
561
            'EE_DMS_Core_4_7_0'                                                                                           => array(
562
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
563
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
564
            ),
565
            'EE_DMS_Core_4_8_0'                                                                                           => array(
566
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
567
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
568
            ),
569
            'EE_DMS_Core_4_9_0'                                                                                           => array(
570
                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
571
                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
572
            ),
573
            'EventEspresso\core\services\assets\Registry'                                                                 => array(
574
                'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
575
                'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
576
            ),
577
            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
578
                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
579
            ),
580
            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
581
                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
582
            ),
583
            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
584
                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
585
            ),
586
            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
587
                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
588
            ),
589
            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
590
                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
591
            ),
592
            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
593
                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
594
            ),
595
            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
596
                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
597
            ),
598
            'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
599
                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
600
            ),
601
            'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
602
                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
603
            ),
604
        );
605
    }
606
607
608
609
    /**
610
     * Registers how core classes are loaded.
611
     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
612
     *        'EE_Request_Handler' => 'load_core'
613
     *        'EE_Messages_Queue'  => 'load_lib'
614
     *        'EEH_Debug_Tools'    => 'load_helper'
615
     * or, if greater control is required, by providing a custom closure. For example:
616
     *        'Some_Class' => function () {
617
     *            return new Some_Class();
618
     *        },
619
     * This is required for instantiating dependencies
620
     * where an interface has been type hinted in a class constructor. For example:
621
     *        'Required_Interface' => function () {
622
     *            return new A_Class_That_Implements_Required_Interface();
623
     *        },
624
     */
625
    protected function _register_core_class_loaders()
626
    {
627
        //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
628
        //be used in a closure.
629
        $request = &$this->_request;
630
        $response = &$this->_response;
631
        $loader = &$this->loader;
632
        $this->_class_loaders = array(
633
            //load_core
634
            'EE_Capabilities'                      => 'load_core',
635
            'EE_Encryption'                        => 'load_core',
636
            'EE_Front_Controller'                  => 'load_core',
637
            'EE_Module_Request_Router'             => 'load_core',
638
            'EE_Registry'                          => 'load_core',
639
            'EE_Request'                           => function () use (&$request) {
640
                return $request;
641
            },
642
            'EE_Response'                          => function () use (&$response) {
643
                return $response;
644
            },
645
            'EE_Request_Handler'                   => 'load_core',
646
            'EE_Session'                           => 'load_core',
647
            //load_lib
648
            'EE_Message_Resource_Manager'          => 'load_lib',
649
            'EE_Message_Type_Collection'           => 'load_lib',
650
            'EE_Message_Type_Collection_Loader'    => 'load_lib',
651
            'EE_Messenger_Collection'              => 'load_lib',
652
            'EE_Messenger_Collection_Loader'       => 'load_lib',
653
            'EE_Messages_Processor'                => 'load_lib',
654
            'EE_Message_Repository'                => 'load_lib',
655
            'EE_Messages_Queue'                    => 'load_lib',
656
            'EE_Messages_Data_Handler_Collection'  => 'load_lib',
657
            'EE_Message_Template_Group_Collection' => 'load_lib',
658
            'EE_Messages_Generator'                => function () {
659
                return EE_Registry::instance()->load_lib(
660
                    'Messages_Generator',
661
                    array(),
662
                    false,
663
                    false
664
                );
665
            },
666
            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
667
                return EE_Registry::instance()->load_lib(
668
                    'Messages_Template_Defaults',
669
                    $arguments,
670
                    false,
671
                    false
672
                );
673
            },
674
            //load_model
675
            'EEM_Attendee'                         => 'load_model',
676
            'EEM_Message_Template_Group'           => 'load_model',
677
            'EEM_Message_Template'                 => 'load_model',
678
            //load_helper
679
            'EEH_Parse_Shortcodes'                 => function () {
680
                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
681
                    return new EEH_Parse_Shortcodes();
682
                }
683
                return null;
684
            },
685
            'EE_Template_Config'                   => function () {
686
                return EE_Config::instance()->template_settings;
687
            },
688
            'EE_Currency_Config'                   => function () {
689
                return EE_Config::instance()->currency;
690
            },
691
            'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) {
692
                return $loader;
693
            },
694
        );
695
    }
696
697
698
699
    /**
700
     * can be used for supplying alternate names for classes,
701
     * or for connecting interface names to instantiable classes
702
     */
703
    protected function _register_core_aliases()
704
    {
705
        $this->_aliases = array(
706
            'CommandBusInterface'                                                 => 'EventEspresso\core\services\commands\CommandBusInterface',
707
            'EventEspresso\core\services\commands\CommandBusInterface'            => 'EventEspresso\core\services\commands\CommandBus',
708
            'CommandHandlerManagerInterface'                                      => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
709
            'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager',
710
            'CapChecker'                                                          => 'EventEspresso\core\services\commands\middleware\CapChecker',
711
            'AddActionHook'                                                       => 'EventEspresso\core\services\commands\middleware\AddActionHook',
712
            'CapabilitiesChecker'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
713
            'CapabilitiesCheckerInterface'                                        => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
714
            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
715
            'CreateRegistrationService'                                           => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
716
            'CreateRegCodeCommandHandler'                                         => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
717
            'CreateRegUrlLinkCommandHandler'                                      => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
718
            'CreateRegistrationCommandHandler'                                    => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
719
            'CopyRegistrationDetailsCommandHandler'                               => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
720
            'CopyRegistrationPaymentsCommandHandler'                              => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
721
            'CancelRegistrationAndTicketLineItemCommandHandler'                   => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
722
            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'           => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
723
            'CreateTicketLineItemCommandHandler'                                  => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
724
            'TableManager'                                                        => 'EventEspresso\core\services\database\TableManager',
725
            'TableAnalysis'                                                       => 'EventEspresso\core\services\database\TableAnalysis',
726
            'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
727
            'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
728
            'EspressoShortcode'                                                   => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
729
            'ShortcodeInterface'                                                  => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
730
            'EventEspresso\core\services\shortcodes\ShortcodeInterface'           => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
731
            'EventEspresso\core\services\cache\CacheStorageInterface'             => 'EventEspresso\core\services\cache\TransientCacheStorage',
732
            'LoaderInterface'                                                     => 'EventEspresso\core\services\loaders\LoaderInterface',
733
            'EventEspresso\core\services\loaders\LoaderInterface'                 => 'EventEspresso\core\services\loaders\Loader',
734
            'CommandFactoryInterface'                                             => 'EventEspresso\core\services\commands\CommandFactoryInterface',
735
            'EventEspresso\core\services\commands\CommandFactoryInterface'        => 'EventEspresso\core\services\commands\CommandFactory',
736
            'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session',
737
            'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
738
            'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
739
            'NoticesContainerInterface'                                            => 'EventEspresso\core\services\notices\NoticesContainerInterface',
740
            'EventEspresso\core\services\notices\NoticesContainerInterface'        => 'EventEspresso\core\services\notices\NoticesContainer',
741
        );
742
    }
743
744
745
746
    /**
747
     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
748
     * request Primarily used by unit tests.
749
     */
750
    public function reset()
751
    {
752
        $this->_register_core_class_loaders();
753
        $this->_register_core_dependencies();
754
    }
755
756
757
}
758
// End of file EE_Dependency_Map.core.php
759
// Location: /EE_Dependency_Map.core.php
760