Completed
Branch FET-10766-extract-activation-d... (a650cc)
by
unknown
87:01 queued 68:06
created
core/EE_Registry.core.php 2 patches
Indentation   +1513 added lines, -1513 removed lines patch added patch discarded remove patch
@@ -22,1519 +22,1519 @@
 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
-        // create reflection
1039
-        $reflector = $this->get_ReflectionClass($class_name);
1040
-        // make sure arguments are an array
1041
-        $arguments = is_array($arguments)
1042
-            ? $arguments
1043
-            : array($arguments);
1044
-        // and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1045
-        // else wrap it in an additional array so that it doesn't get split into multiple parameters
1046
-        $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1047
-            ? $arguments
1048
-            : array($arguments);
1049
-        // attempt to inject dependencies ?
1050
-        if ($this->_dependency_map->has($class_name)) {
1051
-            $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1052
-        }
1053
-        // instantiate the class if possible
1054
-        if ($reflector->isAbstract()) {
1055
-            // nothing to instantiate, loading file was enough
1056
-            // does not throw an exception so $instantiation_mode is unused
1057
-            // $instantiation_mode = "1) no constructor abstract class";
1058
-            return true;
1059
-        }
1060
-        if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) {
1061
-            // no constructor = static methods only... nothing to instantiate, loading file was enough
1062
-            // $instantiation_mode = "2) no constructor but instantiable";
1063
-            return $reflector->newInstance();
1064
-        }
1065
-        if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1066
-            // $instantiation_mode = "3) new_instance_from_db()";
1067
-            return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1068
-        }
1069
-        if (method_exists($class_name, 'new_instance')) {
1070
-            // $instantiation_mode = "4) new_instance()";
1071
-            return call_user_func_array(array($class_name, 'new_instance'), $arguments);
1072
-        }
1073
-        if (method_exists($class_name, 'instance')) {
1074
-            // $instantiation_mode = "5) instance()";
1075
-            return call_user_func_array(array($class_name, 'instance'), $arguments);
1076
-        }
1077
-        if ($reflector->isInstantiable()) {
1078
-            // $instantiation_mode = "6) constructor";
1079
-            return $reflector->newInstanceArgs($arguments);
1080
-        }
1081
-        // heh ? something's not right !
1082
-        throw new EE_Error(
1083
-            sprintf(
1084
-                __('The %s file %s could not be instantiated.', 'event_espresso'),
1085
-                $type,
1086
-                $class_name
1087
-            )
1088
-        );
1089
-    }
1090
-
1091
-
1092
-
1093
-    /**
1094
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1095
-     * @param array $array
1096
-     * @return bool
1097
-     */
1098
-    protected function _array_is_numerically_and_sequentially_indexed(array $array)
1099
-    {
1100
-        return ! empty($array)
1101
-            ? array_keys($array) === range(0, count($array) - 1)
1102
-            : true;
1103
-    }
1104
-
1105
-
1106
-
1107
-    /**
1108
-     * getReflectionClass
1109
-     * checks if a ReflectionClass object has already been generated for a class
1110
-     * and returns that instead of creating a new one
1111
-     *
1112
-     * @param string $class_name
1113
-     * @return ReflectionClass
1114
-     * @throws ReflectionException
1115
-     */
1116
-    public function get_ReflectionClass($class_name)
1117
-    {
1118
-        if (
1119
-            ! isset($this->_reflectors[$class_name])
1120
-            || ! $this->_reflectors[$class_name] instanceof ReflectionClass
1121
-        ) {
1122
-            $this->_reflectors[$class_name] = new ReflectionClass($class_name);
1123
-        }
1124
-        return $this->_reflectors[$class_name];
1125
-    }
1126
-
1127
-
1128
-
1129
-    /**
1130
-     * _resolve_dependencies
1131
-     * examines the constructor for the requested class to determine
1132
-     * if any dependencies exist, and if they can be injected.
1133
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1134
-     * PLZ NOTE: this is achieved by type hinting the constructor params
1135
-     * For example:
1136
-     *        if attempting to load a class "Foo" with the following constructor:
1137
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
1138
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
1139
-     *        but only IF they are NOT already present in the incoming arguments array,
1140
-     *        and the correct classes can be loaded
1141
-     *
1142
-     * @param ReflectionClass $reflector
1143
-     * @param string          $class_name
1144
-     * @param array           $arguments
1145
-     * @return array
1146
-     * @throws EE_Error
1147
-     * @throws ReflectionException
1148
-     */
1149
-    protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1150
-    {
1151
-        // let's examine the constructor
1152
-        $constructor = $reflector->getConstructor();
1153
-        // whu? huh? nothing?
1154
-        if (! $constructor) {
1155
-            return $arguments;
1156
-        }
1157
-        // get constructor parameters
1158
-        $params = $constructor->getParameters();
1159
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1160
-        $argument_keys = array_keys($arguments);
1161
-        // now loop thru all of the constructors expected parameters
1162
-        foreach ($params as $index => $param) {
1163
-            // is this a dependency for a specific class ?
1164
-            $param_class = $param->getClass()
1165
-                ? $param->getClass()->name
1166
-                : null;
1167
-            // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1168
-            $param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1169
-                ? $this->_dependency_map->get_alias($param_class, $class_name)
1170
-                : $param_class;
1171
-            if (
1172
-                // param is not even a class
1173
-                $param_class === null
1174
-                // and something already exists in the incoming arguments for this param
1175
-                && array_key_exists($index, $argument_keys)
1176
-                && array_key_exists($argument_keys[$index], $arguments)
1177
-            ) {
1178
-                // so let's skip this argument and move on to the next
1179
-                continue;
1180
-            }
1181
-            if (
1182
-                // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1183
-                $param_class !== null
1184
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1185
-                && $arguments[$argument_keys[$index]] instanceof $param_class
1186
-            ) {
1187
-                // skip this argument and move on to the next
1188
-                continue;
1189
-            }
1190
-            if (
1191
-                // parameter is type hinted as a class, and should be injected
1192
-                $param_class !== null
1193
-                && $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1194
-            ) {
1195
-                $arguments = $this->_resolve_dependency(
1196
-                    $class_name,
1197
-                    $param_class,
1198
-                    $arguments,
1199
-                    $index,
1200
-                    $argument_keys
1201
-                );
1202
-            } else {
1203
-                try {
1204
-                    $arguments[$index] = $param->isDefaultValueAvailable()
1205
-                        ? $param->getDefaultValue()
1206
-                        : null;
1207
-                } catch (ReflectionException $e) {
1208
-                    throw new ReflectionException(
1209
-                        sprintf(
1210
-                            esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'),
1211
-                            $e->getMessage(),
1212
-                            $param->getName(),
1213
-                            $class_name
1214
-                        )
1215
-                    );
1216
-                }
1217
-            }
1218
-        }
1219
-        return $arguments;
1220
-    }
1221
-
1222
-
1223
-
1224
-    /**
1225
-     * @param string $class_name
1226
-     * @param string $param_class
1227
-     * @param array  $arguments
1228
-     * @param mixed  $index
1229
-     * @param array  $argument_keys
1230
-     * @return array
1231
-     * @throws EE_Error
1232
-     * @throws ReflectionException
1233
-     * @throws InvalidArgumentException
1234
-     * @throws InvalidInterfaceException
1235
-     * @throws InvalidDataTypeException
1236
-     */
1237
-    protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys)
1238
-    {
1239
-        $dependency = null;
1240
-        // should dependency be loaded from cache ?
1241
-        $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1242
-            $class_name,
1243
-            $param_class
1244
-        );
1245
-        $cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1246
-        // we might have a dependency...
1247
-        // let's MAYBE try and find it in our cache if that's what's been requested
1248
-        $cached_class = $cache_on
1249
-            ? $this->_get_cached_class($param_class)
1250
-            : null;
1251
-        // and grab it if it exists
1252
-        if ($cached_class instanceof $param_class) {
1253
-            $dependency = $cached_class;
1254
-        } else if ($param_class !== $class_name) {
1255
-            // obtain the loader method from the dependency map
1256
-            $loader = $this->_dependency_map->class_loader($param_class);
1257
-            // is loader a custom closure ?
1258
-            if ($loader instanceof Closure) {
1259
-                $dependency = $loader($arguments);
1260
-            } else {
1261
-                // set the cache on property for the recursive loading call
1262
-                $this->_cache_on = $cache_on;
1263
-                // if not, then let's try and load it via the registry
1264
-                if ($loader && method_exists($this, $loader)) {
1265
-                    $dependency = $this->{$loader}($param_class);
1266
-                } else {
1267
-                    $dependency = LoaderFactory::getLoader()->load(
1268
-                        $param_class,
1269
-                        array(),
1270
-                        $cache_on
1271
-                    );
1272
-                }
1273
-            }
1274
-        }
1275
-        // did we successfully find the correct dependency ?
1276
-        if ($dependency instanceof $param_class) {
1277
-            // then let's inject it into the incoming array of arguments at the correct location
1278
-            $arguments[$index] = $dependency;
1279
-        }
1280
-        return $arguments;
1281
-    }
1282
-
1283
-
1284
-
1285
-    /**
1286
-     * _set_cached_class
1287
-     * attempts to cache the instantiated class locally
1288
-     * in one of the following places, in the following order:
1289
-     *        $this->{class_abbreviation}   ie:    $this->CART
1290
-     *        $this->{$class_name}          ie:    $this->Some_Class
1291
-     *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1292
-     *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1293
-     *
1294
-     * @param object $class_obj
1295
-     * @param string $class_name
1296
-     * @param string $class_prefix
1297
-     * @param bool   $from_db
1298
-     * @return void
1299
-     */
1300
-    protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1301
-    {
1302
-        if ($class_name === 'EE_Registry' || empty($class_obj)) {
1303
-            return;
1304
-        }
1305
-        // return newly instantiated class
1306
-        $class_abbreviation = $this->get_class_abbreviation($class_name, '');
1307
-        if ($class_abbreviation) {
1308
-            $this->{$class_abbreviation} = $class_obj;
1309
-            return;
1310
-        }
1311
-        $class_name = str_replace('\\', '_', $class_name);
1312
-        if (property_exists($this, $class_name)) {
1313
-            $this->{$class_name} = $class_obj;
1314
-            return;
1315
-        }
1316
-        if ($class_prefix === 'addon') {
1317
-            $this->addons->{$class_name} = $class_obj;
1318
-            return;
1319
-        }
1320
-        if (! $from_db) {
1321
-            $this->LIB->{$class_name} = $class_obj;
1322
-        }
1323
-    }
1324
-
1325
-
1326
-
1327
-    /**
1328
-     * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1329
-     *
1330
-     * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1331
-     *                          in the EE_Dependency_Map::$_class_loaders array,
1332
-     *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1333
-     * @param array  $arguments
1334
-     * @return object
1335
-     */
1336
-    public static function factory($classname, $arguments = array())
1337
-    {
1338
-        $loader = self::instance()->_dependency_map->class_loader($classname);
1339
-        if ($loader instanceof Closure) {
1340
-            return $loader($arguments);
1341
-        }
1342
-        if (method_exists(self::instance(), $loader)) {
1343
-            return self::instance()->{$loader}($classname, $arguments);
1344
-        }
1345
-        return null;
1346
-    }
1347
-
1348
-
1349
-
1350
-    /**
1351
-     * Gets the addon by its name/slug (not classname. For that, just
1352
-     * use the classname as the property name on EE_Config::instance()->addons)
1353
-     *
1354
-     * @param string $name
1355
-     * @return EE_Addon
1356
-     */
1357
-    public function get_addon_by_name($name)
1358
-    {
1359
-        foreach ($this->addons as $addon) {
1360
-            if ($addon->name() === $name) {
1361
-                return $addon;
1362
-            }
1363
-        }
1364
-        return null;
1365
-    }
1366
-
1367
-
1368
-
1369
-    /**
1370
-     * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their
1371
-     * name() function) They're already available on EE_Config::instance()->addons as properties, where each property's
1372
-     * name is the addon's classname. So if you just want to get the addon by classname, use
1373
-     * EE_Config::instance()->addons->{classname}
1374
-     *
1375
-     * @return EE_Addon[] where the KEYS are the addon's name()
1376
-     */
1377
-    public function get_addons_by_name()
1378
-    {
1379
-        $addons = array();
1380
-        foreach ($this->addons as $addon) {
1381
-            $addons[$addon->name()] = $addon;
1382
-        }
1383
-        return $addons;
1384
-    }
1385
-
1386
-
1387
-
1388
-    /**
1389
-     * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1390
-     * a stale copy of it around
1391
-     *
1392
-     * @param string $model_name
1393
-     * @return \EEM_Base
1394
-     * @throws \EE_Error
1395
-     */
1396
-    public function reset_model($model_name)
1397
-    {
1398
-        $model_class_name = strpos($model_name, 'EEM_') !== 0
1399
-            ? "EEM_{$model_name}"
1400
-            : $model_name;
1401
-        if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1402
-            return null;
1403
-        }
1404
-        //get that model reset it and make sure we nuke the old reference to it
1405
-        if ($this->LIB->{$model_class_name} instanceof $model_class_name
1406
-            && is_callable(
1407
-                array($model_class_name, 'reset')
1408
-            )) {
1409
-            $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1410
-        } else {
1411
-            throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1412
-        }
1413
-        return $this->LIB->{$model_class_name};
1414
-    }
1415
-
1416
-
1417
-
1418
-    /**
1419
-     * Resets the registry.
1420
-     * The criteria for what gets reset is based on what can be shared between sites on the same request when
1421
-     * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1422
-     * - $_dependency_map
1423
-     * - $_class_abbreviations
1424
-     * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1425
-     * - $REQ:  Still on the same request so no need to change.
1426
-     * - $CAP: There is no site specific state in the EE_Capability class.
1427
-     * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1428
-     * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1429
-     * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1430
-     *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1431
-     *             switch or on the restore.
1432
-     * - $modules
1433
-     * - $shortcodes
1434
-     * - $widgets
1435
-     *
1436
-     * @param boolean $hard             [deprecated]
1437
-     * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1438
-     *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1439
-     *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1440
-     * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1441
-     *                                  client
1442
-     *                                  code instead can just change the model context to a different blog id if
1443
-     *                                  necessary
1444
-     * @return EE_Registry
1445
-     * @throws EE_Error
1446
-     * @throws ReflectionException
1447
-     */
1448
-    public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1449
-    {
1450
-        $instance = self::instance();
1451
-        $instance->_cache_on = true;
1452
-        // reset some "special" classes
1453
-        EEH_Activation::reset();
1454
-        $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1455
-        $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1456
-        $instance->CART = null;
1457
-        $instance->MRM = null;
1458
-        $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1459
-        //messages reset
1460
-        EED_Messages::reset();
1461
-        //handle of objects cached on LIB
1462
-        foreach (array('LIB', 'modules') as $cache) {
1463
-            foreach ($instance->{$cache} as $class_name => $class) {
1464
-                if (self::_reset_and_unset_object($class, $reset_models)) {
1465
-                    unset($instance->{$cache}->{$class_name});
1466
-                }
1467
-            }
1468
-        }
1469
-        return $instance;
1470
-    }
1471
-
1472
-
1473
-
1474
-    /**
1475
-     * if passed object implements ResettableInterface, then call it's reset() method
1476
-     * if passed object implements InterminableInterface, then return false,
1477
-     * to indicate that it should NOT be cleared from the Registry cache
1478
-     *
1479
-     * @param      $object
1480
-     * @param bool $reset_models
1481
-     * @return bool returns true if cached object should be unset
1482
-     */
1483
-    private static function _reset_and_unset_object($object, $reset_models)
1484
-    {
1485
-        if (! is_object($object)) {
1486
-            // don't unset anything that's not an object
1487
-            return false;
1488
-        }
1489
-        if ($object instanceof EED_Module) {
1490
-            $object::reset();
1491
-            // don't unset modules
1492
-            return false;
1493
-        }
1494
-        if ($object instanceof ResettableInterface) {
1495
-            if ($object instanceof EEM_Base) {
1496
-                if ($reset_models) {
1497
-                    $object->reset();
1498
-                    return true;
1499
-                }
1500
-                return false;
1501
-            }
1502
-            $object->reset();
1503
-            return true;
1504
-        }
1505
-        if (! $object instanceof InterminableInterface) {
1506
-            return true;
1507
-        }
1508
-        return false;
1509
-    }
1510
-
1511
-
1512
-
1513
-    /**
1514
-     * Gets all the custom post type models defined
1515
-     *
1516
-     * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1517
-     */
1518
-    public function cpt_models()
1519
-    {
1520
-        $cpt_models = array();
1521
-        foreach ($this->non_abstract_db_models as $short_name => $classname) {
1522
-            if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1523
-                $cpt_models[$short_name] = $classname;
1524
-            }
1525
-        }
1526
-        return $cpt_models;
1527
-    }
1528
-
1529
-
1530
-
1531
-    /**
1532
-     * @return \EE_Config
1533
-     */
1534
-    public static function CFG()
1535
-    {
1536
-        return self::instance()->CFG;
1537
-    }
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
+		// create reflection
1039
+		$reflector = $this->get_ReflectionClass($class_name);
1040
+		// make sure arguments are an array
1041
+		$arguments = is_array($arguments)
1042
+			? $arguments
1043
+			: array($arguments);
1044
+		// and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1045
+		// else wrap it in an additional array so that it doesn't get split into multiple parameters
1046
+		$arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1047
+			? $arguments
1048
+			: array($arguments);
1049
+		// attempt to inject dependencies ?
1050
+		if ($this->_dependency_map->has($class_name)) {
1051
+			$arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1052
+		}
1053
+		// instantiate the class if possible
1054
+		if ($reflector->isAbstract()) {
1055
+			// nothing to instantiate, loading file was enough
1056
+			// does not throw an exception so $instantiation_mode is unused
1057
+			// $instantiation_mode = "1) no constructor abstract class";
1058
+			return true;
1059
+		}
1060
+		if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) {
1061
+			// no constructor = static methods only... nothing to instantiate, loading file was enough
1062
+			// $instantiation_mode = "2) no constructor but instantiable";
1063
+			return $reflector->newInstance();
1064
+		}
1065
+		if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1066
+			// $instantiation_mode = "3) new_instance_from_db()";
1067
+			return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1068
+		}
1069
+		if (method_exists($class_name, 'new_instance')) {
1070
+			// $instantiation_mode = "4) new_instance()";
1071
+			return call_user_func_array(array($class_name, 'new_instance'), $arguments);
1072
+		}
1073
+		if (method_exists($class_name, 'instance')) {
1074
+			// $instantiation_mode = "5) instance()";
1075
+			return call_user_func_array(array($class_name, 'instance'), $arguments);
1076
+		}
1077
+		if ($reflector->isInstantiable()) {
1078
+			// $instantiation_mode = "6) constructor";
1079
+			return $reflector->newInstanceArgs($arguments);
1080
+		}
1081
+		// heh ? something's not right !
1082
+		throw new EE_Error(
1083
+			sprintf(
1084
+				__('The %s file %s could not be instantiated.', 'event_espresso'),
1085
+				$type,
1086
+				$class_name
1087
+			)
1088
+		);
1089
+	}
1090
+
1091
+
1092
+
1093
+	/**
1094
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1095
+	 * @param array $array
1096
+	 * @return bool
1097
+	 */
1098
+	protected function _array_is_numerically_and_sequentially_indexed(array $array)
1099
+	{
1100
+		return ! empty($array)
1101
+			? array_keys($array) === range(0, count($array) - 1)
1102
+			: true;
1103
+	}
1104
+
1105
+
1106
+
1107
+	/**
1108
+	 * getReflectionClass
1109
+	 * checks if a ReflectionClass object has already been generated for a class
1110
+	 * and returns that instead of creating a new one
1111
+	 *
1112
+	 * @param string $class_name
1113
+	 * @return ReflectionClass
1114
+	 * @throws ReflectionException
1115
+	 */
1116
+	public function get_ReflectionClass($class_name)
1117
+	{
1118
+		if (
1119
+			! isset($this->_reflectors[$class_name])
1120
+			|| ! $this->_reflectors[$class_name] instanceof ReflectionClass
1121
+		) {
1122
+			$this->_reflectors[$class_name] = new ReflectionClass($class_name);
1123
+		}
1124
+		return $this->_reflectors[$class_name];
1125
+	}
1126
+
1127
+
1128
+
1129
+	/**
1130
+	 * _resolve_dependencies
1131
+	 * examines the constructor for the requested class to determine
1132
+	 * if any dependencies exist, and if they can be injected.
1133
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1134
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
1135
+	 * For example:
1136
+	 *        if attempting to load a class "Foo" with the following constructor:
1137
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
1138
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
1139
+	 *        but only IF they are NOT already present in the incoming arguments array,
1140
+	 *        and the correct classes can be loaded
1141
+	 *
1142
+	 * @param ReflectionClass $reflector
1143
+	 * @param string          $class_name
1144
+	 * @param array           $arguments
1145
+	 * @return array
1146
+	 * @throws EE_Error
1147
+	 * @throws ReflectionException
1148
+	 */
1149
+	protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1150
+	{
1151
+		// let's examine the constructor
1152
+		$constructor = $reflector->getConstructor();
1153
+		// whu? huh? nothing?
1154
+		if (! $constructor) {
1155
+			return $arguments;
1156
+		}
1157
+		// get constructor parameters
1158
+		$params = $constructor->getParameters();
1159
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1160
+		$argument_keys = array_keys($arguments);
1161
+		// now loop thru all of the constructors expected parameters
1162
+		foreach ($params as $index => $param) {
1163
+			// is this a dependency for a specific class ?
1164
+			$param_class = $param->getClass()
1165
+				? $param->getClass()->name
1166
+				: null;
1167
+			// BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1168
+			$param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1169
+				? $this->_dependency_map->get_alias($param_class, $class_name)
1170
+				: $param_class;
1171
+			if (
1172
+				// param is not even a class
1173
+				$param_class === null
1174
+				// and something already exists in the incoming arguments for this param
1175
+				&& array_key_exists($index, $argument_keys)
1176
+				&& array_key_exists($argument_keys[$index], $arguments)
1177
+			) {
1178
+				// so let's skip this argument and move on to the next
1179
+				continue;
1180
+			}
1181
+			if (
1182
+				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1183
+				$param_class !== null
1184
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1185
+				&& $arguments[$argument_keys[$index]] instanceof $param_class
1186
+			) {
1187
+				// skip this argument and move on to the next
1188
+				continue;
1189
+			}
1190
+			if (
1191
+				// parameter is type hinted as a class, and should be injected
1192
+				$param_class !== null
1193
+				&& $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1194
+			) {
1195
+				$arguments = $this->_resolve_dependency(
1196
+					$class_name,
1197
+					$param_class,
1198
+					$arguments,
1199
+					$index,
1200
+					$argument_keys
1201
+				);
1202
+			} else {
1203
+				try {
1204
+					$arguments[$index] = $param->isDefaultValueAvailable()
1205
+						? $param->getDefaultValue()
1206
+						: null;
1207
+				} catch (ReflectionException $e) {
1208
+					throw new ReflectionException(
1209
+						sprintf(
1210
+							esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'),
1211
+							$e->getMessage(),
1212
+							$param->getName(),
1213
+							$class_name
1214
+						)
1215
+					);
1216
+				}
1217
+			}
1218
+		}
1219
+		return $arguments;
1220
+	}
1221
+
1222
+
1223
+
1224
+	/**
1225
+	 * @param string $class_name
1226
+	 * @param string $param_class
1227
+	 * @param array  $arguments
1228
+	 * @param mixed  $index
1229
+	 * @param array  $argument_keys
1230
+	 * @return array
1231
+	 * @throws EE_Error
1232
+	 * @throws ReflectionException
1233
+	 * @throws InvalidArgumentException
1234
+	 * @throws InvalidInterfaceException
1235
+	 * @throws InvalidDataTypeException
1236
+	 */
1237
+	protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys)
1238
+	{
1239
+		$dependency = null;
1240
+		// should dependency be loaded from cache ?
1241
+		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1242
+			$class_name,
1243
+			$param_class
1244
+		);
1245
+		$cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1246
+		// we might have a dependency...
1247
+		// let's MAYBE try and find it in our cache if that's what's been requested
1248
+		$cached_class = $cache_on
1249
+			? $this->_get_cached_class($param_class)
1250
+			: null;
1251
+		// and grab it if it exists
1252
+		if ($cached_class instanceof $param_class) {
1253
+			$dependency = $cached_class;
1254
+		} else if ($param_class !== $class_name) {
1255
+			// obtain the loader method from the dependency map
1256
+			$loader = $this->_dependency_map->class_loader($param_class);
1257
+			// is loader a custom closure ?
1258
+			if ($loader instanceof Closure) {
1259
+				$dependency = $loader($arguments);
1260
+			} else {
1261
+				// set the cache on property for the recursive loading call
1262
+				$this->_cache_on = $cache_on;
1263
+				// if not, then let's try and load it via the registry
1264
+				if ($loader && method_exists($this, $loader)) {
1265
+					$dependency = $this->{$loader}($param_class);
1266
+				} else {
1267
+					$dependency = LoaderFactory::getLoader()->load(
1268
+						$param_class,
1269
+						array(),
1270
+						$cache_on
1271
+					);
1272
+				}
1273
+			}
1274
+		}
1275
+		// did we successfully find the correct dependency ?
1276
+		if ($dependency instanceof $param_class) {
1277
+			// then let's inject it into the incoming array of arguments at the correct location
1278
+			$arguments[$index] = $dependency;
1279
+		}
1280
+		return $arguments;
1281
+	}
1282
+
1283
+
1284
+
1285
+	/**
1286
+	 * _set_cached_class
1287
+	 * attempts to cache the instantiated class locally
1288
+	 * in one of the following places, in the following order:
1289
+	 *        $this->{class_abbreviation}   ie:    $this->CART
1290
+	 *        $this->{$class_name}          ie:    $this->Some_Class
1291
+	 *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1292
+	 *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1293
+	 *
1294
+	 * @param object $class_obj
1295
+	 * @param string $class_name
1296
+	 * @param string $class_prefix
1297
+	 * @param bool   $from_db
1298
+	 * @return void
1299
+	 */
1300
+	protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1301
+	{
1302
+		if ($class_name === 'EE_Registry' || empty($class_obj)) {
1303
+			return;
1304
+		}
1305
+		// return newly instantiated class
1306
+		$class_abbreviation = $this->get_class_abbreviation($class_name, '');
1307
+		if ($class_abbreviation) {
1308
+			$this->{$class_abbreviation} = $class_obj;
1309
+			return;
1310
+		}
1311
+		$class_name = str_replace('\\', '_', $class_name);
1312
+		if (property_exists($this, $class_name)) {
1313
+			$this->{$class_name} = $class_obj;
1314
+			return;
1315
+		}
1316
+		if ($class_prefix === 'addon') {
1317
+			$this->addons->{$class_name} = $class_obj;
1318
+			return;
1319
+		}
1320
+		if (! $from_db) {
1321
+			$this->LIB->{$class_name} = $class_obj;
1322
+		}
1323
+	}
1324
+
1325
+
1326
+
1327
+	/**
1328
+	 * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1329
+	 *
1330
+	 * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1331
+	 *                          in the EE_Dependency_Map::$_class_loaders array,
1332
+	 *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1333
+	 * @param array  $arguments
1334
+	 * @return object
1335
+	 */
1336
+	public static function factory($classname, $arguments = array())
1337
+	{
1338
+		$loader = self::instance()->_dependency_map->class_loader($classname);
1339
+		if ($loader instanceof Closure) {
1340
+			return $loader($arguments);
1341
+		}
1342
+		if (method_exists(self::instance(), $loader)) {
1343
+			return self::instance()->{$loader}($classname, $arguments);
1344
+		}
1345
+		return null;
1346
+	}
1347
+
1348
+
1349
+
1350
+	/**
1351
+	 * Gets the addon by its name/slug (not classname. For that, just
1352
+	 * use the classname as the property name on EE_Config::instance()->addons)
1353
+	 *
1354
+	 * @param string $name
1355
+	 * @return EE_Addon
1356
+	 */
1357
+	public function get_addon_by_name($name)
1358
+	{
1359
+		foreach ($this->addons as $addon) {
1360
+			if ($addon->name() === $name) {
1361
+				return $addon;
1362
+			}
1363
+		}
1364
+		return null;
1365
+	}
1366
+
1367
+
1368
+
1369
+	/**
1370
+	 * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their
1371
+	 * name() function) They're already available on EE_Config::instance()->addons as properties, where each property's
1372
+	 * name is the addon's classname. So if you just want to get the addon by classname, use
1373
+	 * EE_Config::instance()->addons->{classname}
1374
+	 *
1375
+	 * @return EE_Addon[] where the KEYS are the addon's name()
1376
+	 */
1377
+	public function get_addons_by_name()
1378
+	{
1379
+		$addons = array();
1380
+		foreach ($this->addons as $addon) {
1381
+			$addons[$addon->name()] = $addon;
1382
+		}
1383
+		return $addons;
1384
+	}
1385
+
1386
+
1387
+
1388
+	/**
1389
+	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1390
+	 * a stale copy of it around
1391
+	 *
1392
+	 * @param string $model_name
1393
+	 * @return \EEM_Base
1394
+	 * @throws \EE_Error
1395
+	 */
1396
+	public function reset_model($model_name)
1397
+	{
1398
+		$model_class_name = strpos($model_name, 'EEM_') !== 0
1399
+			? "EEM_{$model_name}"
1400
+			: $model_name;
1401
+		if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1402
+			return null;
1403
+		}
1404
+		//get that model reset it and make sure we nuke the old reference to it
1405
+		if ($this->LIB->{$model_class_name} instanceof $model_class_name
1406
+			&& is_callable(
1407
+				array($model_class_name, 'reset')
1408
+			)) {
1409
+			$this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1410
+		} else {
1411
+			throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1412
+		}
1413
+		return $this->LIB->{$model_class_name};
1414
+	}
1415
+
1416
+
1417
+
1418
+	/**
1419
+	 * Resets the registry.
1420
+	 * The criteria for what gets reset is based on what can be shared between sites on the same request when
1421
+	 * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1422
+	 * - $_dependency_map
1423
+	 * - $_class_abbreviations
1424
+	 * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1425
+	 * - $REQ:  Still on the same request so no need to change.
1426
+	 * - $CAP: There is no site specific state in the EE_Capability class.
1427
+	 * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1428
+	 * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1429
+	 * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1430
+	 *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1431
+	 *             switch or on the restore.
1432
+	 * - $modules
1433
+	 * - $shortcodes
1434
+	 * - $widgets
1435
+	 *
1436
+	 * @param boolean $hard             [deprecated]
1437
+	 * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1438
+	 *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1439
+	 *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1440
+	 * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1441
+	 *                                  client
1442
+	 *                                  code instead can just change the model context to a different blog id if
1443
+	 *                                  necessary
1444
+	 * @return EE_Registry
1445
+	 * @throws EE_Error
1446
+	 * @throws ReflectionException
1447
+	 */
1448
+	public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1449
+	{
1450
+		$instance = self::instance();
1451
+		$instance->_cache_on = true;
1452
+		// reset some "special" classes
1453
+		EEH_Activation::reset();
1454
+		$hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1455
+		$instance->CFG = EE_Config::reset($hard, $reinstantiate);
1456
+		$instance->CART = null;
1457
+		$instance->MRM = null;
1458
+		$instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1459
+		//messages reset
1460
+		EED_Messages::reset();
1461
+		//handle of objects cached on LIB
1462
+		foreach (array('LIB', 'modules') as $cache) {
1463
+			foreach ($instance->{$cache} as $class_name => $class) {
1464
+				if (self::_reset_and_unset_object($class, $reset_models)) {
1465
+					unset($instance->{$cache}->{$class_name});
1466
+				}
1467
+			}
1468
+		}
1469
+		return $instance;
1470
+	}
1471
+
1472
+
1473
+
1474
+	/**
1475
+	 * if passed object implements ResettableInterface, then call it's reset() method
1476
+	 * if passed object implements InterminableInterface, then return false,
1477
+	 * to indicate that it should NOT be cleared from the Registry cache
1478
+	 *
1479
+	 * @param      $object
1480
+	 * @param bool $reset_models
1481
+	 * @return bool returns true if cached object should be unset
1482
+	 */
1483
+	private static function _reset_and_unset_object($object, $reset_models)
1484
+	{
1485
+		if (! is_object($object)) {
1486
+			// don't unset anything that's not an object
1487
+			return false;
1488
+		}
1489
+		if ($object instanceof EED_Module) {
1490
+			$object::reset();
1491
+			// don't unset modules
1492
+			return false;
1493
+		}
1494
+		if ($object instanceof ResettableInterface) {
1495
+			if ($object instanceof EEM_Base) {
1496
+				if ($reset_models) {
1497
+					$object->reset();
1498
+					return true;
1499
+				}
1500
+				return false;
1501
+			}
1502
+			$object->reset();
1503
+			return true;
1504
+		}
1505
+		if (! $object instanceof InterminableInterface) {
1506
+			return true;
1507
+		}
1508
+		return false;
1509
+	}
1510
+
1511
+
1512
+
1513
+	/**
1514
+	 * Gets all the custom post type models defined
1515
+	 *
1516
+	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1517
+	 */
1518
+	public function cpt_models()
1519
+	{
1520
+		$cpt_models = array();
1521
+		foreach ($this->non_abstract_db_models as $short_name => $classname) {
1522
+			if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1523
+				$cpt_models[$short_name] = $classname;
1524
+			}
1525
+		}
1526
+		return $cpt_models;
1527
+	}
1528
+
1529
+
1530
+
1531
+	/**
1532
+	 * @return \EE_Config
1533
+	 */
1534
+	public static function CFG()
1535
+	{
1536
+		return self::instance()->CFG;
1537
+	}
1538 1538
 
