Completed
Branch FET-10768-extract-admin-bar (46d5db)
by
unknown
119:49 queued 108:29
created
core/EE_Registry.core.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -272,6 +272,7 @@
 block discarded – undo
272 272
 
273 273
     /**
274 274
      * @param mixed string | EED_Module $module
275
+     * @param string $module
275 276
      * @throws EE_Error
276 277
      * @throws ReflectionException
277 278
      */
Please login to merge, or discard this patch.
Indentation   +1529 added lines, -1529 removed lines patch added patch discarded remove patch
@@ -22,1535 +22,1535 @@
 block discarded – undo
22 22
 class EE_Registry implements ResettableInterface
23 23
 {
24 24
 
25
-    /**
26
-     * @var EE_Registry $_instance
27
-     */
28
-    private static $_instance;
29
-
30
-    /**
31
-     * @var EE_Dependency_Map $_dependency_map
32
-     */
33
-    protected $_dependency_map;
34
-
35
-    /**
36
-     * @var array $_class_abbreviations
37
-     */
38
-    protected $_class_abbreviations = array();
39
-
40
-    /**
41
-     * @var CommandBusInterface $BUS
42
-     */
43
-    public $BUS;
44
-
45
-    /**
46
-     * @var EE_Cart $CART
47
-     */
48
-    public $CART;
49
-
50
-    /**
51
-     * @var EE_Config $CFG
52
-     */
53
-    public $CFG;
54
-
55
-    /**
56
-     * @var EE_Network_Config $NET_CFG
57
-     */
58
-    public $NET_CFG;
59
-
60
-    /**
61
-     * StdClass object for storing library classes in
62
-     *
63
-     * @var StdClass $LIB
64
-     */
65
-    public $LIB;
66
-
67
-    /**
68
-     * @var EE_Request_Handler $REQ
69
-     */
70
-    public $REQ;
71
-
72
-    /**
73
-     * @var EE_Session $SSN
74
-     */
75
-    public $SSN;
76
-
77
-    /**
78
-     * @since 4.5.0
79
-     * @var EE_Capabilities $CAP
80
-     */
81
-    public $CAP;
82
-
83
-    /**
84
-     * @since 4.9.0
85
-     * @var EE_Message_Resource_Manager $MRM
86
-     */
87
-    public $MRM;
88
-
89
-
90
-    /**
91
-     * @var Registry $AssetsRegistry
92
-     */
93
-    public $AssetsRegistry;
94
-
95
-    /**
96
-     * StdClass object for holding addons which have registered themselves to work with EE core
97
-     *
98
-     * @var EE_Addon[] $addons
99
-     */
100
-    public $addons;
101
-
102
-    /**
103
-     * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
104
-     *
105
-     * @var EEM_Base[] $models
106
-     */
107
-    public $models = array();
108
-
109
-    /**
110
-     * @var EED_Module[] $modules
111
-     */
112
-    public $modules;
113
-
114
-    /**
115
-     * @var EES_Shortcode[] $shortcodes
116
-     */
117
-    public $shortcodes;
118
-
119
-    /**
120
-     * @var WP_Widget[] $widgets
121
-     */
122
-    public $widgets;
123
-
124
-    /**
125
-     * this is an array of all implemented model names (i.e. not the parent abstract models, or models
126
-     * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
127
-     * Keys are model "short names" (eg "Event") as used in model relations, and values are
128
-     * classnames (eg "EEM_Event")
129
-     *
130
-     * @var array $non_abstract_db_models
131
-     */
132
-    public $non_abstract_db_models = array();
133
-
134
-
135
-    /**
136
-     * internationalization for JS strings
137
-     *    usage:   EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' );
138
-     *    in js file:  var translatedString = eei18n.string_key;
139
-     *
140
-     * @var array $i18n_js_strings
141
-     */
142
-    public static $i18n_js_strings = array();
143
-
144
-
145
-    /**
146
-     * $main_file - path to espresso.php
147
-     *
148
-     * @var array $main_file
149
-     */
150
-    public $main_file;
151
-
152
-    /**
153
-     * array of ReflectionClass objects where the key is the class name
154
-     *
155
-     * @var ReflectionClass[] $_reflectors
156
-     */
157
-    public $_reflectors;
158
-
159
-    /**
160
-     * boolean flag to indicate whether or not to load/save dependencies from/to the cache
161
-     *
162
-     * @var boolean $_cache_on
163
-     */
164
-    protected $_cache_on = true;
165
-
166
-
167
-
168
-    /**
169
-     * @singleton method used to instantiate class object
170
-     * @param  EE_Dependency_Map $dependency_map
171
-     * @return EE_Registry instance
172
-     * @throws InvalidArgumentException
173
-     * @throws InvalidInterfaceException
174
-     * @throws InvalidDataTypeException
175
-     */
176
-    public static function instance(EE_Dependency_Map $dependency_map = null)
177
-    {
178
-        // check if class object is instantiated
179
-        if (! self::$_instance instanceof EE_Registry) {
180
-            self::$_instance = new self($dependency_map);
181
-        }
182
-        return self::$_instance;
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * protected constructor to prevent direct creation
189
-     *
190
-     * @Constructor
191
-     * @param  EE_Dependency_Map $dependency_map
192
-     * @throws InvalidDataTypeException
193
-     * @throws InvalidInterfaceException
194
-     * @throws InvalidArgumentException
195
-     */
196
-    protected function __construct(EE_Dependency_Map $dependency_map)
197
-    {
198
-        $this->_dependency_map = $dependency_map;
199
-        $this->LIB = new stdClass();
200
-        $this->addons = new stdClass();
201
-        $this->modules = new stdClass();
202
-        $this->shortcodes = new stdClass();
203
-        $this->widgets = new stdClass();
204
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
205
-    }
206
-
207
-
208
-
209
-    /**
210
-     * initialize
211
-     *
212
-     * @throws EE_Error
213
-     * @throws ReflectionException
214
-     */
215
-    public function initialize()
216
-    {
217
-        $this->_class_abbreviations = apply_filters(
218
-            'FHEE__EE_Registry____construct___class_abbreviations',
219
-            array(
220
-                'EE_Config'                                       => 'CFG',
221
-                'EE_Session'                                      => 'SSN',
222
-                'EE_Capabilities'                                 => 'CAP',
223
-                'EE_Cart'                                         => 'CART',
224
-                'EE_Network_Config'                               => 'NET_CFG',
225
-                'EE_Request_Handler'                              => 'REQ',
226
-                'EE_Message_Resource_Manager'                     => 'MRM',
227
-                'EventEspresso\core\services\commands\CommandBus' => 'BUS',
228
-                'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
229
-            )
230
-        );
231
-        $this->load_core('Base', array(), true);
232
-        // add our request and response objects to the cache
233
-        $request_loader = $this->_dependency_map->class_loader('EE_Request');
234
-        $this->_set_cached_class(
235
-            $request_loader(),
236
-            'EE_Request'
237
-        );
238
-        $response_loader = $this->_dependency_map->class_loader('EE_Response');
239
-        $this->_set_cached_class(
240
-            $response_loader(),
241
-            'EE_Response'
242
-        );
243
-        add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
244
-    }
245
-
246
-
247
-
248
-    /**
249
-     * @return void
250
-     */
251
-    public function init()
252
-    {
253
-        // Get current page protocol
254
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
255
-        // Output admin-ajax.php URL with same protocol as current page
256
-        self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
257
-        self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
258
-    }
259
-
260
-
261
-
262
-    /**
263
-     * localize_i18n_js_strings
264
-     *
265
-     * @return string
266
-     */
267
-    public static function localize_i18n_js_strings()
268
-    {
269
-        $i18n_js_strings = (array)self::$i18n_js_strings;
270
-        foreach ($i18n_js_strings as $key => $value) {
271
-            if (is_scalar($value)) {
272
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
273
-            }
274
-        }
275
-        return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
276
-    }
277
-
278
-
279
-
280
-    /**
281
-     * @param mixed string | EED_Module $module
282
-     * @throws EE_Error
283
-     * @throws ReflectionException
284
-     */
285
-    public function add_module($module)
286
-    {
287
-        if ($module instanceof EED_Module) {
288
-            $module_class = get_class($module);
289
-            $this->modules->{$module_class} = $module;
290
-        } else {
291
-            if (! class_exists('EE_Module_Request_Router')) {
292
-                $this->load_core('Module_Request_Router');
293
-            }
294
-            EE_Module_Request_Router::module_factory($module);
295
-        }
296
-    }
297
-
298
-
299
-
300
-    /**
301
-     * @param string $module_name
302
-     * @return mixed EED_Module | NULL
303
-     */
304
-    public function get_module($module_name = '')
305
-    {
306
-        return isset($this->modules->{$module_name})
307
-            ? $this->modules->{$module_name}
308
-            : null;
309
-    }
310
-
311
-
312
-
313
-    /**
314
-     * loads core classes - must be singletons
315
-     *
316
-     * @param string $class_name - simple class name ie: session
317
-     * @param mixed  $arguments
318
-     * @param bool   $load_only
319
-     * @return mixed
320
-     * @throws EE_Error
321
-     * @throws ReflectionException
322
-     */
323
-    public function load_core($class_name, $arguments = array(), $load_only = false)
324
-    {
325
-        $core_paths = apply_filters(
326
-            'FHEE__EE_Registry__load_core__core_paths',
327
-            array(
328
-                EE_CORE,
329
-                EE_ADMIN,
330
-                EE_CPTS,
331
-                EE_CORE . 'data_migration_scripts' . DS,
332
-                EE_CORE . 'capabilities' . DS,
333
-                EE_CORE . 'request_stack' . DS,
334
-                EE_CORE . 'middleware' . DS,
335
-            )
336
-        );
337
-        // retrieve instantiated class
338
-        return $this->_load(
339
-            $core_paths,
340
-            'EE_',
341
-            $class_name,
342
-            'core',
343
-            $arguments,
344
-            false,
345
-            true,
346
-            $load_only
347
-        );
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * loads service classes
354
-     *
355
-     * @param string $class_name - simple class name ie: session
356
-     * @param mixed  $arguments
357
-     * @param bool   $load_only
358
-     * @return mixed
359
-     * @throws EE_Error
360
-     * @throws ReflectionException
361
-     */
362
-    public function load_service($class_name, $arguments = array(), $load_only = false)
363
-    {
364
-        $service_paths = apply_filters(
365
-            'FHEE__EE_Registry__load_service__service_paths',
366
-            array(
367
-                EE_CORE . 'services' . DS,
368
-            )
369
-        );
370
-        // retrieve instantiated class
371
-        return $this->_load(
372
-            $service_paths,
373
-            'EE_',
374
-            $class_name,
375
-            'class',
376
-            $arguments,
377
-            false,
378
-            true,
379
-            $load_only
380
-        );
381
-    }
382
-
383
-
384
-
385
-    /**
386
-     * loads data_migration_scripts
387
-     *
388
-     * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
389
-     * @param mixed  $arguments
390
-     * @return EE_Data_Migration_Script_Base|mixed
391
-     * @throws EE_Error
392
-     * @throws ReflectionException
393
-     */
394
-    public function load_dms($class_name, $arguments = array())
395
-    {
396
-        // retrieve instantiated class
397
-        return $this->_load(
398
-            EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(),
399
-            'EE_DMS_',
400
-            $class_name,
401
-            'dms',
402
-            $arguments,
403
-            false,
404
-            false
405
-        );
406
-    }
407
-
408
-
409
-
410
-    /**
411
-     * loads object creating classes - must be singletons
412
-     *
413
-     * @param string $class_name - simple class name ie: attendee
414
-     * @param mixed  $arguments  - an array of arguments to pass to the class
415
-     * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to
416
-     *                           instantiate
417
-     * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then
418
-     *                           set this to FALSE (ie. when instantiating model objects from client in a loop)
419
-     * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate
420
-     *                           (default)
421
-     * @return EE_Base_Class | bool
422
-     * @throws EE_Error
423
-     * @throws ReflectionException
424
-     */
425
-    public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
426
-    {
427
-        $paths = apply_filters(
428
-            'FHEE__EE_Registry__load_class__paths', array(
429
-            EE_CORE,
430
-            EE_CLASSES,
431
-            EE_BUSINESS,
432
-        )
433
-        );
434
-        // retrieve instantiated class
435
-        return $this->_load(
436
-            $paths,
437
-            'EE_',
438
-            $class_name,
439
-            'class',
440
-            $arguments,
441
-            $from_db,
442
-            $cache,
443
-            $load_only
444
-        );
445
-    }
446
-
447
-
448
-
449
-    /**
450
-     * loads helper classes - must be singletons
451
-     *
452
-     * @param string $class_name - simple class name ie: price
453
-     * @param mixed  $arguments
454
-     * @param bool   $load_only
455
-     * @return EEH_Base | bool
456
-     * @throws EE_Error
457
-     * @throws ReflectionException
458
-     */
459
-    public function load_helper($class_name, $arguments = array(), $load_only = true)
460
-    {
461
-        // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
462
-        $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
463
-        // retrieve instantiated class
464
-        return $this->_load(
465
-            $helper_paths,
466
-            'EEH_',
467
-            $class_name,
468
-            'helper',
469
-            $arguments,
470
-            false,
471
-            true,
472
-            $load_only
473
-        );
474
-    }
475
-
476
-
477
-
478
-    /**
479
-     * loads core classes - must be singletons
480
-     *
481
-     * @param string $class_name - simple class name ie: session
482
-     * @param mixed  $arguments
483
-     * @param bool   $load_only
484
-     * @param bool   $cache      whether to cache the object or not.
485
-     * @return mixed
486
-     * @throws EE_Error
487
-     * @throws ReflectionException
488
-     */
489
-    public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
490
-    {
491
-        $paths = array(
492
-            EE_LIBRARIES,
493
-            EE_LIBRARIES . 'messages' . DS,
494
-            EE_LIBRARIES . 'shortcodes' . DS,
495
-            EE_LIBRARIES . 'qtips' . DS,
496
-            EE_LIBRARIES . 'payment_methods' . DS,
497
-        );
498
-        // retrieve instantiated class
499
-        return $this->_load(
500
-            $paths,
501
-            'EE_',
502
-            $class_name,
503
-            'lib',
504
-            $arguments,
505
-            false,
506
-            $cache,
507
-            $load_only
508
-        );
509
-    }
510
-
511
-
512
-
513
-    /**
514
-     * loads model classes - must be singletons
515
-     *
516
-     * @param string $class_name - simple class name ie: price
517
-     * @param mixed  $arguments
518
-     * @param bool   $load_only
519
-     * @return EEM_Base | bool
520
-     * @throws EE_Error
521
-     * @throws ReflectionException
522
-     */
523
-    public function load_model($class_name, $arguments = array(), $load_only = false)
524
-    {
525
-        $paths = apply_filters(
526
-            'FHEE__EE_Registry__load_model__paths', array(
527
-            EE_MODELS,
528
-            EE_CORE,
529
-        )
530
-        );
531
-        // retrieve instantiated class
532
-        return $this->_load(
533
-            $paths,
534
-            'EEM_',
535
-            $class_name,
536
-            'model',
537
-            $arguments,
538
-            false,
539
-            true,
540
-            $load_only
541
-        );
542
-    }
543
-
544
-
545
-
546
-    /**
547
-     * loads model classes - must be singletons
548
-     *
549
-     * @param string $class_name - simple class name ie: price
550
-     * @param mixed  $arguments
551
-     * @param bool   $load_only
552
-     * @return mixed | bool
553
-     * @throws EE_Error
554
-     * @throws ReflectionException
555
-     */
556
-    public function load_model_class($class_name, $arguments = array(), $load_only = true)
557
-    {
558
-        $paths = array(
559
-            EE_MODELS . 'fields' . DS,
560
-            EE_MODELS . 'helpers' . DS,
561
-            EE_MODELS . 'relations' . DS,
562
-            EE_MODELS . 'strategies' . DS,
563
-        );
564
-        // retrieve instantiated class
565
-        return $this->_load(
566
-            $paths,
567
-            'EE_',
568
-            $class_name,
569
-            '',
570
-            $arguments,
571
-            false,
572
-            true,
573
-            $load_only
574
-        );
575
-    }
576
-
577
-
578
-
579
-    /**
580
-     * Determines if $model_name is the name of an actual EE model.
581
-     *
582
-     * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
583
-     * @return boolean
584
-     */
585
-    public function is_model_name($model_name)
586
-    {
587
-        return isset($this->models[$model_name]);
588
-    }
589
-
590
-
591
-
592
-    /**
593
-     * generic class loader
594
-     *
595
-     * @param string $path_to_file - directory path to file location, not including filename
596
-     * @param string $file_name    - file name  ie:  my_file.php, including extension
597
-     * @param string $type         - file type - core? class? helper? model?
598
-     * @param mixed  $arguments
599
-     * @param bool   $load_only
600
-     * @return mixed
601
-     * @throws EE_Error
602
-     * @throws ReflectionException
603
-     */
604
-    public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
605
-    {
606
-        // retrieve instantiated class
607
-        return $this->_load(
608
-            $path_to_file,
609
-            '',
610
-            $file_name,
611
-            $type,
612
-            $arguments,
613
-            false,
614
-            true,
615
-            $load_only
616
-        );
617
-    }
618
-
619
-
620
-
621
-    /**
622
-     * @param string $path_to_file - directory path to file location, not including filename
623
-     * @param string $class_name   - full class name  ie:  My_Class
624
-     * @param string $type         - file type - core? class? helper? model?
625
-     * @param mixed  $arguments
626
-     * @param bool   $load_only
627
-     * @return bool|EE_Addon|object
628
-     * @throws EE_Error
629
-     * @throws ReflectionException
630
-     */
631
-    public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
632
-    {
633
-        // retrieve instantiated class
634
-        return $this->_load(
635
-            $path_to_file,
636
-            'addon',
637
-            $class_name,
638
-            $type,
639
-            $arguments,
640
-            false,
641
-            true,
642
-            $load_only
643
-        );
644
-    }
645
-
646
-
647
-
648
-    /**
649
-     * instantiates, caches, and automatically resolves dependencies
650
-     * for classes that use a Fully Qualified Class Name.
651
-     * if the class is not capable of being loaded using PSR-4 autoloading,
652
-     * then you need to use one of the existing load_*() methods
653
-     * which can resolve the classname and filepath from the passed arguments
654
-     *
655
-     * @param bool|string $class_name   Fully Qualified Class Name
656
-     * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
657
-     * @param bool        $cache        whether to cache the instantiated object for reuse
658
-     * @param bool        $from_db      some classes are instantiated from the db
659
-     *                                  and thus call a different method to instantiate
660
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
661
-     * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
662
-     * @return bool|null|mixed          null = failure to load or instantiate class object.
663
-     *                                  object = class loaded and instantiated successfully.
664
-     *                                  bool = fail or success when $load_only is true
665
-     * @throws EE_Error
666
-     * @throws ReflectionException
667
-     */
668
-    public function create(
669
-        $class_name = false,
670
-        $arguments = array(),
671
-        $cache = false,
672
-        $from_db = false,
673
-        $load_only = false,
674
-        $addon = false
675
-    ) {
676
-        $class_name = ltrim($class_name, '\\');
677
-        $class_name = $this->_dependency_map->get_alias($class_name);
678
-        $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
679
-        // if a non-FQCN was passed, then verifyClassExists() might return an object
680
-        // or it could return null if the class just could not be found anywhere
681
-        if ($class_exists instanceof $class_name || $class_exists === null){
682
-            // either way, return the results
683
-            return $class_exists;
684
-        }
685
-        $class_name = $class_exists;
686
-        // if we're only loading the class and it already exists, then let's just return true immediately
687
-        if ($load_only) {
688
-            return true;
689
-        }
690
-        $addon = $addon
691
-            ? 'addon'
692
-            : '';
693
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
694
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
695
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
696
-        if ($this->_cache_on && $cache && ! $load_only) {
697
-            // return object if it's already cached
698
-            $cached_class = $this->_get_cached_class($class_name, $addon);
699
-            if ($cached_class !== null) {
700
-                return $cached_class;
701
-            }
702
-        }
703
-        // obtain the loader method from the dependency map
704
-        $loader = $this->_dependency_map->class_loader($class_name);
705
-        // instantiate the requested object
706
-        if ($loader instanceof Closure) {
707
-            $class_obj = $loader($arguments);
708
-        } else if ($loader && method_exists($this, $loader)) {
709
-            $class_obj = $this->{$loader}($class_name, $arguments);
710
-        } else {
711
-            $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
712
-        }
713
-        if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) {
714
-            // save it for later... kinda like gum  { : $
715
-            $this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
716
-        }
717
-        $this->_cache_on = true;
718
-        return $class_obj;
719
-    }
720
-
721
-
722
-
723
-    /**
724
-     * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
725
-     *
726
-     * @param string $class_name
727
-     * @param array  $arguments
728
-     * @param int    $attempt
729
-     * @return mixed
730
-     */
731
-    private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) {
732
-        if (is_object($class_name) || class_exists($class_name)) {
733
-            return $class_name;
734
-        }
735
-        switch ($attempt) {
736
-            case 1:
737
-                // if it's a FQCN then maybe the class is registered with a preceding \
738
-                $class_name = strpos($class_name, '\\') !== false
739
-                    ? '\\' . ltrim($class_name, '\\')
740
-                    : $class_name;
741
-                break;
742
-            case 2:
743
-                //
744
-                $loader = $this->_dependency_map->class_loader($class_name);
745
-                if ($loader && method_exists($this, $loader)) {
746
-                    return $this->{$loader}($class_name, $arguments);
747
-                }
748
-                break;
749
-            case 3:
750
-            default;
751
-                return null;
752
-        }
753
-        $attempt++;
754
-        return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
755
-    }
756
-
757
-
758
-
759
-    /**
760
-     * instantiates, caches, and injects dependencies for classes
761
-     *
762
-     * @param array       $file_paths   an array of paths to folders to look in
763
-     * @param string      $class_prefix EE  or EEM or... ???
764
-     * @param bool|string $class_name   $class name
765
-     * @param string      $type         file type - core? class? helper? model?
766
-     * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
767
-     * @param bool        $from_db      some classes are instantiated from the db
768
-     *                                  and thus call a different method to instantiate
769
-     * @param bool        $cache        whether to cache the instantiated object for reuse
770
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
771
-     * @return bool|null|object null = failure to load or instantiate class object.
772
-     *                                  object = class loaded and instantiated successfully.
773
-     *                                  bool = fail or success when $load_only is true
774
-     * @throws EE_Error
775
-     * @throws ReflectionException
776
-     */
777
-    protected function _load(
778
-        $file_paths = array(),
779
-        $class_prefix = 'EE_',
780
-        $class_name = false,
781
-        $type = 'class',
782
-        $arguments = array(),
783
-        $from_db = false,
784
-        $cache = true,
785
-        $load_only = false
786
-    ) {
787
-        $class_name = ltrim($class_name, '\\');
788
-        // strip php file extension
789
-        $class_name = str_replace('.php', '', trim($class_name));
790
-        // does the class have a prefix ?
791
-        if (! empty($class_prefix) && $class_prefix !== 'addon') {
792
-            // make sure $class_prefix is uppercase
793
-            $class_prefix = strtoupper(trim($class_prefix));
794
-            // add class prefix ONCE!!!
795
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
796
-        }
797
-        $class_name = $this->_dependency_map->get_alias($class_name);
798
-        $class_exists = class_exists($class_name);
799
-        // if we're only loading the class and it already exists, then let's just return true immediately
800
-        if ($load_only && $class_exists) {
801
-            return true;
802
-        }
803
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
804
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
805
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
806
-        if ($this->_cache_on && $cache && ! $load_only) {
807
-            // return object if it's already cached
808
-            $cached_class = $this->_get_cached_class($class_name, $class_prefix);
809
-            if ($cached_class !== null) {
810
-                return $cached_class;
811
-            }
812
-        }
813
-        // if the class doesn't already exist.. then we need to try and find the file and load it
814
-        if (! $class_exists) {
815
-            // get full path to file
816
-            $path = $this->_resolve_path($class_name, $type, $file_paths);
817
-            // load the file
818
-            $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
819
-            // if loading failed, or we are only loading a file but NOT instantiating an object
820
-            if (! $loaded || $load_only) {
821
-                // return boolean if only loading, or null if an object was expected
822
-                return $load_only
823
-                    ? $loaded
824
-                    : null;
825
-            }
826
-        }
827
-        // instantiate the requested object
828
-        $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
829
-        if ($this->_cache_on && $cache) {
830
-            // save it for later... kinda like gum  { : $
831
-            $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
832
-        }
833
-        $this->_cache_on = true;
834
-        return $class_obj;
835
-    }
836
-
837
-
838
-
839
-    /**
840
-     * @param string $class_name
841
-     * @param string $default have to specify something, but not anything that will conflict
842
-     * @return mixed|string
843
-     */
844
-    protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
845
-    {
846
-        return isset($this->_class_abbreviations[$class_name])
847
-            ? $this->_class_abbreviations[$class_name]
848
-            : $default;
849
-    }
850
-
851
-    /**
852
-     * attempts to find a cached version of the requested class
853
-     * by looking in the following places:
854
-     *        $this->{$class_abbreviation}            ie:    $this->CART
855
-     *        $this->{$class_name}                        ie:    $this->Some_Class
856
-     *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
857
-     *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
858
-     *
859
-     * @param string $class_name
860
-     * @param string $class_prefix
861
-     * @return mixed
862
-     */
863
-    protected function _get_cached_class($class_name, $class_prefix = '')
864
-    {
865
-        if ($class_name === 'EE_Registry') {
866
-            return $this;
867
-        }
868
-        $class_abbreviation = $this->get_class_abbreviation($class_name);
869
-        $class_name = str_replace('\\', '_', $class_name);
870
-        // check if class has already been loaded, and return it if it has been
871
-        if (isset($this->{$class_abbreviation})) {
872
-            return $this->{$class_abbreviation};
873
-        }
874
-        if (isset ($this->{$class_name})) {
875
-            return $this->{$class_name};
876
-        }
877
-        if (isset ($this->LIB->{$class_name})) {
878
-            return $this->LIB->{$class_name};
879
-        }
880
-        if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
881
-            return $this->addons->{$class_name};
882
-        }
883
-        return null;
884
-    }
885
-
886
-
887
-
888
-    /**
889
-     * removes a cached version of the requested class
890
-     *
891
-     * @param string  $class_name
892
-     * @param boolean $addon
893
-     * @return boolean
894
-     */
895
-    public function clear_cached_class($class_name, $addon = false)
896
-    {
897
-        $class_abbreviation = $this->get_class_abbreviation($class_name);
898
-        $class_name = str_replace('\\', '_', $class_name);
899
-        // check if class has already been loaded, and return it if it has been
900
-        if (isset($this->{$class_abbreviation})) {
901
-            $this->{$class_abbreviation} = null;
902
-            return true;
903
-        }
904
-        if (isset($this->{$class_name})) {
905
-            $this->{$class_name} = null;
906
-            return true;
907
-        }
908
-        if (isset($this->LIB->{$class_name})) {
909
-            unset($this->LIB->{$class_name});
910
-            return true;
911
-        }
912
-        if ($addon && isset($this->addons->{$class_name})) {
913
-            unset($this->addons->{$class_name});
914
-            return true;
915
-        }
916
-        return false;
917
-    }
918
-
919
-
920
-
921
-    /**
922
-     * attempts to find a full valid filepath for the requested class.
923
-     * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
924
-     * then returns that path if the target file has been found and is readable
925
-     *
926
-     * @param string $class_name
927
-     * @param string $type
928
-     * @param array  $file_paths
929
-     * @return string | bool
930
-     */
931
-    protected function _resolve_path($class_name, $type = '', $file_paths = array())
932
-    {
933
-        // make sure $file_paths is an array
934
-        $file_paths = is_array($file_paths)
935
-            ? $file_paths
936
-            : array($file_paths);
937
-        // cycle thru paths
938
-        foreach ($file_paths as $key => $file_path) {
939
-            // convert all separators to proper DS, if no filepath, then use EE_CLASSES
940
-            $file_path = $file_path
941
-                ? str_replace(array('/', '\\'), DS, $file_path)
942
-                : EE_CLASSES;
943
-            // prep file type
944
-            $type = ! empty($type)
945
-                ? trim($type, '.') . '.'
946
-                : '';
947
-            // build full file path
948
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
949
-            //does the file exist and can be read ?
950
-            if (is_readable($file_paths[$key])) {
951
-                return $file_paths[$key];
952
-            }
953
-        }
954
-        return false;
955
-    }
956
-
957
-
958
-
959
-    /**
960
-     * basically just performs a require_once()
961
-     * but with some error handling
962
-     *
963
-     * @param  string $path
964
-     * @param  string $class_name
965
-     * @param  string $type
966
-     * @param  array  $file_paths
967
-     * @return bool
968
-     * @throws EE_Error
969
-     * @throws ReflectionException
970
-     */
971
-    protected function _require_file($path, $class_name, $type = '', $file_paths = array())
972
-    {
973
-        // don't give up! you gotta...
974
-        try {
975
-            //does the file exist and can it be read ?
976
-            if (! $path) {
977
-                // so sorry, can't find the file
978
-                throw new EE_Error (
979
-                    sprintf(
980
-                        esc_html__(
981
-                            'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s',
982
-                            'event_espresso'
983
-                        ),
984
-                        trim($type, '.'),
985
-                        $class_name,
986
-                        '<br />' . implode(',<br />', $file_paths)
987
-                    )
988
-                );
989
-            }
990
-            // get the file
991
-            require_once($path);
992
-            // if the class isn't already declared somewhere
993
-            if (class_exists($class_name, false) === false) {
994
-                // so sorry, not a class
995
-                throw new EE_Error(
996
-                    sprintf(
997
-                        esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
998
-                        $type,
999
-                        $path,
1000
-                        $class_name
1001
-                    )
1002
-                );
1003
-            }
1004
-        } catch (EE_Error $e) {
1005
-            $e->get_error();
1006
-            return false;
1007
-        }
1008
-        return true;
1009
-    }
1010
-
1011
-
1012
-
1013
-    /**
1014
-     * _create_object
1015
-     * Attempts to instantiate the requested class via any of the
1016
-     * commonly used instantiation methods employed throughout EE.
1017
-     * The priority for instantiation is as follows:
1018
-     *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
1019
-     *        - model objects via their 'new_instance_from_db' method
1020
-     *        - model objects via their 'new_instance' method
1021
-     *        - "singleton" classes" via their 'instance' method
1022
-     *    - standard instantiable classes via their __constructor
1023
-     * Prior to instantiation, if the classname exists in the dependency_map,
1024
-     * then the constructor for the requested class will be examined to determine
1025
-     * if any dependencies exist, and if they can be injected.
1026
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1027
-     *
1028
-     * @param string $class_name
1029
-     * @param array  $arguments
1030
-     * @param string $type
1031
-     * @param bool   $from_db
1032
-     * @return null|object
1033
-     * @throws EE_Error
1034
-     * @throws ReflectionException
1035
-     */
1036
-    protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
1037
-    {
1038
-        $class_obj = null;
1039
-        $instantiation_mode = '0) none';
1040
-        // don't give up! you gotta...
1041
-        try {
1042
-            // create reflection
1043
-            $reflector = $this->get_ReflectionClass($class_name);
1044
-            // make sure arguments are an array
1045
-            $arguments = is_array($arguments)
1046
-                ? $arguments
1047
-                : array($arguments);
1048
-            // and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1049
-            // else wrap it in an additional array so that it doesn't get split into multiple parameters
1050
-            $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1051
-                ? $arguments
1052
-                : array($arguments);
1053
-            // attempt to inject dependencies ?
1054
-            if ($this->_dependency_map->has($class_name)) {
1055
-                $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1056
-            }
1057
-            // instantiate the class if possible
1058
-            if ($reflector->isAbstract()) {
1059
-                // nothing to instantiate, loading file was enough
1060
-                // does not throw an exception so $instantiation_mode is unused
1061
-                // $instantiation_mode = "1) no constructor abstract class";
1062
-                $class_obj = true;
1063
-            } else if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) {
1064
-                // no constructor = static methods only... nothing to instantiate, loading file was enough
1065
-                $instantiation_mode = '2) no constructor but instantiable';
1066
-                $class_obj = $reflector->newInstance();
1067
-            } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1068
-                $instantiation_mode = '3) new_instance_from_db()';
1069
-                $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1070
-            } else if (method_exists($class_name, 'new_instance')) {
1071
-                $instantiation_mode = '4) new_instance()';
1072
-                $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments);
1073
-            } else if (method_exists($class_name, 'instance')) {
1074
-                $instantiation_mode = '5) instance()';
1075
-                $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments);
1076
-            } else if ($reflector->isInstantiable()) {
1077
-                $instantiation_mode = '6) constructor';
1078
-                $class_obj = $reflector->newInstanceArgs($arguments);
1079
-            } else {
1080
-                // heh ? something's not right !
1081
-                throw new EE_Error(
1082
-                    sprintf(
1083
-                        esc_html__('The %s file %s could not be instantiated.', 'event_espresso'),
1084
-                        $type,
1085
-                        $class_name
1086
-                    )
1087
-                );
1088
-            }
1089
-        } catch (Exception $e) {
1090
-            if (! $e instanceof EE_Error) {
1091
-                $e = new EE_Error(
1092
-                    sprintf(
1093
-                        esc_html__(
1094
-                            'The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s',
1095
-                            'event_espresso'
1096
-                        ),
1097
-                        $class_name,
1098
-                        '<br />',
1099
-                        $e->getMessage(),
1100
-                        $instantiation_mode
1101
-                    )
1102
-                );
1103
-            }
1104
-            $e->get_error();
1105
-        }
1106
-        return $class_obj;
1107
-    }
1108
-
1109
-
1110
-
1111
-    /**
1112
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1113
-     * @param array $array
1114
-     * @return bool
1115
-     */
1116
-    protected function _array_is_numerically_and_sequentially_indexed(array $array)
1117
-    {
1118
-        return ! empty($array)
1119
-            ? array_keys($array) === range(0, count($array) - 1)
1120
-            : true;
1121
-    }
1122
-
1123
-
1124
-
1125
-    /**
1126
-     * getReflectionClass
1127
-     * checks if a ReflectionClass object has already been generated for a class
1128
-     * and returns that instead of creating a new one
1129
-     *
1130
-     * @param string $class_name
1131
-     * @return ReflectionClass
1132
-     * @throws ReflectionException
1133
-     */
1134
-    public function get_ReflectionClass($class_name)
1135
-    {
1136
-        if (
1137
-            ! isset($this->_reflectors[$class_name])
1138
-            || ! $this->_reflectors[$class_name] instanceof ReflectionClass
1139
-        ) {
1140
-            $this->_reflectors[$class_name] = new ReflectionClass($class_name);
1141
-        }
1142
-        return $this->_reflectors[$class_name];
1143
-    }
1144
-
1145
-
1146
-
1147
-    /**
1148
-     * _resolve_dependencies
1149
-     * examines the constructor for the requested class to determine
1150
-     * if any dependencies exist, and if they can be injected.
1151
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1152
-     * PLZ NOTE: this is achieved by type hinting the constructor params
1153
-     * For example:
1154
-     *        if attempting to load a class "Foo" with the following constructor:
1155
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
1156
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
1157
-     *        but only IF they are NOT already present in the incoming arguments array,
1158
-     *        and the correct classes can be loaded
1159
-     *
1160
-     * @param ReflectionClass $reflector
1161
-     * @param string          $class_name
1162
-     * @param array           $arguments
1163
-     * @return array
1164
-     * @throws EE_Error
1165
-     * @throws ReflectionException
1166
-     */
1167
-    protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1168
-    {
1169
-        // let's examine the constructor
1170
-        $constructor = $reflector->getConstructor();
1171
-        // whu? huh? nothing?
1172
-        if (! $constructor) {
1173
-            return $arguments;
1174
-        }
1175
-        // get constructor parameters
1176
-        $params = $constructor->getParameters();
1177
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1178
-        $argument_keys = array_keys($arguments);
1179
-        // now loop thru all of the constructors expected parameters
1180
-        foreach ($params as $index => $param) {
1181
-            // is this a dependency for a specific class ?
1182
-            $param_class = $param->getClass()
1183
-                ? $param->getClass()->name
1184
-                : null;
1185
-            // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1186
-            $param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1187
-                ? $this->_dependency_map->get_alias($param_class, $class_name)
1188
-                : $param_class;
1189
-            if (
1190
-                // param is not even a class
1191
-                $param_class === null
1192
-                // and something already exists in the incoming arguments for this param
1193
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1194
-            ) {
1195
-                // so let's skip this argument and move on to the next
1196
-                continue;
1197
-            }
1198
-            if (
1199
-                // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1200
-                $param_class !== null
1201
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1202
-                && $arguments[$argument_keys[$index]] instanceof $param_class
1203
-            ) {
1204
-                // skip this argument and move on to the next
1205
-                continue;
1206
-            }
1207
-            if (
1208
-                // parameter is type hinted as a class, and should be injected
1209
-                $param_class !== null
1210
-                && $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1211
-            ) {
1212
-                $arguments = $this->_resolve_dependency(
1213
-                    $class_name,
1214
-                    $param_class,
1215
-                    $arguments,
1216
-                    $index,
1217
-                    $argument_keys
1218
-                );
1219
-            } else {
1220
-                try {
1221
-                    $arguments[$index] = $param->isDefaultValueAvailable()
1222
-                        ? $param->getDefaultValue()
1223
-                        : null;
1224
-                } catch (ReflectionException $e) {
1225
-                    throw new ReflectionException(
1226
-                        sprintf(
1227
-                            esc_html__('%1$s for parameter "$%2$s"', 'event_espresso'),
1228
-                            $e->getMessage(),
1229
-                            $param->getName()
1230
-                        )
1231
-                    );
1232
-                }
1233
-            }
1234
-        }
1235
-        return $arguments;
1236
-    }
1237
-
1238
-
1239
-
1240
-    /**
1241
-     * @param string $class_name
1242
-     * @param string $param_class
1243
-     * @param array  $arguments
1244
-     * @param mixed  $index
1245
-     * @param array  $argument_keys
1246
-     * @return array
1247
-     * @throws EE_Error
1248
-     * @throws ReflectionException
1249
-     * @throws InvalidArgumentException
1250
-     * @throws InvalidInterfaceException
1251
-     * @throws InvalidDataTypeException
1252
-     */
1253
-    protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys)
1254
-    {
1255
-        $dependency = null;
1256
-        // should dependency be loaded from cache ?
1257
-        $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1258
-            $class_name,
1259
-            $param_class
1260
-        );
1261
-        $cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1262
-        // we might have a dependency...
1263
-        // let's MAYBE try and find it in our cache if that's what's been requested
1264
-        $cached_class = $cache_on
1265
-            ? $this->_get_cached_class($param_class)
1266
-            : null;
1267
-        // and grab it if it exists
1268
-        if ($cached_class instanceof $param_class) {
1269
-            $dependency = $cached_class;
1270
-        } else if ($param_class !== $class_name) {
1271
-            // obtain the loader method from the dependency map
1272
-            $loader = $this->_dependency_map->class_loader($param_class);
1273
-            // is loader a custom closure ?
1274
-            if ($loader instanceof Closure) {
1275
-                $dependency = $loader($arguments);
1276
-            } else {
1277
-                // set the cache on property for the recursive loading call
1278
-                $this->_cache_on = $cache_on;
1279
-                // if not, then let's try and load it via the registry
1280
-                if ($loader && method_exists($this, $loader)) {
1281
-                    $dependency = $this->{$loader}($param_class);
1282
-                } else {
1283
-                    $dependency = LoaderFactory::getLoader()->load(
1284
-                        $param_class,
1285
-                        array(),
1286
-                        $cache_on
1287
-                    );
1288
-                }
1289
-            }
1290
-        }
1291
-        // did we successfully find the correct dependency ?
1292
-        if ($dependency instanceof $param_class) {
1293
-            // then let's inject it into the incoming array of arguments at the correct location
1294
-            $arguments[$index] = $dependency;
1295
-        }
1296
-        return $arguments;
1297
-    }
1298
-
1299
-
1300
-
1301
-    /**
1302
-     * _set_cached_class
1303
-     * attempts to cache the instantiated class locally
1304
-     * in one of the following places, in the following order:
1305
-     *        $this->{class_abbreviation}   ie:    $this->CART
1306
-     *        $this->{$class_name}          ie:    $this->Some_Class
1307
-     *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1308
-     *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1309
-     *
1310
-     * @param object $class_obj
1311
-     * @param string $class_name
1312
-     * @param string $class_prefix
1313
-     * @param bool   $from_db
1314
-     * @return void
1315
-     */
1316
-    protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1317
-    {
1318
-        if ($class_name === 'EE_Registry' || empty($class_obj)) {
1319
-            return;
1320
-        }
1321
-        // return newly instantiated class
1322
-        $class_abbreviation = $this->get_class_abbreviation($class_name, '');
1323
-        if ($class_abbreviation) {
1324
-            $this->{$class_abbreviation} = $class_obj;
1325
-            return;
1326
-        }
1327
-        $class_name = str_replace('\\', '_', $class_name);
1328
-        if (property_exists($this, $class_name)) {
1329
-            $this->{$class_name} = $class_obj;
1330
-            return;
1331
-        }
1332
-        if ($class_prefix === 'addon') {
1333
-            $this->addons->{$class_name} = $class_obj;
1334
-            return;
1335
-        }
1336
-        if (! $from_db) {
1337
-            $this->LIB->{$class_name} = $class_obj;
1338
-        }
1339
-    }
1340
-
1341
-
1342
-
1343
-    /**
1344
-     * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1345
-     *
1346
-     * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1347
-     *                          in the EE_Dependency_Map::$_class_loaders array,
1348
-     *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1349
-     * @param array  $arguments
1350
-     * @return object
1351
-     */
1352
-    public static function factory($classname, $arguments = array())
1353
-    {
1354
-        $loader = self::instance()->_dependency_map->class_loader($classname);
1355
-        if ($loader instanceof Closure) {
1356
-            return $loader($arguments);
1357
-        }
1358
-        if (method_exists(self::instance(), $loader)) {
1359
-            return self::instance()->{$loader}($classname, $arguments);
1360
-        }
1361
-        return null;
1362
-    }
1363
-
1364
-
1365
-
1366
-    /**
1367
-     * Gets the addon by its name/slug (not classname. For that, just
1368
-     * use the classname as the property name on EE_Config::instance()->addons)
1369
-     *
1370
-     * @param string $name
1371
-     * @return EE_Addon
1372
-     */
1373
-    public function get_addon_by_name($name)
1374
-    {
1375
-        foreach ($this->addons as $addon) {
1376
-            if ($addon->name() === $name) {
1377
-                return $addon;
1378
-            }
1379
-        }
1380
-        return null;
1381
-    }
1382
-
1383
-
1384
-
1385
-    /**
1386
-     * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their
1387
-     * name() function) They're already available on EE_Config::instance()->addons as properties, where each property's
1388
-     * name is the addon's classname. So if you just want to get the addon by classname, use
1389
-     * EE_Config::instance()->addons->{classname}
1390
-     *
1391
-     * @return EE_Addon[] where the KEYS are the addon's name()
1392
-     */
1393
-    public function get_addons_by_name()
1394
-    {
1395
-        $addons = array();
1396
-        foreach ($this->addons as $addon) {
1397
-            $addons[$addon->name()] = $addon;
1398
-        }
1399
-        return $addons;
1400
-    }
1401
-
1402
-
1403
-
1404
-    /**
1405
-     * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1406
-     * a stale copy of it around
1407
-     *
1408
-     * @param string $model_name
1409
-     * @return \EEM_Base
1410
-     * @throws \EE_Error
1411
-     */
1412
-    public function reset_model($model_name)
1413
-    {
1414
-        $model_class_name = strpos($model_name, 'EEM_') !== 0
1415
-            ? "EEM_{$model_name}"
1416
-            : $model_name;
1417
-        if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1418
-            return null;
1419
-        }
1420
-        //get that model reset it and make sure we nuke the old reference to it
1421
-        if ($this->LIB->{$model_class_name} instanceof $model_class_name
1422
-            && is_callable(
1423
-                array($model_class_name, 'reset')
1424
-            )) {
1425
-            $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1426
-        } else {
1427
-            throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1428
-        }
1429
-        return $this->LIB->{$model_class_name};
1430
-    }
1431
-
1432
-
1433
-
1434
-    /**
1435
-     * Resets the registry.
1436
-     * The criteria for what gets reset is based on what can be shared between sites on the same request when
1437
-     * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1438
-     * - $_dependency_map
1439
-     * - $_class_abbreviations
1440
-     * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1441
-     * - $REQ:  Still on the same request so no need to change.
1442
-     * - $CAP: There is no site specific state in the EE_Capability class.
1443
-     * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1444
-     * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1445
-     * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1446
-     *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1447
-     *             switch or on the restore.
1448
-     * - $modules
1449
-     * - $shortcodes
1450
-     * - $widgets
1451
-     *
1452
-     * @param boolean $hard             [deprecated]
1453
-     * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1454
-     *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1455
-     *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1456
-     * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1457
-     *                                  client
1458
-     *                                  code instead can just change the model context to a different blog id if
1459
-     *                                  necessary
1460
-     * @return EE_Registry
1461
-     * @throws EE_Error
1462
-     * @throws ReflectionException
1463
-     */
1464
-    public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1465
-    {
1466
-        $instance = self::instance();
1467
-        $instance->_cache_on = true;
1468
-        // reset some "special" classes
1469
-        EEH_Activation::reset();
1470
-        $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1471
-        $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1472
-        $instance->CART = null;
1473
-        $instance->MRM = null;
1474
-        $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1475
-        //messages reset
1476
-        EED_Messages::reset();
1477
-        //handle of objects cached on LIB
1478
-        foreach (array('LIB', 'modules') as $cache) {
1479
-            foreach ($instance->{$cache} as $class_name => $class) {
1480
-                if (self::_reset_and_unset_object($class, $reset_models)) {
1481
-                    unset($instance->{$cache}->{$class_name});
1482
-                }
1483
-            }
1484
-        }
1485
-        return $instance;
1486
-    }
1487
-
1488
-
1489
-
1490
-    /**
1491
-     * if passed object implements ResettableInterface, then call it's reset() method
1492
-     * if passed object implements InterminableInterface, then return false,
1493
-     * to indicate that it should NOT be cleared from the Registry cache
1494
-     *
1495
-     * @param      $object
1496
-     * @param bool $reset_models
1497
-     * @return bool returns true if cached object should be unset
1498
-     */
1499
-    private static function _reset_and_unset_object($object, $reset_models)
1500
-    {
1501
-        if (! is_object($object)) {
1502
-            // don't unset anything that's not an object
1503
-            return false;
1504
-        }
1505
-        if ($object instanceof EED_Module) {
1506
-            $object::reset();
1507
-            // don't unset modules
1508
-            return false;
1509
-        }
1510
-        if ($object instanceof ResettableInterface) {
1511
-            if ($object instanceof EEM_Base) {
1512
-                if ($reset_models) {
1513
-                    $object->reset();
1514
-                    return true;
1515
-                }
1516
-                return false;
1517
-            }
1518
-            $object->reset();
1519
-            return true;
1520
-        }
1521
-        if (! $object instanceof InterminableInterface) {
1522
-            return true;
1523
-        }
1524
-        return false;
1525
-    }
1526
-
1527
-
1528
-
1529
-    /**
1530
-     * Gets all the custom post type models defined
1531
-     *
1532
-     * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1533
-     */
1534
-    public function cpt_models()
1535
-    {
1536
-        $cpt_models = array();
1537
-        foreach ($this->non_abstract_db_models as $short_name => $classname) {
1538
-            if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1539
-                $cpt_models[$short_name] = $classname;
1540
-            }
1541
-        }
1542
-        return $cpt_models;
1543
-    }
1544
-
1545
-
1546
-
1547
-    /**
1548
-     * @return \EE_Config
1549
-     */
1550
-    public static function CFG()
1551
-    {
1552
-        return self::instance()->CFG;
1553
-    }
25
+	/**
26
+	 * @var EE_Registry $_instance
27
+	 */
28
+	private static $_instance;
29
+
30
+	/**
31
+	 * @var EE_Dependency_Map $_dependency_map
32
+	 */
33
+	protected $_dependency_map;
34
+
35
+	/**
36
+	 * @var array $_class_abbreviations
37
+	 */
38
+	protected $_class_abbreviations = array();
39
+
40
+	/**
41
+	 * @var CommandBusInterface $BUS
42
+	 */
43
+	public $BUS;
44
+
45
+	/**
46
+	 * @var EE_Cart $CART
47
+	 */
48
+	public $CART;
49
+
50
+	/**
51
+	 * @var EE_Config $CFG
52
+	 */
53
+	public $CFG;
54
+
55
+	/**
56
+	 * @var EE_Network_Config $NET_CFG
57
+	 */
58
+	public $NET_CFG;
59
+
60
+	/**
61
+	 * StdClass object for storing library classes in
62
+	 *
63
+	 * @var StdClass $LIB
64
+	 */
65
+	public $LIB;
66
+
67
+	/**
68
+	 * @var EE_Request_Handler $REQ
69
+	 */
70
+	public $REQ;
71
+
72
+	/**
73
+	 * @var EE_Session $SSN
74
+	 */
75
+	public $SSN;
76
+
77
+	/**
78
+	 * @since 4.5.0
79
+	 * @var EE_Capabilities $CAP
80
+	 */
81
+	public $CAP;
82
+
83
+	/**
84
+	 * @since 4.9.0
85
+	 * @var EE_Message_Resource_Manager $MRM
86
+	 */
87
+	public $MRM;
88
+
89
+
90
+	/**
91
+	 * @var Registry $AssetsRegistry
92
+	 */
93
+	public $AssetsRegistry;
94
+
95
+	/**
96
+	 * StdClass object for holding addons which have registered themselves to work with EE core
97
+	 *
98
+	 * @var EE_Addon[] $addons
99
+	 */
100
+	public $addons;
101
+
102
+	/**
103
+	 * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
104
+	 *
105
+	 * @var EEM_Base[] $models
106
+	 */
107
+	public $models = array();
108
+
109
+	/**
110
+	 * @var EED_Module[] $modules
111
+	 */
112
+	public $modules;
113
+
114
+	/**
115
+	 * @var EES_Shortcode[] $shortcodes
116
+	 */
117
+	public $shortcodes;
118
+
119
+	/**
120
+	 * @var WP_Widget[] $widgets
121
+	 */
122
+	public $widgets;
123
+
124
+	/**
125
+	 * this is an array of all implemented model names (i.e. not the parent abstract models, or models
126
+	 * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
127
+	 * Keys are model "short names" (eg "Event") as used in model relations, and values are
128
+	 * classnames (eg "EEM_Event")
129
+	 *
130
+	 * @var array $non_abstract_db_models
131
+	 */
132
+	public $non_abstract_db_models = array();
133
+
134
+
135
+	/**
136
+	 * internationalization for JS strings
137
+	 *    usage:   EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' );
138
+	 *    in js file:  var translatedString = eei18n.string_key;
139
+	 *
140
+	 * @var array $i18n_js_strings
141
+	 */
142
+	public static $i18n_js_strings = array();
143
+
144
+
145
+	/**
146
+	 * $main_file - path to espresso.php
147
+	 *
148
+	 * @var array $main_file
149
+	 */
150
+	public $main_file;
151
+
152
+	/**
153
+	 * array of ReflectionClass objects where the key is the class name
154
+	 *
155
+	 * @var ReflectionClass[] $_reflectors
156
+	 */
157
+	public $_reflectors;
158
+
159
+	/**
160
+	 * boolean flag to indicate whether or not to load/save dependencies from/to the cache
161
+	 *
162
+	 * @var boolean $_cache_on
163
+	 */
164
+	protected $_cache_on = true;
165
+
166
+
167
+
168
+	/**
169
+	 * @singleton method used to instantiate class object
170
+	 * @param  EE_Dependency_Map $dependency_map
171
+	 * @return EE_Registry instance
172
+	 * @throws InvalidArgumentException
173
+	 * @throws InvalidInterfaceException
174
+	 * @throws InvalidDataTypeException
175
+	 */
176
+	public static function instance(EE_Dependency_Map $dependency_map = null)
177
+	{
178
+		// check if class object is instantiated
179
+		if (! self::$_instance instanceof EE_Registry) {
180
+			self::$_instance = new self($dependency_map);
181
+		}
182
+		return self::$_instance;
183
+	}
184
+
185
+
186
+
187
+	/**
188
+	 * protected constructor to prevent direct creation
189
+	 *
190
+	 * @Constructor
191
+	 * @param  EE_Dependency_Map $dependency_map
192
+	 * @throws InvalidDataTypeException
193
+	 * @throws InvalidInterfaceException
194
+	 * @throws InvalidArgumentException
195
+	 */
196
+	protected function __construct(EE_Dependency_Map $dependency_map)
197
+	{
198
+		$this->_dependency_map = $dependency_map;
199
+		$this->LIB = new stdClass();
200
+		$this->addons = new stdClass();
201
+		$this->modules = new stdClass();
202
+		$this->shortcodes = new stdClass();
203
+		$this->widgets = new stdClass();
204
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
205
+	}
206
+
207
+
208
+
209
+	/**
210
+	 * initialize
211
+	 *
212
+	 * @throws EE_Error
213
+	 * @throws ReflectionException
214
+	 */
215
+	public function initialize()
216
+	{
217
+		$this->_class_abbreviations = apply_filters(
218
+			'FHEE__EE_Registry____construct___class_abbreviations',
219
+			array(
220
+				'EE_Config'                                       => 'CFG',
221
+				'EE_Session'                                      => 'SSN',
222
+				'EE_Capabilities'                                 => 'CAP',
223
+				'EE_Cart'                                         => 'CART',
224
+				'EE_Network_Config'                               => 'NET_CFG',
225
+				'EE_Request_Handler'                              => 'REQ',
226
+				'EE_Message_Resource_Manager'                     => 'MRM',
227
+				'EventEspresso\core\services\commands\CommandBus' => 'BUS',
228
+				'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
229
+			)
230
+		);
231
+		$this->load_core('Base', array(), true);
232
+		// add our request and response objects to the cache
233
+		$request_loader = $this->_dependency_map->class_loader('EE_Request');
234
+		$this->_set_cached_class(
235
+			$request_loader(),
236
+			'EE_Request'
237
+		);
238
+		$response_loader = $this->_dependency_map->class_loader('EE_Response');
239
+		$this->_set_cached_class(
240
+			$response_loader(),
241
+			'EE_Response'
242
+		);
243
+		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
244
+	}
245
+
246
+
247
+
248
+	/**
249
+	 * @return void
250
+	 */
251
+	public function init()
252
+	{
253
+		// Get current page protocol
254
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
255
+		// Output admin-ajax.php URL with same protocol as current page
256
+		self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
257
+		self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
258
+	}
259
+
260
+
261
+
262
+	/**
263
+	 * localize_i18n_js_strings
264
+	 *
265
+	 * @return string
266
+	 */
267
+	public static function localize_i18n_js_strings()
268
+	{
269
+		$i18n_js_strings = (array)self::$i18n_js_strings;
270
+		foreach ($i18n_js_strings as $key => $value) {
271
+			if (is_scalar($value)) {
272
+				$i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
273
+			}
274
+		}
275
+		return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
276
+	}
277
+
278
+
279
+
280
+	/**
281
+	 * @param mixed string | EED_Module $module
282
+	 * @throws EE_Error
283
+	 * @throws ReflectionException
284
+	 */
285
+	public function add_module($module)
286
+	{
287
+		if ($module instanceof EED_Module) {
288
+			$module_class = get_class($module);
289
+			$this->modules->{$module_class} = $module;
290
+		} else {
291
+			if (! class_exists('EE_Module_Request_Router')) {
292
+				$this->load_core('Module_Request_Router');
293
+			}
294
+			EE_Module_Request_Router::module_factory($module);
295
+		}
296
+	}
297
+
298
+
299
+
300
+	/**
301
+	 * @param string $module_name
302
+	 * @return mixed EED_Module | NULL
303
+	 */
304
+	public function get_module($module_name = '')
305
+	{
306
+		return isset($this->modules->{$module_name})
307
+			? $this->modules->{$module_name}
308
+			: null;
309
+	}
310
+
311
+
312
+
313
+	/**
314
+	 * loads core classes - must be singletons
315
+	 *
316
+	 * @param string $class_name - simple class name ie: session
317
+	 * @param mixed  $arguments
318
+	 * @param bool   $load_only
319
+	 * @return mixed
320
+	 * @throws EE_Error
321
+	 * @throws ReflectionException
322
+	 */
323
+	public function load_core($class_name, $arguments = array(), $load_only = false)
324
+	{
325
+		$core_paths = apply_filters(
326
+			'FHEE__EE_Registry__load_core__core_paths',
327
+			array(
328
+				EE_CORE,
329
+				EE_ADMIN,
330
+				EE_CPTS,
331
+				EE_CORE . 'data_migration_scripts' . DS,
332
+				EE_CORE . 'capabilities' . DS,
333
+				EE_CORE . 'request_stack' . DS,
334
+				EE_CORE . 'middleware' . DS,
335
+			)
336
+		);
337
+		// retrieve instantiated class
338
+		return $this->_load(
339
+			$core_paths,
340
+			'EE_',
341
+			$class_name,
342
+			'core',
343
+			$arguments,
344
+			false,
345
+			true,
346
+			$load_only
347
+		);
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * loads service classes
354
+	 *
355
+	 * @param string $class_name - simple class name ie: session
356
+	 * @param mixed  $arguments
357
+	 * @param bool   $load_only
358
+	 * @return mixed
359
+	 * @throws EE_Error
360
+	 * @throws ReflectionException
361
+	 */
362
+	public function load_service($class_name, $arguments = array(), $load_only = false)
363
+	{
364
+		$service_paths = apply_filters(
365
+			'FHEE__EE_Registry__load_service__service_paths',
366
+			array(
367
+				EE_CORE . 'services' . DS,
368
+			)
369
+		);
370
+		// retrieve instantiated class
371
+		return $this->_load(
372
+			$service_paths,
373
+			'EE_',
374
+			$class_name,
375
+			'class',
376
+			$arguments,
377
+			false,
378
+			true,
379
+			$load_only
380
+		);
381
+	}
382
+
383
+
384
+
385
+	/**
386
+	 * loads data_migration_scripts
387
+	 *
388
+	 * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
389
+	 * @param mixed  $arguments
390
+	 * @return EE_Data_Migration_Script_Base|mixed
391
+	 * @throws EE_Error
392
+	 * @throws ReflectionException
393
+	 */
394
+	public function load_dms($class_name, $arguments = array())
395
+	{
396
+		// retrieve instantiated class
397
+		return $this->_load(
398
+			EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(),
399
+			'EE_DMS_',
400
+			$class_name,
401
+			'dms',
402
+			$arguments,
403
+			false,
404
+			false
405
+		);
406
+	}
407
+
408
+
409
+
410
+	/**
411
+	 * loads object creating classes - must be singletons
412
+	 *
413
+	 * @param string $class_name - simple class name ie: attendee
414
+	 * @param mixed  $arguments  - an array of arguments to pass to the class
415
+	 * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to
416
+	 *                           instantiate
417
+	 * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then
418
+	 *                           set this to FALSE (ie. when instantiating model objects from client in a loop)
419
+	 * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate
420
+	 *                           (default)
421
+	 * @return EE_Base_Class | bool
422
+	 * @throws EE_Error
423
+	 * @throws ReflectionException
424
+	 */
425
+	public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
426
+	{
427
+		$paths = apply_filters(
428
+			'FHEE__EE_Registry__load_class__paths', array(
429
+			EE_CORE,
430
+			EE_CLASSES,
431
+			EE_BUSINESS,
432
+		)
433
+		);
434
+		// retrieve instantiated class
435
+		return $this->_load(
436
+			$paths,
437
+			'EE_',
438
+			$class_name,
439
+			'class',
440
+			$arguments,
441
+			$from_db,
442
+			$cache,
443
+			$load_only
444
+		);
445
+	}
446
+
447
+
448
+
449
+	/**
450
+	 * loads helper classes - must be singletons
451
+	 *
452
+	 * @param string $class_name - simple class name ie: price
453
+	 * @param mixed  $arguments
454
+	 * @param bool   $load_only
455
+	 * @return EEH_Base | bool
456
+	 * @throws EE_Error
457
+	 * @throws ReflectionException
458
+	 */
459
+	public function load_helper($class_name, $arguments = array(), $load_only = true)
460
+	{
461
+		// todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
462
+		$helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
463
+		// retrieve instantiated class
464
+		return $this->_load(
465
+			$helper_paths,
466
+			'EEH_',
467
+			$class_name,
468
+			'helper',
469
+			$arguments,
470
+			false,
471
+			true,
472
+			$load_only
473
+		);
474
+	}
475
+
476
+
477
+
478
+	/**
479
+	 * loads core classes - must be singletons
480
+	 *
481
+	 * @param string $class_name - simple class name ie: session
482
+	 * @param mixed  $arguments
483
+	 * @param bool   $load_only
484
+	 * @param bool   $cache      whether to cache the object or not.
485
+	 * @return mixed
486
+	 * @throws EE_Error
487
+	 * @throws ReflectionException
488
+	 */
489
+	public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
490
+	{
491
+		$paths = array(
492
+			EE_LIBRARIES,
493
+			EE_LIBRARIES . 'messages' . DS,
494
+			EE_LIBRARIES . 'shortcodes' . DS,
495
+			EE_LIBRARIES . 'qtips' . DS,
496
+			EE_LIBRARIES . 'payment_methods' . DS,
497
+		);
498
+		// retrieve instantiated class
499
+		return $this->_load(
500
+			$paths,
501
+			'EE_',
502
+			$class_name,
503
+			'lib',
504
+			$arguments,
505
+			false,
506
+			$cache,
507
+			$load_only
508
+		);
509
+	}
510
+
511
+
512
+
513
+	/**
514
+	 * loads model classes - must be singletons
515
+	 *
516
+	 * @param string $class_name - simple class name ie: price
517
+	 * @param mixed  $arguments
518
+	 * @param bool   $load_only
519
+	 * @return EEM_Base | bool
520
+	 * @throws EE_Error
521
+	 * @throws ReflectionException
522
+	 */
523
+	public function load_model($class_name, $arguments = array(), $load_only = false)
524
+	{
525
+		$paths = apply_filters(
526
+			'FHEE__EE_Registry__load_model__paths', array(
527
+			EE_MODELS,
528
+			EE_CORE,
529
+		)
530
+		);
531
+		// retrieve instantiated class
532
+		return $this->_load(
533
+			$paths,
534
+			'EEM_',
535
+			$class_name,
536
+			'model',
537
+			$arguments,
538
+			false,
539
+			true,
540
+			$load_only
541
+		);
542
+	}
543
+
544
+
545
+
546
+	/**
547
+	 * loads model classes - must be singletons
548
+	 *
549
+	 * @param string $class_name - simple class name ie: price
550
+	 * @param mixed  $arguments
551
+	 * @param bool   $load_only
552
+	 * @return mixed | bool
553
+	 * @throws EE_Error
554
+	 * @throws ReflectionException
555
+	 */
556
+	public function load_model_class($class_name, $arguments = array(), $load_only = true)
557
+	{
558
+		$paths = array(
559
+			EE_MODELS . 'fields' . DS,
560
+			EE_MODELS . 'helpers' . DS,
561
+			EE_MODELS . 'relations' . DS,
562
+			EE_MODELS . 'strategies' . DS,
563
+		);
564
+		// retrieve instantiated class
565
+		return $this->_load(
566
+			$paths,
567
+			'EE_',
568
+			$class_name,
569
+			'',
570
+			$arguments,
571
+			false,
572
+			true,
573
+			$load_only
574
+		);
575
+	}
576
+
577
+
578
+
579
+	/**
580
+	 * Determines if $model_name is the name of an actual EE model.
581
+	 *
582
+	 * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
583
+	 * @return boolean
584
+	 */
585
+	public function is_model_name($model_name)
586
+	{
587
+		return isset($this->models[$model_name]);
588
+	}
589
+
590
+
591
+
592
+	/**
593
+	 * generic class loader
594
+	 *
595
+	 * @param string $path_to_file - directory path to file location, not including filename
596
+	 * @param string $file_name    - file name  ie:  my_file.php, including extension
597
+	 * @param string $type         - file type - core? class? helper? model?
598
+	 * @param mixed  $arguments
599
+	 * @param bool   $load_only
600
+	 * @return mixed
601
+	 * @throws EE_Error
602
+	 * @throws ReflectionException
603
+	 */
604
+	public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
605
+	{
606
+		// retrieve instantiated class
607
+		return $this->_load(
608
+			$path_to_file,
609
+			'',
610
+			$file_name,
611
+			$type,
612
+			$arguments,
613
+			false,
614
+			true,
615
+			$load_only
616
+		);
617
+	}
618
+
619
+
620
+
621
+	/**
622
+	 * @param string $path_to_file - directory path to file location, not including filename
623
+	 * @param string $class_name   - full class name  ie:  My_Class
624
+	 * @param string $type         - file type - core? class? helper? model?
625
+	 * @param mixed  $arguments
626
+	 * @param bool   $load_only
627
+	 * @return bool|EE_Addon|object
628
+	 * @throws EE_Error
629
+	 * @throws ReflectionException
630
+	 */
631
+	public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
632
+	{
633
+		// retrieve instantiated class
634
+		return $this->_load(
635
+			$path_to_file,
636
+			'addon',
637
+			$class_name,
638
+			$type,
639
+			$arguments,
640
+			false,
641
+			true,
642
+			$load_only
643
+		);
644
+	}
645
+
646
+
647
+
648
+	/**
649
+	 * instantiates, caches, and automatically resolves dependencies
650
+	 * for classes that use a Fully Qualified Class Name.
651
+	 * if the class is not capable of being loaded using PSR-4 autoloading,
652
+	 * then you need to use one of the existing load_*() methods
653
+	 * which can resolve the classname and filepath from the passed arguments
654
+	 *
655
+	 * @param bool|string $class_name   Fully Qualified Class Name
656
+	 * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
657
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
658
+	 * @param bool        $from_db      some classes are instantiated from the db
659
+	 *                                  and thus call a different method to instantiate
660
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
661
+	 * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
662
+	 * @return bool|null|mixed          null = failure to load or instantiate class object.
663
+	 *                                  object = class loaded and instantiated successfully.
664
+	 *                                  bool = fail or success when $load_only is true
665
+	 * @throws EE_Error
666
+	 * @throws ReflectionException
667
+	 */
668
+	public function create(
669
+		$class_name = false,
670
+		$arguments = array(),
671
+		$cache = false,
672
+		$from_db = false,
673
+		$load_only = false,
674
+		$addon = false
675
+	) {
676
+		$class_name = ltrim($class_name, '\\');
677
+		$class_name = $this->_dependency_map->get_alias($class_name);
678
+		$class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
679
+		// if a non-FQCN was passed, then verifyClassExists() might return an object
680
+		// or it could return null if the class just could not be found anywhere
681
+		if ($class_exists instanceof $class_name || $class_exists === null){
682
+			// either way, return the results
683
+			return $class_exists;
684
+		}
685
+		$class_name = $class_exists;
686
+		// if we're only loading the class and it already exists, then let's just return true immediately
687
+		if ($load_only) {
688
+			return true;
689
+		}
690
+		$addon = $addon
691
+			? 'addon'
692
+			: '';
693
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
694
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
695
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
696
+		if ($this->_cache_on && $cache && ! $load_only) {
697
+			// return object if it's already cached
698
+			$cached_class = $this->_get_cached_class($class_name, $addon);
699
+			if ($cached_class !== null) {
700
+				return $cached_class;
701
+			}
702
+		}
703
+		// obtain the loader method from the dependency map
704
+		$loader = $this->_dependency_map->class_loader($class_name);
705
+		// instantiate the requested object
706
+		if ($loader instanceof Closure) {
707
+			$class_obj = $loader($arguments);
708
+		} else if ($loader && method_exists($this, $loader)) {
709
+			$class_obj = $this->{$loader}($class_name, $arguments);
710
+		} else {
711
+			$class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
712
+		}
713
+		if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) {
714
+			// save it for later... kinda like gum  { : $
715
+			$this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
716
+		}
717
+		$this->_cache_on = true;
718
+		return $class_obj;
719
+	}
720
+
721
+
722
+
723
+	/**
724
+	 * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
725
+	 *
726
+	 * @param string $class_name
727
+	 * @param array  $arguments
728
+	 * @param int    $attempt
729
+	 * @return mixed
730
+	 */
731
+	private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) {
732
+		if (is_object($class_name) || class_exists($class_name)) {
733
+			return $class_name;
734
+		}
735
+		switch ($attempt) {
736
+			case 1:
737
+				// if it's a FQCN then maybe the class is registered with a preceding \
738
+				$class_name = strpos($class_name, '\\') !== false
739
+					? '\\' . ltrim($class_name, '\\')
740
+					: $class_name;
741
+				break;
742
+			case 2:
743
+				//
744
+				$loader = $this->_dependency_map->class_loader($class_name);
745
+				if ($loader && method_exists($this, $loader)) {
746
+					return $this->{$loader}($class_name, $arguments);
747
+				}
748
+				break;
749
+			case 3:
750
+			default;
751
+				return null;
752
+		}
753
+		$attempt++;
754
+		return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
755
+	}
756
+
757
+
758
+
759
+	/**
760
+	 * instantiates, caches, and injects dependencies for classes
761
+	 *
762
+	 * @param array       $file_paths   an array of paths to folders to look in
763
+	 * @param string      $class_prefix EE  or EEM or... ???
764
+	 * @param bool|string $class_name   $class name
765
+	 * @param string      $type         file type - core? class? helper? model?
766
+	 * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
767
+	 * @param bool        $from_db      some classes are instantiated from the db
768
+	 *                                  and thus call a different method to instantiate
769
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
770
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
771
+	 * @return bool|null|object null = failure to load or instantiate class object.
772
+	 *                                  object = class loaded and instantiated successfully.
773
+	 *                                  bool = fail or success when $load_only is true
774
+	 * @throws EE_Error
775
+	 * @throws ReflectionException
776
+	 */
777
+	protected function _load(
778
+		$file_paths = array(),
779
+		$class_prefix = 'EE_',
780
+		$class_name = false,
781
+		$type = 'class',
782
+		$arguments = array(),
783
+		$from_db = false,
784
+		$cache = true,
785
+		$load_only = false
786
+	) {
787
+		$class_name = ltrim($class_name, '\\');
788
+		// strip php file extension
789
+		$class_name = str_replace('.php', '', trim($class_name));
790
+		// does the class have a prefix ?
791
+		if (! empty($class_prefix) && $class_prefix !== 'addon') {
792
+			// make sure $class_prefix is uppercase
793
+			$class_prefix = strtoupper(trim($class_prefix));
794
+			// add class prefix ONCE!!!
795
+			$class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
796
+		}
797
+		$class_name = $this->_dependency_map->get_alias($class_name);
798
+		$class_exists = class_exists($class_name);
799
+		// if we're only loading the class and it already exists, then let's just return true immediately
800
+		if ($load_only && $class_exists) {
801
+			return true;
802
+		}
803
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
804
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
805
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
806
+		if ($this->_cache_on && $cache && ! $load_only) {
807
+			// return object if it's already cached
808
+			$cached_class = $this->_get_cached_class($class_name, $class_prefix);
809
+			if ($cached_class !== null) {
810
+				return $cached_class;
811
+			}
812
+		}
813
+		// if the class doesn't already exist.. then we need to try and find the file and load it
814
+		if (! $class_exists) {
815
+			// get full path to file
816
+			$path = $this->_resolve_path($class_name, $type, $file_paths);
817
+			// load the file
818
+			$loaded = $this->_require_file($path, $class_name, $type, $file_paths);
819
+			// if loading failed, or we are only loading a file but NOT instantiating an object
820
+			if (! $loaded || $load_only) {
821
+				// return boolean if only loading, or null if an object was expected
822
+				return $load_only
823
+					? $loaded
824
+					: null;
825
+			}
826
+		}
827
+		// instantiate the requested object
828
+		$class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
829
+		if ($this->_cache_on && $cache) {
830
+			// save it for later... kinda like gum  { : $
831
+			$this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
832
+		}
833
+		$this->_cache_on = true;
834
+		return $class_obj;
835
+	}
836
+
837
+
838
+
839
+	/**
840
+	 * @param string $class_name
841
+	 * @param string $default have to specify something, but not anything that will conflict
842
+	 * @return mixed|string
843
+	 */
844
+	protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
845
+	{
846
+		return isset($this->_class_abbreviations[$class_name])
847
+			? $this->_class_abbreviations[$class_name]
848
+			: $default;
849
+	}
850
+
851
+	/**
852
+	 * attempts to find a cached version of the requested class
853
+	 * by looking in the following places:
854
+	 *        $this->{$class_abbreviation}            ie:    $this->CART
855
+	 *        $this->{$class_name}                        ie:    $this->Some_Class
856
+	 *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
857
+	 *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
858
+	 *
859
+	 * @param string $class_name
860
+	 * @param string $class_prefix
861
+	 * @return mixed
862
+	 */
863
+	protected function _get_cached_class($class_name, $class_prefix = '')
864
+	{
865
+		if ($class_name === 'EE_Registry') {
866
+			return $this;
867
+		}
868
+		$class_abbreviation = $this->get_class_abbreviation($class_name);
869
+		$class_name = str_replace('\\', '_', $class_name);
870
+		// check if class has already been loaded, and return it if it has been
871
+		if (isset($this->{$class_abbreviation})) {
872
+			return $this->{$class_abbreviation};
873
+		}
874
+		if (isset ($this->{$class_name})) {
875
+			return $this->{$class_name};
876
+		}
877
+		if (isset ($this->LIB->{$class_name})) {
878
+			return $this->LIB->{$class_name};
879
+		}
880
+		if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
881
+			return $this->addons->{$class_name};
882
+		}
883
+		return null;
884
+	}
885
+
886
+
887
+
888
+	/**
889
+	 * removes a cached version of the requested class
890
+	 *
891
+	 * @param string  $class_name
892
+	 * @param boolean $addon
893
+	 * @return boolean
894
+	 */
895
+	public function clear_cached_class($class_name, $addon = false)
896
+	{
897
+		$class_abbreviation = $this->get_class_abbreviation($class_name);
898
+		$class_name = str_replace('\\', '_', $class_name);
899
+		// check if class has already been loaded, and return it if it has been
900
+		if (isset($this->{$class_abbreviation})) {
901
+			$this->{$class_abbreviation} = null;
902
+			return true;
903
+		}
904
+		if (isset($this->{$class_name})) {
905
+			$this->{$class_name} = null;
906
+			return true;
907
+		}
908
+		if (isset($this->LIB->{$class_name})) {
909
+			unset($this->LIB->{$class_name});
910
+			return true;
911
+		}
912
+		if ($addon && isset($this->addons->{$class_name})) {
913
+			unset($this->addons->{$class_name});
914
+			return true;
915
+		}
916
+		return false;
917
+	}
918
+
919
+
920
+
921
+	/**
922
+	 * attempts to find a full valid filepath for the requested class.
923
+	 * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
924
+	 * then returns that path if the target file has been found and is readable
925
+	 *
926
+	 * @param string $class_name
927
+	 * @param string $type
928
+	 * @param array  $file_paths
929
+	 * @return string | bool
930
+	 */
931
+	protected function _resolve_path($class_name, $type = '', $file_paths = array())
932
+	{
933
+		// make sure $file_paths is an array
934
+		$file_paths = is_array($file_paths)
935
+			? $file_paths
936
+			: array($file_paths);
937
+		// cycle thru paths
938
+		foreach ($file_paths as $key => $file_path) {
939
+			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
940
+			$file_path = $file_path
941
+				? str_replace(array('/', '\\'), DS, $file_path)
942
+				: EE_CLASSES;
943
+			// prep file type
944
+			$type = ! empty($type)
945
+				? trim($type, '.') . '.'
946
+				: '';
947
+			// build full file path
948
+			$file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
949
+			//does the file exist and can be read ?
950
+			if (is_readable($file_paths[$key])) {
951
+				return $file_paths[$key];
952
+			}
953
+		}
954
+		return false;
955
+	}
956
+
957
+
958
+
959
+	/**
960
+	 * basically just performs a require_once()
961
+	 * but with some error handling
962
+	 *
963
+	 * @param  string $path
964
+	 * @param  string $class_name
965
+	 * @param  string $type
966
+	 * @param  array  $file_paths
967
+	 * @return bool
968
+	 * @throws EE_Error
969
+	 * @throws ReflectionException
970
+	 */
971
+	protected function _require_file($path, $class_name, $type = '', $file_paths = array())
972
+	{
973
+		// don't give up! you gotta...
974
+		try {
975
+			//does the file exist and can it be read ?
976
+			if (! $path) {
977
+				// so sorry, can't find the file
978
+				throw new EE_Error (
979
+					sprintf(
980
+						esc_html__(
981
+							'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s',
982
+							'event_espresso'
983
+						),
984
+						trim($type, '.'),
985
+						$class_name,
986
+						'<br />' . implode(',<br />', $file_paths)
987
+					)
988
+				);
989
+			}
990
+			// get the file
991
+			require_once($path);
992
+			// if the class isn't already declared somewhere
993
+			if (class_exists($class_name, false) === false) {
994
+				// so sorry, not a class
995
+				throw new EE_Error(
996
+					sprintf(
997
+						esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
998
+						$type,
999
+						$path,
1000
+						$class_name
1001
+					)
1002
+				);
1003
+			}
1004
+		} catch (EE_Error $e) {
1005
+			$e->get_error();
1006
+			return false;
1007
+		}
1008
+		return true;
1009
+	}
1010
+
1011
+
1012
+
1013
+	/**
1014
+	 * _create_object
1015
+	 * Attempts to instantiate the requested class via any of the
1016
+	 * commonly used instantiation methods employed throughout EE.
1017
+	 * The priority for instantiation is as follows:
1018
+	 *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
1019
+	 *        - model objects via their 'new_instance_from_db' method
1020
+	 *        - model objects via their 'new_instance' method
1021
+	 *        - "singleton" classes" via their 'instance' method
1022
+	 *    - standard instantiable classes via their __constructor
1023
+	 * Prior to instantiation, if the classname exists in the dependency_map,
1024
+	 * then the constructor for the requested class will be examined to determine
1025
+	 * if any dependencies exist, and if they can be injected.
1026
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1027
+	 *
1028
+	 * @param string $class_name
1029
+	 * @param array  $arguments
1030
+	 * @param string $type
1031
+	 * @param bool   $from_db
1032
+	 * @return null|object
1033
+	 * @throws EE_Error
1034
+	 * @throws ReflectionException
1035
+	 */
1036
+	protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
1037
+	{
1038
+		$class_obj = null;
1039
+		$instantiation_mode = '0) none';
1040
+		// don't give up! you gotta...
1041
+		try {
1042
+			// create reflection
1043
+			$reflector = $this->get_ReflectionClass($class_name);
1044
+			// make sure arguments are an array
1045
+			$arguments = is_array($arguments)
1046
+				? $arguments
1047
+				: array($arguments);
1048
+			// and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1049
+			// else wrap it in an additional array so that it doesn't get split into multiple parameters
1050
+			$arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1051
+				? $arguments
1052
+				: array($arguments);
1053
+			// attempt to inject dependencies ?
1054
+			if ($this->_dependency_map->has($class_name)) {
1055
+				$arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1056
+			}
1057
+			// instantiate the class if possible
1058
+			if ($reflector->isAbstract()) {
1059
+				// nothing to instantiate, loading file was enough
1060
+				// does not throw an exception so $instantiation_mode is unused
1061
+				// $instantiation_mode = "1) no constructor abstract class";
1062
+				$class_obj = true;
1063
+			} else if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) {
1064
+				// no constructor = static methods only... nothing to instantiate, loading file was enough
1065
+				$instantiation_mode = '2) no constructor but instantiable';
1066
+				$class_obj = $reflector->newInstance();
1067
+			} else if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1068
+				$instantiation_mode = '3) new_instance_from_db()';
1069
+				$class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1070
+			} else if (method_exists($class_name, 'new_instance')) {
1071
+				$instantiation_mode = '4) new_instance()';
1072
+				$class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments);
1073
+			} else if (method_exists($class_name, 'instance')) {
1074
+				$instantiation_mode = '5) instance()';
1075
+				$class_obj = call_user_func_array(array($class_name, 'instance'), $arguments);
1076
+			} else if ($reflector->isInstantiable()) {
1077
+				$instantiation_mode = '6) constructor';
1078
+				$class_obj = $reflector->newInstanceArgs($arguments);
1079
+			} else {
1080
+				// heh ? something's not right !
1081
+				throw new EE_Error(
1082
+					sprintf(
1083
+						esc_html__('The %s file %s could not be instantiated.', 'event_espresso'),
1084
+						$type,
1085
+						$class_name
1086
+					)
1087
+				);
1088
+			}
1089
+		} catch (Exception $e) {
1090
+			if (! $e instanceof EE_Error) {
1091
+				$e = new EE_Error(
1092
+					sprintf(
1093
+						esc_html__(
1094
+							'The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s',
1095
+							'event_espresso'
1096
+						),
1097
+						$class_name,
1098
+						'<br />',
1099
+						$e->getMessage(),
1100
+						$instantiation_mode
1101
+					)
1102
+				);
1103
+			}
1104
+			$e->get_error();
1105
+		}
1106
+		return $class_obj;
1107
+	}
1108
+
1109
+
1110
+
1111
+	/**
1112
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1113
+	 * @param array $array
1114
+	 * @return bool
1115
+	 */
1116
+	protected function _array_is_numerically_and_sequentially_indexed(array $array)
1117
+	{
1118
+		return ! empty($array)
1119
+			? array_keys($array) === range(0, count($array) - 1)
1120
+			: true;
1121
+	}
1122
+
1123
+
1124
+
1125
+	/**
1126
+	 * getReflectionClass
1127
+	 * checks if a ReflectionClass object has already been generated for a class
1128
+	 * and returns that instead of creating a new one
1129
+	 *
1130
+	 * @param string $class_name
1131
+	 * @return ReflectionClass
1132
+	 * @throws ReflectionException
1133
+	 */
1134
+	public function get_ReflectionClass($class_name)
1135
+	{
1136
+		if (
1137
+			! isset($this->_reflectors[$class_name])
1138
+			|| ! $this->_reflectors[$class_name] instanceof ReflectionClass
1139
+		) {
1140
+			$this->_reflectors[$class_name] = new ReflectionClass($class_name);
1141
+		}
1142
+		return $this->_reflectors[$class_name];
1143
+	}
1144
+
1145
+
1146
+
1147
+	/**
1148
+	 * _resolve_dependencies
1149
+	 * examines the constructor for the requested class to determine
1150
+	 * if any dependencies exist, and if they can be injected.
1151
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1152
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
1153
+	 * For example:
1154
+	 *        if attempting to load a class "Foo" with the following constructor:
1155
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
1156
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
1157
+	 *        but only IF they are NOT already present in the incoming arguments array,
1158
+	 *        and the correct classes can be loaded
1159
+	 *
1160
+	 * @param ReflectionClass $reflector
1161
+	 * @param string          $class_name
1162
+	 * @param array           $arguments
1163
+	 * @return array
1164
+	 * @throws EE_Error
1165
+	 * @throws ReflectionException
1166
+	 */
1167
+	protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1168
+	{
1169
+		// let's examine the constructor
1170
+		$constructor = $reflector->getConstructor();
1171
+		// whu? huh? nothing?
1172
+		if (! $constructor) {
1173
+			return $arguments;
1174
+		}
1175
+		// get constructor parameters
1176
+		$params = $constructor->getParameters();
1177
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1178
+		$argument_keys = array_keys($arguments);
1179
+		// now loop thru all of the constructors expected parameters
1180
+		foreach ($params as $index => $param) {
1181
+			// is this a dependency for a specific class ?
1182
+			$param_class = $param->getClass()
1183
+				? $param->getClass()->name
1184
+				: null;
1185
+			// BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1186
+			$param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1187
+				? $this->_dependency_map->get_alias($param_class, $class_name)
1188
+				: $param_class;
1189
+			if (
1190
+				// param is not even a class
1191
+				$param_class === null
1192
+				// and something already exists in the incoming arguments for this param
1193
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1194
+			) {
1195
+				// so let's skip this argument and move on to the next
1196
+				continue;
1197
+			}
1198
+			if (
1199
+				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1200
+				$param_class !== null
1201
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1202
+				&& $arguments[$argument_keys[$index]] instanceof $param_class
1203
+			) {
1204
+				// skip this argument and move on to the next
1205
+				continue;
1206
+			}
1207
+			if (
1208
+				// parameter is type hinted as a class, and should be injected
1209
+				$param_class !== null
1210
+				&& $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1211
+			) {
1212
+				$arguments = $this->_resolve_dependency(
1213
+					$class_name,
1214
+					$param_class,
1215
+					$arguments,
1216
+					$index,
1217
+					$argument_keys
1218
+				);
1219
+			} else {
1220
+				try {
1221
+					$arguments[$index] = $param->isDefaultValueAvailable()
1222
+						? $param->getDefaultValue()
1223
+						: null;
1224
+				} catch (ReflectionException $e) {
1225
+					throw new ReflectionException(
1226
+						sprintf(
1227
+							esc_html__('%1$s for parameter "$%2$s"', 'event_espresso'),
1228
+							$e->getMessage(),
1229
+							$param->getName()
1230
+						)
1231
+					);
1232
+				}
1233
+			}
1234
+		}
1235
+		return $arguments;
1236
+	}
1237
+
1238
+
1239
+
1240
+	/**
1241
+	 * @param string $class_name
1242
+	 * @param string $param_class
1243
+	 * @param array  $arguments
1244
+	 * @param mixed  $index
1245
+	 * @param array  $argument_keys
1246
+	 * @return array
1247
+	 * @throws EE_Error
1248
+	 * @throws ReflectionException
1249
+	 * @throws InvalidArgumentException
1250
+	 * @throws InvalidInterfaceException
1251
+	 * @throws InvalidDataTypeException
1252
+	 */
1253
+	protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys)
1254
+	{
1255
+		$dependency = null;
1256
+		// should dependency be loaded from cache ?
1257
+		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1258
+			$class_name,
1259
+			$param_class
1260
+		);
1261
+		$cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1262
+		// we might have a dependency...
1263
+		// let's MAYBE try and find it in our cache if that's what's been requested
1264
+		$cached_class = $cache_on
1265
+			? $this->_get_cached_class($param_class)
1266
+			: null;
1267
+		// and grab it if it exists
1268
+		if ($cached_class instanceof $param_class) {
1269
+			$dependency = $cached_class;
1270
+		} else if ($param_class !== $class_name) {
1271
+			// obtain the loader method from the dependency map
1272
+			$loader = $this->_dependency_map->class_loader($param_class);
1273
+			// is loader a custom closure ?
1274
+			if ($loader instanceof Closure) {
1275
+				$dependency = $loader($arguments);
1276
+			} else {
1277
+				// set the cache on property for the recursive loading call
1278
+				$this->_cache_on = $cache_on;
1279
+				// if not, then let's try and load it via the registry
1280
+				if ($loader && method_exists($this, $loader)) {
1281
+					$dependency = $this->{$loader}($param_class);
1282
+				} else {
1283
+					$dependency = LoaderFactory::getLoader()->load(
1284
+						$param_class,
1285
+						array(),
1286
+						$cache_on
1287
+					);
1288
+				}
1289
+			}
1290
+		}
1291
+		// did we successfully find the correct dependency ?
1292
+		if ($dependency instanceof $param_class) {
1293
+			// then let's inject it into the incoming array of arguments at the correct location
1294
+			$arguments[$index] = $dependency;
1295
+		}
1296
+		return $arguments;
1297
+	}
1298
+
1299
+
1300
+
1301
+	/**
1302
+	 * _set_cached_class
1303
+	 * attempts to cache the instantiated class locally
1304
+	 * in one of the following places, in the following order:
1305
+	 *        $this->{class_abbreviation}   ie:    $this->CART
1306
+	 *        $this->{$class_name}          ie:    $this->Some_Class
1307
+	 *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1308
+	 *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1309
+	 *
1310
+	 * @param object $class_obj
1311
+	 * @param string $class_name
1312
+	 * @param string $class_prefix
1313
+	 * @param bool   $from_db
1314
+	 * @return void
1315
+	 */
1316
+	protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1317
+	{
1318
+		if ($class_name === 'EE_Registry' || empty($class_obj)) {
1319
+			return;
1320
+		}
1321
+		// return newly instantiated class
1322
+		$class_abbreviation = $this->get_class_abbreviation($class_name, '');
1323
+		if ($class_abbreviation) {
1324
+			$this->{$class_abbreviation} = $class_obj;
1325
+			return;
1326
+		}
1327
+		$class_name = str_replace('\\', '_', $class_name);
1328
+		if (property_exists($this, $class_name)) {
1329
+			$this->{$class_name} = $class_obj;
1330
+			return;
1331
+		}
1332
+		if ($class_prefix === 'addon') {
1333
+			$this->addons->{$class_name} = $class_obj;
1334
+			return;
1335
+		}
1336
+		if (! $from_db) {
1337
+			$this->LIB->{$class_name} = $class_obj;
1338
+		}
1339
+	}
1340
+
1341
+
1342
+
1343
+	/**
1344
+	 * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1345
+	 *
1346
+	 * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1347
+	 *                          in the EE_Dependency_Map::$_class_loaders array,
1348
+	 *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1349
+	 * @param array  $arguments
1350
+	 * @return object
1351
+	 */
1352
+	public static function factory($classname, $arguments = array())
1353
+	{
1354
+		$loader = self::instance()->_dependency_map->class_loader($classname);
1355
+		if ($loader instanceof Closure) {
1356
+			return $loader($arguments);
1357
+		}
1358
+		if (method_exists(self::instance(), $loader)) {
1359
+			return self::instance()->{$loader}($classname, $arguments);
1360
+		}
1361
+		return null;
1362
+	}
1363
+
1364
+
1365
+
1366
+	/**
1367
+	 * Gets the addon by its name/slug (not classname. For that, just
1368
+	 * use the classname as the property name on EE_Config::instance()->addons)
1369
+	 *
1370
+	 * @param string $name
1371
+	 * @return EE_Addon
1372
+	 */
1373
+	public function get_addon_by_name($name)
1374
+	{
1375
+		foreach ($this->addons as $addon) {
1376
+			if ($addon->name() === $name) {
1377
+				return $addon;
1378
+			}
1379
+		}
1380
+		return null;
1381
+	}
1382
+
1383
+
1384
+
1385
+	/**
1386
+	 * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their
1387
+	 * name() function) They're already available on EE_Config::instance()->addons as properties, where each property's
1388
+	 * name is the addon's classname. So if you just want to get the addon by classname, use
1389
+	 * EE_Config::instance()->addons->{classname}
1390
+	 *
1391
+	 * @return EE_Addon[] where the KEYS are the addon's name()
1392
+	 */
1393
+	public function get_addons_by_name()
1394
+	{
1395
+		$addons = array();
1396
+		foreach ($this->addons as $addon) {
1397
+			$addons[$addon->name()] = $addon;
1398
+		}
1399
+		return $addons;
1400
+	}
1401
+
1402
+
1403
+
1404
+	/**
1405
+	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1406
+	 * a stale copy of it around
1407
+	 *
1408
+	 * @param string $model_name
1409
+	 * @return \EEM_Base
1410
+	 * @throws \EE_Error
1411
+	 */
1412
+	public function reset_model($model_name)
1413
+	{
1414
+		$model_class_name = strpos($model_name, 'EEM_') !== 0
1415
+			? "EEM_{$model_name}"
1416
+			: $model_name;
1417
+		if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1418
+			return null;
1419
+		}
1420
+		//get that model reset it and make sure we nuke the old reference to it
1421
+		if ($this->LIB->{$model_class_name} instanceof $model_class_name
1422
+			&& is_callable(
1423
+				array($model_class_name, 'reset')
1424
+			)) {
1425
+			$this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1426
+		} else {
1427
+			throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1428
+		}
1429
+		return $this->LIB->{$model_class_name};
1430
+	}
1431
+
1432
+
1433
+
1434
+	/**
1435
+	 * Resets the registry.
1436
+	 * The criteria for what gets reset is based on what can be shared between sites on the same request when
1437
+	 * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1438
+	 * - $_dependency_map
1439
+	 * - $_class_abbreviations
1440
+	 * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1441
+	 * - $REQ:  Still on the same request so no need to change.
1442
+	 * - $CAP: There is no site specific state in the EE_Capability class.
1443
+	 * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1444
+	 * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1445
+	 * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1446
+	 *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1447
+	 *             switch or on the restore.
1448
+	 * - $modules
1449
+	 * - $shortcodes
1450
+	 * - $widgets
1451
+	 *
1452
+	 * @param boolean $hard             [deprecated]
1453
+	 * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1454
+	 *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1455
+	 *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1456
+	 * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1457
+	 *                                  client
1458
+	 *                                  code instead can just change the model context to a different blog id if
1459
+	 *                                  necessary
1460
+	 * @return EE_Registry
1461
+	 * @throws EE_Error
1462
+	 * @throws ReflectionException
1463
+	 */
1464
+	public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1465
+	{
1466
+		$instance = self::instance();
1467
+		$instance->_cache_on = true;
1468
+		// reset some "special" classes
1469
+		EEH_Activation::reset();
1470
+		$hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1471
+		$instance->CFG = EE_Config::reset($hard, $reinstantiate);
1472
+		$instance->CART = null;
1473
+		$instance->MRM = null;
1474
+		$instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1475
+		//messages reset
1476
+		EED_Messages::reset();
1477
+		//handle of objects cached on LIB
1478
+		foreach (array('LIB', 'modules') as $cache) {
1479
+			foreach ($instance->{$cache} as $class_name => $class) {
1480
+				if (self::_reset_and_unset_object($class, $reset_models)) {
1481
+					unset($instance->{$cache}->{$class_name});
1482
+				}
1483
+			}
1484
+		}
1485
+		return $instance;
1486
+	}
1487
+
1488
+
1489
+
1490
+	/**
1491
+	 * if passed object implements ResettableInterface, then call it's reset() method
1492
+	 * if passed object implements InterminableInterface, then return false,
1493
+	 * to indicate that it should NOT be cleared from the Registry cache
1494
+	 *
1495
+	 * @param      $object
1496
+	 * @param bool $reset_models
1497
+	 * @return bool returns true if cached object should be unset
1498
+	 */
1499
+	private static function _reset_and_unset_object($object, $reset_models)
1500
+	{
1501
+		if (! is_object($object)) {
1502
+			// don't unset anything that's not an object
1503
+			return false;
1504
+		}
1505
+		if ($object instanceof EED_Module) {
1506
+			$object::reset();
1507
+			// don't unset modules
1508
+			return false;
1509
+		}
1510
+		if ($object instanceof ResettableInterface) {
1511
+			if ($object instanceof EEM_Base) {
1512
+				if ($reset_models) {
1513
+					$object->reset();
1514
+					return true;
1515
+				}
1516
+				return false;
1517
+			}
1518
+			$object->reset();
1519
+			return true;
1520
+		}
1521
+		if (! $object instanceof InterminableInterface) {
1522
+			return true;
1523
+		}
1524
+		return false;
1525
+	}
1526
+
1527
+
1528
+
1529
+	/**
1530
+	 * Gets all the custom post type models defined
1531
+	 *
1532
+	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1533
+	 */
1534
+	public function cpt_models()
1535
+	{
1536
+		$cpt_models = array();
1537
+		foreach ($this->non_abstract_db_models as $short_name => $classname) {
1538
+			if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1539
+				$cpt_models[$short_name] = $classname;
1540
+			}
1541
+		}
1542
+		return $cpt_models;
1543
+	}
1544
+
1545
+
1546
+
1547
+	/**
1548
+	 * @return \EE_Config
1549
+	 */
1550
+	public static function CFG()
1551
+	{
1552
+		return self::instance()->CFG;
1553
+	}
1554 1554
 
