Completed
Branch FET/11450/reserved-instance-in... (cfa977)
by
unknown
69:04 queued 55:58
created

EE_Dependency_Map::has()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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