1539 1539
 
1540 1540
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 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
             }
@@ -1151,7 +1151,7 @@  discard block
 block discarded – undo
1151 1151
         // let's examine the constructor
1152 1152
         $constructor = $reflector->getConstructor();
1153 1153
         // whu? huh? nothing?
1154
-        if (! $constructor) {
1154
+        if ( ! $constructor) {
1155 1155
             return $arguments;
1156 1156
         }
1157 1157
         // get constructor parameters
@@ -1317,7 +1317,7 @@  discard block
 block discarded – undo
1317 1317
             $this->addons->{$class_name} = $class_obj;
1318 1318
             return;
1319 1319
         }
1320
-        if (! $from_db) {
1320
+        if ( ! $from_db) {
1321 1321
             $this->LIB->{$class_name} = $class_obj;
1322 1322
         }
1323 1323
     }
@@ -1398,7 +1398,7 @@  discard block
 block discarded – undo
1398 1398
         $model_class_name = strpos($model_name, 'EEM_') !== 0
1399 1399
             ? "EEM_{$model_name}"
1400 1400
             : $model_name;
1401
-        if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1401
+        if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1402 1402
             return null;
1403 1403
         }
1404 1404
         //get that model reset it and make sure we nuke the old reference to it
@@ -1451,7 +1451,7 @@  discard block
 block discarded – undo
1451 1451
         $instance->_cache_on = true;
1452 1452
         // reset some "special" classes
1453 1453
         EEH_Activation::reset();
1454
-        $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1454
+        $hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard);
1455 1455
         $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1456 1456
         $instance->CART = null;
1457 1457
         $instance->MRM = null;
@@ -1482,7 +1482,7 @@  discard block
 block discarded – undo
1482 1482
      */
1483 1483
     private static function _reset_and_unset_object($object, $reset_models)