1555 1555
 
1556 1556
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
     public static function instance(EE_Dependency_Map $dependency_map = null)
177 177
     {
178 178
         // check if class object is instantiated
179
-        if (! self::$_instance instanceof EE_Registry) {
179
+        if ( ! self::$_instance instanceof EE_Registry) {
180 180
             self::$_instance = new self($dependency_map);
181 181
         }
182 182
         return self::$_instance;
@@ -266,13 +266,13 @@  discard block
 block discarded – undo
266 266
      */
267 267
     public static function localize_i18n_js_strings()
268 268
     {
269
-        $i18n_js_strings = (array)self::$i18n_js_strings;
269
+        $i18n_js_strings = (array) self::$i18n_js_strings;
270 270
         foreach ($i18n_js_strings as $key => $value) {
271 271
             if (is_scalar($value)) {
272
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
272
+                $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
273 273
             }
274 274
         }
275
-        return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
275
+        return '/* <![CDATA[ */ var eei18n = '.wp_json_encode($i18n_js_strings).'; /* ]]> */';
276 276
     }
277 277
 
278 278
 
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
             $module_class = get_class($module);
289 289
             $this->modules->{$module_class} = $module;
290 290
         } else {
291
-            if (! class_exists('EE_Module_Request_Router')) {
291
+            if ( ! class_exists('EE_Module_Request_Router')) {
292 292
                 $this->load_core('Module_Request_Router');
293 293
             }
294 294
             EE_Module_Request_Router::module_factory($module);
@@ -328,10 +328,10 @@  discard block
 block discarded – undo
328 328
                 EE_CORE,
329 329
                 EE_ADMIN,
330 330
                 EE_CPTS,
331
-                EE_CORE . 'data_migration_scripts' . DS,
332
-                EE_CORE . 'capabilities' . DS,
333
-                EE_CORE . 'request_stack' . DS,
334
-                EE_CORE . 'middleware' . DS,
331
+                EE_CORE.'data_migration_scripts'.DS,
332
+                EE_CORE.'capabilities'.DS,
333
+                EE_CORE.'request_stack'.DS,
334
+                EE_CORE.'middleware'.DS,
335 335
             )
336 336
         );
337 337
         // retrieve instantiated class
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
         $service_paths = apply_filters(
365 365
             'FHEE__EE_Registry__load_service__service_paths',
366 366
             array(
367
-                EE_CORE . 'services' . DS,
367
+                EE_CORE.'services'.DS,
368 368
             )
369 369
         );
370 370
         // retrieve instantiated class
@@ -490,10 +490,10 @@  discard block
 block discarded – undo
490 490
     {
491 491
         $paths = array(
492 492
             EE_LIBRARIES,
493
-            EE_LIBRARIES . 'messages' . DS,
494
-            EE_LIBRARIES . 'shortcodes' . DS,
495
-            EE_LIBRARIES . 'qtips' . DS,
496
-            EE_LIBRARIES . 'payment_methods' . DS,
493
+            EE_LIBRARIES.'messages'.DS,
494
+            EE_LIBRARIES.'shortcodes'.DS,
495
+            EE_LIBRARIES.'qtips'.DS,
496
+            EE_LIBRARIES.'payment_methods'.DS,
497 497
         );
498 498
         // retrieve instantiated class
499 499
         return $this->_load(
@@ -556,10 +556,10 @@  discard block
 block discarded – undo
556 556
     public function load_model_class($class_name, $arguments = array(), $load_only = true)
557 557
     {
558 558
         $paths = array(
559
-            EE_MODELS . 'fields' . DS,
560
-            EE_MODELS . 'helpers' . DS,
561
-            EE_MODELS . 'relations' . DS,
562
-            EE_MODELS . 'strategies' . DS,
559
+            EE_MODELS.'fields'.DS,
560
+            EE_MODELS.'helpers'.DS,
561
+            EE_MODELS.'relations'.DS,
562
+            EE_MODELS.'strategies'.DS,
563 563
         );
564 564
         // retrieve instantiated class
565 565
         return $this->_load(
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
         $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
679 679
         // if a non-FQCN was passed, then verifyClassExists() might return an object
680 680
         // or it could return null if the class just could not be found anywhere
681
-        if ($class_exists instanceof $class_name || $class_exists === null){
681
+        if ($class_exists instanceof $class_name || $class_exists === null) {
682 682
             // either way, return the results
683 683
             return $class_exists;
684 684
         }
@@ -736,7 +736,7 @@  discard block
 block discarded – undo
736 736
             case 1:
737 737
                 // if it's a FQCN then maybe the class is registered with a preceding \
738 738
                 $class_name = strpos($class_name, '\\') !== false
739
-                    ? '\\' . ltrim($class_name, '\\')
739
+                    ? '\\'.ltrim($class_name, '\\')
740 740
                     : $class_name;
741 741
                 break;
742 742
             case 2:
@@ -788,11 +788,11 @@  discard block
 block discarded – undo
788 788
         // strip php file extension
789 789
         $class_name = str_replace('.php', '', trim($class_name));
790 790
         // does the class have a prefix ?
791
-        if (! empty($class_prefix) && $class_prefix !== 'addon') {
791
+        if ( ! empty($class_prefix) && $class_prefix !== 'addon') {
792 792
             // make sure $class_prefix is uppercase
793 793
             $class_prefix = strtoupper(trim($class_prefix));
794 794
             // add class prefix ONCE!!!
795
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
795
+            $class_name = $class_prefix.str_replace($class_prefix, '', $class_name);
796 796
         }
797 797
         $class_name = $this->_dependency_map->get_alias($class_name);
798 798
         $class_exists = class_exists($class_name);
@@ -811,13 +811,13 @@  discard block
 block discarded – undo
811 811
             }
812 812
         }
813 813
         // if the class doesn't already exist.. then we need to try and find the file and load it
814
-        if (! $class_exists) {
814
+        if ( ! $class_exists) {
815 815
             // get full path to file
816 816
             $path = $this->_resolve_path($class_name, $type, $file_paths);
817 817
             // load the file
818 818
             $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
819 819
             // if loading failed, or we are only loading a file but NOT instantiating an object
820
-            if (! $loaded || $load_only) {
820
+            if ( ! $loaded || $load_only) {
821 821
                 // return boolean if only loading, or null if an object was expected
822 822
                 return $load_only
823 823
                     ? $loaded
@@ -942,10 +942,10 @@  discard block
 block discarded – undo
942 942
                 : EE_CLASSES;
943 943
             // prep file type
944 944
             $type = ! empty($type)
945
-                ? trim($type, '.') . '.'
945
+                ? trim($type, '.').'.'
946 946
                 : '';
947 947
             // build full file path
948
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
948
+            $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php';
949 949
             //does the file exist and can be read ?
950 950
             if (is_readable($file_paths[$key])) {
951 951
                 return $file_paths[$key];
@@ -973,9 +973,9 @@  discard block
 block discarded – undo
973 973
         // don't give up! you gotta...
974 974
         try {
975 975
             //does the file exist and can it be read ?
976
-            if (! $path) {
976
+            if ( ! $path) {
977 977
                 // so sorry, can't find the file
978
-                throw new EE_Error (
978
+                throw new EE_Error(
979 979
                     sprintf(
980 980
                         esc_html__(
981 981
                             'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s',
@@ -983,7 +983,7 @@  discard block
 block discarded – undo
983 983
                         ),
984 984
                         trim($type, '.'),
985 985
                         $class_name,
986
-                        '<br />' . implode(',<br />', $file_paths)
986
+                        '<br />'.implode(',<br />', $file_paths)
987 987
                     )
988 988
                 );
989 989
             }
@@ -1087,7 +1087,7 @@  discard block
 block discarded – undo
1087 1087
                 );
1088 1088
             }
1089 1089
         } catch (Exception $e) {
1090
-            if (! $e instanceof EE_Error) {
1090
+            if ( ! $e instanceof EE_Error) {
1091 1091
                 $e = new EE_Error(
1092 1092
                     sprintf(
1093 1093
                         esc_html__(
@@ -1169,7 +1169,7 @@  discard block
 block discarded – undo
1169 1169
         // let's examine the constructor
1170 1170
         $constructor = $reflector->getConstructor();
1171 1171
         // whu? huh? nothing?
1172
-        if (! $constructor) {
1172
+        if ( ! $constructor) {
1173 1173
             return $arguments;
1174 1174
         }
1175 1175
         // get constructor parameters
@@ -1333,7 +1333,7 @@  discard block
 block discarded – undo
1333 1333
             $this->addons->{$class_name} = $class_obj;
1334 1334
             return;
1335 1335
         }
1336
-        if (! $from_db) {
1336
+        if ( ! $from_db) {
1337 1337
             $this->LIB->{$class_name} = $class_obj;
1338 1338
         }
1339 1339
     }
@@ -1414,7 +1414,7 @@  discard block
 block discarded – undo
1414 1414
         $model_class_name = strpos($model_name, 'EEM_') !== 0
1415 1415
             ? "EEM_{$model_name}"
1416 1416
             : $model_name;
1417
-        if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1417
+        if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1418 1418
             return null;
1419 1419
         }
1420 1420
         //get that model reset it and make sure we nuke the old reference to it
@@ -1467,7 +1467,7 @@  discard block
 block discarded – undo
1467 1467
         $instance->_cache_on = true;
1468 1468
         // reset some "special" classes
1469 1469
         EEH_Activation::reset();
1470
-        $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1470
+        $hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard);
1471 1471
         $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1472 1472
         $instance->CART = null;
1473 1473
         $instance->MRM = null;
@@ -1498,7 +1498,7 @@  discard block
 block discarded – undo
1498 1498
      */
1499 1499
     private static function _reset_and_unset_object($object, $reset_models)
1500 1500
     {
1501
-        if (! is_object($object)) {
1501
+        if ( ! is_object($object)) {
1502 1502
             // don't unset anything that's not an object
1503 1503
             return false;
1504 1504
         }
@@ -1518,7 +1518,7 @@  discard block
 block discarded – undo
1518 1518
             $object->reset();
1519 1519
             return true;
1520 1520
         }
1521
-        if (! $object instanceof InterminableInterface) {
1521
+        if ( ! $object instanceof InterminableInterface) {
1522 1522
             return true;
1523 1523
         }
1524 1524
         return false;
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 use EventEspresso\core\exceptions\InvalidDataTypeException;
3 3
 use EventEspresso\core\exceptions\InvalidInterfaceException;
4
-use EventEspresso\core\services\loaders\LoaderFactory;
5 4
 use EventEspresso\core\services\loaders\LoaderInterface;
6 5
 
7 6
 if (! defined('EVENT_ESPRESSO_VERSION')) {
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\loaders\LoaderFactory;
5 5
 use EventEspresso\core\services\loaders\LoaderInterface;
6 6
 
7
-if (! defined('EVENT_ESPRESSO_VERSION')) {
7
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8 8
     exit('No direct script access allowed');
9 9
 }
10 10
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
     public static function instance(EE_Request $request = null, EE_Response $response = null)
131 131
     {
132 132
         // check if class object is instantiated, and instantiated properly
133
-        if (! self::$_instance instanceof EE_Dependency_Map) {
133
+        if ( ! self::$_instance instanceof EE_Dependency_Map) {
134 134
             self::$_instance = new EE_Dependency_Map($request, $response);
135 135
         }
136 136
         return self::$_instance;
@@ -185,16 +185,16 @@  discard block
 block discarded – undo
185 185
     ) {
186 186
         $class = trim($class, '\\');
187 187
         $registered = false;
188
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
189
-            self::$_instance->_dependency_map[ $class ] = array();
188
+        if (empty(self::$_instance->_dependency_map[$class])) {
189
+            self::$_instance->_dependency_map[$class] = array();
190 190
         }
191 191
         // we need to make sure that any aliases used when registering a dependency
192 192
         // get resolved to the correct class name
193
-        foreach ((array)$dependencies as $dependency => $load_source) {
193
+        foreach ((array) $dependencies as $dependency => $load_source) {
194 194
             $alias = self::$_instance->get_alias($dependency);
195 195
             if (
196 196
                 $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
197
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
197
+                || ! isset(self::$_instance->_dependency_map[$class][$alias])
198 198
             ) {
199 199
                 unset($dependencies[$dependency]);
200 200
                 $dependencies[$alias] = $load_source;
@@ -207,13 +207,13 @@  discard block
 block discarded – undo
207 207
         // ie: with A = B + C, entries in B take precedence over duplicate entries in C
208 208
         // Union is way faster than array_merge() but should be used with caution...
209 209
         // especially with numerically indexed arrays
210
-        $dependencies += self::$_instance->_dependency_map[ $class ];
210
+        $dependencies += self::$_instance->_dependency_map[$class];
211 211
         // now we need to ensure that the resulting dependencies
212 212
         // array only has the entries that are required for the class
213 213
         // so first count how many dependencies were originally registered for the class
214
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
214
+        $dependency_count = count(self::$_instance->_dependency_map[$class]);
215 215
         // if that count is non-zero (meaning dependencies were already registered)
216
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
216
+        self::$_instance->_dependency_map[$class] = $dependency_count
217 217
             // then truncate the  final array to match that count
218 218
             ? array_slice($dependencies, 0, $dependency_count)
219 219
             // otherwise just take the incoming array because nothing previously existed
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      */
232 232
     public static function register_class_loader($class_name, $loader = 'load_core')
233 233
     {
234
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
234
+        if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
235 235
             throw new DomainException(
236 236
                 esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
237 237
             );
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
             );
256 256
         }
257 257
         $class_name = self::$_instance->get_alias($class_name);
258
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
258
+        if ( ! isset(self::$_instance->_class_loaders[$class_name])) {
259 259
             self::$_instance->_class_loaders[$class_name] = $loader;
260 260
             return true;
261 261
         }
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
     public function class_loader($class_name)
341 341
     {
342 342
         // all legacy models use load_model()
343
-        if(strpos($class_name, 'EEM_') === 0){
343
+        if (strpos($class_name, 'EEM_') === 0) {
344 344
             return 'load_model';
345 345
         }
346 346
         $class_name = $this->get_alias($class_name);
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
     public function add_alias($class_name, $alias, $for_class = '')
370 370
     {
371 371
         if ($for_class !== '') {
372
-            if (! isset($this->_aliases[$for_class])) {
372
+            if ( ! isset($this->_aliases[$for_class])) {
373 373
                 $this->_aliases[$for_class] = array();
374 374
             }
375 375
             $this->_aliases[$for_class][$class_name] = $alias;
@@ -415,10 +415,10 @@  discard block
 block discarded – undo
415 415
      */
416 416
     public function get_alias($class_name = '', $for_class = '')
417 417
     {
418
-        if (! $this->has_alias($class_name, $for_class)) {
418
+        if ( ! $this->has_alias($class_name, $for_class)) {
419 419
             return $class_name;
420 420
         }
421
-        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
421
+        if ($for_class !== '' && isset($this->_aliases[$for_class][$class_name])) {
422 422
             return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
423 423
         }
424 424
         return $this->get_alias($this->_aliases[$class_name]);
@@ -664,10 +664,10 @@  discard block
 block discarded – undo
664 664
             'EE_Front_Controller'                  => 'load_core',
665 665
             'EE_Module_Request_Router'             => 'load_core',
666 666
             'EE_Registry'                          => 'load_core',
667
-            'EE_Request'                           => function () use (&$request) {
667
+            'EE_Request'                           => function() use (&$request) {
668 668
                 return $request;
669 669
             },
670
-            'EE_Response'                          => function () use (&$response) {
670
+            'EE_Response'                          => function() use (&$response) {
671 671
                 return $response;
672 672
             },
673 673
             'EE_Request_Handler'                   => 'load_core',
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
             'EE_Messages_Queue'                    => 'load_lib',
685 685
             'EE_Messages_Data_Handler_Collection'  => 'load_lib',
686 686
             'EE_Message_Template_Group_Collection' => 'load_lib',
687
-            'EE_Messages_Generator'                => function () {
687
+            'EE_Messages_Generator'                => function() {
688 688
                 return EE_Registry::instance()->load_lib(
689 689
                     'Messages_Generator',
690 690
                     array(),
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
                     false
693 693
                 );
694 694
             },
695
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
695
+            'EE_Messages_Template_Defaults'        => function($arguments = array()) {
696 696
                 return EE_Registry::instance()->load_lib(
697 697
                     'Messages_Template_Defaults',
698 698
                     $arguments,
@@ -705,19 +705,19 @@  discard block
 block discarded – undo
705 705
             // 'EEM_Message_Template_Group'           => 'load_model',
706 706
             // 'EEM_Message_Template'                 => 'load_model',
707 707
             //load_helper
708
-            'EEH_Parse_Shortcodes'                 => function () {
708
+            'EEH_Parse_Shortcodes'                 => function() {
709 709
                 if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
710 710
                     return new EEH_Parse_Shortcodes();
711 711
                 }
712 712
                 return null;
713 713
             },
714
-            'EE_Template_Config'                   => function () {
714
+            'EE_Template_Config'                   => function() {
715 715
                 return EE_Config::instance()->template_settings;
716 716
             },
717
-            'EE_Currency_Config'                   => function () {
717
+            'EE_Currency_Config'                   => function() {
718 718
                 return EE_Config::instance()->currency;
719 719
             },
720
-            'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) {
720
+            'EventEspresso\core\services\loaders\Loader' => function() use (&$loader) {
721 721
                 return $loader;
722 722
             },
723 723
         );
Please login to merge, or discard this patch.
Indentation   +775 added lines, -775 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\services\loaders\LoaderInterface;
6 6
 
7 7
 if (! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('No direct script access allowed');
8
+	exit('No direct script access allowed');
9 9
 }
10 10
 
11 11
 
@@ -22,780 +22,780 @@  discard block
 block discarded – undo
22 22
 class EE_Dependency_Map
23 23
 {
24 24
 
25
-    /**
26
-     * This means that the requested class dependency is not present in the dependency map
27
-     */
28
-    const not_registered = 0;
29
-
30
-    /**
31
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
32
-     */
33
-    const load_new_object = 1;
34
-
35
-    /**
36
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
37
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
38
-     */
39
-    const load_from_cache = 2;
40
-
41
-    /**
42
-     * When registering a dependency,
43
-     * this indicates to keep any existing dependencies that already exist,
44
-     * and simply discard any new dependencies declared in the incoming data
45
-     */
46
-    const KEEP_EXISTING_DEPENDENCIES = 0;
47
-
48
-    /**
49
-     * When registering a dependency,
50
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
51
-     */
52
-    const OVERWRITE_DEPENDENCIES = 1;
53
-
54
-
55
-
56
-    /**
57
-     * @type EE_Dependency_Map $_instance
58
-     */
59
-    protected static $_instance;
60
-
61
-    /**
62
-     * @type EE_Request $request
63
-     */
64
-    protected $_request;
65
-
66
-    /**
67
-     * @type EE_Response $response
68
-     */
69
-    protected $_response;
70
-
71
-    /**
72
-     * @type LoaderInterface $loader
73
-     */
74
-    protected $loader;
75
-
76
-    /**
77
-     * @type array $_dependency_map
78
-     */
79
-    protected $_dependency_map = array();
80
-
81
-    /**
82
-     * @type array $_class_loaders
83
-     */
84
-    protected $_class_loaders = array();
85
-
86
-    /**
87
-     * @type array $_aliases
88
-     */
89
-    protected $_aliases = array();
90
-
91
-
92
-
93
-    /**
94
-     * EE_Dependency_Map constructor.
95
-     *
96
-     * @param EE_Request  $request
97
-     * @param EE_Response $response
98
-     */
99
-    protected function __construct(EE_Request $request, EE_Response $response)
100
-    {
101
-        $this->_request = $request;
102
-        $this->_response = $response;
103
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
104
-        do_action('EE_Dependency_Map____construct');
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * @throws InvalidDataTypeException
111
-     * @throws InvalidInterfaceException
112
-     * @throws InvalidArgumentException
113
-     */
114
-    public function initialize()
115
-    {
116
-        $this->_register_core_dependencies();
117
-        $this->_register_core_class_loaders();
118
-        $this->_register_core_aliases();
119
-    }
120
-
121
-
122
-
123
-    /**
124
-     * @singleton method used to instantiate class object
125
-     * @access    public
126
-     * @param EE_Request  $request
127
-     * @param EE_Response $response
128
-     * @return EE_Dependency_Map
129
-     */
130
-    public static function instance(EE_Request $request = null, EE_Response $response = null)
131
-    {
132
-        // check if class object is instantiated, and instantiated properly
133
-        if (! self::$_instance instanceof EE_Dependency_Map) {
134
-            self::$_instance = new EE_Dependency_Map($request, $response);
135
-        }
136
-        return self::$_instance;
137
-    }
138
-
139
-
140
-
141
-    /**
142
-     * @param LoaderInterface $loader
143
-     */
144
-    public function setLoader(LoaderInterface $loader)
145
-    {
146
-        $this->loader = $loader;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * @param string $class
153
-     * @param array  $dependencies
154
-     * @param int    $overwrite
155
-     * @return bool
156
-     */
157
-    public static function register_dependencies(
158
-        $class,
159
-        array $dependencies,
160
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
161
-    ) {
162
-        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * Assigns an array of class names and corresponding load sources (new or cached)
169
-     * to the class specified by the first parameter.
170
-     * IMPORTANT !!!
171
-     * The order of elements in the incoming $dependencies array MUST match
172
-     * the order of the constructor parameters for the class in question.
173
-     * This is especially important when overriding any existing dependencies that are registered.
174
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
175
-     *
176
-     * @param string $class
177
-     * @param array  $dependencies
178
-     * @param int    $overwrite
179
-     * @return bool
180
-     */
181
-    public function registerDependencies(
182
-        $class,
183
-        array $dependencies,
184
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
185
-    ) {
186
-        $class = trim($class, '\\');
187
-        $registered = false;
188
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
189
-            self::$_instance->_dependency_map[ $class ] = array();
190
-        }
191
-        // we need to make sure that any aliases used when registering a dependency
192
-        // get resolved to the correct class name
193
-        foreach ((array)$dependencies as $dependency => $load_source) {
194
-            $alias = self::$_instance->get_alias($dependency);
195
-            if (
196
-                $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
197
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
198
-            ) {
199
-                unset($dependencies[$dependency]);
200
-                $dependencies[$alias] = $load_source;
201
-                $registered = true;
202
-            }
203
-        }
204
-        // now add our two lists of dependencies together.
205
-        // using Union (+=) favours the arrays in precedence from left to right,
206
-        // so $dependencies is NOT overwritten because it is listed first
207
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
208
-        // Union is way faster than array_merge() but should be used with caution...
209
-        // especially with numerically indexed arrays
210
-        $dependencies += self::$_instance->_dependency_map[ $class ];
211
-        // now we need to ensure that the resulting dependencies
212
-        // array only has the entries that are required for the class
213
-        // so first count how many dependencies were originally registered for the class
214
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
215
-        // if that count is non-zero (meaning dependencies were already registered)
216
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
217
-            // then truncate the  final array to match that count
218
-            ? array_slice($dependencies, 0, $dependency_count)
219
-            // otherwise just take the incoming array because nothing previously existed
220
-            : $dependencies;
221
-        return $registered;
222
-    }
223
-
224
-
225
-
226
-    /**
227
-     * @param string $class_name
228
-     * @param string $loader
229
-     * @return bool
230
-     * @throws DomainException
231
-     */
232
-    public static function register_class_loader($class_name, $loader = 'load_core')
233
-    {
234
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
235
-            throw new DomainException(
236
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
237
-            );
238
-        }
239
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
240
-        if (
241
-            ! is_callable($loader)
242
-            && (
243
-                strpos($loader, 'load_') !== 0
244
-                || ! method_exists('EE_Registry', $loader)
245
-            )
246
-        ) {
247
-            throw new DomainException(
248
-                sprintf(
249
-                    esc_html__(
250
-                        '"%1$s" is not a valid loader method on EE_Registry.',
251
-                        'event_espresso'
252
-                    ),
253
-                    $loader
254
-                )
255
-            );
256
-        }
257
-        $class_name = self::$_instance->get_alias($class_name);
258
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
259
-            self::$_instance->_class_loaders[$class_name] = $loader;
260
-            return true;
261
-        }
262
-        return false;
263
-    }
264
-
265
-
266
-
267
-    /**
268
-     * @return array
269
-     */
270
-    public function dependency_map()
271
-    {
272
-        return $this->_dependency_map;
273
-    }
274
-
275
-
276
-
277
-    /**
278
-     * returns TRUE if dependency map contains a listing for the provided class name
279
-     *
280
-     * @param string $class_name
281
-     * @return boolean
282
-     */
283
-    public function has($class_name = '')
284
-    {
285
-        // all legacy models have the same dependencies
286
-        if (strpos($class_name, 'EEM_') === 0) {
287
-            $class_name = 'LEGACY_MODELS';
288
-        }
289
-        return isset($this->_dependency_map[$class_name]) ? true : false;
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
296
-     *
297
-     * @param string $class_name
298
-     * @param string $dependency
299
-     * @return bool
300
-     */
301
-    public function has_dependency_for_class($class_name = '', $dependency = '')
302
-    {
303
-        // all legacy models have the same dependencies
304
-        if (strpos($class_name, 'EEM_') === 0) {
305
-            $class_name = 'LEGACY_MODELS';
306
-        }
307
-        $dependency = $this->get_alias($dependency);
308
-        return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency])
309
-            ? true
310
-            : false;
311
-    }
312
-
313
-
314
-
315
-    /**
316
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
317
-     *
318
-     * @param string $class_name
319
-     * @param string $dependency
320
-     * @return int
321
-     */
322
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
323
-    {
324
-        // all legacy models have the same dependencies
325
-        if (strpos($class_name, 'EEM_') === 0) {
326
-            $class_name = 'LEGACY_MODELS';
327
-        }
328
-        $dependency = $this->get_alias($dependency);
329
-        return $this->has_dependency_for_class($class_name, $dependency)
330
-            ? $this->_dependency_map[$class_name][$dependency]
331
-            : EE_Dependency_Map::not_registered;
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * @param string $class_name
338
-     * @return string | Closure
339
-     */
340
-    public function class_loader($class_name)
341
-    {
342
-        // all legacy models use load_model()
343
-        if(strpos($class_name, 'EEM_') === 0){
344
-            return 'load_model';
345
-        }
346
-        $class_name = $this->get_alias($class_name);
347
-        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * @return array
354
-     */
355
-    public function class_loaders()
356
-    {
357
-        return $this->_class_loaders;
358
-    }
359
-
360
-
361
-
362
-    /**
363
-     * adds an alias for a classname
364
-     *
365
-     * @param string $class_name the class name that should be used (concrete class to replace interface)
366
-     * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
367
-     * @param string $for_class  the class that has the dependency (is type hinting for the interface)
368
-     */
369
-    public function add_alias($class_name, $alias, $for_class = '')
370
-    {
371
-        if ($for_class !== '') {
372
-            if (! isset($this->_aliases[$for_class])) {
373
-                $this->_aliases[$for_class] = array();
374
-            }
375
-            $this->_aliases[$for_class][$class_name] = $alias;
376
-        }
377
-        $this->_aliases[$class_name] = $alias;
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * returns TRUE if the provided class name has an alias
384
-     *
385
-     * @param string $class_name
386
-     * @param string $for_class
387
-     * @return bool
388
-     */
389
-    public function has_alias($class_name = '', $for_class = '')
390
-    {
391
-        return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])
392
-               || (
393
-                   isset($this->_aliases[$class_name])
394
-                   && ! is_array($this->_aliases[$class_name])
395
-               );
396
-    }
397
-
398
-
399
-
400
-    /**
401
-     * returns alias for class name if one exists, otherwise returns the original classname
402
-     * functions recursively, so that multiple aliases can be used to drill down to a classname
403
-     *  for example:
404
-     *      if the following two entries were added to the _aliases array:
405
-     *          array(
406
-     *              'interface_alias'           => 'some\namespace\interface'
407
-     *              'some\namespace\interface'  => 'some\namespace\classname'
408
-     *          )
409
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
410
-     *      to load an instance of 'some\namespace\classname'
411
-     *
412
-     * @param string $class_name
413
-     * @param string $for_class
414
-     * @return string
415
-     */
416
-    public function get_alias($class_name = '', $for_class = '')
417
-    {
418
-        if (! $this->has_alias($class_name, $for_class)) {
419
-            return $class_name;
420
-        }
421
-        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
422
-            return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
423
-        }
424
-        return $this->get_alias($this->_aliases[$class_name]);
425
-    }
426
-
427
-
428
-
429
-    /**
430
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
431
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
432
-     * This is done by using the following class constants:
433
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
434
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
435
-     */
436
-    protected function _register_core_dependencies()
437
-    {
438
-        $this->_dependency_map = array(
439
-            'EE_Request_Handler'                                                                                          => array(
440
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
441
-            ),
442
-            'EE_System'                                                                                                   => array(
443
-                'EE_Registry'                                => EE_Dependency_Map::load_from_cache,
444
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
445
-                'EE_Capabilities'                            => EE_Dependency_Map::load_from_cache,
446
-                'EE_Request'                                 => EE_Dependency_Map::load_from_cache,
447
-                'EE_Maintenance_Mode'                        => EE_Dependency_Map::load_from_cache,
448
-            ),
449
-            'EE_Session'                                                                                                  => array(
450
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
451
-                'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
452
-            ),
453
-            'EE_Cart'                                                                                                     => array(
454
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
455
-            ),
456
-            'EE_Front_Controller'                                                                                         => array(
457
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
458
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
459
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
460
-            ),
461
-            'EE_Messenger_Collection_Loader'                                                                              => array(
462
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
463
-            ),
464
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
465
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
466
-            ),
467
-            'EE_Message_Resource_Manager'                                                                                 => array(
468
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
469
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
470
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
471
-            ),
472
-            'EE_Message_Factory'                                                                                          => array(
473
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
474
-            ),
475
-            'EE_messages'                                                                                                 => array(
476
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
477
-            ),
478
-            'EE_Messages_Generator'                                                                                       => array(
479
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
480
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
481
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
482
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
483
-            ),
484
-            'EE_Messages_Processor'                                                                                       => array(
485
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
486
-            ),
487
-            'EE_Messages_Queue'                                                                                           => array(
488
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
489
-            ),
490
-            'EE_Messages_Template_Defaults'                                                                               => array(
491
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
492
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
493
-            ),
494
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
495
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
496
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
497
-            ),
498
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
499
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
500
-            ),
501
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
502
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
503
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
504
-            ),
505
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
506
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
507
-            ),
508
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
509
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
510
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
511
-            ),
512
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
513
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
514
-            ),
515
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
516
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
517
-            ),
518
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
519
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
520
-            ),
521
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
522
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
523
-            ),
524
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
525
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
526
-            ),
527
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
528
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
529
-            ),
530
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
531
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
532
-            ),
533
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
534
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
535
-            ),
536
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
537
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
538
-            ),
539
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
540
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
541
-            ),
542
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
543
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
544
-            ),
545
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
546
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
547
-            ),
548
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
549
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
550
-            ),
551
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
552
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
553
-            ),
554
-            'EE_Data_Migration_Class_Base'                                                                                => array(
555
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
556
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
557
-            ),
558
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
559
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
560
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
561
-            ),
562
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
563
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
564
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
565
-            ),
566
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
567
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
568
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
569
-            ),
570
-            'EE_DMS_Core_4_4_0'                                                                                           => 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_5_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_6_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_7_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_8_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_9_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
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
595
-                'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
596
-                'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
597
-            ),
598
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
599
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
600
-            ),
601
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
602
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
603
-            ),
604
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
605
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
606
-            ),
607
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
608
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
609
-            ),
610
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
611
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
612
-            ),
613
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
614
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
615
-            ),
616
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
617
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
618
-            ),
619
-            'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
620
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
621
-            ),
622
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
623
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
624
-            ),
625
-            'EventEspresso\core\services\orm\ModelFieldFactory'                                                   => array(
626
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
627
-            ),
628
-            'LEGACY_MODELS'                                                   => array(
629
-                null,
630
-                'EventEspresso\core\services\orm\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
631
-            ),
632
-            'EE_Module_Request_Router' => array(
633
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
634
-            ),
635
-        );
636
-    }
637
-
638
-
639
-
640
-    /**
641
-     * Registers how core classes are loaded.
642
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
643
-     *        'EE_Request_Handler' => 'load_core'
644
-     *        'EE_Messages_Queue'  => 'load_lib'
645
-     *        'EEH_Debug_Tools'    => 'load_helper'
646
-     * or, if greater control is required, by providing a custom closure. For example:
647
-     *        'Some_Class' => function () {
648
-     *            return new Some_Class();
649
-     *        },
650
-     * This is required for instantiating dependencies
651
-     * where an interface has been type hinted in a class constructor. For example:
652
-     *        'Required_Interface' => function () {
653
-     *            return new A_Class_That_Implements_Required_Interface();
654
-     *        },
655
-     *
656
-     * @throws InvalidInterfaceException
657
-     * @throws InvalidDataTypeException
658
-     * @throws InvalidArgumentException
659
-     */
660
-    protected function _register_core_class_loaders()
661
-    {
662
-        //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
663
-        //be used in a closure.
664
-        $request = &$this->_request;
665
-        $response = &$this->_response;
666
-        $loader = &$this->loader;
667
-        $this->_class_loaders = array(
668
-            //load_core
669
-            'EE_Capabilities'                      => 'load_core',
670
-            'EE_Encryption'                        => 'load_core',
671
-            'EE_Front_Controller'                  => 'load_core',
672
-            'EE_Module_Request_Router'             => 'load_core',
673
-            'EE_Registry'                          => 'load_core',
674
-            'EE_Request'                           => function () use (&$request) {
675
-                return $request;
676
-            },
677
-            'EE_Response'                          => function () use (&$response) {
678
-                return $response;
679
-            },
680
-            'EE_Request_Handler'                   => 'load_core',
681
-            'EE_Session'                           => 'load_core',
682
-            'EE_Cron_Tasks'                        => 'load_core',
683
-            'EE_System'                            => 'load_core',
684
-            'EE_Maintenance_Mode'                  => 'load_core',
685
-            'EE_Register_CPTs'                     => 'load_core',
686
-            'EE_Admin'                             => 'load_core',
687
-            //load_lib
688
-            'EE_Message_Resource_Manager'          => 'load_lib',
689
-            'EE_Message_Type_Collection'           => 'load_lib',
690
-            'EE_Message_Type_Collection_Loader'    => 'load_lib',
691
-            'EE_Messenger_Collection'              => 'load_lib',
692
-            'EE_Messenger_Collection_Loader'       => 'load_lib',
693
-            'EE_Messages_Processor'                => 'load_lib',
694
-            'EE_Message_Repository'                => 'load_lib',
695
-            'EE_Messages_Queue'                    => 'load_lib',
696
-            'EE_Messages_Data_Handler_Collection'  => 'load_lib',
697
-            'EE_Message_Template_Group_Collection' => 'load_lib',
698
-            'EE_Messages_Generator'                => function () {
699
-                return EE_Registry::instance()->load_lib(
700
-                    'Messages_Generator',
701
-                    array(),
702
-                    false,
703
-                    false
704
-                );
705
-            },
706
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
707
-                return EE_Registry::instance()->load_lib(
708
-                    'Messages_Template_Defaults',
709
-                    $arguments,
710
-                    false,
711
-                    false
712
-                );
713
-            },
714
-            //load_model
715
-            // 'EEM_Attendee'                         => 'load_model',
716
-            // 'EEM_Message_Template_Group'           => 'load_model',
717
-            // 'EEM_Message_Template'                 => 'load_model',
718
-            //load_helper
719
-            'EEH_Parse_Shortcodes'                 => function () {
720
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
721
-                    return new EEH_Parse_Shortcodes();
722
-                }
723
-                return null;
724
-            },
725
-            'EE_Template_Config'                   => function () {
726
-                return EE_Config::instance()->template_settings;
727
-            },
728
-            'EE_Currency_Config'                   => function () {
729
-                return EE_Config::instance()->currency;
730
-            },
731
-            'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) {
732
-                return $loader;
733
-            },
734
-        );
735
-    }
736
-
737
-
738
-
739
-    /**
740
-     * can be used for supplying alternate names for classes,
741
-     * or for connecting interface names to instantiable classes
742
-     */
743
-    protected function _register_core_aliases()
744
-    {
745
-        $this->_aliases = array(
746
-            'CommandBusInterface'                                                 => 'EventEspresso\core\services\commands\CommandBusInterface',
747
-            'EventEspresso\core\services\commands\CommandBusInterface'            => 'EventEspresso\core\services\commands\CommandBus',
748
-            'CommandHandlerManagerInterface'                                      => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
749
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager',
750
-            'CapChecker'                                                          => 'EventEspresso\core\services\commands\middleware\CapChecker',
751
-            'AddActionHook'                                                       => 'EventEspresso\core\services\commands\middleware\AddActionHook',
752
-            'CapabilitiesChecker'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
753
-            'CapabilitiesCheckerInterface'                                        => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
754
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
755
-            'CreateRegistrationService'                                           => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
756
-            'CreateRegCodeCommandHandler'                                         => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
757
-            'CreateRegUrlLinkCommandHandler'                                      => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
758
-            'CreateRegistrationCommandHandler'                                    => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
759
-            'CopyRegistrationDetailsCommandHandler'                               => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
760
-            'CopyRegistrationPaymentsCommandHandler'                              => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
761
-            'CancelRegistrationAndTicketLineItemCommandHandler'                   => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
762
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'           => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
763
-            'CreateTicketLineItemCommandHandler'                                  => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
764
-            'TableManager'                                                        => 'EventEspresso\core\services\database\TableManager',
765
-            'TableAnalysis'                                                       => 'EventEspresso\core\services\database\TableAnalysis',
766
-            'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
767
-            'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
768
-            'EspressoShortcode'                                                   => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
769
-            'ShortcodeInterface'                                                  => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
770
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'           => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
771
-            'EventEspresso\core\services\cache\CacheStorageInterface'             => 'EventEspresso\core\services\cache\TransientCacheStorage',
772
-            'LoaderInterface'                                                     => 'EventEspresso\core\services\loaders\LoaderInterface',
773
-            'EventEspresso\core\services\loaders\LoaderInterface'                 => 'EventEspresso\core\services\loaders\Loader',
774
-            'CommandFactoryInterface'                                             => 'EventEspresso\core\services\commands\CommandFactoryInterface',
775
-            'EventEspresso\core\services\commands\CommandFactoryInterface'        => 'EventEspresso\core\services\commands\CommandFactory',
776
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session',
777
-            'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
778
-            'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
779
-            'NoticesContainerInterface'                                            => 'EventEspresso\core\services\notices\NoticesContainerInterface',
780
-            'EventEspresso\core\services\notices\NoticesContainerInterface'        => 'EventEspresso\core\services\notices\NoticesContainer',
781
-        );
782
-    }
783
-
784
-
785
-
786
-    /**
787
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
788
-     * request Primarily used by unit tests.
789
-     *
790
-     * @throws InvalidDataTypeException
791
-     * @throws InvalidInterfaceException
792
-     * @throws InvalidArgumentException
793
-     */
794
-    public function reset()
795
-    {
796
-        $this->_register_core_class_loaders();
797
-        $this->_register_core_dependencies();
798
-    }
25
+	/**
26
+	 * This means that the requested class dependency is not present in the dependency map
27
+	 */
28
+	const not_registered = 0;
29
+
30
+	/**
31
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
32
+	 */
33
+	const load_new_object = 1;
34
+
35
+	/**
36
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
37
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
38
+	 */
39
+	const load_from_cache = 2;
40
+
41
+	/**
42
+	 * When registering a dependency,
43
+	 * this indicates to keep any existing dependencies that already exist,
44
+	 * and simply discard any new dependencies declared in the incoming data
45
+	 */
46
+	const KEEP_EXISTING_DEPENDENCIES = 0;
47
+
48
+	/**
49
+	 * When registering a dependency,
50
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
51
+	 */
52
+	const OVERWRITE_DEPENDENCIES = 1;
53
+
54
+
55
+
56
+	/**
57
+	 * @type EE_Dependency_Map $_instance
58
+	 */
59
+	protected static $_instance;
60
+
61
+	/**
62
+	 * @type EE_Request $request
63
+	 */
64
+	protected $_request;
65
+
66
+	/**
67
+	 * @type EE_Response $response
68
+	 */
69
+	protected $_response;
70
+
71
+	/**
72
+	 * @type LoaderInterface $loader
73
+	 */
74
+	protected $loader;
75
+
76
+	/**
77
+	 * @type array $_dependency_map
78
+	 */
79
+	protected $_dependency_map = array();
80
+
81
+	/**
82
+	 * @type array $_class_loaders
83
+	 */
84
+	protected $_class_loaders = array();
85
+
86
+	/**
87
+	 * @type array $_aliases
88
+	 */
89
+	protected $_aliases = array();
90
+
91
+
92
+
93
+	/**
94
+	 * EE_Dependency_Map constructor.
95
+	 *
96
+	 * @param EE_Request  $request
97
+	 * @param EE_Response $response
98
+	 */
99
+	protected function __construct(EE_Request $request, EE_Response $response)
100
+	{
101
+		$this->_request = $request;
102
+		$this->_response = $response;
103
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
104
+		do_action('EE_Dependency_Map____construct');
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * @throws InvalidDataTypeException
111
+	 * @throws InvalidInterfaceException
112
+	 * @throws InvalidArgumentException
113
+	 */
114
+	public function initialize()
115
+	{
116
+		$this->_register_core_dependencies();
117
+		$this->_register_core_class_loaders();
118
+		$this->_register_core_aliases();
119
+	}
120
+
121
+
122
+
123
+	/**
124
+	 * @singleton method used to instantiate class object
125
+	 * @access    public
126
+	 * @param EE_Request  $request
127
+	 * @param EE_Response $response
128
+	 * @return EE_Dependency_Map
129
+	 */
130
+	public static function instance(EE_Request $request = null, EE_Response $response = null)
131
+	{
132
+		// check if class object is instantiated, and instantiated properly
133
+		if (! self::$_instance instanceof EE_Dependency_Map) {
134
+			self::$_instance = new EE_Dependency_Map($request, $response);
135
+		}
136
+		return self::$_instance;
137
+	}
138
+
139
+
140
+
141
+	/**
142
+	 * @param LoaderInterface $loader
143
+	 */
144
+	public function setLoader(LoaderInterface $loader)
145
+	{
146
+		$this->loader = $loader;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * @param string $class
153
+	 * @param array  $dependencies
154
+	 * @param int    $overwrite
155
+	 * @return bool
156
+	 */
157
+	public static function register_dependencies(
158
+		$class,
159
+		array $dependencies,
160
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
161
+	) {
162
+		return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * Assigns an array of class names and corresponding load sources (new or cached)
169
+	 * to the class specified by the first parameter.
170
+	 * IMPORTANT !!!
171
+	 * The order of elements in the incoming $dependencies array MUST match
172
+	 * the order of the constructor parameters for the class in question.
173
+	 * This is especially important when overriding any existing dependencies that are registered.
174
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
175
+	 *
176
+	 * @param string $class
177
+	 * @param array  $dependencies
178
+	 * @param int    $overwrite
179
+	 * @return bool
180
+	 */
181
+	public function registerDependencies(
182
+		$class,
183
+		array $dependencies,
184
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
185
+	) {
186
+		$class = trim($class, '\\');
187
+		$registered = false;
188
+		if (empty(self::$_instance->_dependency_map[ $class ])) {
189
+			self::$_instance->_dependency_map[ $class ] = array();
190
+		}
191
+		// we need to make sure that any aliases used when registering a dependency
192
+		// get resolved to the correct class name
193
+		foreach ((array)$dependencies as $dependency => $load_source) {
194
+			$alias = self::$_instance->get_alias($dependency);
195
+			if (
196
+				$overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
197
+				|| ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
198
+			) {
199
+				unset($dependencies[$dependency]);
200
+				$dependencies[$alias] = $load_source;
201
+				$registered = true;
202
+			}
203
+		}
204
+		// now add our two lists of dependencies together.
205
+		// using Union (+=) favours the arrays in precedence from left to right,
206
+		// so $dependencies is NOT overwritten because it is listed first
207
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
208
+		// Union is way faster than array_merge() but should be used with caution...
209
+		// especially with numerically indexed arrays
210
+		$dependencies += self::$_instance->_dependency_map[ $class ];
211
+		// now we need to ensure that the resulting dependencies
212
+		// array only has the entries that are required for the class
213
+		// so first count how many dependencies were originally registered for the class
214
+		$dependency_count = count(self::$_instance->_dependency_map[ $class ]);
215
+		// if that count is non-zero (meaning dependencies were already registered)
216
+		self::$_instance->_dependency_map[ $class ] = $dependency_count
217
+			// then truncate the  final array to match that count
218
+			? array_slice($dependencies, 0, $dependency_count)
219
+			// otherwise just take the incoming array because nothing previously existed
220
+			: $dependencies;
221
+		return $registered;
222
+	}
223
+
224
+
225
+
226
+	/**
227
+	 * @param string $class_name
228
+	 * @param string $loader
229
+	 * @return bool
230
+	 * @throws DomainException
231
+	 */
232
+	public static function register_class_loader($class_name, $loader = 'load_core')
233
+	{
234
+		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
235
+			throw new DomainException(
236
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
237
+			);
238
+		}
239
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
240
+		if (
241
+			! is_callable($loader)
242
+			&& (
243
+				strpos($loader, 'load_') !== 0
244
+				|| ! method_exists('EE_Registry', $loader)
245
+			)
246
+		) {
247
+			throw new DomainException(
248
+				sprintf(
249
+					esc_html__(
250
+						'"%1$s" is not a valid loader method on EE_Registry.',
251
+						'event_espresso'
252
+					),
253
+					$loader
254
+				)
255
+			);
256
+		}
257
+		$class_name = self::$_instance->get_alias($class_name);
258
+		if (! isset(self::$_instance->_class_loaders[$class_name])) {
259
+			self::$_instance->_class_loaders[$class_name] = $loader;
260
+			return true;
261
+		}
262
+		return false;
263
+	}
264
+
265
+
266
+
267
+	/**
268
+	 * @return array
269
+	 */
270
+	public function dependency_map()
271
+	{
272
+		return $this->_dependency_map;
273
+	}
274
+
275
+
276
+
277
+	/**
278
+	 * returns TRUE if dependency map contains a listing for the provided class name
279
+	 *
280
+	 * @param string $class_name
281
+	 * @return boolean
282
+	 */
283
+	public function has($class_name = '')
284
+	{
285
+		// all legacy models have the same dependencies
286
+		if (strpos($class_name, 'EEM_') === 0) {
287
+			$class_name = 'LEGACY_MODELS';
288
+		}
289
+		return isset($this->_dependency_map[$class_name]) ? true : false;
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
296
+	 *
297
+	 * @param string $class_name
298
+	 * @param string $dependency
299
+	 * @return bool
300
+	 */
301
+	public function has_dependency_for_class($class_name = '', $dependency = '')
302
+	{
303
+		// all legacy models have the same dependencies
304
+		if (strpos($class_name, 'EEM_') === 0) {
305
+			$class_name = 'LEGACY_MODELS';
306
+		}
307
+		$dependency = $this->get_alias($dependency);
308
+		return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency])
309
+			? true
310
+			: false;
311
+	}
312
+
313
+
314
+
315
+	/**
316
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
317
+	 *
318
+	 * @param string $class_name
319
+	 * @param string $dependency
320
+	 * @return int
321
+	 */
322
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
323
+	{
324
+		// all legacy models have the same dependencies
325
+		if (strpos($class_name, 'EEM_') === 0) {
326
+			$class_name = 'LEGACY_MODELS';
327
+		}
328
+		$dependency = $this->get_alias($dependency);
329
+		return $this->has_dependency_for_class($class_name, $dependency)
330
+			? $this->_dependency_map[$class_name][$dependency]
331
+			: EE_Dependency_Map::not_registered;
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * @param string $class_name
338
+	 * @return string | Closure
339
+	 */
340
+	public function class_loader($class_name)
341
+	{
342
+		// all legacy models use load_model()
343
+		if(strpos($class_name, 'EEM_') === 0){
344
+			return 'load_model';
345
+		}
346
+		$class_name = $this->get_alias($class_name);
347
+		return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * @return array
354
+	 */
355
+	public function class_loaders()
356
+	{
357
+		return $this->_class_loaders;
358
+	}
359
+
360
+
361
+
362
+	/**
363
+	 * adds an alias for a classname
364
+	 *
365
+	 * @param string $class_name the class name that should be used (concrete class to replace interface)
366
+	 * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
367
+	 * @param string $for_class  the class that has the dependency (is type hinting for the interface)
368
+	 */
369
+	public function add_alias($class_name, $alias, $for_class = '')
370
+	{
371
+		if ($for_class !== '') {
372
+			if (! isset($this->_aliases[$for_class])) {
373
+				$this->_aliases[$for_class] = array();
374
+			}
375
+			$this->_aliases[$for_class][$class_name] = $alias;
376
+		}
377
+		$this->_aliases[$class_name] = $alias;
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * returns TRUE if the provided class name has an alias
384
+	 *
385
+	 * @param string $class_name
386
+	 * @param string $for_class
387
+	 * @return bool
388
+	 */
389
+	public function has_alias($class_name = '', $for_class = '')
390
+	{
391
+		return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])
392
+			   || (
393
+				   isset($this->_aliases[$class_name])
394
+				   && ! is_array($this->_aliases[$class_name])
395
+			   );
396
+	}
397
+
398
+
399
+
400
+	/**
401
+	 * returns alias for class name if one exists, otherwise returns the original classname
402
+	 * functions recursively, so that multiple aliases can be used to drill down to a classname
403
+	 *  for example:
404
+	 *      if the following two entries were added to the _aliases array:
405
+	 *          array(
406
+	 *              'interface_alias'           => 'some\namespace\interface'
407
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
408
+	 *          )
409
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
410
+	 *      to load an instance of 'some\namespace\classname'
411
+	 *
412
+	 * @param string $class_name
413
+	 * @param string $for_class
414
+	 * @return string
415
+	 */
416
+	public function get_alias($class_name = '', $for_class = '')
417
+	{
418
+		if (! $this->has_alias($class_name, $for_class)) {
419
+			return $class_name;
420
+		}
421
+		if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
422
+			return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
423
+		}
424
+		return $this->get_alias($this->_aliases[$class_name]);
425
+	}
426
+
427
+
428
+
429
+	/**
430
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
431
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
432
+	 * This is done by using the following class constants:
433
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
434
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
435
+	 */
436
+	protected function _register_core_dependencies()
437
+	{
438
+		$this->_dependency_map = array(
439
+			'EE_Request_Handler'                                                                                          => array(
440
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
441
+			),
442
+			'EE_System'                                                                                                   => array(
443
+				'EE_Registry'                                => EE_Dependency_Map::load_from_cache,
444
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
445
+				'EE_Capabilities'                            => EE_Dependency_Map::load_from_cache,
446
+				'EE_Request'                                 => EE_Dependency_Map::load_from_cache,
447
+				'EE_Maintenance_Mode'                        => EE_Dependency_Map::load_from_cache,
448
+			),
449
+			'EE_Session'                                                                                                  => array(
450
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
451
+				'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
452
+			),
453
+			'EE_Cart'                                                                                                     => array(
454
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
455
+			),
456
+			'EE_Front_Controller'                                                                                         => array(
457
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
458
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
459
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
460
+			),
461
+			'EE_Messenger_Collection_Loader'                                                                              => array(
462
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
463
+			),
464
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
465
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
466
+			),
467
+			'EE_Message_Resource_Manager'                                                                                 => array(
468
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
469
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
470
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
471
+			),
472
+			'EE_Message_Factory'                                                                                          => array(
473
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
474
+			),
475
+			'EE_messages'                                                                                                 => array(
476
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
477
+			),
478
+			'EE_Messages_Generator'                                                                                       => array(
479
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
480
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
481
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
482
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
483
+			),
484
+			'EE_Messages_Processor'                                                                                       => array(
485
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
486
+			),
487
+			'EE_Messages_Queue'                                                                                           => array(
488
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
489
+			),
490
+			'EE_Messages_Template_Defaults'                                                                               => array(
491
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
492
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
493
+			),
494
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
495
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
496
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
497
+			),
498
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
499
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
500
+			),
501
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
502
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
503
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
504
+			),
505
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
506
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
507
+			),
508
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
509
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
510
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
511
+			),
512
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
513
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
514
+			),
515
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
516
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
517
+			),
518
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
519
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
520
+			),
521
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
522
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
523
+			),
524
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
525
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
526
+			),
527
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
528
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
529
+			),
530
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
531
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
532
+			),
533
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
534
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
535
+			),
536
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
537
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
538
+			),
539
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
540
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
541
+			),
542
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
543
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
544
+			),
545
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
546
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
547
+			),
548
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
549
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
550
+			),
551
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
552
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
553
+			),
554
+			'EE_Data_Migration_Class_Base'                                                                                => array(
555
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
556
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
557
+			),
558
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
559
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
560
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
561
+			),
562
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
563
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
564
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
565
+			),
566
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
567
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
568
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
569
+			),
570
+			'EE_DMS_Core_4_4_0'                                                                                           => 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_5_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_6_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_7_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_8_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_9_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
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
595
+				'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
596
+				'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
597
+			),
598
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
599
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
600
+			),
601
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
602
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
603
+			),
604
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
605
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
606
+			),
607
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
608
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
609
+			),
610
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
611
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
612
+			),
613
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
614
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
615
+			),
616
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
617
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
618
+			),
619
+			'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
620
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
621
+			),
622
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
623
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
624
+			),
625
+			'EventEspresso\core\services\orm\ModelFieldFactory'                                                   => array(
626
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
627
+			),
628
+			'LEGACY_MODELS'                                                   => array(
629
+				null,
630
+				'EventEspresso\core\services\orm\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
631
+			),
632
+			'EE_Module_Request_Router' => array(
633
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
634
+			),
635
+		);
636
+	}
637
+
638
+
639
+
640
+	/**
641
+	 * Registers how core classes are loaded.
642
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
643
+	 *        'EE_Request_Handler' => 'load_core'
644
+	 *        'EE_Messages_Queue'  => 'load_lib'
645
+	 *        'EEH_Debug_Tools'    => 'load_helper'
646
+	 * or, if greater control is required, by providing a custom closure. For example:
647
+	 *        'Some_Class' => function () {
648
+	 *            return new Some_Class();
649
+	 *        },
650
+	 * This is required for instantiating dependencies
651
+	 * where an interface has been type hinted in a class constructor. For example:
652
+	 *        'Required_Interface' => function () {
653
+	 *            return new A_Class_That_Implements_Required_Interface();
654
+	 *        },
655
+	 *
656
+	 * @throws InvalidInterfaceException
657
+	 * @throws InvalidDataTypeException
658
+	 * @throws InvalidArgumentException
659
+	 */
660
+	protected function _register_core_class_loaders()
661
+	{
662
+		//for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
663
+		//be used in a closure.
664
+		$request = &$this->_request;
665
+		$response = &$this->_response;
666
+		$loader = &$this->loader;
667
+		$this->_class_loaders = array(
668
+			//load_core
669
+			'EE_Capabilities'                      => 'load_core',
670
+			'EE_Encryption'                        => 'load_core',
671
+			'EE_Front_Controller'                  => 'load_core',
672
+			'EE_Module_Request_Router'             => 'load_core',
673
+			'EE_Registry'                          => 'load_core',
674
+			'EE_Request'                           => function () use (&$request) {
675
+				return $request;
676
+			},
677
+			'EE_Response'                          => function () use (&$response) {
678
+				return $response;
679
+			},
680
+			'EE_Request_Handler'                   => 'load_core',
681
+			'EE_Session'                           => 'load_core',
682
+			'EE_Cron_Tasks'                        => 'load_core',
683
+			'EE_System'                            => 'load_core',
684
+			'EE_Maintenance_Mode'                  => 'load_core',
685
+			'EE_Register_CPTs'                     => 'load_core',
686
+			'EE_Admin'                             => 'load_core',
687
+			//load_lib
688
+			'EE_Message_Resource_Manager'          => 'load_lib',
689
+			'EE_Message_Type_Collection'           => 'load_lib',
690
+			'EE_Message_Type_Collection_Loader'    => 'load_lib',
691
+			'EE_Messenger_Collection'              => 'load_lib',
692
+			'EE_Messenger_Collection_Loader'       => 'load_lib',
693
+			'EE_Messages_Processor'                => 'load_lib',
694
+			'EE_Message_Repository'                => 'load_lib',
695
+			'EE_Messages_Queue'                    => 'load_lib',
696
+			'EE_Messages_Data_Handler_Collection'  => 'load_lib',
697
+			'EE_Message_Template_Group_Collection' => 'load_lib',
698
+			'EE_Messages_Generator'                => function () {
699
+				return EE_Registry::instance()->load_lib(
700
+					'Messages_Generator',
701
+					array(),
702
+					false,
703
+					false
704
+				);
705
+			},
706
+			'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
707
+				return EE_Registry::instance()->load_lib(
708
+					'Messages_Template_Defaults',
709
+					$arguments,
710
+					false,
711
+					false
712
+				);
713
+			},
714
+			//load_model
715
+			// 'EEM_Attendee'                         => 'load_model',
716
+			// 'EEM_Message_Template_Group'           => 'load_model',
717
+			// 'EEM_Message_Template'                 => 'load_model',
718
+			//load_helper
719
+			'EEH_Parse_Shortcodes'                 => function () {
720
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
721
+					return new EEH_Parse_Shortcodes();
722
+				}
723
+				return null;
724
+			},
725
+			'EE_Template_Config'                   => function () {
726
+				return EE_Config::instance()->template_settings;
727
+			},
728
+			'EE_Currency_Config'                   => function () {
729
+				return EE_Config::instance()->currency;
730
+			},
731
+			'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) {
732
+				return $loader;
733
+			},
734
+		);
735
+	}
736
+
737
+
738
+
739
+	/**
740
+	 * can be used for supplying alternate names for classes,
741
+	 * or for connecting interface names to instantiable classes
742
+	 */
743
+	protected function _register_core_aliases()
744
+	{
745
+		$this->_aliases = array(
746
+			'CommandBusInterface'                                                 => 'EventEspresso\core\services\commands\CommandBusInterface',
747
+			'EventEspresso\core\services\commands\CommandBusInterface'            => 'EventEspresso\core\services\commands\CommandBus',
748
+			'CommandHandlerManagerInterface'                                      => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
749
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager',
750
+			'CapChecker'                                                          => 'EventEspresso\core\services\commands\middleware\CapChecker',
751
+			'AddActionHook'                                                       => 'EventEspresso\core\services\commands\middleware\AddActionHook',
752
+			'CapabilitiesChecker'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
753
+			'CapabilitiesCheckerInterface'                                        => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
754
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
755
+			'CreateRegistrationService'                                           => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
756
+			'CreateRegCodeCommandHandler'                                         => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
757
+			'CreateRegUrlLinkCommandHandler'                                      => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
758
+			'CreateRegistrationCommandHandler'                                    => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
759
+			'CopyRegistrationDetailsCommandHandler'                               => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
760
+			'CopyRegistrationPaymentsCommandHandler'                              => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
761
+			'CancelRegistrationAndTicketLineItemCommandHandler'                   => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
762
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'           => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
763
+			'CreateTicketLineItemCommandHandler'                                  => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
764
+			'TableManager'                                                        => 'EventEspresso\core\services\database\TableManager',
765
+			'TableAnalysis'                                                       => 'EventEspresso\core\services\database\TableAnalysis',
766
+			'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
767
+			'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
768
+			'EspressoShortcode'                                                   => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
769
+			'ShortcodeInterface'                                                  => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
770
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'           => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
771
+			'EventEspresso\core\services\cache\CacheStorageInterface'             => 'EventEspresso\core\services\cache\TransientCacheStorage',
772
+			'LoaderInterface'                                                     => 'EventEspresso\core\services\loaders\LoaderInterface',
773
+			'EventEspresso\core\services\loaders\LoaderInterface'                 => 'EventEspresso\core\services\loaders\Loader',
774
+			'CommandFactoryInterface'                                             => 'EventEspresso\core\services\commands\CommandFactoryInterface',
775
+			'EventEspresso\core\services\commands\CommandFactoryInterface'        => 'EventEspresso\core\services\commands\CommandFactory',
776
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session',
777
+			'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
778
+			'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
779
+			'NoticesContainerInterface'                                            => 'EventEspresso\core\services\notices\NoticesContainerInterface',
780
+			'EventEspresso\core\services\notices\NoticesContainerInterface'        => 'EventEspresso\core\services\notices\NoticesContainer',
781
+		);
782
+	}
783
+
784
+
785
+
786
+	/**
787
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
788
+	 * request Primarily used by unit tests.
789
+	 *
790
+	 * @throws InvalidDataTypeException
791
+	 * @throws InvalidInterfaceException
792
+	 * @throws InvalidArgumentException
793
+	 */
794
+	public function reset()
795
+	{
796
+		$this->_register_core_class_loaders();
797
+		$this->_register_core_dependencies();
798
+	}
799 799
 
800 800
 
801 801
 }
Please login to merge, or discard this patch.
core/EE_Load_Espresso_Core.core.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\exceptions\InvalidInterfaceException;
4 4
 use EventEspresso\core\services\loaders\LoaderFactory;
5 5
 
6
-if (! defined('EVENT_ESPRESSO_VERSION')) {
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7 7
     exit('No direct script access allowed');
8 8
 }
9 9
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function __construct()
53 53
     {
54
-        espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php');
54
+        espresso_load_required('EventEspresso\core\Factory', EE_CORE.'Factory.php');
55 55
     }
56 56
 
57 57
 
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
         $this->_load_class_tools();
106 106
         // load interfaces
107 107
         espresso_load_required('EEI_Payment_Method_Interfaces',
108
-            EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php');
108
+            EE_LIBRARIES.'payment_methods'.DS.'EEI_Payment_Method_Interfaces.php');
109 109
         // deprecated functions
110
-        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
110
+        espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php');
111 111
         // WP cron jobs
112 112
         $loader->getShared('EE_Cron_Tasks');
113 113
         $loader->getShared('EE_Request_Handler');
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
      */
144 144
     public function dependency_map()
145 145
     {
146
-        if (! $this->dependency_map instanceof EE_Dependency_Map) {
146
+        if ( ! $this->dependency_map instanceof EE_Dependency_Map) {
147 147
             throw new EE_Error(
148 148
                 sprintf(
149 149
                     __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
      */
163 163
     public function registry()
164 164
     {
165
-        if (! $this->registry instanceof EE_Registry) {
165
+        if ( ! $this->registry instanceof EE_Registry) {
166 166
             throw new EE_Error(
167 167
                 sprintf(
168 168
                     __('Invalid EE_Registry: "%1$s"', 'event_espresso'),
@@ -180,14 +180,14 @@  discard block
 block discarded – undo
180 180
      */
181 181
     private function _load_dependency_map()
182 182
     {
183
-        if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
183
+        if ( ! is_readable(EE_CORE.'EE_Dependency_Map.core.php')) {
184 184
             EE_Error::add_error(
185 185
                 __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
186 186
                 __FILE__, __FUNCTION__, __LINE__
187 187
             );
188 188
             wp_die(EE_Error::get_notices());
189 189
         }
190
-        require_once(EE_CORE . 'EE_Dependency_Map.core.php');
190
+        require_once(EE_CORE.'EE_Dependency_Map.core.php');
191 191
         return EE_Dependency_Map::instance($this->request, $this->response);
192 192
     }
193 193
 
@@ -198,14 +198,14 @@  discard block
 block discarded – undo
198 198
      */
199 199
     private function _load_registry()
200 200
     {
201
-        if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
201
+        if ( ! is_readable(EE_CORE.'EE_Registry.core.php')) {
202 202
             EE_Error::add_error(
203 203
                 __('The EE_Registry core class could not be loaded.', 'event_espresso'),
204 204
                 __FILE__, __FUNCTION__, __LINE__
205 205
             );
206 206
             wp_die(EE_Error::get_notices());
207 207
         }
208
-        require_once(EE_CORE . 'EE_Registry.core.php');
208
+        require_once(EE_CORE.'EE_Registry.core.php');
209 209
         return EE_Registry::instance($this->dependency_map);
210 210
     }
211 211
 
@@ -216,13 +216,13 @@  discard block
 block discarded – undo
216 216
      */
217 217
     private function _load_class_tools()
218 218
     {
219
-        if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
219
+        if ( ! is_readable(EE_HELPERS.'EEH_Class_Tools.helper.php')) {
220 220
             EE_Error::add_error(
221 221
                 __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
222 222
                 __FILE__, __FUNCTION__, __LINE__
223 223
             );
224 224
         }
225
-        require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
225
+        require_once(EE_HELPERS.'EEH_Class_Tools.helper.php');
226 226
     }
227 227
 
228 228
 
Please login to merge, or discard this patch.
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\loaders\LoaderFactory;
5 5
 
6 6
 if (! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -24,208 +24,208 @@  discard block
 block discarded – undo
24 24
 class EE_Load_Espresso_Core implements EEI_Request_Decorator, EEI_Request_Stack_Core_App
25 25
 {
26 26
 
27
-    /**
28
-     * @var EE_Request $request
29
-     */
30
-    protected $request;
31
-
32
-    /**
33
-     * @var EE_Response $response
34
-     */
35
-    protected $response;
36
-
37
-    /**
38
-     * @var EE_Dependency_Map $dependency_map
39
-     */
40
-    protected $dependency_map;
41
-
42
-    /**
43
-     * @var EE_Registry $registry
44
-     */
45
-    protected $registry;
46
-
47
-
48
-
49
-    /**
50
-     * EE_Load_Espresso_Core constructor
51
-     */
52
-    public function __construct()
53
-    {
54
-        espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php');
55
-    }
56
-
57
-
58
-
59
-    /**
60
-     * handle
61
-     * sets hooks for running rest of system
62
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
63
-     * starting EE Addons from any other point may lead to problems
64
-     *
65
-     * @param EE_Request  $request
66
-     * @param EE_Response $response
67
-     * @return EE_Response
68
-     * @throws EE_Error
69
-     * @throws InvalidDataTypeException
70
-     * @throws InvalidInterfaceException
71
-     * @throws InvalidArgumentException
72
-     */
73
-    public function handle_request(EE_Request $request, EE_Response $response)
74
-    {
75
-        $this->request = $request;
76
-        $this->response = $response;
77
-        // info about how to load classes required by other classes
78
-        $this->dependency_map = $this->_load_dependency_map();
79
-        // central repository for classes
80
-        $this->registry = $this->_load_registry();
81
-        // PSR4 Autoloaders
82
-        $this->registry->load_core('EE_Psr4AutoloaderInit');
83
-        do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
84
-        $loader = LoaderFactory::getLoader($this->registry);
85
-        $this->dependency_map->setLoader($loader);
86
-        // build DI container
87
-        // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop();
88
-        // $OpenCoffeeShop->addRecipes();
89
-        // $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
90
-        // workarounds for PHP < 5.3
91
-        $this->_load_class_tools();
92
-        // load interfaces
93
-        espresso_load_required('EEI_Payment_Method_Interfaces',
94
-            EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php');
95
-        // deprecated functions
96
-        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
97
-        // WP cron jobs
98
-        $loader->getShared('EE_Cron_Tasks');
99
-        $loader->getShared('EE_Request_Handler');
100
-        $loader->getShared('EE_System');
101
-        return $this->response;
102
-    }
103
-
104
-
105
-
106
-    /**
107
-     * @return EE_Request
108
-     */
109
-    public function request()
110
-    {
111
-        return $this->request;
112
-    }
113
-
114
-
115
-
116
-    /**
117
-     * @return EE_Response
118
-     */
119
-    public function response()
120
-    {
121
-        return $this->response;
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * @return EE_Dependency_Map
128
-     * @throws EE_Error
129
-     */
130
-    public function dependency_map()
131
-    {
132
-        if (! $this->dependency_map instanceof EE_Dependency_Map) {
133
-            throw new EE_Error(
134
-                sprintf(
135
-                    __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
136
-                    print_r($this->dependency_map, true)
137
-                )
138
-            );
139
-        }
140
-        return $this->dependency_map;
141
-    }
142
-
143
-
144
-
145
-    /**
146
-     * @return EE_Registry
147
-     * @throws EE_Error
148
-     */
149
-    public function registry()
150
-    {
151
-        if (! $this->registry instanceof EE_Registry) {
152
-            throw new EE_Error(
153
-                sprintf(
154
-                    __('Invalid EE_Registry: "%1$s"', 'event_espresso'),
155
-                    print_r($this->registry, true)
156
-                )
157
-            );
158
-        }
159
-        return $this->registry;
160
-    }
161
-
162
-
163
-
164
-    /**
165
-     * @return EE_Dependency_Map
166
-     */
167
-    private function _load_dependency_map()
168
-    {
169
-        if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
170
-            EE_Error::add_error(
171
-                __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
172
-                __FILE__, __FUNCTION__, __LINE__
173
-            );
174
-            wp_die(EE_Error::get_notices());
175
-        }
176
-        require_once(EE_CORE . 'EE_Dependency_Map.core.php');
177
-        return EE_Dependency_Map::instance($this->request, $this->response);
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     * @return EE_Registry
184
-     */
185
-    private function _load_registry()
186
-    {
187
-        if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
188
-            EE_Error::add_error(
189
-                __('The EE_Registry core class could not be loaded.', 'event_espresso'),
190
-                __FILE__, __FUNCTION__, __LINE__
191
-            );
192
-            wp_die(EE_Error::get_notices());
193
-        }
194
-        require_once(EE_CORE . 'EE_Registry.core.php');
195
-        return EE_Registry::instance($this->dependency_map);
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * @return void
202
-     */
203
-    private function _load_class_tools()
204
-    {
205
-        if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
206
-            EE_Error::add_error(
207
-                __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
208
-                __FILE__, __FUNCTION__, __LINE__
209
-            );
210
-        }
211
-        require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
212
-    }
213
-
214
-
215
-
216
-    /**
217
-     * called after the request stack has been fully processed
218
-     * if any of the middleware apps has requested the plugin be deactivated, then we do that now
219
-     *
220
-     * @param EE_Request  $request
221
-     * @param EE_Response $response
222
-     */
223
-    public function handle_response(EE_Request $request, EE_Response $response)
224
-    {
225
-        if ($response->plugin_deactivated()) {
226
-            espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
227
-        }
228
-    }
27
+	/**
28
+	 * @var EE_Request $request
29
+	 */
30
+	protected $request;
31
+
32
+	/**
33
+	 * @var EE_Response $response
34
+	 */
35
+	protected $response;
36
+
37
+	/**
38
+	 * @var EE_Dependency_Map $dependency_map
39
+	 */
40
+	protected $dependency_map;
41
+
42
+	/**
43
+	 * @var EE_Registry $registry
44
+	 */
45
+	protected $registry;
46
+
47
+
48
+
49
+	/**
50
+	 * EE_Load_Espresso_Core constructor
51
+	 */
52
+	public function __construct()
53
+	{
54
+		espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php');
55
+	}
56
+
57
+
58
+
59
+	/**
60
+	 * handle
61
+	 * sets hooks for running rest of system
62
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
63
+	 * starting EE Addons from any other point may lead to problems
64
+	 *
65
+	 * @param EE_Request  $request
66
+	 * @param EE_Response $response
67
+	 * @return EE_Response
68
+	 * @throws EE_Error
69
+	 * @throws InvalidDataTypeException
70
+	 * @throws InvalidInterfaceException
71
+	 * @throws InvalidArgumentException
72
+	 */
73
+	public function handle_request(EE_Request $request, EE_Response $response)
74
+	{
75
+		$this->request = $request;
76
+		$this->response = $response;
77
+		// info about how to load classes required by other classes
78
+		$this->dependency_map = $this->_load_dependency_map();
79
+		// central repository for classes
80
+		$this->registry = $this->_load_registry();
81
+		// PSR4 Autoloaders
82
+		$this->registry->load_core('EE_Psr4AutoloaderInit');
83
+		do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
84
+		$loader = LoaderFactory::getLoader($this->registry);
85
+		$this->dependency_map->setLoader($loader);
86
+		// build DI container
87
+		// $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop();
88
+		// $OpenCoffeeShop->addRecipes();
89
+		// $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
90
+		// workarounds for PHP < 5.3
91
+		$this->_load_class_tools();
92
+		// load interfaces
93
+		espresso_load_required('EEI_Payment_Method_Interfaces',
94
+			EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php');
95
+		// deprecated functions
96
+		espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
97
+		// WP cron jobs
98
+		$loader->getShared('EE_Cron_Tasks');
99
+		$loader->getShared('EE_Request_Handler');
100
+		$loader->getShared('EE_System');
101
+		return $this->response;
102
+	}
103
+
104
+
105
+
106
+	/**
107
+	 * @return EE_Request
108
+	 */
109
+	public function request()
110
+	{
111
+		return $this->request;
112
+	}
113
+
114
+
115
+
116
+	/**
117
+	 * @return EE_Response
118
+	 */
119
+	public function response()
120
+	{
121
+		return $this->response;
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * @return EE_Dependency_Map
128
+	 * @throws EE_Error
129
+	 */
130
+	public function dependency_map()
131
+	{
132
+		if (! $this->dependency_map instanceof EE_Dependency_Map) {
133
+			throw new EE_Error(
134
+				sprintf(
135
+					__('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
136
+					print_r($this->dependency_map, true)
137
+				)
138
+			);
139
+		}
140
+		return $this->dependency_map;
141
+	}
142
+
143
+
144
+
145
+	/**
146
+	 * @return EE_Registry
147
+	 * @throws EE_Error
148
+	 */
149
+	public function registry()
150
+	{
151
+		if (! $this->registry instanceof EE_Registry) {
152
+			throw new EE_Error(
153
+				sprintf(
154
+					__('Invalid EE_Registry: "%1$s"', 'event_espresso'),
155
+					print_r($this->registry, true)
156
+				)
157
+			);
158
+		}
159
+		return $this->registry;
160
+	}
161
+
162
+
163
+
164
+	/**
165
+	 * @return EE_Dependency_Map
166
+	 */
167
+	private function _load_dependency_map()
168
+	{
169
+		if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
170
+			EE_Error::add_error(
171
+				__('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
172
+				__FILE__, __FUNCTION__, __LINE__
173
+			);
174
+			wp_die(EE_Error::get_notices());
175
+		}
176
+		require_once(EE_CORE . 'EE_Dependency_Map.core.php');
177
+		return EE_Dependency_Map::instance($this->request, $this->response);
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 * @return EE_Registry
184
+	 */
185
+	private function _load_registry()
186
+	{
187
+		if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
188
+			EE_Error::add_error(
189
+				__('The EE_Registry core class could not be loaded.', 'event_espresso'),
190
+				__FILE__, __FUNCTION__, __LINE__
191
+			);
192
+			wp_die(EE_Error::get_notices());
193
+		}
194
+		require_once(EE_CORE . 'EE_Registry.core.php');
195
+		return EE_Registry::instance($this->dependency_map);
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * @return void
202
+	 */
203
+	private function _load_class_tools()
204
+	{
205
+		if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
206
+			EE_Error::add_error(
207
+				__('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
208
+				__FILE__, __FUNCTION__, __LINE__
209
+			);
210
+		}
211
+		require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
212
+	}
213
+
214
+
215
+
216
+	/**
217
+	 * called after the request stack has been fully processed
218
+	 * if any of the middleware apps has requested the plugin be deactivated, then we do that now
219
+	 *
220
+	 * @param EE_Request  $request
221
+	 * @param EE_Response $response
222
+	 */
223
+	public function handle_response(EE_Request $request, EE_Response $response)
224
+	{
225
+		if ($response->plugin_deactivated()) {
226
+			espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
227
+		}
228
+	}
229 229
 
230 230
 
231 231
 
Please login to merge, or discard this patch.
core/db_models/EEM_Transaction.model.php 2 patches
Indentation   +363 added lines, -363 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 require_once(EE_MODELS . 'EEM_Base.model.php');
7 7
 
@@ -17,193 +17,193 @@  discard block
 block discarded – undo
17 17
 class EEM_Transaction extends EEM_Base
18 18
 {
19 19
 
20
-    // private instance of the Transaction object
21
-    protected static $_instance;
22
-
23
-    /**
24
-     * Status ID(STS_ID on esp_status table) to indicate the transaction is complete,
25
-     * but payment is pending. This is the state for transactions where payment is promised
26
-     * from an offline gateway.
27
-     */
28
-    //	const open_status_code = 'TPN';
29
-
30
-    /**
31
-     * Status ID(STS_ID on esp_status table) to indicate the transaction failed,
32
-     * either due to a technical reason (server or computer crash during registration),
33
-     *  or some other reason that prevent the collection of any useful contact information from any of the registrants
34
-     */
35
-    const failed_status_code = 'TFL';
36
-
37
-    /**
38
-     * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned,
39
-     * either due to a technical reason (server or computer crash during registration),
40
-     * or due to an abandoned cart after registrant chose not to complete the registration process
41
-     * HOWEVER...
42
-     * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one
43
-     * registrant
44
-     */
45
-    const abandoned_status_code = 'TAB';
46
-
47
-    /**
48
-     * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction,
49
-     * meaning that monies are still owing: TXN_paid < TXN_total
50
-     */
51
-    const incomplete_status_code = 'TIN';
52
-
53
-    /**
54
-     * Status ID (STS_ID on esp_status table) to indicate a complete transaction.
55
-     * meaning that NO monies are owing: TXN_paid == TXN_total
56
-     */
57
-    const complete_status_code = 'TCM';
58
-
59
-    /**
60
-     *  Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid.
61
-     *  This is the same as complete, but site admins actually owe clients the moneys!  TXN_paid > TXN_total
62
-     */
63
-    const overpaid_status_code = 'TOP';
64
-
65
-
66
-    /**
67
-     *    private constructor to prevent direct creation
68
-     *
69
-     * @Constructor
70
-     * @access protected
71
-     *
72
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
73
-     *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
74
-     *                         date time model field objects.  Default is NULL (and will be assumed using the set
75
-     *                         timezone in the 'timezone_string' wp option)
76
-     *
77
-     * @return EEM_Transaction
78
-     * @throws \EE_Error
79
-     */
80
-    protected function __construct($timezone)
81
-    {
82
-        $this->singular_item = __('Transaction', 'event_espresso');
83
-        $this->plural_item   = __('Transactions', 'event_espresso');
84
-
85
-        $this->_tables                 = array(
86
-            'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID')
87
-        );
88
-        $this->_fields                 = array(
89
-            'TransactionTable' => array(
90
-                'TXN_ID'           => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')),
91
-                'TXN_timestamp'    => new EE_Datetime_Field('TXN_timestamp',
92
-                    __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now,
93
-                    $timezone),
94
-                'TXN_total'        => new EE_Money_Field('TXN_total',
95
-                    __('Total value of Transaction', 'event_espresso'), false, 0),
96
-                'TXN_paid'         => new EE_Money_Field('TXN_paid',
97
-                    __('Amount paid towards transaction to date', 'event_espresso'), false, 0),
98
-                'STS_ID'           => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'),
99
-                    false, EEM_Transaction::failed_status_code, 'Status'),
100
-                'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data',
101
-                    __('Serialized session data', 'event_espresso'), true, ''),
102
-                'TXN_hash_salt'    => new EE_Plain_Text_Field('TXN_hash_salt',
103
-                    __('Transaction Hash Salt', 'event_espresso'), true, ''),
104
-                'PMD_ID'           => new EE_Foreign_Key_Int_Field('PMD_ID',
105
-                    __("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'),
106
-                'TXN_reg_steps'    => new EE_Serialized_Text_Field('TXN_reg_steps',
107
-                    __('Registration Steps', 'event_espresso'), false, array()),
108
-            )
109
-        );
110
-        $this->_model_relations        = array(
111
-            'Registration'   => new EE_Has_Many_Relation(),
112
-            'Payment'        => new EE_Has_Many_Relation(),
113
-            'Status'         => new EE_Belongs_To_Relation(),
114
-            'Line_Item'      => new EE_Has_Many_Relation(false),
115
-            //you can delete a transaction without needing to delete its line items
116
-            'Payment_Method' => new EE_Belongs_To_Relation(),
117
-            'Message'        => new EE_Has_Many_Relation()
118
-        );
119
-        $this->_model_chain_to_wp_user = 'Registration.Event';
120
-        parent::__construct($timezone);
121
-
122
-    }
123
-
124
-
125
-    /**
126
-     *    txn_status_array
127
-     * get list of transaction statuses
128
-     *
129
-     * @access public
130
-     * @return array
131
-     */
132
-    public static function txn_status_array()
133
-    {
134
-        return apply_filters(
135
-            'FHEE__EEM_Transaction__txn_status_array',
136
-            array(
137
-                EEM_Transaction::overpaid_status_code,
138
-                EEM_Transaction::complete_status_code,
139
-                EEM_Transaction::incomplete_status_code,
140
-                EEM_Transaction::abandoned_status_code,
141
-                EEM_Transaction::failed_status_code,
142
-            )
143
-        );
144
-    }
145
-
146
-    /**
147
-     *        get the revenue per day  for the Transaction Admin page Reports Tab
148
-     *
149
-     * @access        public
150
-     *
151
-     * @param string $period
152
-     *
153
-     * @return \stdClass[]
154
-     */
155
-    public function get_revenue_per_day_report($period = '-1 month')
156
-    {
157
-        $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)),
158
-            'Y-m-d H:i:s', 'UTC');
159
-
160
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp');
161
-
162
-        return $this->_get_all_wpdb_results(
163
-            array(
164
-                array(
165
-                    'TXN_timestamp' => array('>=', $sql_date)
166
-                ),
167
-                'group_by' => 'txnDate',
168
-                'order_by' => array('TXN_timestamp' => 'ASC')
169
-            ),
170
-            OBJECT,
171
-            array(
172
-                'txnDate' => array('DATE(' . $query_interval . ')', '%s'),
173
-                'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d')
174
-            )
175
-        );
176
-    }
177
-
178
-
179
-    /**
180
-     *        get the revenue per event  for the Transaction Admin page Reports Tab
181
-     *
182
-     * @access        public
183
-     *
184
-     * @param string $period
185
-     *
186
-     * @throws \EE_Error
187
-     * @return mixed
188
-     */
189
-    public function get_revenue_per_event_report($period = '-1 month')
190
-    {
191
-        global $wpdb;
192
-        $transaction_table          = $wpdb->prefix . 'esp_transaction';
193
-        $registration_table         = $wpdb->prefix . 'esp_registration';
194
-        $registration_payment_table = $wpdb->prefix . 'esp_registration_payment';
195
-        $event_table                = $wpdb->posts;
196
-        $payment_table              = $wpdb->prefix . 'esp_payment';
197
-        $sql_date                   = date('Y-m-d H:i:s', strtotime($period));
198
-        $approved_payment_status    = EEM_Payment::status_id_approved;
199
-        $extra_event_on_join        = '';
200
-        //exclude events not authored by user if permissions in effect
201
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
202
-            $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id();
203
-        }
204
-
205
-        return $wpdb->get_results(
206
-            "SELECT
20
+	// private instance of the Transaction object
21
+	protected static $_instance;
22
+
23
+	/**
24
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction is complete,
25
+	 * but payment is pending. This is the state for transactions where payment is promised
26
+	 * from an offline gateway.
27
+	 */
28
+	//	const open_status_code = 'TPN';
29
+
30
+	/**
31
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction failed,
32
+	 * either due to a technical reason (server or computer crash during registration),
33
+	 *  or some other reason that prevent the collection of any useful contact information from any of the registrants
34
+	 */
35
+	const failed_status_code = 'TFL';
36
+
37
+	/**
38
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned,
39
+	 * either due to a technical reason (server or computer crash during registration),
40
+	 * or due to an abandoned cart after registrant chose not to complete the registration process
41
+	 * HOWEVER...
42
+	 * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one
43
+	 * registrant
44
+	 */
45
+	const abandoned_status_code = 'TAB';
46
+
47
+	/**
48
+	 * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction,
49
+	 * meaning that monies are still owing: TXN_paid < TXN_total
50
+	 */
51
+	const incomplete_status_code = 'TIN';
52
+
53
+	/**
54
+	 * Status ID (STS_ID on esp_status table) to indicate a complete transaction.
55
+	 * meaning that NO monies are owing: TXN_paid == TXN_total
56
+	 */
57
+	const complete_status_code = 'TCM';
58
+
59
+	/**
60
+	 *  Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid.
61
+	 *  This is the same as complete, but site admins actually owe clients the moneys!  TXN_paid > TXN_total
62
+	 */
63
+	const overpaid_status_code = 'TOP';
64
+
65
+
66
+	/**
67
+	 *    private constructor to prevent direct creation
68
+	 *
69
+	 * @Constructor
70
+	 * @access protected
71
+	 *
72
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
73
+	 *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
74
+	 *                         date time model field objects.  Default is NULL (and will be assumed using the set
75
+	 *                         timezone in the 'timezone_string' wp option)
76
+	 *
77
+	 * @return EEM_Transaction
78
+	 * @throws \EE_Error
79
+	 */
80
+	protected function __construct($timezone)
81
+	{
82
+		$this->singular_item = __('Transaction', 'event_espresso');
83
+		$this->plural_item   = __('Transactions', 'event_espresso');
84
+
85
+		$this->_tables                 = array(
86
+			'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID')
87
+		);
88
+		$this->_fields                 = array(
89
+			'TransactionTable' => array(
90
+				'TXN_ID'           => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')),
91
+				'TXN_timestamp'    => new EE_Datetime_Field('TXN_timestamp',
92
+					__('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now,
93
+					$timezone),
94
+				'TXN_total'        => new EE_Money_Field('TXN_total',
95
+					__('Total value of Transaction', 'event_espresso'), false, 0),
96
+				'TXN_paid'         => new EE_Money_Field('TXN_paid',
97
+					__('Amount paid towards transaction to date', 'event_espresso'), false, 0),
98
+				'STS_ID'           => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'),
99
+					false, EEM_Transaction::failed_status_code, 'Status'),
100
+				'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data',
101
+					__('Serialized session data', 'event_espresso'), true, ''),
102
+				'TXN_hash_salt'    => new EE_Plain_Text_Field('TXN_hash_salt',
103
+					__('Transaction Hash Salt', 'event_espresso'), true, ''),
104
+				'PMD_ID'           => new EE_Foreign_Key_Int_Field('PMD_ID',
105
+					__("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'),
106
+				'TXN_reg_steps'    => new EE_Serialized_Text_Field('TXN_reg_steps',
107
+					__('Registration Steps', 'event_espresso'), false, array()),
108
+			)
109
+		);
110
+		$this->_model_relations        = array(
111
+			'Registration'   => new EE_Has_Many_Relation(),
112
+			'Payment'        => new EE_Has_Many_Relation(),
113
+			'Status'         => new EE_Belongs_To_Relation(),
114
+			'Line_Item'      => new EE_Has_Many_Relation(false),
115
+			//you can delete a transaction without needing to delete its line items
116
+			'Payment_Method' => new EE_Belongs_To_Relation(),
117
+			'Message'        => new EE_Has_Many_Relation()
118
+		);
119
+		$this->_model_chain_to_wp_user = 'Registration.Event';
120
+		parent::__construct($timezone);
121
+
122
+	}
123
+
124
+
125
+	/**
126
+	 *    txn_status_array
127
+	 * get list of transaction statuses
128
+	 *
129
+	 * @access public
130
+	 * @return array
131
+	 */
132
+	public static function txn_status_array()
133
+	{
134
+		return apply_filters(
135
+			'FHEE__EEM_Transaction__txn_status_array',
136
+			array(
137
+				EEM_Transaction::overpaid_status_code,
138
+				EEM_Transaction::complete_status_code,
139
+				EEM_Transaction::incomplete_status_code,
140
+				EEM_Transaction::abandoned_status_code,
141
+				EEM_Transaction::failed_status_code,
142
+			)
143
+		);
144
+	}
145
+
146
+	/**
147
+	 *        get the revenue per day  for the Transaction Admin page Reports Tab
148
+	 *
149
+	 * @access        public
150
+	 *
151
+	 * @param string $period
152
+	 *
153
+	 * @return \stdClass[]
154
+	 */
155
+	public function get_revenue_per_day_report($period = '-1 month')
156
+	{
157
+		$sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)),
158
+			'Y-m-d H:i:s', 'UTC');
159
+
160
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp');
161
+
162
+		return $this->_get_all_wpdb_results(
163
+			array(
164
+				array(
165
+					'TXN_timestamp' => array('>=', $sql_date)
166
+				),
167
+				'group_by' => 'txnDate',
168
+				'order_by' => array('TXN_timestamp' => 'ASC')
169
+			),
170
+			OBJECT,
171
+			array(
172
+				'txnDate' => array('DATE(' . $query_interval . ')', '%s'),
173
+				'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d')
174
+			)
175
+		);
176
+	}
177
+
178
+
179
+	/**
180
+	 *        get the revenue per event  for the Transaction Admin page Reports Tab
181
+	 *
182
+	 * @access        public
183
+	 *
184
+	 * @param string $period
185
+	 *
186
+	 * @throws \EE_Error
187
+	 * @return mixed
188
+	 */
189
+	public function get_revenue_per_event_report($period = '-1 month')
190
+	{
191
+		global $wpdb;
192
+		$transaction_table          = $wpdb->prefix . 'esp_transaction';
193
+		$registration_table         = $wpdb->prefix . 'esp_registration';
194
+		$registration_payment_table = $wpdb->prefix . 'esp_registration_payment';
195
+		$event_table                = $wpdb->posts;
196
+		$payment_table              = $wpdb->prefix . 'esp_payment';
197
+		$sql_date                   = date('Y-m-d H:i:s', strtotime($period));
198
+		$approved_payment_status    = EEM_Payment::status_id_approved;
199
+		$extra_event_on_join        = '';
200
+		//exclude events not authored by user if permissions in effect
201
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
202
+			$extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id();
203
+		}
204
+
205
+		return $wpdb->get_results(
206
+			"SELECT
207 207
 			Transaction_Event.event_name AS event_name,
208 208
 			SUM(Transaction_Event.paid) AS revenue
209 209
 			FROM
@@ -230,185 +230,185 @@  discard block
 block discarded – undo
230 230
 					$extra_event_on_join
231 231
 				) AS Transaction_Event
232 232
 			GROUP BY event_name",
233
-            OBJECT
234
-        );
235
-    }
236
-
237
-
238
-    /**
239
-     * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the
240
-     * $_REQUEST global variable. Either way, tries to find the current transaction (through
241
-     * the registration pointed to by reg_url_link), if not returns null
242
-     *
243
-     * @param string $reg_url_link
244
-     *
245
-     * @return EE_Transaction
246
-     */
247
-    public function get_transaction_from_reg_url_link($reg_url_link = '')
248
-    {
249
-        return $this->get_one(array(
250
-            array(
251
-                'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link',
252
-                    '')
253
-            )
254
-        ));
255
-    }
256
-
257
-
258
-    /**
259
-     * Updates the provided EE_Transaction with all the applicable payments
260
-     * (or fetch the EE_Transaction from its ID)
261
-     *
262
-     * @deprecated
263
-     *
264
-     * @param EE_Transaction|int $transaction_obj_or_id
265
-     * @param boolean            $save_txn whether or not to save the transaction during this function call
266
-     *
267
-     * @return boolean
268
-     * @throws \EE_Error
269
-     */
270
-    public function update_based_on_payments($transaction_obj_or_id, $save_txn = true)
271
-    {
272
-        EE_Error::doing_it_wrong(
273
-            __CLASS__ . '::' . __FUNCTION__,
274
-            sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
275
-                'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'),
276
-            '4.6.0'
277
-        );
278
-        /** @type EE_Transaction_Processor $transaction_processor */
279
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
280
-
281
-        return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
282
-            $this->ensure_is_obj($transaction_obj_or_id)
283
-        );
284
-    }
285
-
286
-    /**
287
-     * Deletes "junk" transactions that were probably added by bots. There might be TONS
288
-     * of these, so we are very careful to NOT select (which the models do even when deleting),
289
-     * and so we only use wpdb directly and only do minimal joins.
290
-     * Transactions are considered "junk" if they're failed for longer than a week.
291
-     * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on
292
-     * it, it's probably not junk (regardless of what status it has).
293
-     * The downside to this approach is that is addons are listening for object deletions
294
-     * on EEM_Base::delete() they won't be notified of this.  However, there is an action that plugins can hook into
295
-     * to catch these types of deletions.
296
-     *
297
-     * @global WPDB $wpdb
298
-     * @return mixed
299
-     */
300
-    public function delete_junk_transactions()
301
-    {
302
-        /** @type WPDB $wpdb */
303
-        global $wpdb;
304
-        $deleted             = false;
305
-        $time_to_leave_alone = apply_filters(
306
-            'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone'
307
-            , WEEK_IN_SECONDS
308
-        );
309
-
310
-
311
-        /**
312
-         * This allows code to filter the query arguments used for retrieving the transaction IDs to delete.
313
-         * Useful for plugins that want to exclude transactions matching certain query parameters.
314
-         * The query parameters should be in the format accepted by the EEM_Base model queries.
315
-         */
316
-        $ids_query = apply_filters(
317
-            'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args',
318
-            array(
319
-                0 => array(
320
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
321
-                    'Payment.PAY_ID' => array( 'IS NULL' ),
322
-                    'TXN_timestamp' => array('<', time() - $time_to_leave_alone)
323
-                )
324
-            ),
325
-            $time_to_leave_alone
326
-        );
327
-
328
-
329
-        /**
330
-         * This filter is for when code needs to filter the list of transaction ids that represent transactions
331
-         * about to be deleted based on some other criteria that isn't easily done via the query args filter.
332
-         */
333
-        $txn_ids = apply_filters(
334
-            'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete',
335
-            EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'),
336
-            $time_to_leave_alone
337
-        );
338
-        //now that we have the ids to delete
339
-        if (! empty($txn_ids) && is_array($txn_ids)) {
340
-            // first, make sure these TXN's are removed the "ee_locked_transactions" array
341
-            EEM_Transaction::unset_locked_transactions($txn_ids);
342
-            // let's get deletin'...
343
-            // Why no wpdb->prepare?  Because the data is trusted.
344
-            // We got the ids from the original query to get them FROM
345
-            // the db (which is sanitized) so no need to prepare them again.
346
-            $query   = '
233
+			OBJECT
234
+		);
235
+	}
236
+
237
+
238
+	/**
239
+	 * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the
240
+	 * $_REQUEST global variable. Either way, tries to find the current transaction (through
241
+	 * the registration pointed to by reg_url_link), if not returns null
242
+	 *
243
+	 * @param string $reg_url_link
244
+	 *
245
+	 * @return EE_Transaction
246
+	 */
247
+	public function get_transaction_from_reg_url_link($reg_url_link = '')
248
+	{
249
+		return $this->get_one(array(
250
+			array(
251
+				'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link',
252
+					'')
253
+			)
254
+		));
255
+	}
256
+
257
+
258
+	/**
259
+	 * Updates the provided EE_Transaction with all the applicable payments
260
+	 * (or fetch the EE_Transaction from its ID)
261
+	 *
262
+	 * @deprecated
263
+	 *
264
+	 * @param EE_Transaction|int $transaction_obj_or_id
265
+	 * @param boolean            $save_txn whether or not to save the transaction during this function call
266
+	 *
267
+	 * @return boolean
268
+	 * @throws \EE_Error
269
+	 */
270
+	public function update_based_on_payments($transaction_obj_or_id, $save_txn = true)
271
+	{
272
+		EE_Error::doing_it_wrong(
273
+			__CLASS__ . '::' . __FUNCTION__,
274
+			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
275
+				'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'),
276
+			'4.6.0'
277
+		);
278
+		/** @type EE_Transaction_Processor $transaction_processor */
279
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
280
+
281
+		return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
282
+			$this->ensure_is_obj($transaction_obj_or_id)
283
+		);
284
+	}
285
+
286
+	/**
287
+	 * Deletes "junk" transactions that were probably added by bots. There might be TONS
288
+	 * of these, so we are very careful to NOT select (which the models do even when deleting),
289
+	 * and so we only use wpdb directly and only do minimal joins.
290
+	 * Transactions are considered "junk" if they're failed for longer than a week.
291
+	 * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on
292
+	 * it, it's probably not junk (regardless of what status it has).
293
+	 * The downside to this approach is that is addons are listening for object deletions
294
+	 * on EEM_Base::delete() they won't be notified of this.  However, there is an action that plugins can hook into
295
+	 * to catch these types of deletions.
296
+	 *
297
+	 * @global WPDB $wpdb
298
+	 * @return mixed
299
+	 */
300
+	public function delete_junk_transactions()
301
+	{
302
+		/** @type WPDB $wpdb */
303
+		global $wpdb;
304
+		$deleted             = false;
305
+		$time_to_leave_alone = apply_filters(
306
+			'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone'
307
+			, WEEK_IN_SECONDS
308
+		);
309
+
310
+
311
+		/**
312
+		 * This allows code to filter the query arguments used for retrieving the transaction IDs to delete.
313
+		 * Useful for plugins that want to exclude transactions matching certain query parameters.
314
+		 * The query parameters should be in the format accepted by the EEM_Base model queries.
315
+		 */
316
+		$ids_query = apply_filters(
317
+			'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args',
318
+			array(
319
+				0 => array(
320
+					'STS_ID'        => EEM_Transaction::failed_status_code,
321
+					'Payment.PAY_ID' => array( 'IS NULL' ),
322
+					'TXN_timestamp' => array('<', time() - $time_to_leave_alone)
323
+				)
324
+			),
325
+			$time_to_leave_alone
326
+		);
327
+
328
+
329
+		/**
330
+		 * This filter is for when code needs to filter the list of transaction ids that represent transactions
331
+		 * about to be deleted based on some other criteria that isn't easily done via the query args filter.
332
+		 */
333
+		$txn_ids = apply_filters(
334
+			'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete',
335
+			EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'),
336
+			$time_to_leave_alone
337
+		);
338
+		//now that we have the ids to delete
339
+		if (! empty($txn_ids) && is_array($txn_ids)) {
340
+			// first, make sure these TXN's are removed the "ee_locked_transactions" array
341
+			EEM_Transaction::unset_locked_transactions($txn_ids);
342
+			// let's get deletin'...
343
+			// Why no wpdb->prepare?  Because the data is trusted.
344
+			// We got the ids from the original query to get them FROM
345
+			// the db (which is sanitized) so no need to prepare them again.
346
+			$query   = '
347 347
 				DELETE
348 348
 				FROM ' . $this->table() . '
349 349
 				WHERE
350 350
 					TXN_ID IN ( ' . implode(",", $txn_ids) . ')';
351
-            $deleted = $wpdb->query($query);
352
-        }
353
-        if ($deleted) {
354
-            /**
355
-             * Allows code to do something after the transactions have been deleted.
356
-             */
357
-            do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids);
358
-        }
359
-
360
-        return $deleted;
361
-    }
362
-
363
-
364
-    /**
365
-     * @param array $transaction_IDs
366
-     *
367
-     * @return bool
368
-     */
369
-    public static function unset_locked_transactions(array $transaction_IDs)
370
-    {
371
-        $locked_transactions = get_option('ee_locked_transactions', array());
372
-        $update              = false;
373
-        foreach ($transaction_IDs as $TXN_ID) {
374
-            if (isset($locked_transactions[$TXN_ID])) {
375
-                unset($locked_transactions[$TXN_ID]);
376
-                $update = true;
377
-            }
378
-        }
379
-        if ($update) {
380
-            update_option('ee_locked_transactions', $locked_transactions);
381
-        }
382
-
383
-        return $update;
384
-    }
385
-
386
-
387
-
388
-    /**
389
-     * returns an array of EE_Transaction objects whose timestamp is less than
390
-     * the current time minus the session lifespan, which defaults to 60 minutes
391
-     *
392
-     * @return EE_Base_Class[]|EE_Transaction[]
393
-     * @throws \EE_Error
394
-     */
395
-    public function get_transactions_in_progress()
396
-    {
397
-        return $this->get_all(
398
-            array(
399
-                array(
400
-                    'TXN_timestamp' => array(
401
-                        '>',
402
-                        time() - EE_Registry::instance()->SSN->lifespan()
403
-                    ),
404
-                    'STS_ID' => array(
405
-                        '!=',
406
-                        EEM_Transaction::complete_status_code
407
-                    ),
408
-                )
409
-            )
410
-        );
411
-    }
351
+			$deleted = $wpdb->query($query);
352
+		}
353
+		if ($deleted) {
354
+			/**
355
+			 * Allows code to do something after the transactions have been deleted.
356
+			 */
357
+			do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids);
358
+		}
359
+
360
+		return $deleted;
361
+	}
362
+
363
+
364
+	/**
365
+	 * @param array $transaction_IDs
366
+	 *
367
+	 * @return bool
368
+	 */
369
+	public static function unset_locked_transactions(array $transaction_IDs)
370
+	{
371
+		$locked_transactions = get_option('ee_locked_transactions', array());
372
+		$update              = false;
373
+		foreach ($transaction_IDs as $TXN_ID) {
374
+			if (isset($locked_transactions[$TXN_ID])) {
375
+				unset($locked_transactions[$TXN_ID]);
376
+				$update = true;
377
+			}
378
+		}
379
+		if ($update) {
380
+			update_option('ee_locked_transactions', $locked_transactions);
381
+		}
382
+
383
+		return $update;
384
+	}
385
+
386
+
387
+
388
+	/**
389
+	 * returns an array of EE_Transaction objects whose timestamp is less than
390
+	 * the current time minus the session lifespan, which defaults to 60 minutes
391
+	 *
392
+	 * @return EE_Base_Class[]|EE_Transaction[]
393
+	 * @throws \EE_Error
394
+	 */
395
+	public function get_transactions_in_progress()
396
+	{
397
+		return $this->get_all(
398
+			array(
399
+				array(
400
+					'TXN_timestamp' => array(
401
+						'>',
402
+						time() - EE_Registry::instance()->SSN->lifespan()
403
+					),
404
+					'STS_ID' => array(
405
+						'!=',
406
+						EEM_Transaction::complete_status_code
407
+					),
408
+				)
409
+			)
410
+		);
411
+	}
412 412
 