1484 1484
     {
1485
-        if (! is_object($object)) {
1485
+        if ( ! is_object($object)) {
1486 1486
             // don't unset anything that's not an object
1487 1487
             return false;
1488 1488
         }
@@ -1502,7 +1502,7 @@  discard block
 block discarded – undo
1502 1502
             $object->reset();
1503 1503
             return true;
1504 1504
         }
1505
-        if (! $object instanceof InterminableInterface) {
1505
+        if ( ! $object instanceof InterminableInterface) {
1506 1506
             return true;
1507 1507
         }
1508 1508
         return false;
Please login to merge, or discard this patch.
core/helpers/EEH_Line_Item.helper.php 1 patch
Spacing   +346 added lines, -346 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (!defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2 2
 /**
3 3
  *
4 4
  * EEH_Line_Item
@@ -45,8 +45,8 @@  discard block
 block discarded – undo
45 45
 	 * @return boolean success
46 46
 	 * @throws \EE_Error
47 47
 	 */
48
-	public static function add_unrelated_item( EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL  ){
49
-		$items_subtotal = self::get_pre_tax_subtotal( $parent_line_item );
48
+	public static function add_unrelated_item(EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL) {
49
+		$items_subtotal = self::get_pre_tax_subtotal($parent_line_item);
50 50
 		$line_item = EE_Line_Item::new_instance(array(
51 51
 			'LIN_name' => $name,
52 52
 			'LIN_desc' => $description,
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 			'LIN_quantity' => $quantity,
55 55
 			'LIN_percent' => null,
56 56
 			'LIN_is_taxable' => $taxable,
57
-			'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count( $items_subtotal->children() ) : 0,
57
+			'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0,
58 58
 			'LIN_total' => (float) $unit_price * (int) $quantity,
59 59
 			'LIN_type'=>  EEM_Line_Item::type_line_item,
60 60
 			'LIN_code' => $code,
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 			$line_item,
65 65
 			$parent_line_item
66 66
 		);
67
-		return self::add_item( $parent_line_item, $line_item );
67
+		return self::add_item($parent_line_item, $line_item);
68 68
 	}
69 69
 
70 70
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	 * @return boolean success
87 87
 	 * @throws \EE_Error
88 88
 	 */
89
-	public static function add_percentage_based_item( EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE ){
89
+	public static function add_percentage_based_item(EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE) {
90 90
 		$line_item = EE_Line_Item::new_instance(array(
91 91
 			'LIN_name' => $name,
92 92
 			'LIN_desc' => $description,
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 			'LIN_percent' => $percentage_amount,
95 95
 			'LIN_quantity' => NULL,
96 96
 			'LIN_is_taxable' => $taxable,
97
-			'LIN_total' => (float) ( $percentage_amount * ( $parent_line_item->total() / 100 ) ),
97
+			'LIN_total' => (float) ($percentage_amount * ($parent_line_item->total() / 100)),
98 98
 			'LIN_type'=>  EEM_Line_Item::type_line_item,
99 99
 			'LIN_parent' => $parent_line_item->ID()
100 100
 		));
@@ -123,15 +123,15 @@  discard block
 block discarded – undo
123 123
 	 * @return \EE_Line_Item
124 124
 	 * @throws \EE_Error
125 125
 	 */
126
-	public static function add_ticket_purchase( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ){
127
-		if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total() ) {
128
-			throw new EE_Error( sprintf( __( 'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso' ), $ticket->ID(), $total_line_item->ID() ) );
126
+	public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) {
127
+		if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) {
128
+			throw new EE_Error(sprintf(__('A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso'), $ticket->ID(), $total_line_item->ID()));
129 129
 		}
130 130
 		// either increment the qty for an existing ticket
131
-		$line_item = self::increment_ticket_qty_if_already_in_cart( $total_line_item, $ticket, $qty );
131
+		$line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty);
132 132
 		// or add a new one
133
-		if ( ! $line_item instanceof EE_Line_Item ) {
134
-			$line_item = self::create_ticket_line_item( $total_line_item, $ticket, $qty );
133
+		if ( ! $line_item instanceof EE_Line_Item) {
134
+			$line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty);
135 135
 		}
136 136
 		$total_line_item->recalculate_total_including_taxes();
137 137
 		return $line_item;
@@ -147,11 +147,11 @@  discard block
 block discarded – undo
147 147
 	 * @return \EE_Line_Item
148 148
 	 * @throws \EE_Error
149 149
 	 */
150
-	public static function increment_ticket_qty_if_already_in_cart( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) {
150
+	public static function increment_ticket_qty_if_already_in_cart(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) {
151 151
 		$line_item = null;
152
-		if ( $total_line_item instanceof EE_Line_Item && $total_line_item->is_total() ) {
153
-			$ticket_line_items = EEH_Line_Item::get_ticket_line_items( $total_line_item );
154
-			foreach ( (array)$ticket_line_items as $ticket_line_item ) {
152
+		if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) {
153
+			$ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item);
154
+			foreach ((array) $ticket_line_items as $ticket_line_item) {
155 155
 				if (
156 156
 					$ticket_line_item instanceof EE_Line_Item
157 157
 					&& (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID()
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 				}
162 162
 			}
163 163
 		}
164
-		if ( $line_item instanceof EE_Line_Item ) {
165
-			EEH_Line_Item::increment_quantity( $line_item, $qty );
164
+		if ($line_item instanceof EE_Line_Item) {
165
+			EEH_Line_Item::increment_quantity($line_item, $qty);
166 166
 			return $line_item;
167 167
 		}
168 168
 		return null;
@@ -179,16 +179,16 @@  discard block
 block discarded – undo
179 179
 	 * @return void
180 180
 	 * @throws \EE_Error
181 181
 	 */
182
-	public static function increment_quantity( EE_Line_Item $line_item, $qty = 1 ) {
183
-		if( ! $line_item->is_percent() ) {
182
+	public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) {
183
+		if ( ! $line_item->is_percent()) {
184 184
 			$qty += $line_item->quantity();
185
-			$line_item->set_quantity( $qty );
186
-			$line_item->set_total( $line_item->unit_price() * $qty );
185
+			$line_item->set_quantity($qty);
186
+			$line_item->set_total($line_item->unit_price() * $qty);
187 187
 			$line_item->save();
188 188
 		}
189
-		foreach( $line_item->children() as $child ) {
190
-			if( $child->is_sub_line_item() ) {
191
-				EEH_Line_Item::update_quantity( $child, $qty );
189
+		foreach ($line_item->children() as $child) {
190
+			if ($child->is_sub_line_item()) {
191
+				EEH_Line_Item::update_quantity($child, $qty);
192 192
 			}
193 193
 		}
194 194
 	}
@@ -204,17 +204,17 @@  discard block
 block discarded – undo
204 204
 	 * @return void
205 205
 	 * @throws \EE_Error
206 206
 	 */
207
-	public static function decrement_quantity( EE_Line_Item $line_item, $qty = 1 ) {
208
-		if( ! $line_item->is_percent() ) {
207
+	public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1) {
208
+		if ( ! $line_item->is_percent()) {
209 209
 			$qty = $line_item->quantity() - $qty;
210
-			$qty = max( $qty, 0 );
211
-			$line_item->set_quantity( $qty );
212
-			$line_item->set_total( $line_item->unit_price() * $qty );
210
+			$qty = max($qty, 0);
211
+			$line_item->set_quantity($qty);
212
+			$line_item->set_total($line_item->unit_price() * $qty);
213 213
 			$line_item->save();
214 214
 		}
215
-		foreach( $line_item->children() as $child ) {
216
-			if( $child->is_sub_line_item() ) {
217
-				EEH_Line_Item::update_quantity( $child, $qty );
215
+		foreach ($line_item->children() as $child) {
216
+			if ($child->is_sub_line_item()) {
217
+				EEH_Line_Item::update_quantity($child, $qty);
218 218
 			}
219 219
 		}
220 220
 	}
@@ -229,15 +229,15 @@  discard block
 block discarded – undo
229 229
 	 * @param int          $new_quantity
230 230
 	 * @throws \EE_Error
231 231
 	 */
232
-	public static function update_quantity( EE_Line_Item $line_item, $new_quantity ) {
233
-		if( ! $line_item->is_percent() ) {
234
-			$line_item->set_quantity( $new_quantity );
235
-			$line_item->set_total( $line_item->unit_price() * $new_quantity );
232
+	public static function update_quantity(EE_Line_Item $line_item, $new_quantity) {
233
+		if ( ! $line_item->is_percent()) {
234
+			$line_item->set_quantity($new_quantity);
235
+			$line_item->set_total($line_item->unit_price() * $new_quantity);
236 236
 			$line_item->save();
237 237
 		}
238
-		foreach( $line_item->children() as $child ) {
239
-			if( $child->is_sub_line_item() ) {
240
-				EEH_Line_Item::update_quantity( $child, $new_quantity );
238
+		foreach ($line_item->children() as $child) {
239
+			if ($child->is_sub_line_item()) {
240
+				EEH_Line_Item::update_quantity($child, $new_quantity);
241 241
 			}
242 242
 		}
243 243
 	}
@@ -252,43 +252,43 @@  discard block
 block discarded – undo
252 252
 	 * @return \EE_Line_Item
253 253
 	 * @throws \EE_Error
254 254
 	 */
255
-	public static function create_ticket_line_item( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) {
255
+	public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) {
256 256
 		$datetimes = $ticket->datetimes();
257
-		$first_datetime = reset( $datetimes );
258
-		if( $first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event ) {
257
+		$first_datetime = reset($datetimes);
258
+		if ($first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event) {
259 259
 			$first_datetime_name = $first_datetime->event()->name();
260 260
 		} else {
261
-			$first_datetime_name = __( 'Event', 'event_espresso' );
261
+			$first_datetime_name = __('Event', 'event_espresso');
262 262
 		}
263
-		$event = sprintf( _x( '(For %1$s)', '(For Event Name)', 'event_espresso' ), $first_datetime_name );
263
+		$event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name);
264 264
 		// get event subtotal line
265
-		$events_sub_total = self::get_event_line_item_for_ticket( $total_line_item, $ticket );
265
+		$events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket);
266 266
 		// add $ticket to cart
267
-		$line_item = EE_Line_Item::new_instance( array(
267
+		$line_item = EE_Line_Item::new_instance(array(
268 268
 			'LIN_name'       	=> $ticket->name(),
269
-			'LIN_desc'       		=> $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event,
269
+			'LIN_desc'       		=> $ticket->description() !== '' ? $ticket->description().' '.$event : $event,
270 270
 			'LIN_unit_price' 	=> $ticket->price(),
271 271
 			'LIN_quantity'   	=> $qty,
272 272
 			'LIN_is_taxable' 	=> $ticket->taxable(),
273
-			'LIN_order'      	=> count( $events_sub_total->children() ),
273
+			'LIN_order'      	=> count($events_sub_total->children()),
274 274
 			'LIN_total'      		=> $ticket->price() * $qty,
275 275
 			'LIN_type'       		=> EEM_Line_Item::type_line_item,
276 276
 			'OBJ_ID'         		=> $ticket->ID(),
277 277
 			'OBJ_type'       	=> 'Ticket'
278
-		) );
278
+		));
279 279
 		$line_item = apply_filters(
280 280
 			'FHEE__EEH_Line_Item__create_ticket_line_item__line_item',
281 281
 			$line_item
282 282
 		);
283
-		$events_sub_total->add_child_line_item( $line_item );
283
+		$events_sub_total->add_child_line_item($line_item);
284 284
 		//now add the sub-line items
285 285
 		$running_total_for_ticket = 0;
286
-		foreach ( $ticket->prices( array( 'order_by' => array( 'PRC_order' => 'ASC' ) ) ) as $price ) {
286
+		foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) {
287 287
 			$sign = $price->is_discount() ? -1 : 1;
288 288
 			$price_total = $price->is_percent()
289 289
 				? $running_total_for_ticket * $price->amount() / 100
290 290
 				: $price->amount() * $qty;
291
-			$sub_line_item = EE_Line_Item::new_instance( array(
291
+			$sub_line_item = EE_Line_Item::new_instance(array(
292 292
 				'LIN_name'       	=> $price->name(),
293 293
 				'LIN_desc'       		=> $price->desc(),
294 294
 				'LIN_quantity'   	=> $price->is_percent() ? null : $qty,
@@ -298,18 +298,18 @@  discard block
 block discarded – undo
298 298
 				'LIN_type'       		=> EEM_Line_Item::type_sub_line_item,
299 299
 				'OBJ_ID'         		=> $price->ID(),
300 300
 				'OBJ_type'       	=> 'Price'
301
-			) );
301
+			));
302 302
 			$sub_line_item = apply_filters(
303 303
 				'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item',
304 304
 				$sub_line_item
305 305
 			);
306
-			if ( $price->is_percent() ) {
307
-				$sub_line_item->set_percent( $sign * $price->amount() );
306
+			if ($price->is_percent()) {
307
+				$sub_line_item->set_percent($sign * $price->amount());
308 308
 			} else {
309
-				$sub_line_item->set_unit_price( $sign * $price->amount() );
309
+				$sub_line_item->set_unit_price($sign * $price->amount());
310 310
 			}
311 311
 			$running_total_for_ticket += $price_total;
312
-			$line_item->add_child_line_item( $sub_line_item );
312
+			$line_item->add_child_line_item($sub_line_item);
313 313
 		}
314 314
 		return $line_item;
315 315
 	}
@@ -329,11 +329,11 @@  discard block
 block discarded – undo
329 329
 	 * @return boolean
330 330
 	 * @throws \EE_Error
331 331
 	 */
332
-	public static function add_item( EE_Line_Item $total_line_item, EE_Line_Item $item ){
333
-		$pre_tax_subtotal = self::get_pre_tax_subtotal( $total_line_item );
334
-		if ( $pre_tax_subtotal instanceof EE_Line_Item ){
332
+	public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) {
333
+		$pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item);
334
+		if ($pre_tax_subtotal instanceof EE_Line_Item) {
335 335
 			$success = $pre_tax_subtotal->add_child_line_item($item);
336
-		}else{
336
+		} else {
337 337
 			return FALSE;
338 338
 		}
339 339
 		$total_line_item->recalculate_total_including_taxes();
@@ -352,34 +352,34 @@  discard block
 block discarded – undo
352 352
 	 * @return bool success
353 353
 	 * @throws \EE_Error
354 354
 	 */
355
-	public static function cancel_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) {
355
+	public static function cancel_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) {
356 356
 		// validate incoming line_item
357
-		if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) {
357
+		if ($ticket_line_item->OBJ_type() !== 'Ticket') {
358 358
 			throw new EE_Error(
359 359
 				sprintf(
360
-					__( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ),
360
+					__('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'),
361 361
 					$ticket_line_item->type()
362 362
 				)
363 363
 			);
364 364
 		}
365
-		if ( $ticket_line_item->quantity() < $qty ) {
365
+		if ($ticket_line_item->quantity() < $qty) {
366 366
 			throw new EE_Error(
367 367
 				sprintf(
368
-					__( 'Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso' ),
368
+					__('Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso'),
369 369
 					$qty,
370 370
 					$ticket_line_item->quantity()
371 371
 				)
372 372
 			);
373 373
 		}
374 374
 		// decrement ticket quantity; don't rely on auto-fixing when recalculating totals to do this
375
-		$ticket_line_item->set_quantity( $ticket_line_item->quantity() - $qty );
376
-		foreach( $ticket_line_item->children() as $child_line_item ) {
377
-			if(
375
+		$ticket_line_item->set_quantity($ticket_line_item->quantity() - $qty);
376
+		foreach ($ticket_line_item->children() as $child_line_item) {
377
+			if (
378 378
 				$child_line_item->is_sub_line_item()
379 379
 				&& ! $child_line_item->is_percent()
380 380
 				&& ! $child_line_item->is_cancellation()
381 381
 			) {
382
-				$child_line_item->set_quantity( $child_line_item->quantity() - $qty );
382
+				$child_line_item->set_quantity($child_line_item->quantity() - $qty);
383 383
 			}
384 384
 		}
385 385
 		// get cancellation sub line item
@@ -387,37 +387,37 @@  discard block
 block discarded – undo
387 387
 			$ticket_line_item,
388 388
 			EEM_Line_Item::type_cancellation
389 389
 		);
390
-		$cancellation_line_item = reset( $cancellation_line_item );
390
+		$cancellation_line_item = reset($cancellation_line_item);
391 391
 		// verify that this ticket was indeed previously cancelled
392
-		if ( $cancellation_line_item instanceof EE_Line_Item ) {
392
+		if ($cancellation_line_item instanceof EE_Line_Item) {
393 393
 			// increment cancelled quantity
394
-			$cancellation_line_item->set_quantity( $cancellation_line_item->quantity() + $qty );
394
+			$cancellation_line_item->set_quantity($cancellation_line_item->quantity() + $qty);
395 395
 		} else {
396 396
 			// create cancellation sub line item
397
-			$cancellation_line_item = EE_Line_Item::new_instance( array(
398
-				'LIN_name'       => __( 'Cancellation', 'event_espresso' ),
397
+			$cancellation_line_item = EE_Line_Item::new_instance(array(
398
+				'LIN_name'       => __('Cancellation', 'event_espresso'),
399 399
 				'LIN_desc'       => sprintf(
400
-					_x( 'Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso' ),
400
+					_x('Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso'),
401 401
 					$ticket_line_item->name(),
402
-					current_time( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) )
402
+					current_time(get_option('date_format').' '.get_option('time_format'))
403 403
 				),
404 404
 				'LIN_unit_price' => 0, // $ticket_line_item->unit_price()
405 405
 				'LIN_quantity'   => $qty,
406 406
 				'LIN_is_taxable' => $ticket_line_item->is_taxable(),
407
-				'LIN_order'      => count( $ticket_line_item->children() ),
407
+				'LIN_order'      => count($ticket_line_item->children()),
408 408
 				'LIN_total'      => 0, // $ticket_line_item->unit_price()
409 409
 				'LIN_type'       => EEM_Line_Item::type_cancellation,
410
-			) );
411
-			$ticket_line_item->add_child_line_item( $cancellation_line_item );
410
+			));
411
+			$ticket_line_item->add_child_line_item($cancellation_line_item);
412 412
 		}
413
-		if ( $ticket_line_item->save_this_and_descendants() > 0 ) {
413
+		if ($ticket_line_item->save_this_and_descendants() > 0) {
414 414
 			// decrement parent line item quantity
415 415
 			$event_line_item = $ticket_line_item->parent();
416
-			if ( $event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event' ) {
417
-				$event_line_item->set_quantity( $event_line_item->quantity() - $qty );
416
+			if ($event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event') {
417
+				$event_line_item->set_quantity($event_line_item->quantity() - $qty);
418 418
 				$event_line_item->save();
419 419
 			}
420
-			EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item );
420
+			EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item);
421 421
 			return true;
422 422
 		}
423 423
 		return false;
@@ -435,12 +435,12 @@  discard block
 block discarded – undo
435 435
 	 * @return bool success
436 436
 	 * @throws \EE_Error
437 437
 	 */
438
-	public static function reinstate_canceled_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) {
438
+	public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) {
439 439
 		// validate incoming line_item
440
-		if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) {
440
+		if ($ticket_line_item->OBJ_type() !== 'Ticket') {
441 441
 			throw new EE_Error(
442 442
 				sprintf(
443
-					__( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ),
443
+					__('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'),
444 444
 					$ticket_line_item->type()
445 445
 				)
446 446
 			);
@@ -450,42 +450,42 @@  discard block
 block discarded – undo
450 450
 			$ticket_line_item,
451 451
 			EEM_Line_Item::type_cancellation
452 452
 		);
453
-		$cancellation_line_item = reset( $cancellation_line_item );
453
+		$cancellation_line_item = reset($cancellation_line_item);
454 454
 		// verify that this ticket was indeed previously cancelled
455
-		if ( ! $cancellation_line_item instanceof EE_Line_Item ) {
455
+		if ( ! $cancellation_line_item instanceof EE_Line_Item) {
456 456
 			return false;
457 457
 		}
458
-		if ( $cancellation_line_item->quantity() > $qty ) {
458
+		if ($cancellation_line_item->quantity() > $qty) {
459 459
 			// decrement cancelled quantity
460
-			$cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty );
461
-		} else if ( $cancellation_line_item->quantity() == $qty ) {
460
+			$cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty);
461
+		} else if ($cancellation_line_item->quantity() == $qty) {
462 462
 			// decrement cancelled quantity in case anyone still has the object kicking around
463
-			$cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty );
463
+			$cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty);
464 464
 			// delete because quantity will end up as 0
465 465
 			$cancellation_line_item->delete();
466 466
 			// and attempt to destroy the object,
467 467
 			// even though PHP won't actually destroy it until it needs the memory
468
-			unset( $cancellation_line_item );
468
+			unset($cancellation_line_item);
469 469
 		} else {
470 470
 			// what ?!?! negative quantity ?!?!
471 471
 			throw new EE_Error(
472 472
 				sprintf(
473
-					__( 'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.',
474
-						'event_espresso' ),
473
+					__('Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.',
474
+						'event_espresso'),
475 475
 					$qty,
476 476
 					$cancellation_line_item->quantity()
477 477
 				)
478 478
 			);
479 479
 		}
480 480
 		// increment ticket quantity
481
-		$ticket_line_item->set_quantity( $ticket_line_item->quantity() + $qty );
482
-		if ( $ticket_line_item->save_this_and_descendants() > 0 ) {
481
+		$ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty);
482
+		if ($ticket_line_item->save_this_and_descendants() > 0) {
483 483
 			// increment parent line item quantity
484 484
 			$event_line_item = $ticket_line_item->parent();
485
-			if ( $event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event' ) {
486
-				$event_line_item->set_quantity( $event_line_item->quantity() + $qty );
485
+			if ($event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event') {
486
+				$event_line_item->set_quantity($event_line_item->quantity() + $qty);
487 487
 			}
488
-			EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item );
488
+			EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item);
489 489
 			return true;
490 490
 		}
491 491
 		return false;
@@ -500,8 +500,8 @@  discard block
 block discarded – undo
500 500
 	 * @param EE_Line_Item $line_item
501 501
 	 * @return \EE_Line_Item
502 502
 	 */
503
-	public static function get_grand_total_and_recalculate_everything( EE_Line_Item $line_item ){
504
-		$grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item );
503
+	public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item) {
504
+		$grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item);
505 505
 		return $grand_total_line_item->recalculate_total_including_taxes();
506 506
 	}
507 507
 
@@ -514,11 +514,11 @@  discard block
 block discarded – undo
514 514
 	 * @return \EE_Line_Item
515 515
 	 * @throws \EE_Error
516 516
 	 */
517
-	public static function get_pre_tax_subtotal( EE_Line_Item $total_line_item ){
518
-		$pre_tax_subtotal = $total_line_item->get_child_line_item( 'pre-tax-subtotal' );
517
+	public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) {
518
+		$pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal');
519 519
 		return $pre_tax_subtotal instanceof EE_Line_Item
520 520
 			? $pre_tax_subtotal
521
-			: self::create_pre_tax_subtotal( $total_line_item );
521
+			: self::create_pre_tax_subtotal($total_line_item);
522 522
 	}
523 523
 
524 524
 
@@ -530,9 +530,9 @@  discard block
 block discarded – undo
530 530
 	 * @return \EE_Line_Item
531 531
 	 * @throws \EE_Error
532 532
 	 */
533
-	public static function get_taxes_subtotal( EE_Line_Item $total_line_item ){
534
-		$taxes = $total_line_item->get_child_line_item( 'taxes' );
535
-		return $taxes ? $taxes : self::create_taxes_subtotal( $total_line_item );
533
+	public static function get_taxes_subtotal(EE_Line_Item $total_line_item) {
534
+		$taxes = $total_line_item->get_child_line_item('taxes');
535
+		return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item);
536 536
 	}
537 537
 
538 538
 
@@ -545,12 +545,12 @@  discard block
 block discarded – undo
545 545
 	 * @return void
546 546
 	 * @throws \EE_Error
547 547
 	 */
548
-	public static function set_TXN_ID( EE_Line_Item $line_item, $transaction = NULL ){
549
-		if( $transaction ){
548
+	public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = NULL) {
549
+		if ($transaction) {
550 550
 			/** @type EEM_Transaction $EEM_Transaction */
551
-			$EEM_Transaction = EE_Registry::instance()->load_model( 'Transaction' );
552
-			$TXN_ID = $EEM_Transaction->ensure_is_ID( $transaction );
553
-			$line_item->set_TXN_ID( $TXN_ID );
551
+			$EEM_Transaction = EE_Registry::instance()->load_model('Transaction');
552
+			$TXN_ID = $EEM_Transaction->ensure_is_ID($transaction);
553
+			$line_item->set_TXN_ID($TXN_ID);
554 554
 		}
555 555
 	}
556 556
 
@@ -565,8 +565,8 @@  discard block
 block discarded – undo
565 565
 	 * @return \EE_Line_Item of type total
566 566
 	 * @throws \EE_Error
567 567
 	 */
568
-	public static function create_total_line_item( $transaction = NULL ){
569
-		$total_line_item = EE_Line_Item::new_instance( array(
568
+	public static function create_total_line_item($transaction = NULL) {
569
+		$total_line_item = EE_Line_Item::new_instance(array(
570 570
 			'LIN_code'	=> 'total',
571 571
 			'LIN_name'	=> __('Grand Total', 'event_espresso'),
572 572
 			'LIN_type'	=> EEM_Line_Item::type_total,
@@ -576,9 +576,9 @@  discard block
 block discarded – undo
576 576
 			'FHEE__EEH_Line_Item__create_total_line_item__total_line_item',
577 577
 			$total_line_item
578 578
 		);
579
-		self::set_TXN_ID( $total_line_item, $transaction );
580
-		self::create_pre_tax_subtotal( $total_line_item, $transaction );
581
-		self::create_taxes_subtotal( $total_line_item, $transaction );
579
+		self::set_TXN_ID($total_line_item, $transaction);
580
+		self::create_pre_tax_subtotal($total_line_item, $transaction);
581
+		self::create_taxes_subtotal($total_line_item, $transaction);
582 582
 		return $total_line_item;
583 583
 	}
584 584
 
@@ -592,19 +592,19 @@  discard block
 block discarded – undo
592 592
 	 * @return EE_Line_Item
593 593
 	 * @throws \EE_Error
594 594
 	 */
595
-	protected static function create_pre_tax_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){
596
-		$pre_tax_line_item = EE_Line_Item::new_instance( array(
595
+	protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
596
+		$pre_tax_line_item = EE_Line_Item::new_instance(array(
597 597
 			'LIN_code' 	=> 'pre-tax-subtotal',
598
-			'LIN_name' 	=> __( 'Pre-Tax Subtotal', 'event_espresso' ),
598
+			'LIN_name' 	=> __('Pre-Tax Subtotal', 'event_espresso'),
599 599
 			'LIN_type' 	=> EEM_Line_Item::type_sub_total
600
-		) );
600
+		));
601 601
 		$pre_tax_line_item = apply_filters(
602 602
 			'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item',
603 603
 			$pre_tax_line_item
604 604
 		);
605
-		self::set_TXN_ID( $pre_tax_line_item, $transaction );
606
-		$total_line_item->add_child_line_item( $pre_tax_line_item );
607
-		self::create_event_subtotal( $pre_tax_line_item, $transaction );
605
+		self::set_TXN_ID($pre_tax_line_item, $transaction);
606
+		$total_line_item->add_child_line_item($pre_tax_line_item);
607
+		self::create_event_subtotal($pre_tax_line_item, $transaction);
608 608
 		return $pre_tax_line_item;
609 609
 	}
610 610
 
@@ -619,21 +619,21 @@  discard block
 block discarded – undo
619 619
 	 * @return EE_Line_Item
620 620
 	 * @throws \EE_Error
621 621
 	 */
622
-	protected static function create_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){
622
+	protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
623 623
 		$tax_line_item = EE_Line_Item::new_instance(array(
624 624
 			'LIN_code'	=> 'taxes',
625 625
 			'LIN_name' 	=> __('Taxes', 'event_espresso'),
626 626
 			'LIN_type'	=> EEM_Line_Item::type_tax_sub_total,
627
-			'LIN_order' => 1000,//this should always come last
627
+			'LIN_order' => 1000, //this should always come last
628 628
 		));
629 629
 		$tax_line_item = apply_filters(
630 630
 			'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item',
631 631
 			$tax_line_item
632 632
 		);
633
-		self::set_TXN_ID( $tax_line_item, $transaction );
634
-		$total_line_item->add_child_line_item( $tax_line_item );
633
+		self::set_TXN_ID($tax_line_item, $transaction);
634
+		$total_line_item->add_child_line_item($tax_line_item);
635 635
 		//and lastly, add the actual taxes
636
-		self::apply_taxes( $total_line_item );
636
+		self::apply_taxes($total_line_item);
637 637
 		return $tax_line_item;
638 638
 	}
639 639
 
@@ -648,11 +648,11 @@  discard block
 block discarded – undo
648 648
 	 * @return EE_Line_Item
649 649
 	 * @throws \EE_Error
650 650
 	 */
651
-	public static function create_event_subtotal( EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL ){
651
+	public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL) {
652 652
 		$event_line_item = EE_Line_Item::new_instance(array(
653
-			'LIN_code'	=> self::get_event_code( $event ),
654
-			'LIN_name' 	=> self::get_event_name( $event ),
655
-			'LIN_desc' 	=> self::get_event_desc( $event ),
653
+			'LIN_code'	=> self::get_event_code($event),
654
+			'LIN_name' 	=> self::get_event_name($event),
655
+			'LIN_desc' 	=> self::get_event_desc($event),
656 656
 			'LIN_type'	=> EEM_Line_Item::type_sub_total,
657 657
 			'OBJ_type' 	=> 'Event',
658 658
 			'OBJ_ID' 		=>  $event instanceof EE_Event ? $event->ID() : 0
@@ -661,8 +661,8 @@  discard block
 block discarded – undo
661 661
 			'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item',
662 662
 			$event_line_item
663 663
 		);
664
-		self::set_TXN_ID( $event_line_item, $transaction );
665
-		$pre_tax_line_item->add_child_line_item( $event_line_item );
664
+		self::set_TXN_ID($event_line_item, $transaction);
665
+		$pre_tax_line_item->add_child_line_item($event_line_item);
666 666
 		return $event_line_item;
667 667
 	}
668 668
 
@@ -675,8 +675,8 @@  discard block
 block discarded – undo
675 675
 	 * @return string
676 676
 	 * @throws \EE_Error
677 677
 	 */
678
-	public static function get_event_code( $event ) {
679
-		return 'event-' . ( $event instanceof EE_Event ? $event->ID() : '0' );
678
+	public static function get_event_code($event) {
679
+		return 'event-'.($event instanceof EE_Event ? $event->ID() : '0');
680 680
 	}
681 681
 
682 682
 	/**
@@ -684,8 +684,8 @@  discard block
 block discarded – undo
684 684
 	 * @param EE_Event $event
685 685
 	 * @return string
686 686
 	 */
687
-	public static function get_event_name( $event ) {
688
-		return $event instanceof EE_Event ? $event->name() : __( 'Event', 'event_espresso' );
687
+	public static function get_event_name($event) {
688
+		return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso');
689 689
 	}
690 690
 
691 691
 	/**
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
 	 * @param EE_Event $event
694 694
 	 * @return string
695 695
 	 */
696
-	public static function get_event_desc( $event ) {
696
+	public static function get_event_desc($event) {
697 697
 		return $event instanceof EE_Event ? $event->short_description() : '';
698 698
 	}
699 699
 
@@ -707,27 +707,27 @@  discard block
 block discarded – undo
707 707
 	  * @throws \EE_Error
708 708
 	  * @return EE_Line_Item
709 709
 	  */
710
-	public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) {
710
+	public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) {
711 711
 		$first_datetime = $ticket->first_datetime();
712
-		if ( ! $first_datetime instanceof EE_Datetime ) {
712
+		if ( ! $first_datetime instanceof EE_Datetime) {
713 713
 			throw new EE_Error(
714
-				sprintf( __( 'The supplied ticket (ID %d) has no datetimes', 'event_espresso' ), $ticket->ID() )
714
+				sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID())
715 715
 			);
716 716
 		}
717 717
 		$event = $first_datetime->event();
718
-		if ( ! $event instanceof EE_Event ) {
718
+		if ( ! $event instanceof EE_Event) {
719 719
 			throw new EE_Error(
720 720
 				sprintf(
721
-					__( 'The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso' ),
721
+					__('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'),
722 722
 					$ticket->ID()
723 723
 				)
724 724
 			);
725 725
 		}
726
-		$events_sub_total = EEH_Line_Item::get_event_line_item( $grand_total, $event );
727
-		if ( ! $events_sub_total instanceof EE_Line_Item ) {
726
+		$events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event);
727
+		if ( ! $events_sub_total instanceof EE_Line_Item) {
728 728
 			throw new EE_Error(
729 729
 				sprintf(
730
-					__( 'There is no events sub-total for ticket %s on total line item %d', 'event_espresso' ),
730
+					__('There is no events sub-total for ticket %s on total line item %d', 'event_espresso'),
731 731
 					$ticket->ID(),
732 732
 					$grand_total->ID()
733 733
 				)
@@ -746,31 +746,31 @@  discard block
 block discarded – undo
746 746
 	 * @return EE_Line_Item for the event subtotal which is a child of $grand_total
747 747
 	 * @throws \EE_Error
748 748
 	 */
749
-	public static function get_event_line_item( EE_Line_Item $grand_total, $event ) {
749
+	public static function get_event_line_item(EE_Line_Item $grand_total, $event) {
750 750
 		/** @type EE_Event $event */
751
-		$event = EEM_Event::instance()->ensure_is_obj( $event, true );
751
+		$event = EEM_Event::instance()->ensure_is_obj($event, true);
752 752
 		$event_line_item = NULL;
753 753
 		$found = false;
754
-		foreach ( EEH_Line_Item::get_event_subtotals( $grand_total ) as $event_line_item ) {
754
+		foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) {
755 755
 			// default event subtotal, we should only ever find this the first time this method is called
756
-			if ( ! $event_line_item->OBJ_ID() ) {
756
+			if ( ! $event_line_item->OBJ_ID()) {
757 757
 				// let's use this! but first... set the event details
758
-				EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event );
758
+				EEH_Line_Item::set_event_subtotal_details($event_line_item, $event);
759 759
 				$found = true;
760 760
 				break;
761
-			} else if ( $event_line_item->OBJ_ID() === $event->ID() ) {
761
+			} else if ($event_line_item->OBJ_ID() === $event->ID()) {
762 762
 				// found existing line item for this event in the cart, so break out of loop and use this one
763 763
 				$found = true;
764 764
 				break;
765 765
 			}
766 766
 		}
767
-		if ( ! $found ) {
767
+		if ( ! $found) {
768 768
 			//there is no event sub-total yet, so add it
769
-			$pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total );
769
+			$pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total);
770 770
 			// create a new "event" subtotal below that
771
-			$event_line_item = EEH_Line_Item::create_event_subtotal( $pre_tax_subtotal, null, $event );
771
+			$event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event);
772 772
 			// and set the event details
773
-			EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event );
773
+			EEH_Line_Item::set_event_subtotal_details($event_line_item, $event);
774 774
 		}
775 775
 		return $event_line_item;
776 776
 	}
@@ -791,13 +791,13 @@  discard block
 block discarded – undo
791 791
 		EE_Event $event,
792 792
 		$transaction = null
793 793
 	) {
794
-		if ( $event instanceof EE_Event ) {
795
-			$event_line_item->set_code( self::get_event_code( $event ) );
796
-			$event_line_item->set_name( self::get_event_name( $event ) );
797
-			$event_line_item->set_desc( self::get_event_desc( $event ) );
798
-			$event_line_item->set_OBJ_ID( $event->ID() );
794
+		if ($event instanceof EE_Event) {
795
+			$event_line_item->set_code(self::get_event_code($event));
796
+			$event_line_item->set_name(self::get_event_name($event));
797
+			$event_line_item->set_desc(self::get_event_desc($event));
798
+			$event_line_item->set_OBJ_ID($event->ID());
799 799
 		}
800
-		self::set_TXN_ID( $event_line_item, $transaction );
800
+		self::set_TXN_ID($event_line_item, $transaction);
801 801
 	}
802 802
 
803 803
 
@@ -810,19 +810,19 @@  discard block
 block discarded – undo
810 810
 	 * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
811 811
 	 * @throws \EE_Error
812 812
 	 */
813
-	public static function apply_taxes( EE_Line_Item $total_line_item ){
813
+	public static function apply_taxes(EE_Line_Item $total_line_item) {
814 814
 		/** @type EEM_Price $EEM_Price */
815
-		$EEM_Price = EE_Registry::instance()->load_model( 'Price' );
815
+		$EEM_Price = EE_Registry::instance()->load_model('Price');
816 816
 		// get array of taxes via Price Model
817 817
 		$ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes();
818
-		ksort( $ordered_taxes );
819
-		$taxes_line_item = self::get_taxes_subtotal( $total_line_item );
818
+		ksort($ordered_taxes);
819
+		$taxes_line_item = self::get_taxes_subtotal($total_line_item);
820 820
 		//just to be safe, remove its old tax line items
821 821
 		$taxes_line_item->delete_children_line_items();
822 822
 		//loop thru taxes
823
-		foreach ( $ordered_taxes as $order => $taxes ) {
824
-			foreach ( $taxes as $tax ) {
825
-				if ( $tax instanceof EE_Price ) {
823
+		foreach ($ordered_taxes as $order => $taxes) {
824
+			foreach ($taxes as $tax) {
825
+				if ($tax instanceof EE_Price) {
826 826
 					$tax_line_item = EE_Line_Item::new_instance(
827 827
 						array(
828 828
 							'LIN_name'       => $tax->name(),
@@ -840,7 +840,7 @@  discard block
 block discarded – undo
840 840
 						'FHEE__EEH_Line_Item__apply_taxes__tax_line_item',
841 841
 						$tax_line_item
842 842
 					);
843
-					$taxes_line_item->add_child_line_item( $tax_line_item );
843
+					$taxes_line_item->add_child_line_item($tax_line_item);
844 844
 				}
845 845
 			}
846 846
 		}
@@ -857,10 +857,10 @@  discard block
 block discarded – undo
857 857
 	 * @return float
858 858
 	 * @throws \EE_Error
859 859
 	 */
860
-	public static function ensure_taxes_applied( $total_line_item ){
861
-		$taxes_subtotal = self::get_taxes_subtotal( $total_line_item );
862
-		if( ! $taxes_subtotal->children()){
863
-			self::apply_taxes( $total_line_item );
860
+	public static function ensure_taxes_applied($total_line_item) {
861
+		$taxes_subtotal = self::get_taxes_subtotal($total_line_item);
862
+		if ( ! $taxes_subtotal->children()) {
863
+			self::apply_taxes($total_line_item);
864 864
 		}
865 865
 		return $taxes_subtotal->total();
866 866
 	}
@@ -874,16 +874,16 @@  discard block
 block discarded – undo
874 874
 	 * @return bool
875 875
 	 * @throws \EE_Error
876 876
 	 */
877
-	public static function delete_all_child_items( EE_Line_Item $parent_line_item ) {
877
+	public static function delete_all_child_items(EE_Line_Item $parent_line_item) {
878 878
 		$deleted = 0;
879
-		foreach ( $parent_line_item->children() as $child_line_item ) {
880
-			if ( $child_line_item instanceof EE_Line_Item ) {
881
-				$deleted += EEH_Line_Item::delete_all_child_items( $child_line_item );
882
-				if ( $child_line_item->ID() ) {
879
+		foreach ($parent_line_item->children() as $child_line_item) {
880
+			if ($child_line_item instanceof EE_Line_Item) {
881
+				$deleted += EEH_Line_Item::delete_all_child_items($child_line_item);
882
+				if ($child_line_item->ID()) {
883 883
 					$child_line_item->delete();
884
-					unset( $child_line_item );
884
+					unset($child_line_item);
885 885
 				} else {
886
-					$parent_line_item->delete_child_line_item( $child_line_item->code() );
886
+					$parent_line_item->delete_child_line_item($child_line_item->code());
887 887
 				}
888 888
 				$deleted++;
889 889
 			}
@@ -905,9 +905,9 @@  discard block
 block discarded – undo
905 905
 	 * @param array|bool|string $line_item_codes
906 906
 	 * @return int number of items successfully removed
907 907
 	 */
908
-	public static function delete_items( EE_Line_Item $total_line_item, $line_item_codes = FALSE ) {
908
+	public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = FALSE) {
909 909
 
910
-		if( $total_line_item->type() !== EEM_Line_Item::type_total ){
910
+		if ($total_line_item->type() !== EEM_Line_Item::type_total) {
911 911
 			EE_Error::doing_it_wrong(
912 912
 				'EEH_Line_Item::delete_items',
913 913
 				__(
@@ -917,20 +917,20 @@  discard block
 block discarded – undo
917 917
 				'4.6.18'
918 918
 			);
919 919
 		}
920
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
920
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
921 921
 
922 922
 		// check if only a single line_item_id was passed
923
-		if ( ! empty( $line_item_codes ) && ! is_array( $line_item_codes )) {
923
+		if ( ! empty($line_item_codes) && ! is_array($line_item_codes)) {
924 924
 			// place single line_item_id in an array to appear as multiple line_item_ids
925
-			$line_item_codes = array ( $line_item_codes );
925
+			$line_item_codes = array($line_item_codes);
926 926
 		}
927 927
 		$removals = 0;
928 928
 		// cycle thru line_item_ids
929
-		foreach ( $line_item_codes as $line_item_id ) {
929
+		foreach ($line_item_codes as $line_item_id) {
930 930
 			$removals += $total_line_item->delete_child_line_item($line_item_id);
931 931
 		}
932 932
 
933
-		if ( $removals > 0 ) {
933
+		if ($removals > 0) {
934 934
 			$total_line_item->recalculate_taxes_and_tax_total();
935 935
 			return $removals;
936 936
 		} else {
@@ -963,33 +963,33 @@  discard block
 block discarded – undo
963 963
 		$code = null,
964 964
 		$add_to_existing_line_item = false
965 965
 	) {
966
-		$tax_subtotal = self::get_taxes_subtotal( $total_line_item );
966
+		$tax_subtotal = self::get_taxes_subtotal($total_line_item);
967 967
             $taxable_total = $total_line_item->taxable_total();
968 968
 
969
-            if( $add_to_existing_line_item ) {
970
-                $new_tax = $tax_subtotal->get_child_line_item( $code );
969
+            if ($add_to_existing_line_item) {
970
+                $new_tax = $tax_subtotal->get_child_line_item($code);
971 971
 	            EEM_Line_Item::instance()->delete(
972
-		            array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) )
972
+		            array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID()))
973 973
 	            );
974 974
             } else {
975 975
                 $new_tax = null;
976 976
                 $tax_subtotal->delete_children_line_items();
977 977
             }
978
-            if( $new_tax ) {
979
-                $new_tax->set_total( $new_tax->total() + $amount );
980
-                $new_tax->set_percent( $taxable_total ? $new_tax->total() / $taxable_total * 100 : 0 );
978
+            if ($new_tax) {
979
+                $new_tax->set_total($new_tax->total() + $amount);
980
+                $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0);
981 981
             } else {
982 982
                 //no existing tax item. Create it
983
-				$new_tax = EE_Line_Item::new_instance( array(
983
+				$new_tax = EE_Line_Item::new_instance(array(
984 984
 					'TXN_ID'      => $total_line_item->TXN_ID(),
985
-					'LIN_name'    => $name ? $name : __( 'Tax', 'event_espresso' ),
985
+					'LIN_name'    => $name ? $name : __('Tax', 'event_espresso'),
986 986
 					'LIN_desc'    => $description ? $description : '',
987
-					'LIN_percent' => $taxable_total ? ( $amount / $taxable_total * 100 ) : 0,
987
+					'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0,
988 988
 					'LIN_total'   => $amount,
989 989
 					'LIN_parent'  => $tax_subtotal->ID(),
990 990
 					'LIN_type'    => EEM_Line_Item::type_tax,
991 991
 					'LIN_code'    => $code
992
-				) );
992
+				));
993 993
 			}
994 994
 
995 995
             $new_tax = apply_filters(
@@ -998,7 +998,7 @@  discard block
 block discarded – undo
998 998
 				$total_line_item
999 999
             );
1000 1000
             $new_tax->save();
1001
-            $tax_subtotal->set_total( $new_tax->total() );
1001
+            $tax_subtotal->set_total($new_tax->total());
1002 1002
             $tax_subtotal->save();
1003 1003
             $total_line_item->recalculate_total_including_taxes();
1004 1004
             return $new_tax;
@@ -1020,14 +1020,14 @@  discard block
 block discarded – undo
1020 1020
 		$code_substring_for_whitelist = null
1021 1021
 	) {
1022 1022
 		$whitelisted = false;
1023
-		if( $code_substring_for_whitelist !== null ) {
1024
-			$whitelisted = strpos( $line_item->code(), $code_substring_for_whitelist ) !== false ? true : false;
1023
+		if ($code_substring_for_whitelist !== null) {
1024
+			$whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false ? true : false;
1025 1025
 		}
1026
-		if( ! $whitelisted && $line_item->is_line_item() ) {
1027
-			$line_item->set_is_taxable( $taxable );
1026
+		if ( ! $whitelisted && $line_item->is_line_item()) {
1027
+			$line_item->set_is_taxable($taxable);
1028 1028
 		}
1029
-		foreach( $line_item->children() as $child_line_item ) {
1030
-			EEH_Line_Item::set_line_items_taxable( $child_line_item, $taxable, $code_substring_for_whitelist );
1029
+		foreach ($line_item->children() as $child_line_item) {
1030
+			EEH_Line_Item::set_line_items_taxable($child_line_item, $taxable, $code_substring_for_whitelist);
1031 1031
 		}
1032 1032
 	}
1033 1033
 
@@ -1040,8 +1040,8 @@  discard block
 block discarded – undo
1040 1040
 	 * @param \EE_Line_Item $parent_line_item - the line item to find descendants of
1041 1041
 	 * @return EE_Line_Item[]
1042 1042
 	 */
1043
-	public static function get_event_subtotals( EE_Line_Item $parent_line_item ) {
1044
-		return self::get_subtotals_of_object_type( $parent_line_item, 'Event' );
1043
+	public static function get_event_subtotals(EE_Line_Item $parent_line_item) {
1044
+		return self::get_subtotals_of_object_type($parent_line_item, 'Event');
1045 1045
 	}
1046 1046
 
1047 1047
 
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
 	 * @param string $obj_type
1055 1055
 	 * @return EE_Line_Item[]
1056 1056
 	 */
1057
-	public static function get_subtotals_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) {
1057
+	public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') {
1058 1058
 		return self::_get_descendants_by_type_and_object_type(
1059 1059
 			$parent_line_item,
1060 1060
 			EEM_Line_Item::type_sub_total,
@@ -1071,8 +1071,8 @@  discard block
 block discarded – undo
1071 1071
 	 * @param \EE_Line_Item $parent_line_item - the line item to find descendants of
1072 1072
 	 * @return EE_Line_Item[]
1073 1073
 	 */
1074
-	public static function get_ticket_line_items( EE_Line_Item $parent_line_item ) {
1075
-		return self::get_line_items_of_object_type( $parent_line_item, 'Ticket' );
1074
+	public static function get_ticket_line_items(EE_Line_Item $parent_line_item) {
1075
+		return self::get_line_items_of_object_type($parent_line_item, 'Ticket');
1076 1076
 	}
1077 1077
 
1078 1078
 
@@ -1085,8 +1085,8 @@  discard block
 block discarded – undo
1085 1085
 	 * @param string $obj_type
1086 1086
 	 * @return EE_Line_Item[]
1087 1087
 	 */
1088
-	public static function get_line_items_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) {
1089
-		return self::_get_descendants_by_type_and_object_type( $parent_line_item, EEM_Line_Item::type_line_item, $obj_type );
1088
+	public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') {
1089
+		return self::_get_descendants_by_type_and_object_type($parent_line_item, EEM_Line_Item::type_line_item, $obj_type);
1090 1090
 	}
1091 1091
 
1092 1092
 
@@ -1097,8 +1097,8 @@  discard block
 block discarded – undo
1097 1097
 	 * @param \EE_Line_Item $parent_line_item - the line item to find descendants of
1098 1098
 	 * @return EE_Line_Item[]
1099 1099
 	 */
1100
-	public static function get_tax_descendants( EE_Line_Item $parent_line_item ) {
1101
-		return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_tax );
1100
+	public static function get_tax_descendants(EE_Line_Item $parent_line_item) {
1101
+		return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_tax);
1102 1102
 	}
1103 1103
 
1104 1104
 
@@ -1109,8 +1109,8 @@  discard block
 block discarded – undo
1109 1109
 	 * @param \EE_Line_Item $parent_line_item - the line item to find descendants of
1110 1110
 	 * @return EE_Line_Item[]
1111 1111
 	 */
1112
-	public static function get_line_item_descendants( EE_Line_Item $parent_line_item ) {
1113
-		return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_line_item );
1112
+	public static function get_line_item_descendants(EE_Line_Item $parent_line_item) {
1113
+		return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_line_item);
1114 1114
 	}
1115 1115
 
1116 1116
 
@@ -1123,8 +1123,8 @@  discard block
 block discarded – undo
1123 1123
 	 * @param string $line_item_type one of the EEM_Line_Item constants
1124 1124
 	 * @return EE_Line_Item[]
1125 1125
 	 */
1126
-	public static function get_descendants_of_type( EE_Line_Item $parent_line_item, $line_item_type ) {
1127
-		return self::_get_descendants_by_type_and_object_type( $parent_line_item, $line_item_type, NULL );
1126
+	public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) {
1127
+		return self::_get_descendants_by_type_and_object_type($parent_line_item, $line_item_type, NULL);
1128 1128
 	}
1129 1129
 
1130 1130
 
@@ -1143,8 +1143,8 @@  discard block
 block discarded – undo
1143 1143
 		$obj_type = null
1144 1144
 	) {
1145 1145
 		$objects = array();
1146
-		foreach ( $parent_line_item->children() as $child_line_item ) {
1147
-			if ( $child_line_item instanceof EE_Line_Item ) {
1146
+		foreach ($parent_line_item->children() as $child_line_item) {
1147
+			if ($child_line_item instanceof EE_Line_Item) {
1148 1148
 				if (
1149 1149
 					$child_line_item->type() === $line_item_type
1150 1150
 				    && (
@@ -1184,7 +1184,7 @@  discard block
 block discarded – undo
1184 1184
 		$OBJ_type = '',
1185 1185
 		$OBJ_IDs = array()
1186 1186
 	) {
1187
-		return self::_get_descendants_by_object_type_and_object_ID( $parent_line_item, $OBJ_type, $OBJ_IDs );
1187
+		return self::_get_descendants_by_object_type_and_object_ID($parent_line_item, $OBJ_type, $OBJ_IDs);
1188 1188
 	}
1189 1189
 
1190 1190
 
@@ -1203,12 +1203,12 @@  discard block
 block discarded – undo
1203 1203
 		$OBJ_IDs
1204 1204
 	) {
1205 1205
 		$objects = array();
1206
-		foreach ( $parent_line_item->children() as $child_line_item ) {
1207
-			if ( $child_line_item instanceof EE_Line_Item ) {
1206
+		foreach ($parent_line_item->children() as $child_line_item) {
1207
+			if ($child_line_item instanceof EE_Line_Item) {
1208 1208
 				if (
1209 1209
 					$child_line_item->OBJ_type() === $OBJ_type
1210
-					&& is_array( $OBJ_IDs )
1211
-					&& in_array( $child_line_item->OBJ_ID(), $OBJ_IDs )
1210
+					&& is_array($OBJ_IDs)
1211
+					&& in_array($child_line_item->OBJ_ID(), $OBJ_IDs)
1212 1212
 				) {
1213 1213
 					$objects[] = $child_line_item;
1214 1214
 				} else {
@@ -1238,8 +1238,8 @@  discard block
 block discarded – undo
1238 1238
 	 * @param string $type like one of the EEM_Line_Item::type_*
1239 1239
 	 * @return EE_Line_Item
1240 1240
 	 */
1241
-	public static function get_nearest_descendant_of_type( EE_Line_Item $parent_line_item, $type ) {
1242
-		return self::_get_nearest_descendant( $parent_line_item, 'LIN_type' , $type );
1241
+	public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) {
1242
+		return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type);
1243 1243
 	}
1244 1244
 
1245 1245
 
@@ -1253,8 +1253,8 @@  discard block
 block discarded – undo
1253 1253
 	 * @param string $code any value used for LIN_code
1254 1254
 	 * @return EE_Line_Item
1255 1255
 	 */
1256
-	public static function get_nearest_descendant_having_code( EE_Line_Item $parent_line_item, $code ) {
1257
-		return self::_get_nearest_descendant( $parent_line_item, 'LIN_code' , $code );
1256
+	public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) {
1257
+		return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code);
1258 1258
 	}
1259 1259
 
1260 1260
 
@@ -1268,15 +1268,15 @@  discard block
 block discarded – undo
1268 1268
 	 * @param string $value any value stored in $search_field
1269 1269
 	 * @return EE_Line_Item
1270 1270
 	 */
1271
-	protected static function _get_nearest_descendant( EE_Line_Item $parent_line_item, $search_field, $value ) {
1272
-		foreach( $parent_line_item->children() as $child ){
1273
-			if ( $child->get( $search_field ) == $value ){
1271
+	protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) {
1272
+		foreach ($parent_line_item->children() as $child) {
1273
+			if ($child->get($search_field) == $value) {
1274 1274
 				return $child;
1275 1275
 			}
1276 1276
 		}
1277
-		foreach( $parent_line_item->children() as $child ){
1278
-			$descendant_found = self::_get_nearest_descendant( $child, $search_field, $value );
1279
-			if ( $descendant_found ){
1277
+		foreach ($parent_line_item->children() as $child) {
1278
+			$descendant_found = self::_get_nearest_descendant($child, $search_field, $value);
1279
+			if ($descendant_found) {
1280 1280
 				return $descendant_found;
1281 1281
 			}
1282 1282
 		}
@@ -1293,24 +1293,24 @@  discard block
 block discarded – undo
1293 1293
 	 * @return \EE_Line_Item
1294 1294
 	 * @throws \EE_Error
1295 1295
 	 */
1296
-	public static function find_transaction_grand_total_for_line_item( EE_Line_Item $line_item ){
1297
-		if ( $line_item->TXN_ID() ) {
1298
-			$total_line_item = $line_item->transaction()->total_line_item( false );
1299
-			if ( $total_line_item instanceof EE_Line_Item ) {
1296
+	public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item) {
1297
+		if ($line_item->TXN_ID()) {
1298
+			$total_line_item = $line_item->transaction()->total_line_item(false);
1299
+			if ($total_line_item instanceof EE_Line_Item) {
1300 1300
 				return $total_line_item;
1301 1301
 			}
1302 1302
 		} else {
1303 1303
 			$line_item_parent = $line_item->parent();
1304
-			if ( $line_item_parent instanceof EE_Line_Item ) {
1305
-				if ( $line_item_parent->is_total() ) {
1304
+			if ($line_item_parent instanceof EE_Line_Item) {
1305
+				if ($line_item_parent->is_total()) {
1306 1306
 					return $line_item_parent;
1307 1307
 				}
1308
-				return EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item_parent );
1308
+				return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent);
1309 1309
 			}
1310 1310
 		}
1311 1311
 		throw new EE_Error(
1312 1312
 			sprintf(
1313
-				__( 'A valid grand total for line item %1$d was not found.', 'event_espresso' ),
1313
+				__('A valid grand total for line item %1$d was not found.', 'event_espresso'),
1314 1314
 				$line_item->ID()
1315 1315
 			)
1316 1316
 		);
@@ -1327,31 +1327,31 @@  discard block
 block discarded – undo
1327 1327
 	 * @return void
1328 1328
 	 * @throws \EE_Error
1329 1329
 	 */
1330
-	public static function visualize( EE_Line_Item $line_item, $indentation = 0 ){
1330
+	public static function visualize(EE_Line_Item $line_item, $indentation = 0) {
1331 1331
 		echo defined('EE_TESTS_DIR') ? "\n" : '<br />';
1332
-		if ( ! $indentation ) {
1333
-			echo defined( 'EE_TESTS_DIR' ) ? "\n" : '<br />';
1332
+		if ( ! $indentation) {
1333
+			echo defined('EE_TESTS_DIR') ? "\n" : '<br />';
1334 1334
 		}
1335
-		for( $i = 0; $i < $indentation; $i++ ){
1335
+		for ($i = 0; $i < $indentation; $i++) {
1336 1336
 			echo ". ";
1337 1337
 		}
1338 1338
 		$breakdown = '';
1339
-		if ( $line_item->is_line_item()){
1340
-			if ( $line_item->is_percent() ) {
1339
+		if ($line_item->is_line_item()) {
1340
+			if ($line_item->is_percent()) {
1341 1341
 				$breakdown = "{$line_item->percent()}%";
1342 1342
 			} else {
1343
-				$breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}";
1343
+				$breakdown = '$'."{$line_item->unit_price()} x {$line_item->quantity()}";
1344 1344
 			}
1345 1345
 		}
1346
-		echo $line_item->name() . " [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : " . '$' . "{$line_item->total()}";
1347
-		if ( $breakdown ) {
1346
+		echo $line_item->name()." [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : ".'$'."{$line_item->total()}";
1347
+		if ($breakdown) {
1348 1348
 			echo " ( {$breakdown} )";
1349 1349
 		}
1350
-		if( $line_item->is_taxable() ){
1350
+		if ($line_item->is_taxable()) {
1351 1351
 			echo "  * taxable";
1352 1352
 		}
1353
-		if( $line_item->children() ){
1354
-			foreach($line_item->children() as $child){
1353
+		if ($line_item->children()) {
1354
+			foreach ($line_item->children() as $child) {
1355 1355
 				self::visualize($child, $indentation + 1);
1356 1356
 			}
1357 1357
 		}
@@ -1392,97 +1392,97 @@  discard block
 block discarded – undo
1392 1392
 	 *                                          is theirs, which can be done with
1393 1393
 	 *                                          `EEM_Line_Item::instance()->get_line_item_for_registration( $registration );`
1394 1394
 	 */
1395
-	public static function calculate_reg_final_prices_per_line_item( EE_Line_Item $line_item, $billable_ticket_quantities = array() ) {
1395
+	public static function calculate_reg_final_prices_per_line_item(EE_Line_Item $line_item, $billable_ticket_quantities = array()) {
1396 1396
 		//init running grand total if not already
1397
-		if ( ! isset( $running_totals[ 'total' ] ) ) {
1398
-			$running_totals[ 'total' ] = 0;
1397
+		if ( ! isset($running_totals['total'])) {
1398
+			$running_totals['total'] = 0;
1399 1399
 		}
1400
-		if( ! isset( $running_totals[ 'taxable' ] ) ) {
1401
-			$running_totals[ 'taxable' ] = array( 'total' => 0 );
1400
+		if ( ! isset($running_totals['taxable'])) {
1401
+			$running_totals['taxable'] = array('total' => 0);
1402 1402
 		}
1403
-		foreach ( $line_item->children() as $child_line_item ) {
1404
-			switch ( $child_line_item->type() ) {
1403
+		foreach ($line_item->children() as $child_line_item) {
1404
+			switch ($child_line_item->type()) {
1405 1405
 
1406 1406
 				case EEM_Line_Item::type_sub_total :
1407
-					$running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $child_line_item, $billable_ticket_quantities );
1407
+					$running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item($child_line_item, $billable_ticket_quantities);
1408 1408
 					//combine arrays but preserve numeric keys
1409
-					$running_totals = array_replace_recursive( $running_totals_from_subtotal, $running_totals );
1410
-					$running_totals[ 'total' ] += $running_totals_from_subtotal[ 'total' ];
1411
-					$running_totals[ 'taxable'][ 'total' ] += $running_totals_from_subtotal[ 'taxable' ][ 'total' ];
1409
+					$running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals);
1410
+					$running_totals['total'] += $running_totals_from_subtotal['total'];
1411
+					$running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total'];
1412 1412
 					break;
1413 1413
 
1414 1414
 				case EEM_Line_Item::type_tax_sub_total :
1415 1415
 
1416 1416
 					//find how much the taxes percentage is
1417
-					if ( $child_line_item->percent() !== 0 ) {
1417
+					if ($child_line_item->percent() !== 0) {
1418 1418
 						$tax_percent_decimal = $child_line_item->percent() / 100;
1419 1419
 					} else {
1420 1420
 						$tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100;
1421 1421
 					}
1422 1422
 					//and apply to all the taxable totals, and add to the pretax totals
1423
-					foreach ( $running_totals as $line_item_id => $this_running_total ) {
1423
+					foreach ($running_totals as $line_item_id => $this_running_total) {
1424 1424
 						//"total" and "taxable" array key is an exception
1425
-						if ( $line_item_id === 'taxable' ) {
1425
+						if ($line_item_id === 'taxable') {
1426 1426
 							continue;
1427 1427
 						}
1428
-						$taxable_total = $running_totals[ 'taxable' ][ $line_item_id ];
1429
-						$running_totals[ $line_item_id ] += ( $taxable_total * $tax_percent_decimal );
1428
+						$taxable_total = $running_totals['taxable'][$line_item_id];
1429
+						$running_totals[$line_item_id] += ($taxable_total * $tax_percent_decimal);
1430 1430
 					}
1431 1431
 					break;
1432 1432
 
1433 1433
 				case EEM_Line_Item::type_line_item :
1434 1434
 
1435 1435
 					// ticket line items or ????
1436
-					if ( $child_line_item->OBJ_type() === 'Ticket' ) {
1436
+					if ($child_line_item->OBJ_type() === 'Ticket') {
1437 1437
 						// kk it's a ticket
1438
-						if ( isset( $running_totals[ $child_line_item->ID() ] ) ) {
1438
+						if (isset($running_totals[$child_line_item->ID()])) {
1439 1439
 							//huh? that shouldn't happen.
1440
-							$running_totals[ 'total' ] += $child_line_item->total();
1440
+							$running_totals['total'] += $child_line_item->total();
1441 1441
 						} else {
1442 1442
 							//its not in our running totals yet. great.
1443
-							if ( $child_line_item->is_taxable() ) {
1443
+							if ($child_line_item->is_taxable()) {
1444 1444
 								$taxable_amount = $child_line_item->unit_price();
1445 1445
 							} else {
1446 1446
 								$taxable_amount = 0;
1447 1447
 							}
1448 1448
 							// are we only calculating totals for some tickets?
1449
-							if ( isset( $billable_ticket_quantities[ $child_line_item->OBJ_ID() ] ) ) {
1450
-								$quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ];
1451
-								$running_totals[ $child_line_item->ID() ] = $quantity
1449
+							if (isset($billable_ticket_quantities[$child_line_item->OBJ_ID()])) {
1450
+								$quantity = $billable_ticket_quantities[$child_line_item->OBJ_ID()];
1451
+								$running_totals[$child_line_item->ID()] = $quantity
1452 1452
 									? $child_line_item->unit_price()
1453 1453
 									: 0;
1454
-								$running_totals[ 'taxable' ][ $child_line_item->ID() ] = $quantity
1454
+								$running_totals['taxable'][$child_line_item->ID()] = $quantity
1455 1455
 									? $taxable_amount
1456 1456
 									: 0;
1457 1457
 							} else {
1458 1458
 								$quantity = $child_line_item->quantity();
1459
-								$running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price();
1460
-								$running_totals[ 'taxable' ][ $child_line_item->ID() ] = $taxable_amount;
1459
+								$running_totals[$child_line_item->ID()] = $child_line_item->unit_price();
1460
+								$running_totals['taxable'][$child_line_item->ID()] = $taxable_amount;
1461 1461
 							}
1462
-							$running_totals[ 'taxable' ][ 'total' ] += $taxable_amount * $quantity;
1463
-							$running_totals[ 'total' ] += $child_line_item->unit_price() * $quantity;
1462
+							$running_totals['taxable']['total'] += $taxable_amount * $quantity;
1463
+							$running_totals['total'] += $child_line_item->unit_price() * $quantity;
1464 1464
 						}
1465 1465
 					} else {
1466 1466
 						// it's some other type of item added to the cart
1467 1467
 						// it should affect the running totals
1468 1468
 						// basically we want to convert it into a PERCENT modifier. Because
1469 1469
 						// more clearly affect all registration's final price equally
1470
-						$line_items_percent_of_running_total = $running_totals[ 'total' ] > 0
1471
-							? ( $child_line_item->total() / $running_totals[ 'total' ] ) + 1
1470
+						$line_items_percent_of_running_total = $running_totals['total'] > 0
1471
+							? ($child_line_item->total() / $running_totals['total']) + 1
1472 1472
 							: 1;
1473
-						foreach ( $running_totals as $line_item_id => $this_running_total ) {
1473
+						foreach ($running_totals as $line_item_id => $this_running_total) {
1474 1474
 							//the "taxable" array key is an exception
1475
-							if ( $line_item_id === 'taxable' ) {
1475
+							if ($line_item_id === 'taxable') {
1476 1476
 								continue;
1477 1477
 							}
1478 1478
 							// update the running totals
1479 1479
 							// yes this actually even works for the running grand total!
1480
-							$running_totals[ $line_item_id ] =
1480
+							$running_totals[$line_item_id] =
1481 1481
 								$line_items_percent_of_running_total * $this_running_total;
1482 1482
 
1483
-							if ( $child_line_item->is_taxable() ) {
1484
-								$running_totals[ 'taxable' ][ $line_item_id ] =
1485
-									$line_items_percent_of_running_total * $running_totals[ 'taxable' ][ $line_item_id ];
1483
+							if ($child_line_item->is_taxable()) {
1484
+								$running_totals['taxable'][$line_item_id] =
1485
+									$line_items_percent_of_running_total * $running_totals['taxable'][$line_item_id];
1486 1486
 							}
1487 1487
 						}
1488 1488
 					}
@@ -1500,16 +1500,16 @@  discard block
 block discarded – undo
1500 1500
 	 * @return float | null
1501 1501
 	 * @throws \OutOfRangeException
1502 1502
 	 */
1503
-	public static function calculate_final_price_for_ticket_line_item( \EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item ) {
1503
+	public static function calculate_final_price_for_ticket_line_item(\EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item) {
1504 1504
 		static $final_prices_per_ticket_line_item = array();
1505
-		if ( empty( $final_prices_per_ticket_line_item ) ) {
1505
+		if (empty($final_prices_per_ticket_line_item)) {
1506 1506
 			$final_prices_per_ticket_line_item = \EEH_Line_Item::calculate_reg_final_prices_per_line_item(
1507 1507
 				$total_line_item
1508 1508
 			);
1509 1509
 		}
1510 1510
 		//ok now find this new registration's final price
1511
-		if ( isset( $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ] ) ) {
1512
-			return $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ];
1511
+		if (isset($final_prices_per_ticket_line_item[$ticket_line_item->ID()])) {
1512
+			return $final_prices_per_ticket_line_item[$ticket_line_item->ID()];
1513 1513
 		}
1514 1514
 		$message = sprintf(
1515 1515
 			__(
@@ -1518,11 +1518,11 @@  discard block
 block discarded – undo
1518 1518
 			),
1519 1519
 			$ticket_line_item->ID()
1520 1520
 		);
1521
-		if ( WP_DEBUG ) {
1522
-			$message .= '<br>' . print_r( $final_prices_per_ticket_line_item, true );
1523
-			throw new \OutOfRangeException( $message );
1521
+		if (WP_DEBUG) {
1522
+			$message .= '<br>'.print_r($final_prices_per_ticket_line_item, true);
1523
+			throw new \OutOfRangeException($message);
1524 1524
 		} else {
1525
-			EE_Log::instance()->log( __CLASS__, __FUNCTION__, $message );
1525
+			EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message);
1526 1526
 		}
1527 1527
 		return null;
1528 1528
 	}
@@ -1538,15 +1538,15 @@  discard block
 block discarded – undo
1538 1538
 	 * @return \EE_Line_Item
1539 1539
 	 * @throws \EE_Error
1540 1540
 	 */
1541
-	public static function billable_line_item_tree( EE_Line_Item $line_item, $registrations ) {
1542
-		$copy_li = EEH_Line_Item::billable_line_item( $line_item, $registrations );
1543
-		foreach ( $line_item->children() as $child_li ) {
1544
-			$copy_li->add_child_line_item( EEH_Line_Item::billable_line_item_tree( $child_li, $registrations ) );
1541
+	public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) {
1542
+		$copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations);
1543
+		foreach ($line_item->children() as $child_li) {
1544
+			$copy_li->add_child_line_item(EEH_Line_Item::billable_line_item_tree($child_li, $registrations));
1545 1545
 		}
1546 1546
 		//if this is the grand total line item, make sure the totals all add up
1547 1547
 		//(we could have duplicated this logic AS we copied the line items, but
1548 1548
 		//it seems DRYer this way)
1549
-		if ( $copy_li->type() === EEM_Line_Item::type_total ) {
1549
+		if ($copy_li->type() === EEM_Line_Item::type_total) {
1550 1550
 			$copy_li->recalculate_total_including_taxes();
1551 1551
 		}
1552 1552
 		return $copy_li;
@@ -1563,24 +1563,24 @@  discard block
 block discarded – undo
1563 1563
 	 * @throws \EE_Error
1564 1564
 	 * @param EE_Registration[] $registrations
1565 1565
 	 */
1566
-	public static function billable_line_item( EE_Line_Item $line_item, $registrations ) {
1566
+	public static function billable_line_item(EE_Line_Item $line_item, $registrations) {
1567 1567
 		$new_li_fields = $line_item->model_field_array();
1568
-		if ( $line_item->type() === EEM_Line_Item::type_line_item &&
1568
+		if ($line_item->type() === EEM_Line_Item::type_line_item &&
1569 1569
 			$line_item->OBJ_type() === 'Ticket'
1570 1570
 		) {
1571 1571
 			$count = 0;
1572
-			foreach ( $registrations as $registration ) {
1573
-				if ( $line_item->OBJ_ID() === $registration->ticket_ID() &&
1574
-					in_array( $registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment() )
1572
+			foreach ($registrations as $registration) {
1573
+				if ($line_item->OBJ_ID() === $registration->ticket_ID() &&
1574
+					in_array($registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment())
1575 1575
 				) {
1576 1576
 					$count++;
1577 1577
 				}
1578 1578
 			}
1579
-			$new_li_fields[ 'LIN_quantity' ] = $count;
1579
+			$new_li_fields['LIN_quantity'] = $count;
1580 1580
 		}
1581 1581
 		//don't set the total. We'll leave that up to the code that calculates it
1582
-		unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ], $new_li_fields[ 'LIN_total' ] );
1583
-		return EE_Line_Item::new_instance( $new_li_fields );
1582
+		unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']);
1583
+		return EE_Line_Item::new_instance($new_li_fields);
1584 1584
 	}
1585 1585
 
1586 1586
 
@@ -1593,19 +1593,19 @@  discard block
 block discarded – undo
1593 1593
 	 * @return \EE_Line_Item|null
1594 1594
 	 * @throws \EE_Error
1595 1595
 	 */
1596
-	public static function non_empty_line_items( EE_Line_Item $line_item ) {
1597
-		$copied_li = EEH_Line_Item::non_empty_line_item( $line_item );
1598
-		if ( $copied_li === null ) {
1596
+	public static function non_empty_line_items(EE_Line_Item $line_item) {
1597
+		$copied_li = EEH_Line_Item::non_empty_line_item($line_item);
1598
+		if ($copied_li === null) {
1599 1599
 			return null;
1600 1600
 		}
1601 1601
 		//if this is an event subtotal, we want to only include it if it
1602 1602
 		//has a non-zero total and at least one ticket line item child
1603 1603
 		$ticket_children = 0;
1604
-		foreach ( $line_item->children() as $child_li ) {
1605
-			$child_li_copy = EEH_Line_Item::non_empty_line_items( $child_li );
1606
-			if ( $child_li_copy !== null ) {
1607
-				$copied_li->add_child_line_item( $child_li_copy );
1608
-				if ( $child_li_copy->type() === EEM_Line_Item::type_line_item &&
1604
+		foreach ($line_item->children() as $child_li) {
1605
+			$child_li_copy = EEH_Line_Item::non_empty_line_items($child_li);
1606
+			if ($child_li_copy !== null) {
1607
+				$copied_li->add_child_line_item($child_li_copy);
1608
+				if ($child_li_copy->type() === EEM_Line_Item::type_line_item &&
1609 1609
 					$child_li_copy->OBJ_type() === 'Ticket'
1610 1610
 				) {
1611 1611
 					$ticket_children++;
@@ -1635,8 +1635,8 @@  discard block
 block discarded – undo
1635 1635
 	 * @return EE_Line_Item
1636 1636
 	 * @throws \EE_Error
1637 1637
 	 */
1638
-	public static function non_empty_line_item( EE_Line_Item $line_item ) {
1639
-		if ( $line_item->type() === EEM_Line_Item::type_line_item &&
1638
+	public static function non_empty_line_item(EE_Line_Item $line_item) {
1639
+		if ($line_item->type() === EEM_Line_Item::type_line_item &&
1640 1640
 			$line_item->OBJ_type() === 'Ticket' &&
1641 1641
 			$line_item->quantity() === 0
1642 1642
 		) {
@@ -1644,8 +1644,8 @@  discard block
 block discarded – undo
1644 1644
 		}
1645 1645
 		$new_li_fields = $line_item->model_field_array();
1646 1646
 		//don't set the total. We'll leave that up to the code that calculates it
1647
-		unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ] );
1648
-		return EE_Line_Item::new_instance( $new_li_fields );
1647
+		unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']);
1648
+		return EE_Line_Item::new_instance($new_li_fields);
1649 1649
 	}
1650 1650
 
1651 1651
 
@@ -1657,9 +1657,9 @@  discard block
 block discarded – undo
1657 1657
 	 * @return \EE_Line_Item
1658 1658
 	 * @throws \EE_Error
1659 1659
 	 */
1660
-	public static function get_items_subtotal( EE_Line_Item $total_line_item ){
1661
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0' );
1662
-		return self::get_pre_tax_subtotal( $total_line_item );
1660
+	public static function get_items_subtotal(EE_Line_Item $total_line_item) {
1661
+		EE_Error::doing_it_wrong('EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0');
1662
+		return self::get_pre_tax_subtotal($total_line_item);
1663 1663
 	}
1664 1664
 
1665 1665
 
@@ -1670,9 +1670,9 @@  discard block
 block discarded – undo
1670 1670
 	 * @return \EE_Line_Item
1671 1671
 	 * @throws \EE_Error
1672 1672
 	 */
1673
-	public static function create_default_total_line_item( $transaction = NULL) {
1674
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0' );
1675
-		return self::create_total_line_item( $transaction );
1673
+	public static function create_default_total_line_item($transaction = NULL) {
1674
+		EE_Error::doing_it_wrong('EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0');
1675
+		return self::create_total_line_item($transaction);
1676 1676
 	}
1677 1677
 
1678 1678
 
@@ -1684,9 +1684,9 @@  discard block
 block discarded – undo
1684 1684
 	 * @return \EE_Line_Item
1685 1685
 	 * @throws \EE_Error
1686 1686
 	 */
1687
-	public static function create_default_tickets_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) {
1688
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0' );
1689
-		return self::create_pre_tax_subtotal( $total_line_item, $transaction );
1687
+	public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
1688
+		EE_Error::doing_it_wrong('EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0');
1689
+		return self::create_pre_tax_subtotal($total_line_item, $transaction);
1690 1690
 	}
1691 1691
 
1692 1692
 
@@ -1698,9 +1698,9 @@  discard block
 block discarded – undo
1698 1698
 	 * @return \EE_Line_Item
1699 1699
 	 * @throws \EE_Error
1700 1700
 	 */
1701
-	public static function create_default_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) {
1702
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0' );
1703
-		return self::create_taxes_subtotal( $total_line_item, $transaction );
1701
+	public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
1702
+		EE_Error::doing_it_wrong('EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0');
1703
+		return self::create_taxes_subtotal($total_line_item, $transaction);
1704 1704
 	}
1705 1705
 
1706 1706
 
@@ -1712,9 +1712,9 @@  discard block
 block discarded – undo
1712 1712
 	 * @return \EE_Line_Item
1713 1713
 	 * @throws \EE_Error
1714 1714
 	 */
1715
-	public static function create_default_event_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) {
1716
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0' );
1717
-		return self::create_event_subtotal( $total_line_item, $transaction );
1715
+	public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
1716
+		EE_Error::doing_it_wrong('EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0');
1717
+		return self::create_event_subtotal($total_line_item, $transaction);
1718 1718
 	}
1719 1719
 
1720 1720
 
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 2 patches
Spacing   +24 added lines, -24 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]);
@@ -679,10 +679,10 @@  discard block
 block discarded – undo
679 679
             'EE_Front_Controller'                  => 'load_core',
680 680
             'EE_Module_Request_Router'             => 'load_core',
681 681
             'EE_Registry'                          => 'load_core',
682
-            'EE_Request'                           => function () use (&$request) {
682
+            'EE_Request'                           => function() use (&$request) {
683 683
                 return $request;
684 684
             },
685
-            'EE_Response'                          => function () use (&$response) {
685
+            'EE_Response'                          => function() use (&$response) {
686 686
                 return $response;
687 687
             },
688 688
             'EE_Request_Handler'                   => 'load_core',
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
             'EE_Messages_Data_Handler_Collection'  => 'load_lib',
705 705
             'EE_Message_Template_Group_Collection' => 'load_lib',
706 706
             'EE_Payment_Method_Manager'            => 'load_lib',
707
-            'EE_Messages_Generator'                => function () {
707
+            'EE_Messages_Generator'                => function() {
708 708
                 return EE_Registry::instance()->load_lib(
709 709
                     'Messages_Generator',
710 710
                     array(),
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
                     false
713 713
                 );
714 714
             },
715
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
715
+            'EE_Messages_Template_Defaults'        => function($arguments = array()) {
716 716
                 return EE_Registry::instance()->load_lib(
717 717
                     'Messages_Template_Defaults',
718 718
                     $arguments,
@@ -725,22 +725,22 @@  discard block
 block discarded – undo
725 725
             // 'EEM_Message_Template_Group'           => 'load_model',
726 726
             // 'EEM_Message_Template'                 => 'load_model',
727 727
             //load_helper
728
-            'EEH_Parse_Shortcodes'                 => function () {
728
+            'EEH_Parse_Shortcodes'                 => function() {
729 729
                 if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
730 730
                     return new EEH_Parse_Shortcodes();
731 731
                 }
732 732
                 return null;
733 733
             },
734
-            'EE_Template_Config'                   => function () {
734
+            'EE_Template_Config'                   => function() {
735 735
                 return EE_Config::instance()->template_settings;
736 736
             },
737
-            'EE_Currency_Config'                   => function () {
737
+            'EE_Currency_Config'                   => function() {
738 738
                 return EE_Config::instance()->currency;
739 739
             },
740
-            'EE_Registration_Config'                   => function () {
740
+            'EE_Registration_Config'                   => function() {
741 741
                 return EE_Config::instance()->registration;
742 742
             },
743
-            'EventEspresso\core\services\loaders\Loader' => function () {
743
+            'EventEspresso\core\services\loaders\Loader' => function() {
744 744
                 return LoaderFactory::getLoader();
745 745
             },
746 746
         );
Please login to merge, or discard this patch.
Indentation   +807 added lines, -807 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,812 +22,812 @@  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_Maintenance_Mode'                        => EE_Dependency_Map::load_from_cache,
446
-            ),
447
-            'EE_Session'                                                                                                  => array(
448
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
449
-                'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
450
-            ),
451
-            'EE_Cart'                                                                                                     => array(
452
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
453
-            ),
454
-            'EE_Front_Controller'                                                                                         => array(
455
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
456
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
457
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
458
-            ),
459
-            'EE_Messenger_Collection_Loader'                                                                              => array(
460
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
461
-            ),
462
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
463
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
464
-            ),
465
-            'EE_Message_Resource_Manager'                                                                                 => array(
466
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
467
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
468
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
469
-            ),
470
-            'EE_Message_Factory'                                                                                          => array(
471
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
472
-            ),
473
-            'EE_messages'                                                                                                 => array(
474
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
475
-            ),
476
-            'EE_Messages_Generator'                                                                                       => array(
477
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
478
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
479
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
480
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
481
-            ),
482
-            'EE_Messages_Processor'                                                                                       => array(
483
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
484
-            ),
485
-            'EE_Messages_Queue'                                                                                           => array(
486
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
487
-            ),
488
-            'EE_Messages_Template_Defaults'                                                                               => array(
489
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
490
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
491
-            ),
492
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
493
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
494
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
495
-            ),
496
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
497
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
498
-            ),
499
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
500
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
501
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
502
-            ),
503
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
504
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
505
-            ),
506
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
507
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
508
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
509
-            ),
510
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
511
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
512
-            ),
513
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
514
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
515
-            ),
516
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
517
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
518
-            ),
519
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
520
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
521
-            ),
522
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
523
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
524
-            ),
525
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
526
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
527
-            ),
528
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
529
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
530
-            ),
531
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
532
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
533
-            ),
534
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
535
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
536
-            ),
537
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
538
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
539
-            ),
540
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
541
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
542
-            ),
543
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
544
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
545
-            ),
546
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
547
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
548
-            ),
549
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
550
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
551
-            ),
552
-            'EE_Data_Migration_Class_Base'                                                                                => array(
553
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
554
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
555
-            ),
556
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
557
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
558
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
559
-            ),
560
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
561
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
562
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
563
-            ),
564
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
565
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
566
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
567
-            ),
568
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
569
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
570
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
571
-            ),
572
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
573
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
574
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
575
-            ),
576
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
577
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
578
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
579
-            ),
580
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
581
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
582
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
583
-            ),
584
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
585
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
586
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
587
-            ),
588
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
589
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
590
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
591
-            ),
592
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
593
-                'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
594
-                'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
595
-            ),
596
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
597
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
598
-            ),
599
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
600
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
601
-            ),
602
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
603
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
604
-            ),
605
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
606
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
607
-            ),
608
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
609
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
610
-            ),
611
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
612
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
613
-            ),
614
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
615
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
616
-            ),
617
-            'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
618
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
619
-            ),
620
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'            => array(
621
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
622
-            ),
623
-            'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
624
-                'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
625
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
626
-            ),
627
-            'EventEspresso\core\domain\values\EmailAddress'                              => array(
628
-                null,
629
-                'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
630
-            ),
631
-            'EventEspresso\core\services\orm\ModelFieldFactory' => array(
632
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
633
-            ),
634
-            'LEGACY_MODELS'                                                   => array(
635
-                null,
636
-                'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
637
-            ),
638
-            'EventEspresso\core\services\activation\ActivationsAndUpgradesManager' => array(
639
-                'EventEspresso\core\services\activation\ActivationHandler'   => EE_Dependency_Map::load_from_cache,
640
-                'EventEspresso\core\services\activation\RequestTypeDetector' => EE_Dependency_Map::load_from_cache,
641
-            ),
642
-            'EventEspresso\core\services\activation\ActivationHandler'             => array(
643
-                'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache,
644
-            ),
645
-            'EventEspresso\core\services\activation\InitializeCore'                => array(
646
-                null,
647
-                'EE_Capabilities'           => EE_Dependency_Map::load_from_cache,
648
-                'EE_Data_Migration_Manager' => EE_Dependency_Map::load_from_cache,
649
-                'EE_Maintenance_Mode'       => EE_Dependency_Map::load_from_cache,
650
-            ),
651
-            'EventEspresso\core\services\activation\InitializeAddon' => array(
652
-                null,
653
-                'EE_Data_Migration_Manager' => EE_Dependency_Map::load_from_cache,
654
-                'EE_Maintenance_Mode'       => EE_Dependency_Map::load_from_cache,
655
-                'EE_Registry'               => EE_Dependency_Map::load_from_cache,
656
-            ),
657
-            'EE_Module_Request_Router' => array(
658
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
659
-            ),
660
-        );
661
-    }
662
-
663
-
664
-
665
-    /**
666
-     * Registers how core classes are loaded.
667
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
668
-     *        'EE_Request_Handler' => 'load_core'
669
-     *        'EE_Messages_Queue'  => 'load_lib'
670
-     *        'EEH_Debug_Tools'    => 'load_helper'
671
-     * or, if greater control is required, by providing a custom closure. For example:
672
-     *        'Some_Class' => function () {
673
-     *            return new Some_Class();
674
-     *        },
675
-     * This is required for instantiating dependencies
676
-     * where an interface has been type hinted in a class constructor. For example:
677
-     *        'Required_Interface' => function () {
678
-     *            return new A_Class_That_Implements_Required_Interface();
679
-     *        },
680
-     *
681
-     * @throws InvalidInterfaceException
682
-     * @throws InvalidDataTypeException
683
-     * @throws InvalidArgumentException
684
-     */
685
-    protected function _register_core_class_loaders()
686
-    {
687
-        //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
688
-        //be used in a closure.
689
-        $request = &$this->_request;
690
-        $response = &$this->_response;
691
-        // $loader = &$this->loader;
692
-        $this->_class_loaders = array(
693
-            //load_core
694
-            'EE_Capabilities'                      => 'load_core',
695
-            'EE_Encryption'                        => 'load_core',
696
-            'EE_Front_Controller'                  => 'load_core',
697
-            'EE_Module_Request_Router'             => 'load_core',
698
-            'EE_Registry'                          => 'load_core',
699
-            'EE_Request'                           => function () use (&$request) {
700
-                return $request;
701
-            },
702
-            'EE_Response'                          => function () use (&$response) {
703
-                return $response;
704
-            },
705
-            'EE_Request_Handler'                   => 'load_core',
706
-            'EE_Session'                           => 'load_core',
707
-            'EE_Cron_Tasks'                        => 'load_core',
708
-            'EE_System'                            => 'load_core',
709
-            'EE_Maintenance_Mode'                  => 'load_core',
710
-            'EE_Register_CPTs'                     => 'load_core',
711
-            'EE_Admin'                             => 'load_core',
712
-            'EE_Data_Migration_Manager'            => 'load_core',
713
-            //load_lib
714
-            'EE_Message_Resource_Manager'          => 'load_lib',
715
-            'EE_Message_Type_Collection'           => 'load_lib',
716
-            'EE_Message_Type_Collection_Loader'    => 'load_lib',
717
-            'EE_Messenger_Collection'              => 'load_lib',
718
-            'EE_Messenger_Collection_Loader'       => 'load_lib',
719
-            'EE_Messages_Processor'                => 'load_lib',
720
-            'EE_Message_Repository'                => 'load_lib',
721
-            'EE_Messages_Queue'                    => 'load_lib',
722
-            'EE_Messages_Data_Handler_Collection'  => 'load_lib',
723
-            'EE_Message_Template_Group_Collection' => 'load_lib',
724
-            'EE_Payment_Method_Manager'            => 'load_lib',
725
-            'EE_Messages_Generator'                => function () {
726
-                return EE_Registry::instance()->load_lib(
727
-                    'Messages_Generator',
728
-                    array(),
729
-                    false,
730
-                    false
731
-                );
732
-            },
733
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
734
-                return EE_Registry::instance()->load_lib(
735
-                    'Messages_Template_Defaults',
736
-                    $arguments,
737
-                    false,
738
-                    false
739
-                );
740
-            },
741
-            //load_model
742
-            // 'EEM_Attendee'                         => 'load_model',
743
-            // 'EEM_Message_Template_Group'           => 'load_model',
744
-            // 'EEM_Message_Template'                 => 'load_model',
745
-            //load_helper
746
-            'EEH_Parse_Shortcodes'                 => function () {
747
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
748
-                    return new EEH_Parse_Shortcodes();
749
-                }
750
-                return null;
751
-            },
752
-            'EE_Template_Config'                   => function () {
753
-                return EE_Config::instance()->template_settings;
754
-            },
755
-            'EE_Currency_Config'                   => function () {
756
-                return EE_Config::instance()->currency;
757
-            },
758
-            'EE_Registration_Config'                   => function () {
759
-                return EE_Config::instance()->registration;
760
-            },
761
-            'EventEspresso\core\services\loaders\Loader' => function () {
762
-                return LoaderFactory::getLoader();
763
-            },
764
-        );
765
-    }
766
-
767
-
768
-
769
-    /**
770
-     * can be used for supplying alternate names for classes,
771
-     * or for connecting interface names to instantiable classes
772
-     */
773
-    protected function _register_core_aliases()
774
-    {
775
-        $this->_aliases = array(
776
-            'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
777
-            'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
778
-            'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
779
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
780
-            'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
781
-            'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
782
-            'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
783
-            'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
784
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
785
-            'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
786
-            'CreateRegCodeCommandHandler'                                                  => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
787
-            'CreateRegUrlLinkCommandHandler'                                               => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
788
-            'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
789
-            'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
790
-            'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
791
-            'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
792
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
793
-            'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
794
-            'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
795
-            'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
796
-            'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
797
-            'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
798
-            'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
799
-            'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
800
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
801
-            'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
802
-            'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
803
-            'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
804
-            'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
805
-            'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
806
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
807
-            'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
808
-            'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
809
-            'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
810
-            'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
811
-            'NoticesContainerInterface'                                            => 'EventEspresso\core\services\notices\NoticesContainerInterface',
812
-            'EventEspresso\core\services\notices\NoticesContainerInterface'        => 'EventEspresso\core\services\notices\NoticesContainer',
813
-        );
814
-    }
815
-
816
-
817
-
818
-    /**
819
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
820
-     * request Primarily used by unit tests.
821
-     *
822
-     * @throws InvalidDataTypeException
823
-     * @throws InvalidInterfaceException
824
-     * @throws InvalidArgumentException
825
-     */
826
-    public function reset()
827
-    {
828
-        $this->_register_core_class_loaders();
829
-        $this->_register_core_dependencies();
830
-    }
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_Maintenance_Mode'                        => EE_Dependency_Map::load_from_cache,
446
+			),
447
+			'EE_Session'                                                                                                  => array(
448
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
449
+				'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
450
+			),
451
+			'EE_Cart'                                                                                                     => array(
452
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
453
+			),
454
+			'EE_Front_Controller'                                                                                         => array(
455
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
456
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
457
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
458
+			),
459
+			'EE_Messenger_Collection_Loader'                                                                              => array(
460
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
461
+			),
462
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
463
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
464
+			),
465
+			'EE_Message_Resource_Manager'                                                                                 => array(
466
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
467
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
468
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
469
+			),
470
+			'EE_Message_Factory'                                                                                          => array(
471
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
472
+			),
473
+			'EE_messages'                                                                                                 => array(
474
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
475
+			),
476
+			'EE_Messages_Generator'                                                                                       => array(
477
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
478
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
479
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
480
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
481
+			),
482
+			'EE_Messages_Processor'                                                                                       => array(
483
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
484
+			),
485
+			'EE_Messages_Queue'                                                                                           => array(
486
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
487
+			),
488
+			'EE_Messages_Template_Defaults'                                                                               => array(
489
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
490
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
491
+			),
492
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
493
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
494
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
495
+			),
496
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
497
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
498
+			),
499
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
500
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
501
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
502
+			),
503
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
504
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
505
+			),
506
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
507
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
508
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
509
+			),
510
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
511
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
512
+			),
513
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
514
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
515
+			),
516
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
517
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
518
+			),
519
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
520
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
521
+			),
522
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
523
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
524
+			),
525
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
526
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
527
+			),
528
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
529
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
530
+			),
531
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
532
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
533
+			),
534
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
535
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
536
+			),
537
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
538
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
539
+			),
540
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
541
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
542
+			),
543
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
544
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
545
+			),
546
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
547
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
548
+			),
549
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
550
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
551
+			),
552
+			'EE_Data_Migration_Class_Base'                                                                                => array(
553
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
554
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
555
+			),
556
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
557
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
558
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
559
+			),
560
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
561
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
562
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
563
+			),
564
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
565
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
566
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
567
+			),
568
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
569
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
570
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
571
+			),
572
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
573
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
574
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
575
+			),
576
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
577
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
578
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
579
+			),
580
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
581
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
582
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
583
+			),
584
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
585
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
586
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
587
+			),
588
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
589
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
590
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
591
+			),
592
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
593
+				'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
594
+				'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
595
+			),
596
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
597
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
598
+			),
599
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
600
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
601
+			),
602
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
603
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
604
+			),
605
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
606
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
607
+			),
608
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
609
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
610
+			),
611
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
612
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
613
+			),
614
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
615
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
616
+			),
617
+			'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
618
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
619
+			),
620
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'            => array(
621
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
622
+			),
623
+			'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
624
+				'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
625
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
626
+			),
627
+			'EventEspresso\core\domain\values\EmailAddress'                              => array(
628
+				null,
629
+				'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
630
+			),
631
+			'EventEspresso\core\services\orm\ModelFieldFactory' => array(
632
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
633
+			),
634
+			'LEGACY_MODELS'                                                   => array(
635
+				null,
636
+				'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
637
+			),
638
+			'EventEspresso\core\services\activation\ActivationsAndUpgradesManager' => array(
639
+				'EventEspresso\core\services\activation\ActivationHandler'   => EE_Dependency_Map::load_from_cache,
640
+				'EventEspresso\core\services\activation\RequestTypeDetector' => EE_Dependency_Map::load_from_cache,
641
+			),
642
+			'EventEspresso\core\services\activation\ActivationHandler'             => array(
643
+				'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache,
644
+			),
645
+			'EventEspresso\core\services\activation\InitializeCore'                => array(
646
+				null,
647
+				'EE_Capabilities'           => EE_Dependency_Map::load_from_cache,
648
+				'EE_Data_Migration_Manager' => EE_Dependency_Map::load_from_cache,
649
+				'EE_Maintenance_Mode'       => EE_Dependency_Map::load_from_cache,
650
+			),
651
+			'EventEspresso\core\services\activation\InitializeAddon' => array(
652
+				null,
653
+				'EE_Data_Migration_Manager' => EE_Dependency_Map::load_from_cache,
654
+				'EE_Maintenance_Mode'       => EE_Dependency_Map::load_from_cache,
655
+				'EE_Registry'               => EE_Dependency_Map::load_from_cache,
656
+			),
657
+			'EE_Module_Request_Router' => array(
658
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
659
+			),
660
+		);
661
+	}
662
+
663
+
664
+
665
+	/**
666
+	 * Registers how core classes are loaded.
667
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
668
+	 *        'EE_Request_Handler' => 'load_core'
669
+	 *        'EE_Messages_Queue'  => 'load_lib'
670
+	 *        'EEH_Debug_Tools'    => 'load_helper'
671
+	 * or, if greater control is required, by providing a custom closure. For example:
672
+	 *        'Some_Class' => function () {
673
+	 *            return new Some_Class();
674
+	 *        },
675
+	 * This is required for instantiating dependencies
676
+	 * where an interface has been type hinted in a class constructor. For example:
677
+	 *        'Required_Interface' => function () {
678
+	 *            return new A_Class_That_Implements_Required_Interface();
679
+	 *        },
680
+	 *
681
+	 * @throws InvalidInterfaceException
682
+	 * @throws InvalidDataTypeException
683
+	 * @throws InvalidArgumentException
684
+	 */
685
+	protected function _register_core_class_loaders()
686
+	{
687
+		//for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
688
+		//be used in a closure.
689
+		$request = &$this->_request;
690
+		$response = &$this->_response;
691
+		// $loader = &$this->loader;
692
+		$this->_class_loaders = array(
693
+			//load_core
694
+			'EE_Capabilities'                      => 'load_core',
695
+			'EE_Encryption'                        => 'load_core',
696
+			'EE_Front_Controller'                  => 'load_core',
697
+			'EE_Module_Request_Router'             => 'load_core',
698
+			'EE_Registry'                          => 'load_core',
699
+			'EE_Request'                           => function () use (&$request) {
700
+				return $request;
701
+			},
702
+			'EE_Response'                          => function () use (&$response) {
703
+				return $response;
704
+			},
705
+			'EE_Request_Handler'                   => 'load_core',
706
+			'EE_Session'                           => 'load_core',
707
+			'EE_Cron_Tasks'                        => 'load_core',
708
+			'EE_System'                            => 'load_core',
709
+			'EE_Maintenance_Mode'                  => 'load_core',
710
+			'EE_Register_CPTs'                     => 'load_core',
711
+			'EE_Admin'                             => 'load_core',
712
+			'EE_Data_Migration_Manager'            => 'load_core',
713
+			//load_lib
714
+			'EE_Message_Resource_Manager'          => 'load_lib',
715
+			'EE_Message_Type_Collection'           => 'load_lib',
716
+			'EE_Message_Type_Collection_Loader'    => 'load_lib',
717
+			'EE_Messenger_Collection'              => 'load_lib',
718
+			'EE_Messenger_Collection_Loader'       => 'load_lib',
719
+			'EE_Messages_Processor'                => 'load_lib',
720
+			'EE_Message_Repository'                => 'load_lib',
721
+			'EE_Messages_Queue'                    => 'load_lib',
722
+			'EE_Messages_Data_Handler_Collection'  => 'load_lib',
723
+			'EE_Message_Template_Group_Collection' => 'load_lib',
724
+			'EE_Payment_Method_Manager'            => 'load_lib',
725
+			'EE_Messages_Generator'                => function () {
726
+				return EE_Registry::instance()->load_lib(
727
+					'Messages_Generator',
728
+					array(),
729
+					false,
730
+					false
731
+				);
732
+			},
733
+			'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
734
+				return EE_Registry::instance()->load_lib(
735
+					'Messages_Template_Defaults',
736
+					$arguments,
737
+					false,
738
+					false
739
+				);
740
+			},
741
+			//load_model
742
+			// 'EEM_Attendee'                         => 'load_model',
743
+			// 'EEM_Message_Template_Group'           => 'load_model',
744
+			// 'EEM_Message_Template'                 => 'load_model',
745
+			//load_helper
746
+			'EEH_Parse_Shortcodes'                 => function () {
747
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
748
+					return new EEH_Parse_Shortcodes();
749
+				}
750
+				return null;
751
+			},
752
+			'EE_Template_Config'                   => function () {
753
+				return EE_Config::instance()->template_settings;
754
+			},
755
+			'EE_Currency_Config'                   => function () {
756
+				return EE_Config::instance()->currency;
757
+			},
758
+			'EE_Registration_Config'                   => function () {
759
+				return EE_Config::instance()->registration;
760
+			},
761
+			'EventEspresso\core\services\loaders\Loader' => function () {
762
+				return LoaderFactory::getLoader();
763
+			},
764
+		);
765
+	}
766
+
767
+
768
+
769
+	/**
770
+	 * can be used for supplying alternate names for classes,
771
+	 * or for connecting interface names to instantiable classes
772
+	 */
773
+	protected function _register_core_aliases()
774
+	{
775
+		$this->_aliases = array(
776
+			'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
777
+			'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
778
+			'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
779
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
780
+			'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
781
+			'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
782
+			'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
783
+			'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
784
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
785
+			'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
786
+			'CreateRegCodeCommandHandler'                                                  => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
787
+			'CreateRegUrlLinkCommandHandler'                                               => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
788
+			'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
789
+			'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
790
+			'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
791
+			'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
792
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
793
+			'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
794
+			'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
795
+			'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
796
+			'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
797
+			'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
798
+			'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
799
+			'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
800
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
801
+			'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
802
+			'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
803
+			'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
804
+			'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
805
+			'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
806
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
807
+			'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
808
+			'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
809
+			'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
810
+			'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
811
+			'NoticesContainerInterface'                                            => 'EventEspresso\core\services\notices\NoticesContainerInterface',
812
+			'EventEspresso\core\services\notices\NoticesContainerInterface'        => 'EventEspresso\core\services\notices\NoticesContainer',
813
+		);
814
+	}
815
+
816
+
817
+
818
+	/**
819
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
820
+	 * request Primarily used by unit tests.
821
+	 *
822
+	 * @throws InvalidDataTypeException
823
+	 * @throws InvalidInterfaceException
824
+	 * @throws InvalidArgumentException
825
+	 */
826
+	public function reset()
827
+	{
828
+		$this->_register_core_class_loaders();
829
+		$this->_register_core_dependencies();
830
+	}
831 831
 
832 832
 
833 833
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Payment_Method.lib.php 1 patch
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -22,163 +22,163 @@
 block discarded – undo
22 22
 class EE_Register_Payment_Method implements EEI_Plugin_API
23 23
 {
24 24
 
25
-    /**
26
-     * Holds values for registered payment methods
27
-     *
28
-     * @var array
29
-     */
30
-    protected static $_settings = array();
31
-
32
-
33
-
34
-    /**
35
-     * Method for registering new EE_PMT_Base children
36
-     *
37
-     * @since    4.5.0
38
-     * @param string  $payment_method_id    a unique identifier for this set of modules Required.
39
-     * @param  array  $setup_args           an array of arguments provided for registering modules Required.{
40
-     * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class
41
-     *                                      (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains
42
-     *                                      the files EE_PMT_Payomatic.pm.php)
43
-     *                                      }
44
-     * @throws EE_Error
45
-     * @type array payment_method_paths    an array of full server paths to folders containing any EE_PMT_Base
46
-     *                                      children, or to the EED_Module files themselves
47
-     * @return void
48
-     * @throws InvalidDataTypeException
49
-     * @throws DomainException
50
-     * @throws InvalidArgumentException
51
-     * @throws InvalidInterfaceException
52
-     * @throws InvalidDataTypeException
53
-     */
54
-    public static function register($payment_method_id = null, $setup_args = array())
55
-    {
56
-        //required fields MUST be present, so let's make sure they are.
57
-        if (empty($payment_method_id) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) {
58
-            throw new EE_Error(
59
-                esc_html__(
60
-                    'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
61
-                    'event_espresso'
62
-                )
63
-            );
64
-        }
65
-        //make sure we don't register twice
66
-        if (isset(self::$_settings[$payment_method_id])) {
67
-            return;
68
-        }
69
-        //make sure this was called in the right place!
70
-        if (
71
-            ! did_action('AHEE__EE_System__load_espresso_addons')
72
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
73
-        ) {
74
-            EE_Error::doing_it_wrong(
75
-                __METHOD__,
76
-                esc_html__(
77
-                    'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
78
-                    'event_espresso'
79
-                ),
80
-                '4.3.0'
81
-            );
82
-        }
83
-        //setup $_settings array from incoming values.
84
-        self::$_settings[$payment_method_id] = array(
85
-            // array of full server paths to any EE_PMT_Base children used
86
-            'payment_method_paths' => isset($setup_args['payment_method_paths'])
87
-                ? (array)$setup_args['payment_method_paths']
88
-                : array(),
89
-        );
90
-        // add to list of modules to be registered
91
-        add_filter(
92
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
93
-            array('EE_Register_Payment_Method', 'add_payment_methods')
94
-        );
95
-        // If EE_Payment_Method_Manager::register_payment_methods has already been called,
96
-        // then we need to add our caps for this payment method manually
97
-        if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) {
98
-            $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
99
-            // register payment methods directly
100
-            foreach (self::$_settings[$payment_method_id]['payment_method_paths'] as $payment_method_path) {
101
-                $payment_method_manager->register_payment_method($payment_method_path);
102
-            }
103
-            $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
104
-            $capabilities->addCaps(
105
-                self::getPaymentMethodCapabilities(self::$_settings[$payment_method_id])
106
-            );
107
-        }
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * Filters the list of payment methods to add ours.
114
-     * and they're just full filepaths to FOLDERS containing a payment method class file. Eg.
115
-     *
116
-     * @param array $payment_method_folders array of paths to all payment methods that require registering
117
-     * @return array
118
-     */
119
-    public static function add_payment_methods($payment_method_folders)
120
-    {
121
-        foreach (self::$_settings as $settings) {
122
-            foreach ($settings['payment_method_paths'] as $payment_method_path) {
123
-                $payment_method_folders[] = $payment_method_path;
124
-            }
125
-        }
126
-        return $payment_method_folders;
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * This deregisters a module that was previously registered with a specific $module_id.
133
-     *
134
-     * @since    4.3.0
135
-     *
136
-     * @param string $module_id the name for the module that was previously registered
137
-     * @return void
138
-     * @throws DomainException
139
-     * @throws EE_Error
140
-     * @throws InvalidArgumentException
141
-     * @throws InvalidInterfaceException
142
-     * @throws InvalidDataTypeException
143
-     */
144
-    public static function deregister($module_id = null)
145
-    {
146
-        if (isset(self::$_settings[$module_id])) {
147
-            $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
148
-            $capabilities->removeCaps(
149
-                self::getPaymentMethodCapabilities(self::$_settings[$module_id])
150
-            );
151
-            unset(self::$_settings[$module_id]);
152
-        }
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * returns an array of the caps that get added when a Payment Method is registered
159
-     *
160
-     * @param array $settings
161
-     * @return array
162
-     * @throws DomainException
163
-     * @throws EE_Error
164
-     * @throws InvalidArgumentException
165
-     * @throws InvalidInterfaceException
166
-     * @throws InvalidDataTypeException
167
-     */
168
-    private static function getPaymentMethodCapabilities(array $settings)
169
-    {
170
-        $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
171
-        $payment_method_caps = array('administrator' => array());
172
-        if (isset($settings['payment_method_paths'])) {
173
-            foreach ($settings['payment_method_paths'] as $payment_method_path) {
174
-                $payment_method_caps = $payment_method_manager->addPaymentMethodCap(
175
-                    strtolower(basename($payment_method_path)),
176
-                    $payment_method_caps
177
-                );
178
-            }
179
-        }
180
-        return $payment_method_caps;
181
-    }
25
+	/**
26
+	 * Holds values for registered payment methods
27
+	 *
28
+	 * @var array
29
+	 */
30
+	protected static $_settings = array();
31
+
32
+
33
+
34
+	/**
35
+	 * Method for registering new EE_PMT_Base children
36
+	 *
37
+	 * @since    4.5.0
38
+	 * @param string  $payment_method_id    a unique identifier for this set of modules Required.
39
+	 * @param  array  $setup_args           an array of arguments provided for registering modules Required.{
40
+	 * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class
41
+	 *                                      (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains
42
+	 *                                      the files EE_PMT_Payomatic.pm.php)
43
+	 *                                      }
44
+	 * @throws EE_Error
45
+	 * @type array payment_method_paths    an array of full server paths to folders containing any EE_PMT_Base
46
+	 *                                      children, or to the EED_Module files themselves
47
+	 * @return void
48
+	 * @throws InvalidDataTypeException
49
+	 * @throws DomainException
50
+	 * @throws InvalidArgumentException
51
+	 * @throws InvalidInterfaceException
52
+	 * @throws InvalidDataTypeException
53
+	 */
54
+	public static function register($payment_method_id = null, $setup_args = array())
55
+	{
56
+		//required fields MUST be present, so let's make sure they are.
57
+		if (empty($payment_method_id) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) {
58
+			throw new EE_Error(
59
+				esc_html__(
60
+					'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
61
+					'event_espresso'
62
+				)
63
+			);
64
+		}
65
+		//make sure we don't register twice
66
+		if (isset(self::$_settings[$payment_method_id])) {
67
+			return;
68
+		}
69
+		//make sure this was called in the right place!
70
+		if (
71
+			! did_action('AHEE__EE_System__load_espresso_addons')
72
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
73
+		) {
74
+			EE_Error::doing_it_wrong(
75
+				__METHOD__,
76
+				esc_html__(
77
+					'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
78
+					'event_espresso'
79
+				),
80
+				'4.3.0'
81
+			);
82
+		}
83
+		//setup $_settings array from incoming values.
84
+		self::$_settings[$payment_method_id] = array(
85
+			// array of full server paths to any EE_PMT_Base children used
86
+			'payment_method_paths' => isset($setup_args['payment_method_paths'])
87
+				? (array)$setup_args['payment_method_paths']
88
+				: array(),
89
+		);
90
+		// add to list of modules to be registered
91
+		add_filter(
92
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
93
+			array('EE_Register_Payment_Method', 'add_payment_methods')
94
+		);
95
+		// If EE_Payment_Method_Manager::register_payment_methods has already been called,
96
+		// then we need to add our caps for this payment method manually
97
+		if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) {
98
+			$payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
99
+			// register payment methods directly
100
+			foreach (self::$_settings[$payment_method_id]['payment_method_paths'] as $payment_method_path) {
101
+				$payment_method_manager->register_payment_method($payment_method_path);
102
+			}
103
+			$capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
104
+			$capabilities->addCaps(
105
+				self::getPaymentMethodCapabilities(self::$_settings[$payment_method_id])
106
+			);
107
+		}
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * Filters the list of payment methods to add ours.
114
+	 * and they're just full filepaths to FOLDERS containing a payment method class file. Eg.
115
+	 *
116
+	 * @param array $payment_method_folders array of paths to all payment methods that require registering
117
+	 * @return array
118
+	 */
119
+	public static function add_payment_methods($payment_method_folders)
120
+	{
121
+		foreach (self::$_settings as $settings) {
122
+			foreach ($settings['payment_method_paths'] as $payment_method_path) {
123
+				$payment_method_folders[] = $payment_method_path;
124
+			}
125
+		}
126
+		return $payment_method_folders;
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * This deregisters a module that was previously registered with a specific $module_id.
133
+	 *
134
+	 * @since    4.3.0
135
+	 *
136
+	 * @param string $module_id the name for the module that was previously registered
137
+	 * @return void
138
+	 * @throws DomainException
139
+	 * @throws EE_Error
140
+	 * @throws InvalidArgumentException
141
+	 * @throws InvalidInterfaceException
142
+	 * @throws InvalidDataTypeException
143
+	 */
144
+	public static function deregister($module_id = null)
145
+	{
146
+		if (isset(self::$_settings[$module_id])) {
147
+			$capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
148
+			$capabilities->removeCaps(
149
+				self::getPaymentMethodCapabilities(self::$_settings[$module_id])
150
+			);
151
+			unset(self::$_settings[$module_id]);
152
+		}
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * returns an array of the caps that get added when a Payment Method is registered
159
+	 *
160
+	 * @param array $settings
161
+	 * @return array
162
+	 * @throws DomainException
163
+	 * @throws EE_Error
164
+	 * @throws InvalidArgumentException
165
+	 * @throws InvalidInterfaceException
166
+	 * @throws InvalidDataTypeException
167
+	 */
168
+	private static function getPaymentMethodCapabilities(array $settings)
169
+	{
170
+		$payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
171
+		$payment_method_caps = array('administrator' => array());
172
+		if (isset($settings['payment_method_paths'])) {
173
+			foreach ($settings['payment_method_paths'] as $payment_method_path) {
174
+				$payment_method_caps = $payment_method_manager->addPaymentMethodCap(
175
+					strtolower(basename($payment_method_path)),
176
+					$payment_method_caps
177
+				);
178
+			}
179
+		}
180
+		return $payment_method_caps;
181
+	}
182 182
 
183 183
 }
184 184
 // End of file EE_Register_Payment_Method.lib.php
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Data_Handler_Collection.lib.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (!defined('EVENT_ESPRESSO_VERSION'))
2
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
3 3
 	exit('No direct script access allowed');
4 4
 
5 5
 
@@ -26,10 +26,10 @@  discard block
 block discarded – undo
26 26
 	 *                                                   classname to create an alternative index for retrieving data_handlers.
27 27
 	 * @return bool
28 28
 	 */
29
-	public function add( $data_handler, $data = null) {
29
+	public function add($data_handler, $data = null) {
30 30
 		$data = $data === null ? array() : (array) $data;
31
-		$info['key'] = $this->get_key( get_class( $data_handler ), $data );
32
-		return parent::add( $data_handler, $info );
31
+		$info['key'] = $this->get_key(get_class($data_handler), $data);
32
+		return parent::add($data_handler, $info);
33 33
 	}
34 34
 	
35 35
 
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @return  string      md5 hash using provided info.
46 46
 	 */
47
-	public function get_key( $classname, $data ) {
48
-		return md5( $classname . serialize( $data ) );
47
+	public function get_key($classname, $data) {
48
+		return md5($classname.serialize($data));
49 49
 	}
50 50
 
51 51
 
@@ -61,11 +61,11 @@  discard block
 block discarded – undo
61 61
 	 *
62 62
 	 * @return null|EE_Messages_incoming_data
63 63
 	 */
64
-	public function get_by_key( $key ) {
64
+	public function get_by_key($key) {
65 65
 		$this->rewind();
66
-		while( $this->valid() ) {
66
+		while ($this->valid()) {
67 67
 			$data = $this->getInfo();
68
-			if ( isset( $data['key'] ) && $data['key'] === $key ) {
68
+			if (isset($data['key']) && $data['key'] === $key) {
69 69
 				$handler = $this->current();
70 70
 				$this->rewind();
71 71
 				return $handler;
Please login to merge, or discard this patch.
acceptance_tests/tests/c-TestCustomMessageTemplateCept.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -18,14 +18,14 @@  discard block
 block discarded – undo
18 18
 $event_one_link = $event_two_link = $event_three_link = '';
19 19
 
20 20
 $I->wantTo(
21
-    'Test that when registrations for multiple events are completed, and those events share the same custom'
22
-    . 'template, that that custom template will be used.'
21
+	'Test that when registrations for multiple events are completed, and those events share the same custom'
22
+	. 'template, that that custom template will be used.'
23 23
 );
24 24
 
25 25
 //need the MER plugin active for this test (we'll deactivate it after).
26 26
 $I->ensurePluginActive(
27
-    'event-espresso-mer-multi-event-registration',
28
-    'activated'
27
+	'event-espresso-mer-multi-event-registration',
28
+	'activated'
29 29
 );
30 30
 
31 31
 $I->loginAsAdmin();
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
 
84 84
 
85 85
 $test_registration_details = array(
86
-    'fname' => 'CTGuy',
87
-    'lname' => 'Dude',
88
-    'email' => '[email protected]'
86
+	'fname' => 'CTGuy',
87
+	'lname' => 'Dude',
88
+	'email' => '[email protected]'
89 89
 );
90 90
 
91 91
 $I->amGoingTo('Register for Event One and Event Two and verify Custom Template A was used.');
@@ -111,23 +111,23 @@  discard block
 block discarded – undo
111 111
 $I->loginAsAdmin();
112 112
 $I->amOnMessagesActivityListTablePage();
113 113
 $I->viewMessageInMessagesListTableFor(
114
-    'Registration Approved',
115
-    MessagesAdmin::MESSAGE_STATUS_SENT,
116
-    'Email',
117
-    'Registrant'
114
+	'Registration Approved',
115
+	MessagesAdmin::MESSAGE_STATUS_SENT,
116
+	'Email',
117
+	'Registrant'
118 118
 );
119 119
 $I->seeTextInViewMessageModal($custom_template_a_label);
120 120
 $I->dismissMessageModal();
121 121
 $I->deleteMessageInMessagesListTableFor(
122
-    'Registration Approved',
123
-    MessagesAdmin::MESSAGE_STATUS_SENT,
124
-    'Email',
125
-    'Registrant'
122
+	'Registration Approved',
123
+	MessagesAdmin::MESSAGE_STATUS_SENT,
124
+	'Email',
125
+	'Registrant'
126 126
 );
127 127
 
128 128
 //verify admin context
129 129
 $I->viewMessageInMessagesListTableFor(
130
-    'Registration Approved'
130
+	'Registration Approved'
131 131
 );
132 132
 $I->seeTextInViewMessageModal($custom_template_a_label);
133 133
 $I->dismissMessageModal();
@@ -156,25 +156,25 @@  discard block
 block discarded – undo
156 156
 $I->loginAsAdmin();
157 157
 $I->amOnMessagesActivityListTablePage();
158 158
 $I->viewMessageInMessagesListTableFor(
159
-    'Registration Approved',
160
-    MessagesAdmin::MESSAGE_STATUS_SENT,
161
-    'Email',
162
-    'Registrant'
159
+	'Registration Approved',
160
+	MessagesAdmin::MESSAGE_STATUS_SENT,
161
+	'Email',
162
+	'Registrant'
163 163
 );
164 164
 $I->waitForElementVisible(MessagesAdmin::MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR);
165 165
 $I->dontSeeTextInViewMessageModal($custom_template_a_label);
166 166
 $I->dontSeeTextInViewMessageModal($custom_template_b_label);
167 167
 $I->dismissMessageModal();
168 168
 $I->deleteMessageInMessagesListTableFor(
169
-    'Registration Approved',
170
-    MessagesAdmin::MESSAGE_STATUS_SENT,
171
-    'Email',
172
-    'Registrant'
169
+	'Registration Approved',
170
+	MessagesAdmin::MESSAGE_STATUS_SENT,
171
+	'Email',
172
+	'Registrant'
173 173
 );
174 174
 
175 175
 //verify admin context
176 176
 $I->viewMessageInMessagesListTableFor(
177
-    'Registration Approved'
177
+	'Registration Approved'
178 178
 );
179 179
 $I->waitForElementVisible(MessagesAdmin::MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR);
180 180
 $I->dontSee($custom_template_a_label);
@@ -186,6 +186,6 @@  discard block
 block discarded – undo
186 186
 
187 187
 //deactivate MER plugin so its not active for future tests
188 188
 $I->ensurePluginDeactivated(
189
-    'event-espresso-mer-multi-event-registration',
190
-    'Plugin deactivated'
189
+	'event-espresso-mer-multi-event-registration',
190
+	'Plugin deactivated'
191 191
 );
192 192
\ No newline at end of file
Please login to merge, or discard this patch.
admin/extend/registrations/EE_Event_Registrations_List_Table.class.php 2 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 		$this->_columns = array_merge( $columns, $this->_columns );
91 91
 		$this->_primary_column = '_REG_att_checked_in';
92 92
 		if ( ! empty( $evt_id )
93
-		     && EE_Registry::instance()->CAP->current_user_can(
93
+			 && EE_Registry::instance()->CAP->current_user_can(
94 94
 				'ee_read_registrations',
95 95
 				'espresso_registrations_registrations_reports',
96 96
 				$evt_id
@@ -107,44 +107,44 @@  discard block
 block discarded – undo
107 107
 				),
108 108
 			);
109 109
 		}
110
-        $this->_bottom_buttons['report_filtered'] = array(
111
-            'route'         => 'registrations_checkin_report',
112
-            'extra_request' => array(
113
-                'use_filters' => true,
114
-                'filters'     => array_merge(
115
-                    array(
116
-                        'EVT_ID' => $evt_id,
117
-                    ),
118
-                    array_diff_key(
119
-                        $this->_req_data,
120
-                        array_flip(
121
-                            array(
122
-                                'page',
123
-                                'action',
124
-                                'default_nonce',
125
-                            )
126
-                        )
127
-                    )
128
-                ),
129
-                'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
130
-            ),
131
-        );
110
+		$this->_bottom_buttons['report_filtered'] = array(
111
+			'route'         => 'registrations_checkin_report',
112
+			'extra_request' => array(
113
+				'use_filters' => true,
114
+				'filters'     => array_merge(
115
+					array(
116
+						'EVT_ID' => $evt_id,
117
+					),
118
+					array_diff_key(
119
+						$this->_req_data,
120
+						array_flip(
121
+							array(
122
+								'page',
123
+								'action',
124
+								'default_nonce',
125
+							)
126
+						)
127
+					)
128
+				),
129
+				'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
130
+			),
131
+		);
132 132
 		$this->_sortable_columns = array(
133
-            /**
134
-             * Allows users to change the default sort if they wish.
135
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
136
-             *
137
-             * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
138
-             * change the sorts on any list table involving registration contacts.  If you want to only change the filter
139
-             * for a specific list table you can use the provided reference to this object instance.
140
-             */
133
+			/**
134
+			 * Allows users to change the default sort if they wish.
135
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
136
+			 *
137
+			 * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
138
+			 * change the sorts on any list table involving registration contacts.  If you want to only change the filter
139
+			 * for a specific list table you can use the provided reference to this object instance.
140
+			 */
141 141
 			'ATT_name' => array(
142
-                    'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
143
-                    true,
144
-                    $this
145
-                )
146
-                ? array( 'ATT_lname' => true )
147
-                : array( 'ATT_fname' => true ),
142
+					'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
143
+					true,
144
+					$this
145
+				)
146
+				? array( 'ATT_lname' => true )
147
+				: array( 'ATT_fname' => true ),
148 148
 			'Event'    => array( 'Event.EVT.Name' => false ),
149 149
 		);
150 150
 		$this->_hidden_columns = array();
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 				if ( ! $evt->get_count_of_all_registrations() ) {
204 204
 					continue;
205 205
 				}
206
-                                $evts[] = array(
206
+								$evts[] = array(
207 207
 					'id'    => $evt->ID(),
208 208
 					'text'  => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get( 'EVT_name' ), $evt),
209 209
 					'class' => $evt->is_expired() ? 'ee-expired-event' : '',
@@ -227,8 +227,8 @@  discard block
 block discarded – undo
227 227
 			if ( count( $this->_dtts_for_event ) > 1 ) {
228 228
 				$dtts[0] = __( 'To toggle check-in status, select a datetime.', 'event_espresso' );
229 229
 				foreach ( $this->_dtts_for_event as $dtt ) {
230
-                    $datetime_string = $dtt->name();
231
-                    $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : '';
230
+					$datetime_string = $dtt->name();
231
+					$datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : '';
232 232
 					$datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string;
233 233
 					$dtts[ $dtt->ID() ] = $datetime_string;
234 234
 				}
@@ -301,16 +301,16 @@  discard block
 block discarded – undo
301 301
 
302 302
 
303 303
 
304
-    /**
305
-     * column_REG_att_checked_in
306
-     *
307
-     * @param EE_Registration $item
308
-     * @return string
309
-     * @throws EE_Error
310
-     * @throws InvalidArgumentException
311
-     * @throws InvalidDataTypeException
312
-     * @throws InvalidInterfaceException
313
-     */
304
+	/**
305
+	 * column_REG_att_checked_in
306
+	 *
307
+	 * @param EE_Registration $item
308
+	 * @return string
309
+	 * @throws EE_Error
310
+	 * @throws InvalidArgumentException
311
+	 * @throws InvalidDataTypeException
312
+	 * @throws InvalidInterfaceException
313
+	 */
314 314
 	public function column__REG_att_checked_in( EE_Registration $item ) {
315 315
 		$attendee = $item->attendee();
316 316
 		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
@@ -321,13 +321,13 @@  discard block
 block discarded – undo
321 321
 				$this->_cur_dtt_id = $latest_related_datetime->ID();
322 322
 			}
323 323
 		}
324
-        $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId(
325
-		    $item,
326
-            $this->_cur_dtt_id
327
-        );
324
+		$checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId(
325
+			$item,
326
+			$this->_cur_dtt_id
327
+		);
328 328
 		$nonce = wp_create_nonce( 'checkin_nonce' );
329 329
 		$toggle_active = ! empty ( $this->_cur_dtt_id )
330
-		                 && EE_Registry::instance()->CAP->current_user_can(
330
+						 && EE_Registry::instance()->CAP->current_user_can(
331 331
 			'ee_edit_checkin',
332 332
 			'espresso_registrations_toggle_checkin_status',
333 333
 			$item->ID()
@@ -336,11 +336,11 @@  discard block
 block discarded – undo
336 336
 			: '';
337 337
 		$mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
338 338
 		return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"'
339
-		       . ' data-_regid="' . $item->ID() . '"'
340
-		       . ' data-dttid="' . $this->_cur_dtt_id . '"'
341
-		       . ' data-nonce="' . $nonce . '">'
342
-		       . '</span>'
343
-		       . $mobile_view_content;
339
+			   . ' data-_regid="' . $item->ID() . '"'
340
+			   . ' data-dttid="' . $this->_cur_dtt_id . '"'
341
+			   . ' data-nonce="' . $nonce . '">'
342
+			   . '</span>'
343
+			   . $mobile_view_content;
344 344
 	}
345 345
 
346 346
 
@@ -365,8 +365,8 @@  discard block
 block discarded – undo
365 365
 			'espresso_registrations_edit_attendee'
366 366
 		)
367 367
 			? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">'
368
-			    . $item->attendee()->full_name()
369
-			    . '</a>'
368
+				. $item->attendee()->full_name()
369
+				. '</a>'
370 370
 			: $item->attendee()->full_name();
371 371
 		$name_link .= $item->count() === 1
372 372
 			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	'
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 			? $latest_related_datetime->ID()
402 402
 			: $DTT_ID;
403 403
 		if ( ! empty( $DTT_ID )
404
-		     && EE_Registry::instance()->CAP->current_user_can(
404
+			 && EE_Registry::instance()->CAP->current_user_can(
405 405
 				'ee_read_checkins',
406 406
 				'espresso_registrations_registration_checkins'
407 407
 			)
@@ -515,15 +515,15 @@  discard block
 block discarded – undo
515 515
 				) ? '
516 516
 				<span class="reg-pad-rght">
517 517
 					<a class="status-'
518
-				    . $item->transaction()->status_ID()
519
-				    . '" href="'
520
-				    . $view_txn_lnk_url
521
-				    . '"  title="'
522
-				    . esc_attr__( 'View Transaction', 'event_espresso' )
523
-				    . '">
518
+					. $item->transaction()->status_ID()
519
+					. '" href="'
520
+					. $view_txn_lnk_url
521
+					. '"  title="'
522
+					. esc_attr__( 'View Transaction', 'event_espresso' )
523
+					. '">
524 524
 						'
525
-				    . $item->transaction()->pretty_paid()
526
-				    . '
525
+					. $item->transaction()->pretty_paid()
526
+					. '
527 527
 					</a>
528 528
 				<span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
529 529
 			}
@@ -556,12 +556,12 @@  discard block
 block discarded – undo
556 556
 				'ee_read_transaction',
557 557
 				'espresso_transactions_view_transaction'
558 558
 			) ? '<a href="'
559
-			    . $view_txn_url
560
-			    . '" title="'
561
-			    . esc_attr__( 'View Transaction', 'event_espresso' )
562
-			    . '"><span class="reg-pad-rght">'
563
-			    . $txn_total
564
-			    . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
559
+				. $view_txn_url
560
+				. '" title="'
561
+				. esc_attr__( 'View Transaction', 'event_espresso' )
562
+				. '"><span class="reg-pad-rght">'
563
+				. $txn_total
564
+				. '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
565 565
 		} else {
566 566
 			return '<span class="reg-pad-rght"></span>';
567 567
 		}
Please login to merge, or discard this patch.
Spacing   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -45,51 +45,51 @@  discard block
 block discarded – undo
45 45
 	 *
46 46
 	 * @param \Registrations_Admin_Page $admin_page
47 47
 	 */
48
-	public function __construct( $admin_page ) {
49
-		parent::__construct( $admin_page );
48
+	public function __construct($admin_page) {
49
+		parent::__construct($admin_page);
50 50
 		$this->_status = $this->_admin_page->get_registration_status_array();
51 51
 	}
52 52
 
53 53
 
54 54
 
55 55
 	protected function _setup_data() {
56
-		$this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( $this->_per_page )
57
-			: $this->_admin_page->get_event_attendees( $this->_per_page, false, true );
56
+		$this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page)
57
+			: $this->_admin_page->get_event_attendees($this->_per_page, false, true);
58 58
 		$this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees(
59 59
 			$this->_per_page,
60 60
 			true
61
-		) : $this->_admin_page->get_event_attendees( $this->_per_page, true, true );
61
+		) : $this->_admin_page->get_event_attendees($this->_per_page, true, true);
62 62
 	}
63 63
 
64 64
 
65 65
 
66 66
 	protected function _set_properties() {
67
-		$evt_id = isset( $this->_req_data['event_id'] ) ? $this->_req_data['event_id'] : null;
67
+		$evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
68 68
 		$this->_wp_list_args = array(
69
-			'singular' => __( 'registrant', 'event_espresso' ),
70
-			'plural'   => __( 'registrants', 'event_espresso' ),
69
+			'singular' => __('registrant', 'event_espresso'),
70
+			'plural'   => __('registrants', 'event_espresso'),
71 71
 			'ajax'     => true,
72 72
 			'screen'   => $this->_admin_page->get_current_screen()->id,
73 73
 		);
74 74
 		$columns = array();
75 75
 		//$columns['_Reg_Status'] = '';
76
-		if ( ! empty( $evt_id ) ) {
76
+		if ( ! empty($evt_id)) {
77 77
 			$columns['cb'] = '<input type="checkbox" />'; //Render a checkbox instead of text
78 78
 			$this->_has_checkbox_column = true;
79 79
 		}
80 80
 		$this->_columns = array(
81 81
 			'_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>',
82
-			'ATT_name'            => __( 'Registrant', 'event_espresso' ),
83
-			'ATT_email'           => __( 'Email Address', 'event_espresso' ),
84
-			'Event'               => __( 'Event', 'event_espresso' ),
85
-			'PRC_name'            => __( 'TKT Option', 'event_espresso' ),
86
-			'_REG_final_price'    => __( 'Price', 'event_espresso' ),
87
-			'TXN_paid'            => __( 'Paid', 'event_espresso' ),
88
-			'TXN_total'           => __( 'Total', 'event_espresso' ),
82
+			'ATT_name'            => __('Registrant', 'event_espresso'),
83
+			'ATT_email'           => __('Email Address', 'event_espresso'),
84
+			'Event'               => __('Event', 'event_espresso'),
85
+			'PRC_name'            => __('TKT Option', 'event_espresso'),
86
+			'_REG_final_price'    => __('Price', 'event_espresso'),
87
+			'TXN_paid'            => __('Paid', 'event_espresso'),
88
+			'TXN_total'           => __('Total', 'event_espresso'),
89 89
 		);
90
-		$this->_columns = array_merge( $columns, $this->_columns );
90
+		$this->_columns = array_merge($columns, $this->_columns);
91 91
 		$this->_primary_column = '_REG_att_checked_in';
92
-		if ( ! empty( $evt_id )
92
+		if ( ! empty($evt_id)
93 93
 		     && EE_Registry::instance()->CAP->current_user_can(
94 94
 				'ee_read_registrations',
95 95
 				'espresso_registrations_registrations_reports',
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 					'extra_request' =>
103 103
 						array(
104 104
 							'EVT_ID'     => $evt_id,
105
-							'return_url' => urlencode( "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}" ),
105
+							'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
106 106
 						),
107 107
 				),
108 108
 			);
@@ -143,12 +143,12 @@  discard block
 block discarded – undo
143 143
                     true,
144 144
                     $this
145 145
                 )
146
-                ? array( 'ATT_lname' => true )
147
-                : array( 'ATT_fname' => true ),
148
-			'Event'    => array( 'Event.EVT.Name' => false ),
146
+                ? array('ATT_lname' => true)
147
+                : array('ATT_fname' => true),
148
+			'Event'    => array('Event.EVT.Name' => false),
149 149
 		);
150 150
 		$this->_hidden_columns = array();
151
-		$this->_evt = EEM_Event::instance()->get_one_by_ID( $evt_id );
151
+		$this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id);
152 152
 		$this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array();
153 153
 	}
154 154
 
@@ -158,11 +158,11 @@  discard block
 block discarded – undo
158 158
 	 * @param \EE_Registration $item
159 159
 	 * @return string
160 160
 	 */
161
-	protected function _get_row_class( $item ) {
162
-		$class = parent::_get_row_class( $item );
161
+	protected function _get_row_class($item) {
162
+		$class = parent::_get_row_class($item);
163 163
 		//add status class
164
-		$class .= ' ee-status-strip reg-status-' . $item->status_ID();
165
-		if ( $this->_has_checkbox_column ) {
164
+		$class .= ' ee-status-strip reg-status-'.$item->status_ID();
165
+		if ($this->_has_checkbox_column) {
166 166
 			$class .= ' has-checkbox-column';
167 167
 		}
168 168
 		return $class;
@@ -176,61 +176,61 @@  discard block
 block discarded – undo
176 176
 	 */
177 177
 	protected function _get_table_filters() {
178 178
 		$filters = $where = array();
179
-		$current_EVT_ID = isset( $this->_req_data['event_id'] ) ? (int) $this->_req_data['event_id'] : 0;
180
-		if ( empty( $this->_dtts_for_event ) || count( $this->_dtts_for_event ) === 1 ) {
179
+		$current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0;
180
+		if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) {
181 181
 			//this means we don't have an event so let's setup a filter dropdown for all the events to select
182 182
 			//note possible capability restrictions
183
-			if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_private_events', 'get_events' ) ) {
184
-				$where['status**'] = array( '!=', 'private' );
183
+			if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
184
+				$where['status**'] = array('!=', 'private');
185 185
 			}
186
-			if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_events', 'get_events' ) ) {
186
+			if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
187 187
 				$where['EVT_wp_user'] = get_current_user_id();
188 188
 			}
189 189
 			$events = EEM_Event::instance()->get_all(
190 190
 				array(
191 191
 					$where,
192
-					'order_by' => array( 'Datetime.DTT_EVT_start' => 'DESC' ),
192
+					'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'),
193 193
 				)
194 194
 			);
195 195
 			$evts[] = array(
196 196
 				'id'   => 0,
197
-				'text' => __( 'To toggle Check-in status, select an event', 'event_espresso' ),
197
+				'text' => __('To toggle Check-in status, select an event', 'event_espresso'),
198 198
 			);
199 199
 			$checked = 'checked';
200 200
 			/** @var EE_Event $evt */
201
-			foreach ( $events as $evt ) {
201
+			foreach ($events as $evt) {
202 202
 				//any registrations for this event?
203
-				if ( ! $evt->get_count_of_all_registrations() ) {
203
+				if ( ! $evt->get_count_of_all_registrations()) {
204 204
 					continue;
205 205
 				}
206 206
                                 $evts[] = array(
207 207
 					'id'    => $evt->ID(),
208
-					'text'  => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get( 'EVT_name' ), $evt),
208
+					'text'  => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get('EVT_name'), $evt),
209 209
 					'class' => $evt->is_expired() ? 'ee-expired-event' : '',
210 210
 				);
211
-				if ( $evt->ID() === $current_EVT_ID && $evt->is_expired() ) {
211
+				if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) {
212 212
 					$checked = '';
213 213
 				}
214 214
 			}
215 215
 			$event_filter = '<div class="ee-event-filter">';
216
-			$event_filter .= EEH_Form_Fields::select_input( 'event_id', $evts, $current_EVT_ID );
216
+			$event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID);
217 217
 			$event_filter .= '<span class="ee-event-filter-toggle">';
218
-			$event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> ';
219
-			$event_filter .= __( 'Hide Expired Events', 'event_espresso' );
218
+			$event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" '.$checked.'> ';
219
+			$event_filter .= __('Hide Expired Events', 'event_espresso');
220 220
 			$event_filter .= '</span>';
221 221
 			$event_filter .= '</div>';
222 222
 			$filters[] = $event_filter;
223 223
 		}
224
-		if ( ! empty( $this->_dtts_for_event ) ) {
224
+		if ( ! empty($this->_dtts_for_event)) {
225 225
 			//DTT datetimes filter
226
-			$this->_cur_dtt_id = isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : 0;
227
-			if ( count( $this->_dtts_for_event ) > 1 ) {
228
-				$dtts[0] = __( 'To toggle check-in status, select a datetime.', 'event_espresso' );
229
-				foreach ( $this->_dtts_for_event as $dtt ) {
226
+			$this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0;
227
+			if (count($this->_dtts_for_event) > 1) {
228
+				$dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso');
229
+				foreach ($this->_dtts_for_event as $dtt) {
230 230
                     $datetime_string = $dtt->name();
231
-                    $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : '';
232
-					$datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string;
233
-					$dtts[ $dtt->ID() ] = $datetime_string;
231
+                    $datetime_string = ! empty($datetime_string) ? ' ('.$datetime_string.')' : '';
232
+					$datetime_string = $dtt->start_date_and_time().' - '.$dtt->end_date_and_time().$datetime_string;
233
+					$dtts[$dtt->ID()] = $datetime_string;
234 234
 				}
235 235
 				$input = new EE_Select_Input(
236 236
 					$dtts,
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 					)
242 242
 				);
243 243
 				$filters[] = $input->get_html_for_input();
244
-				$filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">';
244
+				$filters[] = '<input type="hidden" name="event_id" value="'.$current_EVT_ID.'">';
245 245
 			}
246 246
 		}
247 247
 		return $filters;
@@ -260,22 +260,22 @@  discard block
 block discarded – undo
260 260
 	 * @throws \EE_Error
261 261
 	 */
262 262
 	protected function _get_total_event_attendees() {
263
-		$EVT_ID = isset( $this->_req_data['event_id'] ) ? absint( $this->_req_data['event_id'] ) : false;
263
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
264 264
 		$DTT_ID = $this->_cur_dtt_id;
265 265
 		$query_params = array();
266
-		if ( $EVT_ID ) {
266
+		if ($EVT_ID) {
267 267
 			$query_params[0]['EVT_ID'] = $EVT_ID;
268 268
 		}
269 269
 		//if DTT is included we only show for that datetime.  Otherwise we're showing for all datetimes (the event).
270
-		if ( $DTT_ID ) {
270
+		if ($DTT_ID) {
271 271
 			$query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID;
272 272
 		}
273 273
 		$status_ids_array = apply_filters(
274 274
 			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
275
-			array( EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved )
275
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
276 276
 		);
277
-		$query_params[0]['STS_ID'] = array( 'IN', $status_ids_array );
278
-		return EEM_Registration::instance()->count( $query_params );
277
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
278
+		return EEM_Registration::instance()->count($query_params);
279 279
 	}
280 280
 
281 281
 
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 	 * @param \EE_Registration $item
285 285
 	 * @return string
286 286
 	 */
287
-	public function column__Reg_Status( EE_Registration $item ) {
288
-		return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>';
287
+	public function column__Reg_Status(EE_Registration $item) {
288
+		return '<span class="ee-status-strip ee-status-strip-td reg-status-'.$item->status_ID().'"></span>';
289 289
 	}
290 290
 
291 291
 
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 	 * @return string
296 296
 	 * @throws \EE_Error
297 297
 	 */
298
-	public function column_cb( $item ) {
299
-		return sprintf( '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID() );
298
+	public function column_cb($item) {
299
+		return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID());
300 300
 	}
301 301
 
302 302
 
@@ -311,13 +311,13 @@  discard block
 block discarded – undo
311 311
      * @throws InvalidDataTypeException
312 312
      * @throws InvalidInterfaceException
313 313
      */
314
-	public function column__REG_att_checked_in( EE_Registration $item ) {
314
+	public function column__REG_att_checked_in(EE_Registration $item) {
315 315
 		$attendee = $item->attendee();
316 316
 		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
317 317
 
318
-		if ( $this->_cur_dtt_id === 0 && count( $this->_dtts_for_event ) === 1 ) {
318
+		if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) {
319 319
 			$latest_related_datetime = $item->get_latest_related_datetime();
320
-			if ( $latest_related_datetime instanceof EE_Datetime ) {
320
+			if ($latest_related_datetime instanceof EE_Datetime) {
321 321
 				$this->_cur_dtt_id = $latest_related_datetime->ID();
322 322
 			}
323 323
 		}
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
 		    $item,
326 326
             $this->_cur_dtt_id
327 327
         );
328
-		$nonce = wp_create_nonce( 'checkin_nonce' );
329
-		$toggle_active = ! empty ( $this->_cur_dtt_id )
328
+		$nonce = wp_create_nonce('checkin_nonce');
329
+		$toggle_active = ! empty ($this->_cur_dtt_id)
330 330
 		                 && EE_Registry::instance()->CAP->current_user_can(
331 331
 			'ee_edit_checkin',
332 332
 			'espresso_registrations_toggle_checkin_status',
@@ -334,11 +334,11 @@  discard block
 block discarded – undo
334 334
 		)
335 335
 			? ' clickable trigger-checkin'
336 336
 			: '';
337
-		$mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
338
-		return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"'
339
-		       . ' data-_regid="' . $item->ID() . '"'
340
-		       . ' data-dttid="' . $this->_cur_dtt_id . '"'
341
-		       . ' data-nonce="' . $nonce . '">'
337
+		$mobile_view_content = ' <span class="show-on-mobile-view-only">'.$attendee_name.'</span>';
338
+		return '<span class="'.$checkin_status_dashicon->cssClasses().$toggle_active.'"'
339
+		       . ' data-_regid="'.$item->ID().'"'
340
+		       . ' data-dttid="'.$this->_cur_dtt_id.'"'
341
+		       . ' data-nonce="'.$nonce.'">'
342 342
 		       . '</span>'
343 343
 		       . $mobile_view_content;
344 344
 	}
@@ -350,21 +350,21 @@  discard block
 block discarded – undo
350 350
 	 * @return mixed|string|void
351 351
 	 * @throws \EE_Error
352 352
 	 */
353
-	public function column_ATT_name( EE_Registration $item ) {
353
+	public function column_ATT_name(EE_Registration $item) {
354 354
 		$attendee = $item->attendee();
355
-		if ( ! $attendee instanceof EE_Attendee ) {
356
-			return __( 'No contact record for this registration.', 'event_espresso' );
355
+		if ( ! $attendee instanceof EE_Attendee) {
356
+			return __('No contact record for this registration.', 'event_espresso');
357 357
 		}
358 358
 		// edit attendee link
359 359
 		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
360
-			array( 'action' => 'view_registration', '_REG_ID' => $item->ID() ),
360
+			array('action' => 'view_registration', '_REG_ID' => $item->ID()),
361 361
 			REG_ADMIN_URL
362 362
 		);
363 363
 		$name_link = EE_Registry::instance()->CAP->current_user_can(
364 364
 			'ee_edit_contacts',
365 365
 			'espresso_registrations_edit_attendee'
366 366
 		)
367
-			? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">'
367
+			? '<a href="'.$edit_lnk_url.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">'
368 368
 			    . $item->attendee()->full_name()
369 369
 			    . '</a>'
370 370
 			: $item->attendee()->full_name();
@@ -372,10 +372,10 @@  discard block
 block discarded – undo
372 372
 			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	'
373 373
 			: '';
374 374
 		//add group details
375
-		$name_link .= '&nbsp;' . sprintf( __( '(%s of %s)', 'event_espresso' ), $item->count(), $item->group_size() );
375
+		$name_link .= '&nbsp;'.sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size());
376 376
 		//add regcode
377 377
 		$link = EE_Admin_Page::add_query_args_and_nonce(
378
-			array( 'action' => 'view_registration', '_REG_ID' => $item->ID() ),
378
+			array('action' => 'view_registration', '_REG_ID' => $item->ID()),
379 379
 			REG_ADMIN_URL
380 380
 		);
381 381
 		$name_link .= '<br>';
@@ -384,50 +384,50 @@  discard block
 block discarded – undo
384 384
 			'view_registration',
385 385
 			$item->ID()
386 386
 		)
387
-			? '<a href="' . $link . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">'
387
+			? '<a href="'.$link.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">'
388 388
 			  . $item->reg_code()
389 389
 			  . '</a>'
390 390
 			: $item->reg_code();
391 391
 		//status
392 392
 		$name_link .= '<br><span class="ee-status-text-small">';
393
-		$name_link .= EEH_Template::pretty_status( $item->status_ID(), false, 'sentence' );
393
+		$name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence');
394 394
 		$name_link .= '</span>';
395 395
 		$actions = array();
396 396
 		$DTT_ID = $this->_cur_dtt_id;
397
-		$latest_related_datetime = empty( $DTT_ID ) && ! empty( $this->_req_data['event_id'] ) && $item instanceof EE_Registration
397
+		$latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration
398 398
 			? $item->get_latest_related_datetime()
399 399
 			: null;
400 400
 		$DTT_ID = $latest_related_datetime instanceof EE_Datetime
401 401
 			? $latest_related_datetime->ID()
402 402
 			: $DTT_ID;
403
-		if ( ! empty( $DTT_ID )
403
+		if ( ! empty($DTT_ID)
404 404
 		     && EE_Registry::instance()->CAP->current_user_can(
405 405
 				'ee_read_checkins',
406 406
 				'espresso_registrations_registration_checkins'
407 407
 			)
408 408
 		) {
409 409
 			$checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(
410
-				array( 'action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID )
410
+				array('action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID)
411 411
 			);
412 412
 			// get the timestamps for this registration's checkins, related to the selected datetime
413
-			$timestamps = $item->get_many_related( 'Checkin', array( array( 'DTT_ID' => $DTT_ID ) ) );
414
-			if( ! empty( $timestamps ) ) {
413
+			$timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID)));
414
+			if ( ! empty($timestamps)) {
415 415
 				// get the last timestamp
416
-				$last_timestamp = end( $timestamps );
416
+				$last_timestamp = end($timestamps);
417 417
 				// checked in or checked out?
418
-				$checkin_status = $last_timestamp->get( 'CHK_in' )
419
-					? esc_html__( 'Checked In', 'event_espresso' )
420
-					: esc_html__( 'Checked Out', 'event_espresso' );
418
+				$checkin_status = $last_timestamp->get('CHK_in')
419
+					? esc_html__('Checked In', 'event_espresso')
420
+					: esc_html__('Checked Out', 'event_espresso');
421 421
 				// get timestamp string
422
-				$timestamp_string = $last_timestamp->get_datetime( 'CHK_timestamp' );
423
-				$actions['checkin'] = '<a href="' . $checkin_list_url . '" title="' . esc_attr__(
422
+				$timestamp_string = $last_timestamp->get_datetime('CHK_timestamp');
423
+				$actions['checkin'] = '<a href="'.$checkin_list_url.'" title="'.esc_attr__(
424 424
 						'View this registrant\'s check-ins/checkouts for the datetime',
425 425
 						'event_espresso'
426
-					) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>';
426
+					).'">'.$checkin_status.': '.$timestamp_string.'</a>';
427 427
 			}
428 428
 		}
429
-		return ( ! empty( $DTT_ID ) && ! empty( $timestamps ) )
430
-			? sprintf( '%1$s %2$s', $name_link, $this->row_actions( $actions, true ) )
429
+		return ( ! empty($DTT_ID) && ! empty($timestamps))
430
+			? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true))
431 431
 			: $name_link;
432 432
 	}
433 433
 
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 	 * @param \EE_Registration $item
438 438
 	 * @return string
439 439
 	 */
440
-	public function column_ATT_email( EE_Registration $item ) {
440
+	public function column_ATT_email(EE_Registration $item) {
441 441
 		$attendee = $item->attendee();
442 442
 		return $attendee instanceof EE_Attendee ? $attendee->email() : '';
443 443
 	}
@@ -449,22 +449,22 @@  discard block
 block discarded – undo
449 449
 	 * @return bool|string
450 450
 	 * @throws \EE_Error
451 451
 	 */
452
-	public function column_Event( EE_Registration $item ) {
452
+	public function column_Event(EE_Registration $item) {
453 453
 		try {
454 454
 			$event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event();
455 455
 			$chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
456
-				array( 'action' => 'event_registrations', 'event_id' => $event->ID() ),
456
+				array('action' => 'event_registrations', 'event_id' => $event->ID()),
457 457
 				REG_ADMIN_URL
458 458
 			);
459 459
 			$event_label = EE_Registry::instance()->CAP->current_user_can(
460 460
 				'ee_read_checkins',
461 461
 				'espresso_registrations_registration_checkins'
462
-			) ? '<a href="' . $chkin_lnk_url . '" title="' . esc_attr__(
462
+			) ? '<a href="'.$chkin_lnk_url.'" title="'.esc_attr__(
463 463
 					'View Checkins for this Event',
464 464
 					'event_espresso'
465
-				) . '">' . $event->name() . '</a>' : $event->name();
466
-		} catch ( \EventEspresso\core\exceptions\EntityNotFoundException $e ) {
467
-			$event_label = esc_html__( 'Unknown', 'event_espresso' );
465
+				).'">'.$event->name().'</a>' : $event->name();
466
+		} catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) {
467
+			$event_label = esc_html__('Unknown', 'event_espresso');
468 468
 		}
469 469
 		return $event_label;
470 470
 	}
@@ -475,8 +475,8 @@  discard block
 block discarded – undo
475 475
 	 * @param \EE_Registration $item
476 476
 	 * @return mixed|string|void
477 477
 	 */
478
-	public function column_PRC_name( EE_Registration $item ) {
479
-		return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __( "Unknown", "event_espresso" );
478
+	public function column_PRC_name(EE_Registration $item) {
479
+		return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __("Unknown", "event_espresso");
480 480
 	}
481 481
 
482 482
 
@@ -487,8 +487,8 @@  discard block
 block discarded – undo
487 487
 	 * @param \EE_Registration $item
488 488
 	 * @return string
489 489
 	 */
490
-	public function column__REG_final_price( EE_Registration $item ) {
491
-		return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>';
490
+	public function column__REG_final_price(EE_Registration $item) {
491
+		return '<span class="reg-pad-rght">'.' '.$item->pretty_final_price().'</span>';
492 492
 	}
493 493
 
494 494
 
@@ -500,13 +500,13 @@  discard block
 block discarded – undo
500 500
 	 * @return string
501 501
 	 * @throws \EE_Error
502 502
 	 */
503
-	public function column_TXN_paid( EE_Registration $item ) {
504
-		if ( $item->count() === 1 ) {
505
-			if ( $item->transaction()->paid() >= $item->transaction()->total() ) {
503
+	public function column_TXN_paid(EE_Registration $item) {
504
+		if ($item->count() === 1) {
505
+			if ($item->transaction()->paid() >= $item->transaction()->total()) {
506 506
 				return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
507 507
 			} else {
508 508
 				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
509
-					array( 'action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID() ),
509
+					array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()),
510 510
 					TXN_ADMIN_URL
511 511
 				);
512 512
 				return EE_Registry::instance()->CAP->current_user_can(
@@ -519,13 +519,13 @@  discard block
 block discarded – undo
519 519
 				    . '" href="'
520 520
 				    . $view_txn_lnk_url
521 521
 				    . '"  title="'
522
-				    . esc_attr__( 'View Transaction', 'event_espresso' )
522
+				    . esc_attr__('View Transaction', 'event_espresso')
523 523
 				    . '">
524 524
 						'
525 525
 				    . $item->transaction()->pretty_paid()
526 526
 				    . '
527 527
 					</a>
528
-				<span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
528
+				<span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>';
529 529
 			}
530 530
 		} else {
531 531
 			return '<span class="reg-pad-rght"></span>';
@@ -541,13 +541,13 @@  discard block
 block discarded – undo
541 541
 	 * @return string
542 542
 	 * @throws \EE_Error
543 543
 	 */
544
-	public function column_TXN_total( EE_Registration $item ) {
544
+	public function column_TXN_total(EE_Registration $item) {
545 545
 		$txn = $item->transaction();
546
-		$view_txn_url = add_query_arg( array( 'action' => 'view_transaction', 'TXN_ID' => $txn->ID() ), TXN_ADMIN_URL );
547
-		if ( $item->get( 'REG_count' ) === 1 ) {
546
+		$view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL);
547
+		if ($item->get('REG_count') === 1) {
548 548
 			$line_total_obj = $txn->total_line_item();
549 549
 			$txn_total = $line_total_obj instanceof EE_Line_Item
550
-				? $line_total_obj->get_pretty( 'LIN_total' )
550
+				? $line_total_obj->get_pretty('LIN_total')
551 551
 				: __(
552 552
 					'View Transaction',
553 553
 					'event_espresso'
@@ -558,10 +558,10 @@  discard block
 block discarded – undo
558 558
 			) ? '<a href="'
559 559
 			    . $view_txn_url
560 560
 			    . '" title="'
561
-			    . esc_attr__( 'View Transaction', 'event_espresso' )
561
+			    . esc_attr__('View Transaction', 'event_espresso')
562 562
 			    . '"><span class="reg-pad-rght">'
563 563
 			    . $txn_total
564
-			    . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
564
+			    . '</span></a>' : '<span class="reg-pad-rght">'.$txn_total.'</span>';
565 565
 		} else {
566 566
 			return '<span class="reg-pad-rght"></span>';
567 567
 		}
Please login to merge, or discard this patch.
admin/extend/registrations/EE_Registration_CheckIn_List_Table.class.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,8 +90,8 @@
 block discarded – undo
90 90
 
91 91
 
92 92
 	public function column_CHK_in( EE_Checkin $item ) {
93
-        $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item);
94
-        return '<span class="' . $checkin_status_dashicon->cssClasses() . '"></span><span class="show-on-mobile-view-only">' . $item->get_datetime('CHK_timestamp') . '</span>';
93
+		$checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item);
94
+		return '<span class="' . $checkin_status_dashicon->cssClasses() . '"></span><span class="show-on-mobile-view-only">' . $item->get_datetime('CHK_timestamp') . '</span>';
95 95
 	}
96 96
 
97 97
 
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
 
32 32
 
33
-	public function __construct( $admin_page ) {
33
+	public function __construct($admin_page) {
34 34
 		parent::__construct($admin_page);
35 35
 	}
36 36
 
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
 
39 39
 
40 40
 	protected function _setup_data() {
41
-		$this->_data = $this->_get_checkins( $this->_per_page );
42
-		$this->_all_data_count = $this->_get_checkins(  $this->_per_page, TRUE );
41
+		$this->_data = $this->_get_checkins($this->_per_page);
42
+		$this->_all_data_count = $this->_get_checkins($this->_per_page, TRUE);
43 43
 	}
44 44
 
45 45
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 			);
61 61
 
62 62
 		$this->_sortable_columns = array(
63
-			'CHK_timestamp' => array( 'CHK_timestamp' => TRUE )
63
+			'CHK_timestamp' => array('CHK_timestamp' => TRUE)
64 64
 			);
65 65
 
66 66
 		$this->_primary_column = 'CHK_in';
@@ -84,24 +84,24 @@  discard block
 block discarded – undo
84 84
 	}
85 85
 
86 86
 
87
-	function column_cb($item ) {
88
-		return sprintf( '<input type="checkbox" name="checkbox[%1$s]" />', $item->ID() );
87
+	function column_cb($item) {
88
+		return sprintf('<input type="checkbox" name="checkbox[%1$s]" />', $item->ID());
89 89
 	}
90 90
 
91 91
 
92
-	public function column_CHK_in( EE_Checkin $item ) {
92
+	public function column_CHK_in(EE_Checkin $item) {
93 93
         $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item);
94
-        return '<span class="' . $checkin_status_dashicon->cssClasses() . '"></span><span class="show-on-mobile-view-only">' . $item->get_datetime('CHK_timestamp') . '</span>';
94
+        return '<span class="'.$checkin_status_dashicon->cssClasses().'"></span><span class="show-on-mobile-view-only">'.$item->get_datetime('CHK_timestamp').'</span>';
95 95
 	}
96 96
 
97 97
 
98 98
 
99
-	function column_CHK_timestamp( EE_Checkin $item ) {
99
+	function column_CHK_timestamp(EE_Checkin $item) {
100 100
 		$actions = array();
101
-		$delete_url = EE_Admin_Page::add_query_args_and_nonce( array('action' => 'delete_checkin_row', 'DTT_ID' => $this->_req_data['DTT_ID'], '_REGID' => $this->_req_data['_REGID'], 'CHK_ID' => $item->ID() ) );
102
-		$actions['delete_checkin'] = EE_Registry::instance()->CAP->current_user_can( 'ee_delete_checkins', 'espresso_registrations_delete_checkin_row' ) ? '<a href="' . $delete_url . '" title="' . esc_attr__('Click here to delete this check-in record', 'event_espresso') . '">' . __('Delete', 'event_espresso') . '</a>' : '';
101
+		$delete_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'delete_checkin_row', 'DTT_ID' => $this->_req_data['DTT_ID'], '_REGID' => $this->_req_data['_REGID'], 'CHK_ID' => $item->ID()));
102
+		$actions['delete_checkin'] = EE_Registry::instance()->CAP->current_user_can('ee_delete_checkins', 'espresso_registrations_delete_checkin_row') ? '<a href="'.$delete_url.'" title="'.esc_attr__('Click here to delete this check-in record', 'event_espresso').'">'.__('Delete', 'event_espresso').'</a>' : '';
103 103
 
104
-		return sprintf( '%1$s %2$s', $item->get_datetime('CHK_timestamp'), $this->row_actions($actions) );
104
+		return sprintf('%1$s %2$s', $item->get_datetime('CHK_timestamp'), $this->row_actions($actions));
105 105
 	}
106 106
 
107 107
 
@@ -116,30 +116,30 @@  discard block
 block discarded – undo
116 116
 	 * @param bool    $count        Whether to return a count or not
117 117
 	 * @return EE_Checkin[]|int
118 118
 	 */
119
-	protected function _get_checkins( $per_page = 10, $count = FALSE ) {
120
-		$REG_ID = isset( $this->_req_data['_REGID'] ) ? $this->_req_data['_REGID'] : FALSE;
121
-		$DTT_ID = isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : FALSE;
119
+	protected function _get_checkins($per_page = 10, $count = FALSE) {
120
+		$REG_ID = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : FALSE;
121
+		$DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : FALSE;
122 122
 
123 123
 		//if user does not have the capability for the checkins for this registration then get out!
124
-		if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_checkin', 'espresso_registrations_registration_checkins', $REG_ID ) ) {
124
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_checkin', 'espresso_registrations_registration_checkins', $REG_ID)) {
125 125
 			return $count ? 0 : array();
126 126
 		}
127 127
 
128 128
 		//if no reg id then get out cause need a reg id
129
-		if ( empty( $REG_ID ) || empty( $DTT_ID ) )
130
-			throw new EE_Error(__('This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', 'event_espresso') );
129
+		if (empty($REG_ID) || empty($DTT_ID))
130
+			throw new EE_Error(__('This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', 'event_espresso'));
131 131
 
132 132
 		//set orderby
133 133
 		$orderby = 'CHK_timestamp'; //note that with this table we're only providing the option to orderby the timestamp value.
134 134
 
135
-		$order = !empty( $this->_req_data['order'] ) ? $this->_req_data['order'] : 'ASC';
135
+		$order = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
136 136
 
137
-		$current_page = isset( $this->_req_data['paged'] ) && !empty( $this->_req_data['paged'] ) ? $this->_req_data['paged'] : 1;
138
-		$per_page = isset( $this->_req_data['perpage'] ) && !empty( $this->_req_data['perpage'] ) ? $this->_req_data['perpage'] : $per_page;
137
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
138
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
139 139
 		$limit = NULL;
140
-		if ( !$count ) {
141
-			$offset = ($current_page-1)*$per_page;
142
-			$limit = array( $offset, $per_page );
140
+		if ( ! $count) {
141
+			$offset = ($current_page - 1) * $per_page;
142
+			$limit = array($offset, $per_page);
143 143
 		}
144 144
 
145 145
 		$_where = array(
@@ -147,13 +147,13 @@  discard block
 block discarded – undo
147 147
 			'DTT_ID' => $DTT_ID
148 148
 			);
149 149
 
150
-		$query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit );
150
+		$query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
151 151
 
152 152
 		//if no per_page value then we just want to return a count of all Check-ins
153
-		if ( $count )
154
-			return EEM_Checkin::instance()->count( array( $_where ) );
153
+		if ($count)
154
+			return EEM_Checkin::instance()->count(array($_where));
155 155
 
156
-		return $count ? EEM_Checkin::instance()->count( array( $_where ) ) : EEM_Checkin::instance()->get_all($query_params);
156
+		return $count ? EEM_Checkin::instance()->count(array($_where)) : EEM_Checkin::instance()->get_all($query_params);
157 157
 	}
158 158
 
159 159
 } //end class EE_Registration_CheckIn_List_Table
Please login to merge, or discard this patch.
Braces   +9 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\ui\browser\checkins\entities\CheckinStatusDashicon;
2 2
 
3
-if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5
+}
4 6
 /**
5 7
  * Event Espresso
6 8
  *
@@ -126,8 +128,9 @@  discard block
 block discarded – undo
126 128
 		}
127 129
 
128 130
 		//if no reg id then get out cause need a reg id
129
-		if ( empty( $REG_ID ) || empty( $DTT_ID ) )
130
-			throw new EE_Error(__('This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', 'event_espresso') );
131
+		if ( empty( $REG_ID ) || empty( $DTT_ID ) ) {
132
+					throw new EE_Error(__('This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', 'event_espresso') );
133
+		}
131 134
 
132 135
 		//set orderby
133 136
 		$orderby = 'CHK_timestamp'; //note that with this table we're only providing the option to orderby the timestamp value.
@@ -150,8 +153,9 @@  discard block
 block discarded – undo
150 153
 		$query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit );
151 154
 
152 155
 		//if no per_page value then we just want to return a count of all Check-ins
153
-		if ( $count )
154
-			return EEM_Checkin::instance()->count( array( $_where ) );
156
+		if ( $count ) {
157
+					return EEM_Checkin::instance()->count( array( $_where ) );
158
+		}
155 159
 
156 160
 		return $count ? EEM_Checkin::instance()->count( array( $_where ) ) : EEM_Checkin::instance()->get_all($query_params);
157 161
 	}
Please login to merge, or discard this patch.
core/db_classes/EE_Checkin.class.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -13,88 +13,88 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * Used to reference when a registration has been checked out.
18
-     *
19
-     * @type int
20
-     */
21
-    const status_checked_out = 0;
22
-
23
-    /**
24
-     * Used to reference when a registration has been checked in.
25
-     *
26
-     * @type int
27
-     */
28
-    const status_checked_in = 1;
29
-
30
-    /**
31
-     * Used to reference when a registration has never been checked in.
32
-     *
33
-     * @type int
34
-     */
35
-    const status_checked_never = 2;
36
-
37
-
38
-
39
-    /**
40
-     *
41
-     * @param array  $props_n_values    incoming values
42
-     * @param string $timezone          incoming timezone (if not set the timezone set for the website will be used.)
43
-     * @param array  $date_formats      incoming date_formats in an array
44
-     *                                  where the first value is the date_format
45
-     *                                  and the second value is the time format
46
-     * @return EE_Checkin
47
-     * @throws EE_Error
48
-     */
49
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
50
-    {
51
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
52
-        return $has_object
53
-            ? $has_object
54
-            : new self($props_n_values, false, $timezone, $date_formats);
55
-    }
56
-
57
-
58
-
59
-    /**
60
-     * @param array  $props_n_values  incoming values from the database
61
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
62
-     *                                the website will be used.
63
-     * @return EE_Checkin
64
-     * @throws EE_Error
65
-     */
66
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
67
-    {
68
-        return new self($props_n_values, true, $timezone);
69
-    }
70
-
71
-
72
-    public function ID()
73
-    {
74
-        return $this->get('CHK_ID');
75
-    }
76
-
77
-
78
-    public function registration_id()
79
-    {
80
-        return $this->get('REG_ID');
81
-    }
82
-
83
-
84
-    public function datetime_id()
85
-    {
86
-        return $this->get('DTT_ID');
87
-    }
88
-
89
-
90
-    public function status()
91
-    {
92
-        return $this->get('CHK_in');
93
-    }
94
-
95
-
96
-    public function timestamp()
97
-    {
98
-        return $this->get('CHK_timestamp');
99
-    }
16
+	/**
17
+	 * Used to reference when a registration has been checked out.
18
+	 *
19
+	 * @type int
20
+	 */
21
+	const status_checked_out = 0;
22
+
23
+	/**
24
+	 * Used to reference when a registration has been checked in.
25
+	 *
26
+	 * @type int
27
+	 */
28
+	const status_checked_in = 1;
29
+
30
+	/**
31
+	 * Used to reference when a registration has never been checked in.
32
+	 *
33
+	 * @type int
34
+	 */
35
+	const status_checked_never = 2;
36
+
37
+
38
+
39
+	/**
40
+	 *
41
+	 * @param array  $props_n_values    incoming values
42
+	 * @param string $timezone          incoming timezone (if not set the timezone set for the website will be used.)
43
+	 * @param array  $date_formats      incoming date_formats in an array
44
+	 *                                  where the first value is the date_format
45
+	 *                                  and the second value is the time format
46
+	 * @return EE_Checkin
47
+	 * @throws EE_Error
48
+	 */
49
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
50
+	{
51
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
52
+		return $has_object
53
+			? $has_object
54
+			: new self($props_n_values, false, $timezone, $date_formats);
55
+	}
56
+
57
+
58
+
59
+	/**
60
+	 * @param array  $props_n_values  incoming values from the database
61
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
62
+	 *                                the website will be used.
63
+	 * @return EE_Checkin
64
+	 * @throws EE_Error
65
+	 */
66
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
67
+	{
68
+		return new self($props_n_values, true, $timezone);
69
+	}
70
+
71
+
72
+	public function ID()
73
+	{
74
+		return $this->get('CHK_ID');
75
+	}
76
+
77
+
78
+	public function registration_id()
79
+	{
80
+		return $this->get('REG_ID');
81
+	}
82
+
83
+
84
+	public function datetime_id()
85
+	{
86
+		return $this->get('DTT_ID');
87
+	}
88
+
89
+
90
+	public function status()
91
+	{
92
+		return $this->get('CHK_in');
93
+	}
94
+
95
+
96
+	public function timestamp()
97
+	{
98
+		return $this->get('CHK_timestamp');
99
+	}
100 100
 }
Please login to merge, or discard this patch.