413 413
 
414 414
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6
-require_once(EE_MODELS . 'EEM_Base.model.php');
6
+require_once(EE_MODELS.'EEM_Base.model.php');
7 7
 
8 8
 /**
9 9
  *
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
                     __('Registration Steps', 'event_espresso'), false, array()),
108 108
             )
109 109
         );
110
-        $this->_model_relations        = array(
110
+        $this->_model_relations = array(
111 111
             'Registration'   => new EE_Has_Many_Relation(),
112 112
             'Payment'        => new EE_Has_Many_Relation(),
113 113
             'Status'         => new EE_Belongs_To_Relation(),
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
             ),
170 170
             OBJECT,
171 171
             array(
172
-                'txnDate' => array('DATE(' . $query_interval . ')', '%s'),
172
+                'txnDate' => array('DATE('.$query_interval.')', '%s'),
173 173
                 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d')
174 174
             )
175 175
         );
@@ -189,17 +189,17 @@  discard block
 block discarded – undo
189 189
     public function get_revenue_per_event_report($period = '-1 month')
190 190
     {
191 191
         global $wpdb;
192
-        $transaction_table          = $wpdb->prefix . 'esp_transaction';
193
-        $registration_table         = $wpdb->prefix . 'esp_registration';
194
-        $registration_payment_table = $wpdb->prefix . 'esp_registration_payment';
192
+        $transaction_table          = $wpdb->prefix.'esp_transaction';
193
+        $registration_table         = $wpdb->prefix.'esp_registration';
194
+        $registration_payment_table = $wpdb->prefix.'esp_registration_payment';
195 195
         $event_table                = $wpdb->posts;
196
-        $payment_table              = $wpdb->prefix . 'esp_payment';
196
+        $payment_table              = $wpdb->prefix.'esp_payment';
197 197
         $sql_date                   = date('Y-m-d H:i:s', strtotime($period));
198 198
         $approved_payment_status    = EEM_Payment::status_id_approved;
199 199
         $extra_event_on_join        = '';
200 200
         //exclude events not authored by user if permissions in effect
201 201
         if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
202
-            $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id();
202
+            $extra_event_on_join = ' AND Event.post_author = '.get_current_user_id();
203 203
         }
204 204
 
205 205
         return $wpdb->get_results(
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
     public function update_based_on_payments($transaction_obj_or_id, $save_txn = true)
271 271
     {
272 272
         EE_Error::doing_it_wrong(
273
-            __CLASS__ . '::' . __FUNCTION__,
273
+            __CLASS__.'::'.__FUNCTION__,
274 274
             sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
275 275
                 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'),
276 276
             '4.6.0'
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
             array(
319 319
                 0 => array(
320 320
                     'STS_ID'        => EEM_Transaction::failed_status_code,
321
-                    'Payment.PAY_ID' => array( 'IS NULL' ),
321
+                    'Payment.PAY_ID' => array('IS NULL'),
322 322
                     'TXN_timestamp' => array('<', time() - $time_to_leave_alone)
323 323
                 )
324 324
             ),
@@ -336,18 +336,18 @@  discard block
 block discarded – undo
336 336
             $time_to_leave_alone
337 337
         );
338 338
         //now that we have the ids to delete
339
-        if (! empty($txn_ids) && is_array($txn_ids)) {
339
+        if ( ! empty($txn_ids) && is_array($txn_ids)) {
340 340
             // first, make sure these TXN's are removed the "ee_locked_transactions" array
341 341
             EEM_Transaction::unset_locked_transactions($txn_ids);
342 342
             // let's get deletin'...
343 343
             // Why no wpdb->prepare?  Because the data is trusted.
344 344
             // We got the ids from the original query to get them FROM
345 345
             // the db (which is sanitized) so no need to prepare them again.
346
-            $query   = '
346
+            $query = '
347 347
 				DELETE
348
-				FROM ' . $this->table() . '
348
+				FROM ' . $this->table().'
349 349
 				WHERE
350
-					TXN_ID IN ( ' . implode(",", $txn_ids) . ')';
350
+					TXN_ID IN ( ' . implode(",", $txn_ids).')';
351 351
             $deleted = $wpdb->query($query);
352 352
         }
353 353
         if ($deleted) {
Please login to merge, or discard this patch.
core/db_models/EEM_Answer.model.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -125,14 +125,14 @@
 block discarded – undo
125 125
 	public function get_attendee_property_answer_value( EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE ){
126 126
 		$field_name = NULL;
127 127
 		$value = NULL;
128
-                //backward compat: we still want to find the question's ID
129
-                if( is_numeric( $question_system_id ) ) {
130
-                    //find this question's QST_system value
131
-                    $question_id = $question_system_id;
132
-                    $question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' );
133
-                } else {
134
-                    $question_id = (int) EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' );
135
-                }
128
+				//backward compat: we still want to find the question's ID
129
+				if( is_numeric( $question_system_id ) ) {
130
+					//find this question's QST_system value
131
+					$question_id = $question_system_id;
132
+					$question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' );
133
+				} else {
134
+					$question_id = (int) EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' );
135
+				}
136 136
 		//only bother checking if the registration has an attendee
137 137
 		if( $registration->attendee() instanceof EE_Attendee ) {
138 138
 			$field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question( $question_system_id );
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -51,18 +51,18 @@  discard block
 block discarded – undo
51 51
 	/**
52 52
 	 * 	constructor
53 53
 	 */
54
-	protected function __construct( $timezone = NULL ){
55
-		$this->singular_item = __('Answer','event_espresso');
56
-		$this->plural_item = __('Answers','event_espresso');
54
+	protected function __construct($timezone = NULL) {
55
+		$this->singular_item = __('Answer', 'event_espresso');
56
+		$this->plural_item = __('Answers', 'event_espresso');
57 57
 		$this->_tables = array(
58 58
 			'Answer'=> new EE_Primary_Table('esp_answer', 'ANS_ID')
59 59
 		);
60 60
 		$this->_fields = array(
61 61
 			'Answer'=>array(
62
-				'ANS_ID'=> new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID','event_espresso')),
63
-				'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID','event_espresso'), false, 0, 'Registration'),
64
-				'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID','event_espresso'), false, 0, 'Question'),
65
-				'ANS_value'=>new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value','event_espresso'), false, '')
62
+				'ANS_ID'=> new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID', 'event_espresso')),
63
+				'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'),
64
+				'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso'), false, 0, 'Question'),
65
+				'ANS_value'=>new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value', 'event_espresso'), false, '')
66 66
 			));
67 67
 		$this->_model_relations = array(
68 68
 			'Registration'=>new EE_Belongs_To_Relation(),
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 		);
71 71
 		$this->_model_chain_to_wp_user = 'Registration.Event';
72 72
 		$this->_caps_slug = 'registrations';
73
-		parent::__construct( $timezone );
73
+		parent::__construct($timezone);
74 74
 	}
75 75
 
76 76
 
@@ -83,19 +83,19 @@  discard block
 block discarded – undo
83 83
 	 * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value'
84 84
 	 * @return string
85 85
 	 */
86
-	public function get_answer_value_to_question( EE_Registration $registration, $question_id = NULL,$pretty_answer = FALSE ){
87
-		$value = $this->get_attendee_property_answer_value( $registration, $question_id, $pretty_answer );
88
-		if (  $value === NULL ){
89
-			$answer_obj = $this->get_registration_question_answer_object( $registration, $question_id);
90
-			if( $answer_obj instanceof EE_Answer ){
91
-				if($pretty_answer){
86
+	public function get_answer_value_to_question(EE_Registration $registration, $question_id = NULL, $pretty_answer = FALSE) {
87
+		$value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer);
88
+		if ($value === NULL) {
89
+			$answer_obj = $this->get_registration_question_answer_object($registration, $question_id);
90
+			if ($answer_obj instanceof EE_Answer) {
91
+				if ($pretty_answer) {
92 92
 					$value = $answer_obj->pretty_value();
93
-				}else{
93
+				} else {
94 94
 					$value = $answer_obj->value();
95 95
 				}
96 96
 			}
97 97
 		}
98
-		return apply_filters( 'FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id );
98
+		return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id);
99 99
 	}
100 100
 
101 101
 
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
 	 * @param int $question_id
107 107
 	 * @return EE_Answer
108 108
 	 */
109
-	public function get_registration_question_answer_object( EE_Registration $registration, $question_id = NULL){
110
-		$answer_obj = $this->get_one( array( array( 'QST_ID'=>$question_id, 'REG_ID'=>$registration->ID() )));
111
-		return apply_filters( 'FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id );
109
+	public function get_registration_question_answer_object(EE_Registration $registration, $question_id = NULL) {
110
+		$answer_obj = $this->get_one(array(array('QST_ID'=>$question_id, 'REG_ID'=>$registration->ID())));
111
+		return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id);
112 112
 	}
113 113
 
114 114
 
@@ -122,39 +122,39 @@  discard block
 block discarded – undo
122 122
 	 * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or QST_system for
123 123
 	 * a question corresponding to an attendee field, returns null)
124 124
 	 */
125
-	public function get_attendee_property_answer_value( EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE ){
125
+	public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE) {
126 126
 		$field_name = NULL;
127 127
 		$value = NULL;
128 128
                 //backward compat: we still want to find the question's ID
129
-                if( is_numeric( $question_system_id ) ) {
129
+                if (is_numeric($question_system_id)) {
130 130
                     //find this question's QST_system value
131 131
                     $question_id = $question_system_id;
132
-                    $question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' );
132
+                    $question_system_id = EEM_Question::instance()->get_var(array(array('QST_ID' => $question_system_id)), 'QST_system');
133 133
                 } else {
134
-                    $question_id = (int) EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' );
134
+                    $question_id = (int) EEM_Question::instance()->get_var(array(array('QST_system' => $question_system_id)), 'QST_ID');
135 135
                 }
136 136
 		//only bother checking if the registration has an attendee
137
-		if( $registration->attendee() instanceof EE_Attendee ) {
138
-			$field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question( $question_system_id );
139
-			if( $field_name ) {
140
-				if( $pretty_answer ) {
141
-					if( $field_name === 'STA_ID' ) {
137
+		if ($registration->attendee() instanceof EE_Attendee) {
138
+			$field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id);
139
+			if ($field_name) {
140
+				if ($pretty_answer) {
141
+					if ($field_name === 'STA_ID') {
142 142
 						$state = $registration->attendee()->state_obj();
143
-						$value = $state instanceof EE_State ? $state->name() : sprintf( __('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID() );
144
-					} else if($field_name === 'CNT_ISO') {
143
+						$value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID());
144
+					} else if ($field_name === 'CNT_ISO') {
145 145
 						$country = $registration->attendee()->country_obj();
146
-						$value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"),$registration->attendee()->country_ID());
146
+						$value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID());
147 147
 					} else {
148
-						$value = $registration->attendee()->get_pretty( $field_name );
148
+						$value = $registration->attendee()->get_pretty($field_name);
149 149
 					}
150 150
 					//if field name is blank, leave the value as null too
151
-				}else{
152
-					$value = $registration->attendee()->get( $field_name );
151
+				} else {
152
+					$value = $registration->attendee()->get($field_name);
153 153
 				}
154 154
 			}
155 155
 			//if no field was found, leave value blank
156 156
 		}
157
-		return apply_filters( 'FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id );
157
+		return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id);
158 158
 	}
159 159
 
160 160
 
Please login to merge, or discard this patch.
core/services/collections/CollectionInterface.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -113,12 +113,12 @@  discard block
 block discarded – undo
113 113
 	public function previous();
114 114
 
115 115
 		/**
116
-	 * Returns the index of a given object, or false if not found
117
-	 *
118
-	 * @see http://stackoverflow.com/a/8736013
119
-	 * @param $object
120
-	 * @return boolean|int|string
121
-	 */
116
+		 * Returns the index of a given object, or false if not found
117
+		 *
118
+		 * @see http://stackoverflow.com/a/8736013
119
+		 * @param $object
120
+		 * @return boolean|int|string
121
+		 */
122 122
 	public function indexOf( $object );
123 123
 
124 124
 
@@ -160,17 +160,17 @@  discard block
 block discarded – undo
160 160
 
161 161
 
162 162
 
163
-    /**
164
-     * detaches ALL objects from the Collection
165
-     */
166
-    public function detachAll();
163
+	/**
164
+	 * detaches ALL objects from the Collection
165
+	 */
166
+	public function detachAll();
167 167
 
168 168
 
169 169
 
170
-    /**
171
-     * unsets and detaches ALL objects from the Collection
172
-     */
173
-    public function trashAndDetachAll();
170
+	/**
171
+	 * unsets and detaches ALL objects from the Collection
172
+	 */
173
+	public function trashAndDetachAll();
174 174
 
175 175
 }
176 176
 // End of file CollectionInterface.php
Please login to merge, or discard this patch.
core/services/collections/Collection.php 1 patch
Indentation   +28 added lines, -29 removed lines patch added patch discarded remove patch
@@ -83,7 +83,6 @@  discard block
 block discarded – undo
83 83
 
84 84
 	 /**
85 85
 	  * setIdentifier
86
-
87 86
 	  * Sets the data associated with an object in the Collection
88 87
 	  * if no $identifier is supplied, then the spl_object_hash() is used
89 88
 	  *
@@ -352,34 +351,34 @@  discard block
 block discarded – undo
352 351
 
353 352
 
354 353
 
355
-     /**
356
-      * detaches ALL objects from the Collection
357
-      */
358
-     public function detachAll()
359
-     {
360
-         $this->rewind();
361
-         while ($this->valid()) {
362
-             $object = $this->current();
363
-             $this->next();
364
-             $this->detach($object);
365
-         }
366
-     }
367
-
368
-
369
-
370
-     /**
371
-      * unsets and detaches ALL objects from the Collection
372
-      */
373
-     public function trashAndDetachAll()
374
-     {
375
-         $this->rewind();
376
-         while ($this->valid()) {
377
-             $object = $this->current();
378
-             $this->next();
379
-             $this->detach($object);
380
-             unset($object);
381
-         }
382
-     }
354
+	 /**
355
+	  * detaches ALL objects from the Collection
356
+	  */
357
+	 public function detachAll()
358
+	 {
359
+		 $this->rewind();
360
+		 while ($this->valid()) {
361
+			 $object = $this->current();
362
+			 $this->next();
363
+			 $this->detach($object);
364
+		 }
365
+	 }
366
+
367
+
368
+
369
+	 /**
370
+	  * unsets and detaches ALL objects from the Collection
371
+	  */
372
+	 public function trashAndDetachAll()
373
+	 {
374
+		 $this->rewind();
375
+		 while ($this->valid()) {
376
+			 $object = $this->current();
377
+			 $this->next();
378
+			 $this->detach($object);
379
+			 unset($object);
380
+		 }
381
+	 }
383 382
 
384 383
 
385 384
 
Please login to merge, or discard this patch.
core/services/loaders/LoaderFactory.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -79,37 +79,37 @@
 block discarded – undo
79 79
 class LoaderFactory
80 80
 {
81 81
 
82
-    /**
83
-     * @var LoaderInterface $loader ;
84
-     */
85
-    private static $loader;
82
+	/**
83
+	 * @var LoaderInterface $loader ;
84
+	 */
85
+	private static $loader;
86 86
 
87 87
 
88 88
 
89
-    /**
90
-     * @param mixed $generator      provided during  very first instantiation in
91
-     *                              EE_Load_Espresso_Core::handle_request()
92
-     *                              otherwise can be left null
93
-     * @return LoaderInterface
94
-     * @throws InvalidArgumentException
95
-     * @throws InvalidInterfaceException
96
-     * @throws InvalidDataTypeException
97
-     */
98
-    public static function getLoader($generator = null)
99
-    {
100
-        if (! LoaderFactory::$loader instanceof LoaderInterface) {
101
-            $generator = $generator !== null ? $generator : EE_Registry::instance();
102
-            $core_loader = new CoreLoader($generator);
103
-            LoaderFactory::$loader = new Loader(
104
-                $core_loader,
105
-                new CachingLoader(
106
-                    $core_loader,
107
-                    new LooseCollection('')
108
-                )
109
-            );
110
-        }
111
-        return LoaderFactory::$loader;
112
-    }
89
+	/**
90
+	 * @param mixed $generator      provided during  very first instantiation in
91
+	 *                              EE_Load_Espresso_Core::handle_request()
92
+	 *                              otherwise can be left null
93
+	 * @return LoaderInterface
94
+	 * @throws InvalidArgumentException
95
+	 * @throws InvalidInterfaceException
96
+	 * @throws InvalidDataTypeException
97
+	 */
98
+	public static function getLoader($generator = null)
99
+	{
100
+		if (! LoaderFactory::$loader instanceof LoaderInterface) {
101
+			$generator = $generator !== null ? $generator : EE_Registry::instance();
102
+			$core_loader = new CoreLoader($generator);
103
+			LoaderFactory::$loader = new Loader(
104
+				$core_loader,
105
+				new CachingLoader(
106
+					$core_loader,
107
+					new LooseCollection('')
108
+				)
109
+			);
110
+		}
111
+		return LoaderFactory::$loader;
112
+	}
113 113
 
114 114
 
115 115
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@
 block discarded – undo
97 97
      */
98 98
     public static function getLoader($generator = null)
99 99
     {
100
-        if (! LoaderFactory::$loader instanceof LoaderInterface) {
100
+        if ( ! LoaderFactory::$loader instanceof LoaderInterface) {
101 101
             $generator = $generator !== null ? $generator : EE_Registry::instance();
102 102
             $core_loader = new CoreLoader($generator);
103 103
             LoaderFactory::$loader = new Loader(
Please login to merge, or discard this patch.
core/db_models/fields/EE_Datetime_Field.php 1 patch
Indentation   +755 added lines, -755 removed lines patch added patch discarded remove patch
@@ -15,760 +15,760 @@
 block discarded – undo
15 15
 class EE_Datetime_Field extends EE_Model_Field_Base
16 16
 {
17 17
 
18
-    /**
19
-     * The pattern we're looking for is if only the characters 0-9 are found and there are only
20
-     * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
21
-     *
22
-     * @type string unix_timestamp_regex
23
-     */
24
-    const unix_timestamp_regex = '/[0-9]{10,}/';
25
-
26
-    /**
27
-     * @type string mysql_timestamp_format
28
-     */
29
-    const mysql_timestamp_format = 'Y-m-d H:i:s';
30
-
31
-    /**
32
-     * @type string mysql_date_format
33
-     */
34
-    const mysql_date_format = 'Y-m-d';
35
-
36
-    /**
37
-     * @type string mysql_time_format
38
-     */
39
-    const mysql_time_format = 'H:i:s';
40
-
41
-    /**
42
-     * Const for using in the default value. If the field's default is set to this,
43
-     * then we will return the time of calling `get_default_value()`, not
44
-     * just the current time at construction
45
-     */
46
-    const now = 'now';
47
-
48
-    /**
49
-     * The following properties hold the default formats for date and time.
50
-     * Defaults are set via the constructor and can be overridden on class instantiation.
51
-     * However they can also be overridden later by the set_format() method
52
-     * (and corresponding set_date_format, set_time_format methods);
53
-     */
54
-    /**
55
-     * @type string $_date_format
56
-     */
57
-    protected $_date_format = '';
58
-
59
-    /**
60
-     * @type string $_time_format
61
-     */
62
-    protected $_time_format = '';
63
-
64
-    /**
65
-     * @type string $_pretty_date_format
66
-     */
67
-    protected $_pretty_date_format = '';
68
-
69
-    /**
70
-     * @type string $_pretty_time_format
71
-     */
72
-    protected $_pretty_time_format = '';
73
-
74
-    /**
75
-     * @type DateTimeZone $_DateTimeZone
76
-     */
77
-    protected $_DateTimeZone;
78
-
79
-    /**
80
-     * @type DateTimeZone $_UTC_DateTimeZone
81
-     */
82
-    protected $_UTC_DateTimeZone;
83
-
84
-    /**
85
-     * @type DateTimeZone $_blog_DateTimeZone
86
-     */
87
-    protected $_blog_DateTimeZone;
88
-
89
-
90
-    /**
91
-     * This property holds how we want the output returned when getting a datetime string.  It is set for the
92
-     * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
93
-     * and time returned via getters.
94
-     *
95
-     * @var mixed (null|string)
96
-     */
97
-    protected $_date_time_output;
98
-
99
-
100
-    /**
101
-     * timezone string
102
-     * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
103
-     * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
104
-     * coming out of the object to be in.  Default timezone is the current WP timezone option setting
105
-     *
106
-     * @var string
107
-     */
108
-    protected $_timezone_string;
109
-
110
-
111
-    /**
112
-     * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
113
-     * offsets for comparison purposes).
114
-     *
115
-     * @var int
116
-     */
117
-    protected $_blog_offset;
118
-
119
-
120
-
121
-    /**
122
-     * @param string $table_column
123
-     * @param string $nice_name
124
-     * @param bool   $nullable
125
-     * @param string $default_value
126
-     * @param string $timezone_string
127
-     * @param string $date_format
128
-     * @param string $time_format
129
-     * @param string $pretty_date_format
130
-     * @param string $pretty_time_format
131
-     * @throws EE_Error
132
-     * @throws InvalidArgumentException
133
-     */
134
-    public function __construct(
135
-        $table_column,
136
-        $nice_name,
137
-        $nullable,
138
-        $default_value,
139
-        $timezone_string = '',
140
-        $date_format = '',
141
-        $time_format = '',
142
-        $pretty_date_format = '',
143
-        $pretty_time_format = ''
144
-    ) {
145
-
146
-        $this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
147
-        $this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
148
-        $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
149
-        $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
150
-
151
-        parent::__construct($table_column, $nice_name, $nullable, $default_value);
152
-        $this->set_timezone($timezone_string);
153
-        $this->setSchemaFormat('date-time');
154
-    }
155
-
156
-
157
-    /**
158
-     * @return DateTimeZone
159
-     * @throws \EE_Error
160
-     */
161
-    public function get_UTC_DateTimeZone()
162
-    {
163
-        return $this->_UTC_DateTimeZone instanceof DateTimeZone
164
-            ? $this->_UTC_DateTimeZone
165
-            : $this->_create_timezone_object_from_timezone_string('UTC');
166
-    }
167
-
168
-
169
-    /**
170
-     * @return DateTimeZone
171
-     * @throws \EE_Error
172
-     */
173
-    public function get_blog_DateTimeZone()
174
-    {
175
-        return $this->_blog_DateTimeZone instanceof DateTimeZone
176
-            ? $this->_blog_DateTimeZone
177
-            : $this->_create_timezone_object_from_timezone_string('');
178
-    }
179
-
180
-
181
-    /**
182
-     * this prepares any incoming date data and make sure its converted to a utc unix timestamp
183
-     *
184
-     * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
185
-     *                                                              timestamp
186
-     * @return DateTime
187
-     */
188
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
189
-    {
190
-        return $this->_get_date_object($value_inputted_for_field_on_model_object);
191
-    }
192
-
193
-
194
-    /**
195
-     * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
196
-     * getters need to know whether we're just returning the date or the time or both.  By default we return both.
197
-     *
198
-     * @param bool $pretty If we're returning the pretty formats or standard format string.
199
-     * @return string    The final assembled format string.
200
-     */
201
-    protected function _get_date_time_output($pretty = false)
202
-    {
203
-
204
-        switch ($this->_date_time_output) {
205
-            case 'time' :
206
-                return $pretty ? $this->_pretty_time_format : $this->_time_format;
207
-                break;
208
-
209
-            case 'date' :
210
-                return $pretty ? $this->_pretty_date_format : $this->_date_format;
211
-                break;
212
-
213
-            default :
214
-                return $pretty
215
-                    ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
216
-                    : $this->_date_format . ' ' . $this->_time_format;
217
-        }
218
-    }
219
-
220
-
221
-    /**
222
-     * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
223
-     * returned (using the format properties)
224
-     *
225
-     * @param string $what acceptable values are 'time' or 'date'.
226
-     *                     Any other value will be set but will always result
227
-     *                     in both 'date' and 'time' being returned.
228
-     * @return void
229
-     */
230
-    public function set_date_time_output($what = null)
231
-    {
232
-        $this->_date_time_output = $what;
233
-    }
234
-
235
-
236
-    /**
237
-     * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
238
-     * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
239
-     * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
240
-     * We also set some other properties in this method.
241
-     *
242
-     * @param string $timezone_string A valid timezone string as described by @link
243
-     *                                http://www.php.net/manual/en/timezones.php
244
-     * @return void
245
-     * @throws \EE_Error
246
-     */
247
-    public function set_timezone($timezone_string)
248
-    {
249
-        if (empty($timezone_string) && $this->_timezone_string !== null) {
250
-            // leave the timezone AS-IS if we already have one and
251
-            // the function arg didn't provide one
252
-            return;
253
-        }
254
-        $timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
255
-        $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
256
-        $this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
257
-    }
258
-
259
-
260
-    /**
261
-     * _create_timezone_object_from_timezone_name
262
-     *
263
-     * @access protected
264
-     * @param string $timezone_string
265
-     * @return \DateTimeZone
266
-     * @throws \EE_Error
267
-     */
268
-    protected function _create_timezone_object_from_timezone_string($timezone_string = '')
269
-    {
270
-        return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
271
-    }
272
-
273
-
274
-    /**
275
-     * This just returns whatever is set for the current timezone.
276
-     *
277
-     * @access public
278
-     * @return string timezone string
279
-     */
280
-    public function get_timezone()
281
-    {
282
-        return $this->_timezone_string;
283
-    }
284
-
285
-
286
-    /**
287
-     * set the $_date_format property
288
-     *
289
-     * @access public
290
-     * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
291
-     * @param bool   $pretty Whether to set pretty format or not.
292
-     * @return void
293
-     */
294
-    public function set_date_format($format, $pretty = false)
295
-    {
296
-        if ($pretty) {
297
-            $this->_pretty_date_format = $format;
298
-        } else {
299
-            $this->_date_format = $format;
300
-        }
301
-    }
302
-
303
-
304
-    /**
305
-     * return the $_date_format property value.
306
-     *
307
-     * @param bool $pretty Whether to get pretty format or not.
308
-     * @return string
309
-     */
310
-    public function get_date_format($pretty = false)
311
-    {
312
-        return $pretty ? $this->_pretty_date_format : $this->_date_format;
313
-    }
314
-
315
-
316
-    /**
317
-     * set the $_time_format property
318
-     *
319
-     * @access public
320
-     * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
321
-     * @param bool   $pretty Whether to set pretty format or not.
322
-     * @return void
323
-     */
324
-    public function set_time_format($format, $pretty = false)
325
-    {
326
-        if ($pretty) {
327
-            $this->_pretty_time_format = $format;
328
-        } else {
329
-            $this->_time_format = $format;
330
-        }
331
-    }
332
-
333
-
334
-    /**
335
-     * return the $_time_format property value.
336
-     *
337
-     * @param bool $pretty Whether to get pretty format or not.
338
-     * @return string
339
-     */
340
-    public function get_time_format($pretty = false)
341
-    {
342
-        return $pretty ? $this->_pretty_time_format : $this->_time_format;
343
-    }
344
-
345
-
346
-    /**
347
-     * set the $_pretty_date_format property
348
-     *
349
-     * @access public
350
-     * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
351
-     * @return void
352
-     */
353
-    public function set_pretty_date_format($format)
354
-    {
355
-        $this->_pretty_date_format = $format;
356
-    }
357
-
358
-
359
-    /**
360
-     * set the $_pretty_time_format property
361
-     *
362
-     * @access public
363
-     * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
364
-     * @return void
365
-     */
366
-    public function set_pretty_time_format($format)
367
-    {
368
-        $this->_pretty_time_format = $format;
369
-    }
370
-
371
-
372
-    /**
373
-     * Only sets the time portion of the datetime.
374
-     *
375
-     * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
376
-     * @param DateTime        $current            current DateTime object for the datetime field
377
-     * @return DateTime
378
-     */
379
-    public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
380
-    {
381
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
382
-        // Otherwise parse the string.
383
-        if ($time_to_set_string instanceof DateTime) {
384
-            $parsed = array(
385
-                'hour'   => $time_to_set_string->format('H'),
386
-                'minute' => $time_to_set_string->format('i'),
387
-                'second' => $time_to_set_string->format('s'),
388
-            );
389
-        } else {
390
-            //parse incoming string
391
-            $parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
392
-        }
393
-
394
-        //make sure $current is in the correct timezone.
395
-        $current->setTimezone($this->_DateTimeZone);
396
-
397
-        return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
398
-    }
399
-
400
-
401
-    /**
402
-     * Only sets the date portion of the datetime.
403
-     *
404
-     * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
405
-     * @param DateTime        $current            current DateTime object for the datetime field
406
-     * @return DateTime
407
-     */
408
-    public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
409
-    {
410
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
411
-        // Otherwise parse the string.
412
-        if ($date_to_set_string instanceof DateTime) {
413
-            $parsed = array(
414
-                'year'  => $date_to_set_string->format('Y'),
415
-                'month' => $date_to_set_string->format('m'),
416
-                'day'   => $date_to_set_string->format('d'),
417
-            );
418
-        } else {
419
-            //parse incoming string
420
-            $parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
421
-        }
422
-
423
-        //make sure $current is in the correct timezone
424
-        $current->setTimezone($this->_DateTimeZone);
425
-
426
-        return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
427
-    }
428
-
429
-
430
-    /**
431
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
432
-     * datetime gets to this stage it should ALREADY be in UTC time
433
-     *
434
-     * @param  DateTime $DateTime
435
-     * @return string formatted date time for given timezone
436
-     * @throws \EE_Error
437
-     */
438
-    public function prepare_for_get($DateTime)
439
-    {
440
-        return $this->_prepare_for_display($DateTime);
441
-    }
442
-
443
-
444
-    /**
445
-     * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
446
-     * from the set wp timezone.  If so, then it returns the datetime string formatted via
447
-     * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
448
-     * abbreviation to the date_string.
449
-     *
450
-     * @param mixed $DateTime
451
-     * @param null  $schema
452
-     * @return string
453
-     * @throws \EE_Error
454
-     */
455
-    public function prepare_for_pretty_echoing($DateTime, $schema = null)
456
-    {
457
-        return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
458
-    }
459
-
460
-
461
-    /**
462
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
463
-     * timezone).
464
-     *
465
-     * @param DateTime    $DateTime
466
-     * @param bool|string $schema
467
-     * @return string
468
-     * @throws \EE_Error
469
-     */
470
-    protected function _prepare_for_display($DateTime, $schema = false)
471
-    {
472
-        if (! $DateTime instanceof DateTime) {
473
-            if ($this->_nullable) {
474
-                return '';
475
-            } else {
476
-                if (WP_DEBUG) {
477
-                    throw new EE_Error(
478
-                        sprintf(
479
-                            __(
480
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
481
-                                'event_espresso'
482
-                            ),
483
-                            $this->_nicename
484
-                        )
485
-                    );
486
-                } else {
487
-                    $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
488
-                    EE_Error::add_error(
489
-                        sprintf(
490
-                            __(
491
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
492
-                                'event_espresso'
493
-                            ),
494
-                            $this->_nicename
495
-                        )
496
-                    );
497
-                }
498
-            }
499
-        }
500
-        $format_string = $this->_get_date_time_output($schema);
501
-        //make sure datetime_value is in the correct timezone (in case that's been updated).
502
-        $DateTime->setTimezone($this->_DateTimeZone);
503
-        if ($schema) {
504
-            if ($this->_display_timezone()) {
505
-                //must be explicit because schema could equal true.
506
-                if ($schema === 'no_html') {
507
-                    $timezone_string = ' (' . $DateTime->format('T') . ')';
508
-                } else {
509
-                    $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
510
-                }
511
-            } else {
512
-                $timezone_string = '';
513
-            }
514
-
515
-            return $DateTime->format($format_string) . $timezone_string;
516
-        } else {
517
-            return $DateTime->format($format_string);
518
-        }
519
-    }
520
-
521
-
522
-    /**
523
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
524
-     * timezone).
525
-     *
526
-     * @param  mixed $datetime_value u
527
-     * @return string mysql timestamp in UTC
528
-     * @throws \EE_Error
529
-     */
530
-    public function prepare_for_use_in_db($datetime_value)
531
-    {
532
-        //we allow an empty value or DateTime object, but nothing else.
533
-        if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
534
-            throw new EE_Error(
535
-            	sprintf(
536
-            	    __(
537
-            		    'The incoming value being prepared for setting in the database must either be empty or a php 
18
+	/**
19
+	 * The pattern we're looking for is if only the characters 0-9 are found and there are only
20
+	 * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
21
+	 *
22
+	 * @type string unix_timestamp_regex
23
+	 */
24
+	const unix_timestamp_regex = '/[0-9]{10,}/';
25
+
26
+	/**
27
+	 * @type string mysql_timestamp_format
28
+	 */
29
+	const mysql_timestamp_format = 'Y-m-d H:i:s';
30
+
31
+	/**
32
+	 * @type string mysql_date_format
33
+	 */
34
+	const mysql_date_format = 'Y-m-d';
35
+
36
+	/**
37
+	 * @type string mysql_time_format
38
+	 */
39
+	const mysql_time_format = 'H:i:s';
40
+
41
+	/**
42
+	 * Const for using in the default value. If the field's default is set to this,
43
+	 * then we will return the time of calling `get_default_value()`, not
44
+	 * just the current time at construction
45
+	 */
46
+	const now = 'now';
47
+
48
+	/**
49
+	 * The following properties hold the default formats for date and time.
50
+	 * Defaults are set via the constructor and can be overridden on class instantiation.
51
+	 * However they can also be overridden later by the set_format() method
52
+	 * (and corresponding set_date_format, set_time_format methods);
53
+	 */
54
+	/**
55
+	 * @type string $_date_format
56
+	 */
57
+	protected $_date_format = '';
58
+
59
+	/**
60
+	 * @type string $_time_format
61
+	 */
62
+	protected $_time_format = '';
63
+
64
+	/**
65
+	 * @type string $_pretty_date_format
66
+	 */
67
+	protected $_pretty_date_format = '';
68
+
69
+	/**
70
+	 * @type string $_pretty_time_format
71
+	 */
72
+	protected $_pretty_time_format = '';
73
+
74
+	/**
75
+	 * @type DateTimeZone $_DateTimeZone
76
+	 */
77
+	protected $_DateTimeZone;
78
+
79
+	/**
80
+	 * @type DateTimeZone $_UTC_DateTimeZone
81
+	 */
82
+	protected $_UTC_DateTimeZone;
83
+
84
+	/**
85
+	 * @type DateTimeZone $_blog_DateTimeZone
86
+	 */
87
+	protected $_blog_DateTimeZone;
88
+
89
+
90
+	/**
91
+	 * This property holds how we want the output returned when getting a datetime string.  It is set for the
92
+	 * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
93
+	 * and time returned via getters.
94
+	 *
95
+	 * @var mixed (null|string)
96
+	 */
97
+	protected $_date_time_output;
98
+
99
+
100
+	/**
101
+	 * timezone string
102
+	 * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
103
+	 * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
104
+	 * coming out of the object to be in.  Default timezone is the current WP timezone option setting
105
+	 *
106
+	 * @var string
107
+	 */
108
+	protected $_timezone_string;
109
+
110
+
111
+	/**
112
+	 * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
113
+	 * offsets for comparison purposes).
114
+	 *
115
+	 * @var int
116
+	 */
117
+	protected $_blog_offset;
118
+
119
+
120
+
121
+	/**
122
+	 * @param string $table_column
123
+	 * @param string $nice_name
124
+	 * @param bool   $nullable
125
+	 * @param string $default_value
126
+	 * @param string $timezone_string
127
+	 * @param string $date_format
128
+	 * @param string $time_format
129
+	 * @param string $pretty_date_format
130
+	 * @param string $pretty_time_format
131
+	 * @throws EE_Error
132
+	 * @throws InvalidArgumentException
133
+	 */
134
+	public function __construct(
135
+		$table_column,
136
+		$nice_name,
137
+		$nullable,
138
+		$default_value,
139
+		$timezone_string = '',
140
+		$date_format = '',
141
+		$time_format = '',
142
+		$pretty_date_format = '',
143
+		$pretty_time_format = ''
144
+	) {
145
+
146
+		$this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
147
+		$this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
148
+		$this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
149
+		$this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
150
+
151
+		parent::__construct($table_column, $nice_name, $nullable, $default_value);
152
+		$this->set_timezone($timezone_string);
153
+		$this->setSchemaFormat('date-time');
154
+	}
155
+
156
+
157
+	/**
158
+	 * @return DateTimeZone
159
+	 * @throws \EE_Error
160
+	 */
161
+	public function get_UTC_DateTimeZone()
162
+	{
163
+		return $this->_UTC_DateTimeZone instanceof DateTimeZone
164
+			? $this->_UTC_DateTimeZone
165
+			: $this->_create_timezone_object_from_timezone_string('UTC');
166
+	}
167
+
168
+
169
+	/**
170
+	 * @return DateTimeZone
171
+	 * @throws \EE_Error
172
+	 */
173
+	public function get_blog_DateTimeZone()
174
+	{
175
+		return $this->_blog_DateTimeZone instanceof DateTimeZone
176
+			? $this->_blog_DateTimeZone
177
+			: $this->_create_timezone_object_from_timezone_string('');
178
+	}
179
+
180
+
181
+	/**
182
+	 * this prepares any incoming date data and make sure its converted to a utc unix timestamp
183
+	 *
184
+	 * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
185
+	 *                                                              timestamp
186
+	 * @return DateTime
187
+	 */
188
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
189
+	{
190
+		return $this->_get_date_object($value_inputted_for_field_on_model_object);
191
+	}
192
+
193
+
194
+	/**
195
+	 * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
196
+	 * getters need to know whether we're just returning the date or the time or both.  By default we return both.
197
+	 *
198
+	 * @param bool $pretty If we're returning the pretty formats or standard format string.
199
+	 * @return string    The final assembled format string.
200
+	 */
201
+	protected function _get_date_time_output($pretty = false)
202
+	{
203
+
204
+		switch ($this->_date_time_output) {
205
+			case 'time' :
206
+				return $pretty ? $this->_pretty_time_format : $this->_time_format;
207
+				break;
208
+
209
+			case 'date' :
210
+				return $pretty ? $this->_pretty_date_format : $this->_date_format;
211
+				break;
212
+
213
+			default :
214
+				return $pretty
215
+					? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
216
+					: $this->_date_format . ' ' . $this->_time_format;
217
+		}
218
+	}
219
+
220
+
221
+	/**
222
+	 * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
223
+	 * returned (using the format properties)
224
+	 *
225
+	 * @param string $what acceptable values are 'time' or 'date'.
226
+	 *                     Any other value will be set but will always result
227
+	 *                     in both 'date' and 'time' being returned.
228
+	 * @return void
229
+	 */
230
+	public function set_date_time_output($what = null)
231
+	{
232
+		$this->_date_time_output = $what;
233
+	}
234
+
235
+
236
+	/**
237
+	 * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
238
+	 * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
239
+	 * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
240
+	 * We also set some other properties in this method.
241
+	 *
242
+	 * @param string $timezone_string A valid timezone string as described by @link
243
+	 *                                http://www.php.net/manual/en/timezones.php
244
+	 * @return void
245
+	 * @throws \EE_Error
246
+	 */
247
+	public function set_timezone($timezone_string)
248
+	{
249
+		if (empty($timezone_string) && $this->_timezone_string !== null) {
250
+			// leave the timezone AS-IS if we already have one and
251
+			// the function arg didn't provide one
252
+			return;
253
+		}
254
+		$timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
255
+		$this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
256
+		$this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
257
+	}
258
+
259
+
260
+	/**
261
+	 * _create_timezone_object_from_timezone_name
262
+	 *
263
+	 * @access protected
264
+	 * @param string $timezone_string
265
+	 * @return \DateTimeZone
266
+	 * @throws \EE_Error
267
+	 */
268
+	protected function _create_timezone_object_from_timezone_string($timezone_string = '')
269
+	{
270
+		return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
271
+	}
272
+
273
+
274
+	/**
275
+	 * This just returns whatever is set for the current timezone.
276
+	 *
277
+	 * @access public
278
+	 * @return string timezone string
279
+	 */
280
+	public function get_timezone()
281
+	{
282
+		return $this->_timezone_string;
283
+	}
284
+
285
+
286
+	/**
287
+	 * set the $_date_format property
288
+	 *
289
+	 * @access public
290
+	 * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
291
+	 * @param bool   $pretty Whether to set pretty format or not.
292
+	 * @return void
293
+	 */
294
+	public function set_date_format($format, $pretty = false)
295
+	{
296
+		if ($pretty) {
297
+			$this->_pretty_date_format = $format;
298
+		} else {
299
+			$this->_date_format = $format;
300
+		}
301
+	}
302
+
303
+
304
+	/**
305
+	 * return the $_date_format property value.
306
+	 *
307
+	 * @param bool $pretty Whether to get pretty format or not.
308
+	 * @return string
309
+	 */
310
+	public function get_date_format($pretty = false)
311
+	{
312
+		return $pretty ? $this->_pretty_date_format : $this->_date_format;
313
+	}
314
+
315
+
316
+	/**
317
+	 * set the $_time_format property
318
+	 *
319
+	 * @access public
320
+	 * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
321
+	 * @param bool   $pretty Whether to set pretty format or not.
322
+	 * @return void
323
+	 */
324
+	public function set_time_format($format, $pretty = false)
325
+	{
326
+		if ($pretty) {
327
+			$this->_pretty_time_format = $format;
328
+		} else {
329
+			$this->_time_format = $format;
330
+		}
331
+	}
332
+
333
+
334
+	/**
335
+	 * return the $_time_format property value.
336
+	 *
337
+	 * @param bool $pretty Whether to get pretty format or not.
338
+	 * @return string
339
+	 */
340
+	public function get_time_format($pretty = false)
341
+	{
342
+		return $pretty ? $this->_pretty_time_format : $this->_time_format;
343
+	}
344
+
345
+
346
+	/**
347
+	 * set the $_pretty_date_format property
348
+	 *
349
+	 * @access public
350
+	 * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
351
+	 * @return void
352
+	 */
353
+	public function set_pretty_date_format($format)
354
+	{
355
+		$this->_pretty_date_format = $format;
356
+	}
357
+
358
+
359
+	/**
360
+	 * set the $_pretty_time_format property
361
+	 *
362
+	 * @access public
363
+	 * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
364
+	 * @return void
365
+	 */
366
+	public function set_pretty_time_format($format)
367
+	{
368
+		$this->_pretty_time_format = $format;
369
+	}
370
+
371
+
372
+	/**
373
+	 * Only sets the time portion of the datetime.
374
+	 *
375
+	 * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
376
+	 * @param DateTime        $current            current DateTime object for the datetime field
377
+	 * @return DateTime
378
+	 */
379
+	public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
380
+	{
381
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
382
+		// Otherwise parse the string.
383
+		if ($time_to_set_string instanceof DateTime) {
384
+			$parsed = array(
385
+				'hour'   => $time_to_set_string->format('H'),
386
+				'minute' => $time_to_set_string->format('i'),
387
+				'second' => $time_to_set_string->format('s'),
388
+			);
389
+		} else {
390
+			//parse incoming string
391
+			$parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
392
+		}
393
+
394
+		//make sure $current is in the correct timezone.
395
+		$current->setTimezone($this->_DateTimeZone);
396
+
397
+		return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
398
+	}
399
+
400
+
401
+	/**
402
+	 * Only sets the date portion of the datetime.
403
+	 *
404
+	 * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
405
+	 * @param DateTime        $current            current DateTime object for the datetime field
406
+	 * @return DateTime
407
+	 */
408
+	public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
409
+	{
410
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
411
+		// Otherwise parse the string.
412
+		if ($date_to_set_string instanceof DateTime) {
413
+			$parsed = array(
414
+				'year'  => $date_to_set_string->format('Y'),
415
+				'month' => $date_to_set_string->format('m'),
416
+				'day'   => $date_to_set_string->format('d'),
417
+			);
418
+		} else {
419
+			//parse incoming string
420
+			$parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
421
+		}
422
+
423
+		//make sure $current is in the correct timezone
424
+		$current->setTimezone($this->_DateTimeZone);
425
+
426
+		return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
427
+	}
428
+
429
+
430
+	/**
431
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
432
+	 * datetime gets to this stage it should ALREADY be in UTC time
433
+	 *
434
+	 * @param  DateTime $DateTime
435
+	 * @return string formatted date time for given timezone
436
+	 * @throws \EE_Error
437
+	 */
438
+	public function prepare_for_get($DateTime)
439
+	{
440
+		return $this->_prepare_for_display($DateTime);
441
+	}
442
+
443
+
444
+	/**
445
+	 * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
446
+	 * from the set wp timezone.  If so, then it returns the datetime string formatted via
447
+	 * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
448
+	 * abbreviation to the date_string.
449
+	 *
450
+	 * @param mixed $DateTime
451
+	 * @param null  $schema
452
+	 * @return string
453
+	 * @throws \EE_Error
454
+	 */
455
+	public function prepare_for_pretty_echoing($DateTime, $schema = null)
456
+	{
457
+		return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
458
+	}
459
+
460
+
461
+	/**
462
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
463
+	 * timezone).
464
+	 *
465
+	 * @param DateTime    $DateTime
466
+	 * @param bool|string $schema
467
+	 * @return string
468
+	 * @throws \EE_Error
469
+	 */
470
+	protected function _prepare_for_display($DateTime, $schema = false)
471
+	{
472
+		if (! $DateTime instanceof DateTime) {
473
+			if ($this->_nullable) {
474
+				return '';
475
+			} else {
476
+				if (WP_DEBUG) {
477
+					throw new EE_Error(
478
+						sprintf(
479
+							__(
480
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
481
+								'event_espresso'
482
+							),
483
+							$this->_nicename
484
+						)
485
+					);
486
+				} else {
487
+					$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
488
+					EE_Error::add_error(
489
+						sprintf(
490
+							__(
491
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
492
+								'event_espresso'
493
+							),
494
+							$this->_nicename
495
+						)
496
+					);
497
+				}
498
+			}
499
+		}
500
+		$format_string = $this->_get_date_time_output($schema);
501
+		//make sure datetime_value is in the correct timezone (in case that's been updated).
502
+		$DateTime->setTimezone($this->_DateTimeZone);
503
+		if ($schema) {
504
+			if ($this->_display_timezone()) {
505
+				//must be explicit because schema could equal true.
506
+				if ($schema === 'no_html') {
507
+					$timezone_string = ' (' . $DateTime->format('T') . ')';
508
+				} else {
509
+					$timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
510
+				}
511
+			} else {
512
+				$timezone_string = '';
513
+			}
514
+
515
+			return $DateTime->format($format_string) . $timezone_string;
516
+		} else {
517
+			return $DateTime->format($format_string);
518
+		}
519
+	}
520
+
521
+
522
+	/**
523
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
524
+	 * timezone).
525
+	 *
526
+	 * @param  mixed $datetime_value u
527
+	 * @return string mysql timestamp in UTC
528
+	 * @throws \EE_Error
529
+	 */
530
+	public function prepare_for_use_in_db($datetime_value)
531
+	{
532
+		//we allow an empty value or DateTime object, but nothing else.
533
+		if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
534
+			throw new EE_Error(
535
+				sprintf(
536
+					__(
537
+						'The incoming value being prepared for setting in the database must either be empty or a php 
538 538
             		    DateTime object, instead of: %1$s %2$s',
539
-                        'event_espresso'
540
-	                ),
541
-                    '<br />',
542
-                    print_r($datetime_value, true)
543
-                )
544
-            );
545
-        }
546
-
547
-        if ($datetime_value instanceof DateTime) {
548
-            if ( ! $datetime_value instanceof DbSafeDateTime) {
549
-                $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
550
-            }
551
-
552
-            return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format(
553
-                EE_Datetime_Field::mysql_timestamp_format
554
-            );
555
-        }
556
-
557
-        // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
558
-        return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
559
-    }
560
-
561
-
562
-    /**
563
-     * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
564
-     * allowed)
565
-     *
566
-     * @param string $datetime_string mysql timestamp in UTC
567
-     * @return  mixed null | DateTime
568
-     * @throws \EE_Error
569
-     */
570
-    public function prepare_for_set_from_db($datetime_string)
571
-    {
572
-        //if $datetime_value is empty, and ! $this->_nullable, just use time()
573
-        if (empty($datetime_string) && $this->_nullable) {
574
-            return null;
575
-        }
576
-        // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
577
-        if (empty($datetime_string)) {
578
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
579
-        } else {
580
-            $DateTime = DateTime::createFromFormat(
581
-                EE_Datetime_Field::mysql_timestamp_format,
582
-                $datetime_string,
583
-                $this->get_UTC_DateTimeZone()
584
-            );
585
-            if ($DateTime instanceof \DateTime) {
586
-                $DateTime = new DbSafeDateTime(
587
-                    $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
588
-                    $this->get_UTC_DateTimeZone()
589
-                );
590
-            }
591
-        }
592
-
593
-        if (! $DateTime instanceof DbSafeDateTime) {
594
-            // if still no datetime object, then let's just use now
595
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
596
-        }
597
-        // THEN apply the field's set DateTimeZone
598
-        $DateTime->setTimezone($this->_DateTimeZone);
599
-
600
-        return $DateTime;
601
-    }
602
-
603
-
604
-    /**
605
-     * All this method does is determine if we're going to display the timezone string or not on any output.
606
-     * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
607
-     * If so, then true.
608
-     *
609
-     * @return bool true for yes false for no
610
-     * @throws \EE_Error
611
-     */
612
-    protected function _display_timezone()
613
-    {
614
-
615
-        // first let's do a comparison of timezone strings.
616
-        // If they match then we can get out without any further calculations
617
-        $blog_string = get_option('timezone_string');
618
-        if ($blog_string === $this->_timezone_string) {
619
-            return false;
620
-        }
621
-        // now we need to calc the offset for the timezone string so we can compare with the blog offset.
622
-        $this_offset = $this->get_timezone_offset($this->_DateTimeZone);
623
-        $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
624
-        // now compare
625
-        return $blog_offset !== $this_offset;
626
-    }
627
-
628
-
629
-    /**
630
-     * This method returns a php DateTime object for setting on the EE_Base_Class model.
631
-     * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
632
-     * with.
633
-     *
634
-     * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
635
-     *                                                    in the format that is set on the date_field (or DateTime
636
-     *                                                    object)!
637
-     * @return DateTime
638
-     */
639
-    protected function _get_date_object($date_string)
640
-    {
641
-        //first if this is an empty date_string and nullable is allowed, just return null.
642
-        if ($this->_nullable && empty($date_string)) {
643
-            return null;
644
-        }
645
-
646
-        // if incoming date
647
-        if ($date_string instanceof DateTime) {
648
-            $date_string->setTimezone($this->_DateTimeZone);
649
-
650
-            return $date_string;
651
-        }
652
-        // if empty date_string and made it here.
653
-        // Return a datetime object for now in the given timezone.
654
-        if (empty($date_string)) {
655
-            return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
656
-        }
657
-        // if $date_string is matches something that looks like a Unix timestamp let's just use it.
658
-        if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
659
-            try {
660
-                // This is operating under the assumption that the incoming Unix timestamp
661
-                // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
662
-                $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
663
-                $DateTime->setTimestamp($date_string);
664
-
665
-                return $DateTime;
666
-            } catch (Exception $e) {
667
-                // should be rare, but if things got fooled then let's just continue
668
-            }
669
-        }
670
-        //not a unix timestamp.  So we will use the set format on this object and set timezone to
671
-        //create the DateTime object.
672
-        $format = $this->_date_format . ' ' . $this->_time_format;
673
-        try {
674
-            $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
675
-            if ($DateTime instanceof DateTime) {
676
-                $DateTime = new DbSafeDateTime(
677
-                    $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
678
-                    $this->_DateTimeZone
679
-                );
680
-            }
681
-            if (! $DateTime instanceof DbSafeDateTime) {
682
-                throw new EE_Error(
683
-                    sprintf(
684
-                        __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
685
-                        $date_string,
686
-                        $format
687
-                    )
688
-                );
689
-            }
690
-        } catch (Exception $e) {
691
-            // if we made it here then likely then something went really wrong.
692
-            // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
693
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
694
-        }
695
-
696
-        return $DateTime;
697
-    }
698
-
699
-
700
-
701
-    /**
702
-     * get_timezone_transitions
703
-     *
704
-     * @param \DateTimeZone $DateTimeZone
705
-     * @param int           $time
706
-     * @param bool          $first_only
707
-     * @return mixed
708
-     */
709
-    public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
710
-    {
711
-        $time = is_int($time) || $time === null ? $time : strtotime($time);
712
-        $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
713
-        $transitions = $DateTimeZone->getTransitions($time);
714
-        return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
715
-    }
716
-
717
-
718
-
719
-    /**
720
-     * get_timezone_offset
721
-     *
722
-     * @param \DateTimeZone $DateTimeZone
723
-     * @param int           $time
724
-     * @return mixed
725
-     * @throws \DomainException
726
-     */
727
-    public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
728
-    {
729
-        $transitions = $this->get_timezone_transitions($DateTimeZone, $time);
730
-        if ( ! isset($transitions['offset'])) {
731
-            throw new DomainException();
732
-        }
733
-        return $transitions['offset'];
734
-    }
735
-
736
-
737
-    /**
738
-     * This will take an incoming timezone string and return the abbreviation for that timezone
739
-     *
740
-     * @param  string $timezone_string
741
-     * @return string           abbreviation
742
-     * @throws \EE_Error
743
-     */
744
-    public function get_timezone_abbrev($timezone_string)
745
-    {
746
-        $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
747
-        $dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
748
-
749
-        return $dateTime->format('T');
750
-    }
751
-
752
-    /**
753
-     * Overrides the parent to allow for having a dynamic "now" value
754
-     *
755
-     * @return mixed
756
-     */
757
-    public function get_default_value()
758
-    {
759
-        if ($this->_default_value === EE_Datetime_Field::now) {
760
-            return time();
761
-        } else {
762
-            return parent::get_default_value();
763
-        }
764
-    }
765
-
766
-
767
-    public function getSchemaDescription()
768
-    {
769
-        return sprintf(
770
-            esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
771
-            $this->get_nicename()
772
-        );
773
-    }
539
+						'event_espresso'
540
+					),
541
+					'<br />',
542
+					print_r($datetime_value, true)
543
+				)
544
+			);
545
+		}
546
+
547
+		if ($datetime_value instanceof DateTime) {
548
+			if ( ! $datetime_value instanceof DbSafeDateTime) {
549
+				$datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
550
+			}
551
+
552
+			return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format(
553
+				EE_Datetime_Field::mysql_timestamp_format
554
+			);
555
+		}
556
+
557
+		// if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
558
+		return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
559
+	}
560
+
561
+
562
+	/**
563
+	 * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
564
+	 * allowed)
565
+	 *
566
+	 * @param string $datetime_string mysql timestamp in UTC
567
+	 * @return  mixed null | DateTime
568
+	 * @throws \EE_Error
569
+	 */
570
+	public function prepare_for_set_from_db($datetime_string)
571
+	{
572
+		//if $datetime_value is empty, and ! $this->_nullable, just use time()
573
+		if (empty($datetime_string) && $this->_nullable) {
574
+			return null;
575
+		}
576
+		// datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
577
+		if (empty($datetime_string)) {
578
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
579
+		} else {
580
+			$DateTime = DateTime::createFromFormat(
581
+				EE_Datetime_Field::mysql_timestamp_format,
582
+				$datetime_string,
583
+				$this->get_UTC_DateTimeZone()
584
+			);
585
+			if ($DateTime instanceof \DateTime) {
586
+				$DateTime = new DbSafeDateTime(
587
+					$DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
588
+					$this->get_UTC_DateTimeZone()
589
+				);
590
+			}
591
+		}
592
+
593
+		if (! $DateTime instanceof DbSafeDateTime) {
594
+			// if still no datetime object, then let's just use now
595
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
596
+		}
597
+		// THEN apply the field's set DateTimeZone
598
+		$DateTime->setTimezone($this->_DateTimeZone);
599
+
600
+		return $DateTime;
601
+	}
602
+
603
+
604
+	/**
605
+	 * All this method does is determine if we're going to display the timezone string or not on any output.
606
+	 * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
607
+	 * If so, then true.
608
+	 *
609
+	 * @return bool true for yes false for no
610
+	 * @throws \EE_Error
611
+	 */
612
+	protected function _display_timezone()
613
+	{
614
+
615
+		// first let's do a comparison of timezone strings.
616
+		// If they match then we can get out without any further calculations
617
+		$blog_string = get_option('timezone_string');
618
+		if ($blog_string === $this->_timezone_string) {
619
+			return false;
620
+		}
621
+		// now we need to calc the offset for the timezone string so we can compare with the blog offset.
622
+		$this_offset = $this->get_timezone_offset($this->_DateTimeZone);
623
+		$blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
624
+		// now compare
625
+		return $blog_offset !== $this_offset;
626
+	}
627
+
628
+
629
+	/**
630
+	 * This method returns a php DateTime object for setting on the EE_Base_Class model.
631
+	 * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
632
+	 * with.
633
+	 *
634
+	 * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
635
+	 *                                                    in the format that is set on the date_field (or DateTime
636
+	 *                                                    object)!
637
+	 * @return DateTime
638
+	 */
639
+	protected function _get_date_object($date_string)
640
+	{
641
+		//first if this is an empty date_string and nullable is allowed, just return null.
642
+		if ($this->_nullable && empty($date_string)) {
643
+			return null;
644
+		}
645
+
646
+		// if incoming date
647
+		if ($date_string instanceof DateTime) {
648
+			$date_string->setTimezone($this->_DateTimeZone);
649
+
650
+			return $date_string;
651
+		}
652
+		// if empty date_string and made it here.
653
+		// Return a datetime object for now in the given timezone.
654
+		if (empty($date_string)) {
655
+			return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
656
+		}
657
+		// if $date_string is matches something that looks like a Unix timestamp let's just use it.
658
+		if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
659
+			try {
660
+				// This is operating under the assumption that the incoming Unix timestamp
661
+				// is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
662
+				$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
663
+				$DateTime->setTimestamp($date_string);
664
+
665
+				return $DateTime;
666
+			} catch (Exception $e) {
667
+				// should be rare, but if things got fooled then let's just continue
668
+			}
669
+		}
670
+		//not a unix timestamp.  So we will use the set format on this object and set timezone to
671
+		//create the DateTime object.
672
+		$format = $this->_date_format . ' ' . $this->_time_format;
673
+		try {
674
+			$DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
675
+			if ($DateTime instanceof DateTime) {
676
+				$DateTime = new DbSafeDateTime(
677
+					$DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
678
+					$this->_DateTimeZone
679
+				);
680
+			}
681
+			if (! $DateTime instanceof DbSafeDateTime) {
682
+				throw new EE_Error(
683
+					sprintf(
684
+						__('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
685
+						$date_string,
686
+						$format
687
+					)
688
+				);
689
+			}
690
+		} catch (Exception $e) {
691
+			// if we made it here then likely then something went really wrong.
692
+			// Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
693
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
694
+		}
695
+
696
+		return $DateTime;
697
+	}
698
+
699
+
700
+
701
+	/**
702
+	 * get_timezone_transitions
703
+	 *
704
+	 * @param \DateTimeZone $DateTimeZone
705
+	 * @param int           $time
706
+	 * @param bool          $first_only
707
+	 * @return mixed
708
+	 */
709
+	public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
710
+	{
711
+		$time = is_int($time) || $time === null ? $time : strtotime($time);
712
+		$time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
713
+		$transitions = $DateTimeZone->getTransitions($time);
714
+		return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
715
+	}
716
+
717
+
718
+
719
+	/**
720
+	 * get_timezone_offset
721
+	 *
722
+	 * @param \DateTimeZone $DateTimeZone
723
+	 * @param int           $time
724
+	 * @return mixed
725
+	 * @throws \DomainException
726
+	 */
727
+	public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
728
+	{
729
+		$transitions = $this->get_timezone_transitions($DateTimeZone, $time);
730
+		if ( ! isset($transitions['offset'])) {
731
+			throw new DomainException();
732
+		}
733
+		return $transitions['offset'];
734
+	}
735
+
736
+
737
+	/**
738
+	 * This will take an incoming timezone string and return the abbreviation for that timezone
739
+	 *
740
+	 * @param  string $timezone_string
741
+	 * @return string           abbreviation
742
+	 * @throws \EE_Error
743
+	 */
744
+	public function get_timezone_abbrev($timezone_string)
745
+	{
746
+		$timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
747
+		$dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
748
+
749
+		return $dateTime->format('T');
750
+	}
751
+
752
+	/**
753
+	 * Overrides the parent to allow for having a dynamic "now" value
754
+	 *
755
+	 * @return mixed
756
+	 */
757
+	public function get_default_value()
758
+	{
759
+		if ($this->_default_value === EE_Datetime_Field::now) {
760
+			return time();
761
+		} else {
762
+			return parent::get_default_value();
763
+		}
764
+	}
765
+
766
+
767
+	public function getSchemaDescription()
768
+	{
769
+		return sprintf(
770
+			esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
771
+			$this->get_nicename()
772
+		);
773
+	}
774 774
 }
Please login to merge, or discard this patch.