Completed
Branch FET/Gutenberg/11467/espresso-c... (b0019e)
by
unknown
39:36 queued 26:28
created
core/EE_Registry.core.php 1 patch
Indentation   +1587 added lines, -1587 removed lines patch added patch discarded remove patch
@@ -23,1593 +23,1593 @@
 block discarded – undo
23 23
 class EE_Registry implements ResettableInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Registry $_instance
28
-     */
29
-    private static $_instance;
30
-
31
-    /**
32
-     * @var EE_Dependency_Map $_dependency_map
33
-     */
34
-    protected $_dependency_map;
35
-
36
-    /**
37
-     * @var array $_class_abbreviations
38
-     */
39
-    protected $_class_abbreviations = array();
40
-
41
-    /**
42
-     * @var CommandBusInterface $BUS
43
-     */
44
-    public $BUS;
45
-
46
-    /**
47
-     * @var EE_Cart $CART
48
-     */
49
-    public $CART;
50
-
51
-    /**
52
-     * @var EE_Config $CFG
53
-     */
54
-    public $CFG;
55
-
56
-    /**
57
-     * @var EE_Network_Config $NET_CFG
58
-     */
59
-    public $NET_CFG;
60
-
61
-    /**
62
-     * StdClass object for storing library classes in
63
-     *
64
-     * @var StdClass $LIB
65
-     */
66
-    public $LIB;
67
-
68
-    /**
69
-     * @var EE_Request_Handler $REQ
70
-     */
71
-    public $REQ;
72
-
73
-    /**
74
-     * @var EE_Session $SSN
75
-     */
76
-    public $SSN;
77
-
78
-    /**
79
-     * @since 4.5.0
80
-     * @var EE_Capabilities $CAP
81
-     */
82
-    public $CAP;
83
-
84
-    /**
85
-     * @since 4.9.0
86
-     * @var EE_Message_Resource_Manager $MRM
87
-     */
88
-    public $MRM;
89
-
90
-
91
-    /**
92
-     * @var Registry $AssetsRegistry
93
-     */
94
-    public $AssetsRegistry;
95
-
96
-    /**
97
-     * StdClass object for holding addons which have registered themselves to work with EE core
98
-     *
99
-     * @var EE_Addon[] $addons
100
-     */
101
-    public $addons;
102
-
103
-    /**
104
-     * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
105
-     *
106
-     * @var EEM_Base[] $models
107
-     */
108
-    public $models = array();
109
-
110
-    /**
111
-     * @var EED_Module[] $modules
112
-     */
113
-    public $modules;
114
-
115
-    /**
116
-     * @var EES_Shortcode[] $shortcodes
117
-     */
118
-    public $shortcodes;
119
-
120
-    /**
121
-     * @var WP_Widget[] $widgets
122
-     */
123
-    public $widgets;
124
-
125
-    /**
126
-     * this is an array of all implemented model names (i.e. not the parent abstract models, or models
127
-     * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
128
-     * Keys are model "short names" (eg "Event") as used in model relations, and values are
129
-     * classnames (eg "EEM_Event")
130
-     *
131
-     * @var array $non_abstract_db_models
132
-     */
133
-    public $non_abstract_db_models = array();
134
-
135
-
136
-    /**
137
-     * internationalization for JS strings
138
-     *    usage:   EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' );
139
-     *    in js file:  var translatedString = eei18n.string_key;
140
-     *
141
-     * @var array $i18n_js_strings
142
-     */
143
-    public static $i18n_js_strings = array();
144
-
145
-
146
-    /**
147
-     * $main_file - path to espresso.php
148
-     *
149
-     * @var array $main_file
150
-     */
151
-    public $main_file;
152
-
153
-    /**
154
-     * array of ReflectionClass objects where the key is the class name
155
-     *
156
-     * @var ReflectionClass[] $_reflectors
157
-     */
158
-    public $_reflectors;
159
-
160
-    /**
161
-     * boolean flag to indicate whether or not to load/save dependencies from/to the cache
162
-     *
163
-     * @var boolean $_cache_on
164
-     */
165
-    protected $_cache_on = true;
166
-
167
-
168
-
169
-    /**
170
-     * @singleton method used to instantiate class object
171
-     * @param  EE_Dependency_Map $dependency_map
172
-     * @return EE_Registry instance
173
-     * @throws InvalidArgumentException
174
-     * @throws InvalidInterfaceException
175
-     * @throws InvalidDataTypeException
176
-     */
177
-    public static function instance(EE_Dependency_Map $dependency_map = null)
178
-    {
179
-        // check if class object is instantiated
180
-        if (! self::$_instance instanceof EE_Registry) {
181
-            self::$_instance = new self($dependency_map);
182
-        }
183
-        return self::$_instance;
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * protected constructor to prevent direct creation
190
-     *
191
-     * @Constructor
192
-     * @param  EE_Dependency_Map $dependency_map
193
-     * @throws InvalidDataTypeException
194
-     * @throws InvalidInterfaceException
195
-     * @throws InvalidArgumentException
196
-     */
197
-    protected function __construct(EE_Dependency_Map $dependency_map)
198
-    {
199
-        $this->_dependency_map = $dependency_map;
200
-        // $registry_container = new RegistryContainer();
201
-        $this->LIB = new RegistryContainer();
202
-        $this->addons = new RegistryContainer();
203
-        $this->modules = new RegistryContainer();
204
-        $this->shortcodes = new RegistryContainer();
205
-        $this->widgets = new RegistryContainer();
206
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
207
-    }
208
-
209
-
210
-
211
-    /**
212
-     * initialize
213
-     *
214
-     * @throws EE_Error
215
-     * @throws ReflectionException
216
-     */
217
-    public function initialize()
218
-    {
219
-        $this->_class_abbreviations = apply_filters(
220
-            'FHEE__EE_Registry____construct___class_abbreviations',
221
-            array(
222
-                'EE_Config'                                       => 'CFG',
223
-                'EE_Session'                                      => 'SSN',
224
-                'EE_Capabilities'                                 => 'CAP',
225
-                'EE_Cart'                                         => 'CART',
226
-                'EE_Network_Config'                               => 'NET_CFG',
227
-                'EE_Request_Handler'                              => 'REQ',
228
-                'EE_Message_Resource_Manager'                     => 'MRM',
229
-                'EventEspresso\core\services\commands\CommandBus' => 'BUS',
230
-                'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
231
-            )
232
-        );
233
-        $this->load_core('Base', array(), true);
234
-        // add our request and response objects to the cache
235
-        $request_loader = $this->_dependency_map->class_loader(
236
-            'EventEspresso\core\services\request\Request'
237
-        );
238
-        $this->_set_cached_class(
239
-            $request_loader(),
240
-            'EventEspresso\core\services\request\Request'
241
-        );
242
-        $response_loader = $this->_dependency_map->class_loader(
243
-            'EventEspresso\core\services\request\Response'
244
-        );
245
-        $this->_set_cached_class(
246
-            $response_loader(),
247
-            'EventEspresso\core\services\request\Response'
248
-        );
249
-        add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
250
-    }
251
-
252
-
253
-
254
-    /**
255
-     * @return void
256
-     */
257
-    public function init()
258
-    {
259
-        // Get current page protocol
260
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
261
-        // Output admin-ajax.php URL with same protocol as current page
262
-        self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
263
-        self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
264
-    }
265
-
266
-
267
-
268
-    /**
269
-     * localize_i18n_js_strings
270
-     *
271
-     * @return string
272
-     */
273
-    public static function localize_i18n_js_strings()
274
-    {
275
-        $i18n_js_strings = (array)self::$i18n_js_strings;
276
-        foreach ($i18n_js_strings as $key => $value) {
277
-            if (is_scalar($value)) {
278
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
279
-            }
280
-        }
281
-        return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * @param mixed string | EED_Module $module
288
-     * @throws EE_Error
289
-     * @throws ReflectionException
290
-     */
291
-    public function add_module($module)
292
-    {
293
-        if ($module instanceof EED_Module) {
294
-            $module_class = get_class($module);
295
-            $this->modules->{$module_class} = $module;
296
-        } else {
297
-            if ( ! class_exists('EE_Module_Request_Router', false)) {
298
-                $this->load_core('Module_Request_Router');
299
-            }
300
-            EE_Module_Request_Router::module_factory($module);
301
-        }
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * @param string $module_name
308
-     * @return mixed EED_Module | NULL
309
-     */
310
-    public function get_module($module_name = '')
311
-    {
312
-        return isset($this->modules->{$module_name})
313
-            ? $this->modules->{$module_name}
314
-            : null;
315
-    }
316
-
317
-
318
-
319
-    /**
320
-     * loads core classes - must be singletons
321
-     *
322
-     * @param string $class_name - simple class name ie: session
323
-     * @param mixed  $arguments
324
-     * @param bool   $load_only
325
-     * @return mixed
326
-     * @throws EE_Error
327
-     * @throws ReflectionException
328
-     */
329
-    public function load_core($class_name, $arguments = array(), $load_only = false)
330
-    {
331
-        $core_paths = apply_filters(
332
-            'FHEE__EE_Registry__load_core__core_paths',
333
-            array(
334
-                EE_CORE,
335
-                EE_ADMIN,
336
-                EE_CPTS,
337
-                EE_CORE . 'data_migration_scripts' . DS,
338
-                EE_CORE . 'capabilities' . DS,
339
-                EE_CORE . 'request_stack' . DS,
340
-                EE_CORE . 'middleware' . DS,
341
-            )
342
-        );
343
-        // retrieve instantiated class
344
-        return $this->_load(
345
-            $core_paths,
346
-            'EE_',
347
-            $class_name,
348
-            'core',
349
-            $arguments,
350
-            false,
351
-            true,
352
-            $load_only
353
-        );
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * loads service classes
360
-     *
361
-     * @param string $class_name - simple class name ie: session
362
-     * @param mixed  $arguments
363
-     * @param bool   $load_only
364
-     * @return mixed
365
-     * @throws EE_Error
366
-     * @throws ReflectionException
367
-     */
368
-    public function load_service($class_name, $arguments = array(), $load_only = false)
369
-    {
370
-        $service_paths = apply_filters(
371
-            'FHEE__EE_Registry__load_service__service_paths',
372
-            array(
373
-                EE_CORE . 'services' . DS,
374
-            )
375
-        );
376
-        // retrieve instantiated class
377
-        return $this->_load(
378
-            $service_paths,
379
-            'EE_',
380
-            $class_name,
381
-            'class',
382
-            $arguments,
383
-            false,
384
-            true,
385
-            $load_only
386
-        );
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     * loads data_migration_scripts
393
-     *
394
-     * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
395
-     * @param mixed  $arguments
396
-     * @return EE_Data_Migration_Script_Base|mixed
397
-     * @throws EE_Error
398
-     * @throws ReflectionException
399
-     */
400
-    public function load_dms($class_name, $arguments = array())
401
-    {
402
-        // retrieve instantiated class
403
-        return $this->_load(
404
-            EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(),
405
-            'EE_DMS_',
406
-            $class_name,
407
-            'dms',
408
-            $arguments,
409
-            false,
410
-            false
411
-        );
412
-    }
413
-
414
-
415
-
416
-    /**
417
-     * loads object creating classes - must be singletons
418
-     *
419
-     * @param string $class_name - simple class name ie: attendee
420
-     * @param mixed  $arguments  - an array of arguments to pass to the class
421
-     * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to
422
-     *                           instantiate
423
-     * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then
424
-     *                           set this to FALSE (ie. when instantiating model objects from client in a loop)
425
-     * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate
426
-     *                           (default)
427
-     * @return EE_Base_Class | bool
428
-     * @throws EE_Error
429
-     * @throws ReflectionException
430
-     */
431
-    public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
432
-    {
433
-        $paths = apply_filters(
434
-            'FHEE__EE_Registry__load_class__paths', array(
435
-            EE_CORE,
436
-            EE_CLASSES,
437
-            EE_BUSINESS,
438
-        )
439
-        );
440
-        // retrieve instantiated class
441
-        return $this->_load(
442
-            $paths,
443
-            'EE_',
444
-            $class_name,
445
-            'class',
446
-            $arguments,
447
-            $from_db,
448
-            $cache,
449
-            $load_only
450
-        );
451
-    }
452
-
453
-
454
-
455
-    /**
456
-     * loads helper classes - must be singletons
457
-     *
458
-     * @param string $class_name - simple class name ie: price
459
-     * @param mixed  $arguments
460
-     * @param bool   $load_only
461
-     * @return EEH_Base | bool
462
-     * @throws EE_Error
463
-     * @throws ReflectionException
464
-     */
465
-    public function load_helper($class_name, $arguments = array(), $load_only = true)
466
-    {
467
-        // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
468
-        $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
469
-        // retrieve instantiated class
470
-        return $this->_load(
471
-            $helper_paths,
472
-            'EEH_',
473
-            $class_name,
474
-            'helper',
475
-            $arguments,
476
-            false,
477
-            true,
478
-            $load_only
479
-        );
480
-    }
481
-
482
-
483
-
484
-    /**
485
-     * loads core classes - must be singletons
486
-     *
487
-     * @param string $class_name - simple class name ie: session
488
-     * @param mixed  $arguments
489
-     * @param bool   $load_only
490
-     * @param bool   $cache      whether to cache the object or not.
491
-     * @return mixed
492
-     * @throws EE_Error
493
-     * @throws ReflectionException
494
-     */
495
-    public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
496
-    {
497
-        $paths = array(
498
-            EE_LIBRARIES,
499
-            EE_LIBRARIES . 'messages' . DS,
500
-            EE_LIBRARIES . 'shortcodes' . DS,
501
-            EE_LIBRARIES . 'qtips' . DS,
502
-            EE_LIBRARIES . 'payment_methods' . DS,
503
-        );
504
-        // retrieve instantiated class
505
-        return $this->_load(
506
-            $paths,
507
-            'EE_',
508
-            $class_name,
509
-            'lib',
510
-            $arguments,
511
-            false,
512
-            $cache,
513
-            $load_only
514
-        );
515
-    }
516
-
517
-
518
-
519
-    /**
520
-     * loads model classes - must be singletons
521
-     *
522
-     * @param string $class_name - simple class name ie: price
523
-     * @param mixed  $arguments
524
-     * @param bool   $load_only
525
-     * @return EEM_Base | bool
526
-     * @throws EE_Error
527
-     * @throws ReflectionException
528
-     */
529
-    public function load_model($class_name, $arguments = array(), $load_only = false)
530
-    {
531
-        $paths = apply_filters(
532
-            'FHEE__EE_Registry__load_model__paths', array(
533
-            EE_MODELS,
534
-            EE_CORE,
535
-        )
536
-        );
537
-        // retrieve instantiated class
538
-        return $this->_load(
539
-            $paths,
540
-            'EEM_',
541
-            $class_name,
542
-            'model',
543
-            $arguments,
544
-            false,
545
-            true,
546
-            $load_only
547
-        );
548
-    }
549
-
550
-
551
-
552
-    /**
553
-     * loads model classes - must be singletons
554
-     *
555
-     * @param string $class_name - simple class name ie: price
556
-     * @param mixed  $arguments
557
-     * @param bool   $load_only
558
-     * @return mixed | bool
559
-     * @throws EE_Error
560
-     * @throws ReflectionException
561
-     */
562
-    public function load_model_class($class_name, $arguments = array(), $load_only = true)
563
-    {
564
-        $paths = array(
565
-            EE_MODELS . 'fields' . DS,
566
-            EE_MODELS . 'helpers' . DS,
567
-            EE_MODELS . 'relations' . DS,
568
-            EE_MODELS . 'strategies' . DS,
569
-        );
570
-        // retrieve instantiated class
571
-        return $this->_load(
572
-            $paths,
573
-            'EE_',
574
-            $class_name,
575
-            '',
576
-            $arguments,
577
-            false,
578
-            true,
579
-            $load_only
580
-        );
581
-    }
582
-
583
-
584
-
585
-    /**
586
-     * Determines if $model_name is the name of an actual EE model.
587
-     *
588
-     * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
589
-     * @return boolean
590
-     */
591
-    public function is_model_name($model_name)
592
-    {
593
-        return isset($this->models[$model_name]);
594
-    }
595
-
596
-
597
-
598
-    /**
599
-     * generic class loader
600
-     *
601
-     * @param string $path_to_file - directory path to file location, not including filename
602
-     * @param string $file_name    - file name  ie:  my_file.php, including extension
603
-     * @param string $type         - file type - core? class? helper? model?
604
-     * @param mixed  $arguments
605
-     * @param bool   $load_only
606
-     * @return mixed
607
-     * @throws EE_Error
608
-     * @throws ReflectionException
609
-     */
610
-    public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
611
-    {
612
-        // retrieve instantiated class
613
-        return $this->_load(
614
-            $path_to_file,
615
-            '',
616
-            $file_name,
617
-            $type,
618
-            $arguments,
619
-            false,
620
-            true,
621
-            $load_only
622
-        );
623
-    }
624
-
625
-
626
-
627
-    /**
628
-     * @param string $path_to_file - directory path to file location, not including filename
629
-     * @param string $class_name   - full class name  ie:  My_Class
630
-     * @param string $type         - file type - core? class? helper? model?
631
-     * @param mixed  $arguments
632
-     * @param bool   $load_only
633
-     * @return bool|EE_Addon|object
634
-     * @throws EE_Error
635
-     * @throws ReflectionException
636
-     */
637
-    public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
638
-    {
639
-        // retrieve instantiated class
640
-        return $this->_load(
641
-            $path_to_file,
642
-            'addon',
643
-            $class_name,
644
-            $type,
645
-            $arguments,
646
-            false,
647
-            true,
648
-            $load_only
649
-        );
650
-    }
651
-
652
-
653
-
654
-    /**
655
-     * instantiates, caches, and automatically resolves dependencies
656
-     * for classes that use a Fully Qualified Class Name.
657
-     * if the class is not capable of being loaded using PSR-4 autoloading,
658
-     * then you need to use one of the existing load_*() methods
659
-     * which can resolve the classname and filepath from the passed arguments
660
-     *
661
-     * @param bool|string $class_name   Fully Qualified Class Name
662
-     * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
663
-     * @param bool        $cache        whether to cache the instantiated object for reuse
664
-     * @param bool        $from_db      some classes are instantiated from the db
665
-     *                                  and thus call a different method to instantiate
666
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
667
-     * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
668
-     * @return bool|null|mixed          null = failure to load or instantiate class object.
669
-     *                                  object = class loaded and instantiated successfully.
670
-     *                                  bool = fail or success when $load_only is true
671
-     * @throws EE_Error
672
-     * @throws ReflectionException
673
-     */
674
-    public function create(
675
-        $class_name = false,
676
-        $arguments = array(),
677
-        $cache = false,
678
-        $from_db = false,
679
-        $load_only = false,
680
-        $addon = false
681
-    ) {
682
-        $class_name = ltrim($class_name, '\\');
683
-        $class_name = $this->_dependency_map->get_alias($class_name);
684
-        $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
685
-        // if a non-FQCN was passed, then verifyClassExists() might return an object
686
-        // or it could return null if the class just could not be found anywhere
687
-        if ($class_exists instanceof $class_name || $class_exists === null){
688
-            // either way, return the results
689
-            return $class_exists;
690
-        }
691
-        $class_name = $class_exists;
692
-        // if we're only loading the class and it already exists, then let's just return true immediately
693
-        if ($load_only) {
694
-            return true;
695
-        }
696
-        $addon = $addon
697
-            ? 'addon'
698
-            : '';
699
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
700
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
701
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
702
-        if ($this->_cache_on && $cache && ! $load_only) {
703
-            // return object if it's already cached
704
-            $cached_class = $this->_get_cached_class($class_name, $addon);
705
-            if ($cached_class !== null) {
706
-                return $cached_class;
707
-            }
708
-        }
709
-        // obtain the loader method from the dependency map
710
-        $loader = $this->_dependency_map->class_loader($class_name);
711
-        // instantiate the requested object
712
-        if ($loader instanceof Closure) {
713
-            $class_obj = $loader($arguments);
714
-        } else if ($loader && method_exists($this, $loader)) {
715
-            $class_obj = $this->{$loader}($class_name, $arguments);
716
-        } else {
717
-            $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
718
-        }
719
-        if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) {
720
-            // save it for later... kinda like gum  { : $
721
-            $this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
722
-        }
723
-        $this->_cache_on = true;
724
-        return $class_obj;
725
-    }
726
-
727
-
728
-
729
-    /**
730
-     * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
731
-     *
732
-     * @param string $class_name
733
-     * @param array  $arguments
734
-     * @param int    $attempt
735
-     * @return mixed
736
-     */
737
-    private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) {
738
-        if (is_object($class_name) || class_exists($class_name)) {
739
-            return $class_name;
740
-        }
741
-        switch ($attempt) {
742
-            case 1:
743
-                // if it's a FQCN then maybe the class is registered with a preceding \
744
-                $class_name = strpos($class_name, '\\') !== false
745
-                    ? '\\' . ltrim($class_name, '\\')
746
-                    : $class_name;
747
-                break;
748
-            case 2:
749
-                //
750
-                $loader = $this->_dependency_map->class_loader($class_name);
751
-                if ($loader && method_exists($this, $loader)) {
752
-                    return $this->{$loader}($class_name, $arguments);
753
-                }
754
-                break;
755
-            case 3:
756
-            default;
757
-                return null;
758
-        }
759
-        $attempt++;
760
-        return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
761
-    }
762
-
763
-
764
-
765
-    /**
766
-     * instantiates, caches, and injects dependencies for classes
767
-     *
768
-     * @param array       $file_paths   an array of paths to folders to look in
769
-     * @param string      $class_prefix EE  or EEM or... ???
770
-     * @param bool|string $class_name   $class name
771
-     * @param string      $type         file type - core? class? helper? model?
772
-     * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
773
-     * @param bool        $from_db      some classes are instantiated from the db
774
-     *                                  and thus call a different method to instantiate
775
-     * @param bool        $cache        whether to cache the instantiated object for reuse
776
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
777
-     * @return bool|null|object null = failure to load or instantiate class object.
778
-     *                                  object = class loaded and instantiated successfully.
779
-     *                                  bool = fail or success when $load_only is true
780
-     * @throws EE_Error
781
-     * @throws ReflectionException
782
-     */
783
-    protected function _load(
784
-        $file_paths = array(),
785
-        $class_prefix = 'EE_',
786
-        $class_name = false,
787
-        $type = 'class',
788
-        $arguments = array(),
789
-        $from_db = false,
790
-        $cache = true,
791
-        $load_only = false
792
-    ) {
793
-        $class_name = ltrim($class_name, '\\');
794
-        // strip php file extension
795
-        $class_name = str_replace('.php', '', trim($class_name));
796
-        // does the class have a prefix ?
797
-        if (! empty($class_prefix) && $class_prefix !== 'addon') {
798
-            // make sure $class_prefix is uppercase
799
-            $class_prefix = strtoupper(trim($class_prefix));
800
-            // add class prefix ONCE!!!
801
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
802
-        }
803
-        $class_name = $this->_dependency_map->get_alias($class_name);
804
-        $class_exists = class_exists($class_name, false);
805
-        // if we're only loading the class and it already exists, then let's just return true immediately
806
-        if ($load_only && $class_exists) {
807
-            return true;
808
-        }
809
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
810
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
811
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
812
-        if ($this->_cache_on && $cache && ! $load_only) {
813
-            // return object if it's already cached
814
-            $cached_class = $this->_get_cached_class($class_name, $class_prefix);
815
-            if ($cached_class !== null) {
816
-                return $cached_class;
817
-            }
818
-        }
819
-        // if the class doesn't already exist.. then we need to try and find the file and load it
820
-        if (! $class_exists) {
821
-            // get full path to file
822
-            $path = $this->_resolve_path($class_name, $type, $file_paths);
823
-            // load the file
824
-            $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
825
-            // if loading failed, or we are only loading a file but NOT instantiating an object
826
-            if (! $loaded || $load_only) {
827
-                // return boolean if only loading, or null if an object was expected
828
-                return $load_only
829
-                    ? $loaded
830
-                    : null;
831
-            }
832
-        }
833
-        // instantiate the requested object
834
-        $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
835
-        if ($this->_cache_on && $cache) {
836
-            // save it for later... kinda like gum  { : $
837
-            $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
838
-        }
839
-        $this->_cache_on = true;
840
-        return $class_obj;
841
-    }
842
-
843
-
844
-
845
-    /**
846
-     * @param string $class_name
847
-     * @param string $default have to specify something, but not anything that will conflict
848
-     * @return mixed|string
849
-     */
850
-    protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
851
-    {
852
-        return isset($this->_class_abbreviations[$class_name])
853
-            ? $this->_class_abbreviations[$class_name]
854
-            : $default;
855
-    }
856
-
857
-    /**
858
-     * attempts to find a cached version of the requested class
859
-     * by looking in the following places:
860
-     *        $this->{$class_abbreviation}            ie:    $this->CART
861
-     *        $this->{$class_name}                        ie:    $this->Some_Class
862
-     *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
863
-     *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
864
-     *
865
-     * @param string $class_name
866
-     * @param string $class_prefix
867
-     * @return mixed
868
-     * @throws OutOfBoundsException
869
-     */
870
-    protected function _get_cached_class($class_name, $class_prefix = '')
871
-    {
872
-        if ($class_name === 'EE_Registry') {
873
-            return $this;
874
-        }
875
-        $class_abbreviation = $this->get_class_abbreviation($class_name);
876
-        $class_name = str_replace('\\', '_', $class_name);
877
-        // check if class has already been loaded, and return it if it has been
878
-        if (isset($this->{$class_abbreviation})) {
879
-            return $this->{$class_abbreviation};
880
-        }
881
-        if (isset ($this->{$class_name})) {
882
-            return $this->{$class_name};
883
-        }
884
-        if (isset ($this->LIB->{$class_name})) {
885
-            return $this->LIB->{$class_name};
886
-        }
887
-        if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
888
-            return $this->addons->{$class_name};
889
-        }
890
-        return null;
891
-    }
892
-
893
-
894
-
895
-    /**
896
-     * removes a cached version of the requested class
897
-     *
898
-     * @param string  $class_name
899
-     * @param boolean $addon
900
-     * @return boolean
901
-     * @throws OutOfBoundsException
902
-     */
903
-    public function clear_cached_class($class_name, $addon = false)
904
-    {
905
-        $class_abbreviation = $this->get_class_abbreviation($class_name);
906
-        $class_name = str_replace('\\', '_', $class_name);
907
-        // check if class has already been loaded, and return it if it has been
908
-        if (isset($this->{$class_abbreviation})) {
909
-            $this->{$class_abbreviation} = null;
910
-            return true;
911
-        }
912
-        if (isset($this->{$class_name})) {
913
-            $this->{$class_name} = null;
914
-            return true;
915
-        }
916
-        if (isset($this->LIB->{$class_name})) {
917
-            unset($this->LIB->{$class_name});
918
-            return true;
919
-        }
920
-        if ($addon && isset($this->addons->{$class_name})) {
921
-            unset($this->addons->{$class_name});
922
-            return true;
923
-        }
924
-        return false;
925
-    }
926
-
927
-
928
-
929
-    /**
930
-     * attempts to find a full valid filepath for the requested class.
931
-     * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
932
-     * then returns that path if the target file has been found and is readable
933
-     *
934
-     * @param string $class_name
935
-     * @param string $type
936
-     * @param array  $file_paths
937
-     * @return string | bool
938
-     */
939
-    protected function _resolve_path($class_name, $type = '', $file_paths = array())
940
-    {
941
-        // make sure $file_paths is an array
942
-        $file_paths = is_array($file_paths)
943
-            ? $file_paths
944
-            : array($file_paths);
945
-        // cycle thru paths
946
-        foreach ($file_paths as $key => $file_path) {
947
-            // convert all separators to proper DS, if no filepath, then use EE_CLASSES
948
-            $file_path = $file_path
949
-                ? str_replace(array('/', '\\'), DS, $file_path)
950
-                : EE_CLASSES;
951
-            // prep file type
952
-            $type = ! empty($type)
953
-                ? trim($type, '.') . '.'
954
-                : '';
955
-            // build full file path
956
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
957
-            //does the file exist and can be read ?
958
-            if (is_readable($file_paths[$key])) {
959
-                return $file_paths[$key];
960
-            }
961
-        }
962
-        return false;
963
-    }
964
-
965
-
966
-
967
-    /**
968
-     * basically just performs a require_once()
969
-     * but with some error handling
970
-     *
971
-     * @param  string $path
972
-     * @param  string $class_name
973
-     * @param  string $type
974
-     * @param  array  $file_paths
975
-     * @return bool
976
-     * @throws EE_Error
977
-     * @throws ReflectionException
978
-     */
979
-    protected function _require_file($path, $class_name, $type = '', $file_paths = array())
980
-    {
981
-        $this->resolve_legacy_class_parent($class_name);
982
-        // don't give up! you gotta...
983
-        try {
984
-            //does the file exist and can it be read ?
985
-            if (! $path) {
986
-                // just in case the file has already been autoloaded,
987
-                // but discrepancies in the naming schema are preventing it from
988
-                // being loaded via one of the EE_Registry::load_*() methods,
989
-                // then let's try one last hail mary before throwing an exception
990
-                // and call class_exists() again, but with autoloading turned ON
991
-                if(class_exists($class_name)) {
992
-                    return true;
993
-                }
994
-                // so sorry, can't find the file
995
-                throw new EE_Error (
996
-                    sprintf(
997
-                        esc_html__(
998
-                            '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',
999
-                            'event_espresso'
1000
-                        ),
1001
-                        trim($type, '.'),
1002
-                        $class_name,
1003
-                        '<br />' . implode(',<br />', $file_paths)
1004
-                    )
1005
-                );
1006
-            }
1007
-            // get the file
1008
-            require_once($path);
1009
-            // if the class isn't already declared somewhere
1010
-            if (class_exists($class_name, false) === false) {
1011
-                // so sorry, not a class
1012
-                throw new EE_Error(
1013
-                    sprintf(
1014
-                        esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
1015
-                        $type,
1016
-                        $path,
1017
-                        $class_name
1018
-                    )
1019
-                );
1020
-            }
1021
-        } catch (EE_Error $e) {
1022
-            $e->get_error();
1023
-            return false;
1024
-        }
1025
-        return true;
1026
-    }
1027
-
1028
-
1029
-
1030
-    /**
1031
-     * Some of our legacy classes that extended a parent class would simply use a require() statement
1032
-     * before their class declaration in order to ensure that the parent class was loaded.
1033
-     * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class,
1034
-     * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist.
1035
-     *
1036
-     * @param string $class_name
1037
-     */
1038
-    protected function resolve_legacy_class_parent($class_name = '')
1039
-    {
1040
-        try {
1041
-            $legacy_parent_class_map = array(
1042
-                'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php'
1043
-            );
1044
-            if(isset($legacy_parent_class_map[$class_name])) {
1045
-                require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name];
1046
-            }
1047
-        } catch (Exception $exception) {
1048
-        }
1049
-    }
1050
-
1051
-
1052
-
1053
-    /**
1054
-     * _create_object
1055
-     * Attempts to instantiate the requested class via any of the
1056
-     * commonly used instantiation methods employed throughout EE.
1057
-     * The priority for instantiation is as follows:
1058
-     *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
1059
-     *        - model objects via their 'new_instance_from_db' method
1060
-     *        - model objects via their 'new_instance' method
1061
-     *        - "singleton" classes" via their 'instance' method
1062
-     *    - standard instantiable classes via their __constructor
1063
-     * Prior to instantiation, if the classname exists in the dependency_map,
1064
-     * then the constructor for the requested class will be examined to determine
1065
-     * if any dependencies exist, and if they can be injected.
1066
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1067
-     *
1068
-     * @param string $class_name
1069
-     * @param array  $arguments
1070
-     * @param string $type
1071
-     * @param bool   $from_db
1072
-     * @return null|object
1073
-     * @throws EE_Error
1074
-     * @throws ReflectionException
1075
-     */
1076
-    protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
1077
-    {
1078
-        // create reflection
1079
-        $reflector = $this->get_ReflectionClass($class_name);
1080
-        // make sure arguments are an array
1081
-        $arguments = is_array($arguments)
1082
-            ? $arguments
1083
-            : array($arguments);
1084
-        // and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1085
-        // else wrap it in an additional array so that it doesn't get split into multiple parameters
1086
-        $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1087
-            ? $arguments
1088
-            : array($arguments);
1089
-        // attempt to inject dependencies ?
1090
-        if ($this->_dependency_map->has($class_name)) {
1091
-            $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1092
-        }
1093
-        // instantiate the class if possible
1094
-        if ($reflector->isAbstract()) {
1095
-            // nothing to instantiate, loading file was enough
1096
-            // does not throw an exception so $instantiation_mode is unused
1097
-            // $instantiation_mode = "1) no constructor abstract class";
1098
-            return true;
1099
-        }
1100
-        if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) {
1101
-            // no constructor = static methods only... nothing to instantiate, loading file was enough
1102
-            // $instantiation_mode = "2) no constructor but instantiable";
1103
-            return $reflector->newInstance();
1104
-        }
1105
-        if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1106
-            // $instantiation_mode = "3) new_instance_from_db()";
1107
-            return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1108
-        }
1109
-        if (method_exists($class_name, 'new_instance')) {
1110
-            // $instantiation_mode = "4) new_instance()";
1111
-            return call_user_func_array(array($class_name, 'new_instance'), $arguments);
1112
-        }
1113
-        if (method_exists($class_name, 'instance')) {
1114
-            // $instantiation_mode = "5) instance()";
1115
-            return call_user_func_array(array($class_name, 'instance'), $arguments);
1116
-        }
1117
-        if ($reflector->isInstantiable()) {
1118
-            // $instantiation_mode = "6) constructor";
1119
-            return $reflector->newInstanceArgs($arguments);
1120
-        }
1121
-        // heh ? something's not right !
1122
-        throw new EE_Error(
1123
-            sprintf(
1124
-                __('The %s file %s could not be instantiated.', 'event_espresso'),
1125
-                $type,
1126
-                $class_name
1127
-            )
1128
-        );
1129
-    }
1130
-
1131
-
1132
-
1133
-    /**
1134
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1135
-     * @param array $array
1136
-     * @return bool
1137
-     */
1138
-    protected function _array_is_numerically_and_sequentially_indexed(array $array)
1139
-    {
1140
-        return ! empty($array)
1141
-            ? array_keys($array) === range(0, count($array) - 1)
1142
-            : true;
1143
-    }
1144
-
1145
-
1146
-
1147
-    /**
1148
-     * getReflectionClass
1149
-     * checks if a ReflectionClass object has already been generated for a class
1150
-     * and returns that instead of creating a new one
1151
-     *
1152
-     * @param string $class_name
1153
-     * @return ReflectionClass
1154
-     * @throws ReflectionException
1155
-     */
1156
-    public function get_ReflectionClass($class_name)
1157
-    {
1158
-        if (
1159
-            ! isset($this->_reflectors[$class_name])
1160
-            || ! $this->_reflectors[$class_name] instanceof ReflectionClass
1161
-        ) {
1162
-            $this->_reflectors[$class_name] = new ReflectionClass($class_name);
1163
-        }
1164
-        return $this->_reflectors[$class_name];
1165
-    }
1166
-
1167
-
1168
-
1169
-    /**
1170
-     * _resolve_dependencies
1171
-     * examines the constructor for the requested class to determine
1172
-     * if any dependencies exist, and if they can be injected.
1173
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1174
-     * PLZ NOTE: this is achieved by type hinting the constructor params
1175
-     * For example:
1176
-     *        if attempting to load a class "Foo" with the following constructor:
1177
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
1178
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
1179
-     *        but only IF they are NOT already present in the incoming arguments array,
1180
-     *        and the correct classes can be loaded
1181
-     *
1182
-     * @param ReflectionClass $reflector
1183
-     * @param string          $class_name
1184
-     * @param array           $arguments
1185
-     * @return array
1186
-     * @throws EE_Error
1187
-     * @throws ReflectionException
1188
-     */
1189
-    protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1190
-    {
1191
-        // let's examine the constructor
1192
-        $constructor = $reflector->getConstructor();
1193
-        // whu? huh? nothing?
1194
-        if (! $constructor) {
1195
-            return $arguments;
1196
-        }
1197
-        // get constructor parameters
1198
-        $params = $constructor->getParameters();
1199
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1200
-        $argument_keys = array_keys($arguments);
1201
-        // now loop thru all of the constructors expected parameters
1202
-        foreach ($params as $index => $param) {
1203
-            // is this a dependency for a specific class ?
1204
-            $param_class = $param->getClass()
1205
-                ? $param->getClass()->name
1206
-                : null;
1207
-            // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1208
-            $param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1209
-                ? $this->_dependency_map->get_alias($param_class, $class_name)
1210
-                : $param_class;
1211
-            if (
1212
-                // param is not even a class
1213
-                $param_class === null
1214
-                // and something already exists in the incoming arguments for this param
1215
-                && array_key_exists($index, $argument_keys)
1216
-                && array_key_exists($argument_keys[$index], $arguments)
1217
-            ) {
1218
-                // so let's skip this argument and move on to the next
1219
-                continue;
1220
-            }
1221
-            if (
1222
-                // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1223
-                $param_class !== null
1224
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1225
-                && $arguments[$argument_keys[$index]] instanceof $param_class
1226
-            ) {
1227
-                // skip this argument and move on to the next
1228
-                continue;
1229
-            }
1230
-            if (
1231
-                // parameter is type hinted as a class, and should be injected
1232
-                $param_class !== null
1233
-                && $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1234
-            ) {
1235
-                $arguments = $this->_resolve_dependency(
1236
-                    $class_name,
1237
-                    $param_class,
1238
-                    $arguments,
1239
-                    $index,
1240
-                    $argument_keys
1241
-                );
1242
-            } else {
1243
-                try {
1244
-                    $arguments[$index] = $param->isDefaultValueAvailable()
1245
-                        ? $param->getDefaultValue()
1246
-                        : null;
1247
-                } catch (ReflectionException $e) {
1248
-                    throw new ReflectionException(
1249
-                        sprintf(
1250
-                            esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'),
1251
-                            $e->getMessage(),
1252
-                            $param->getName(),
1253
-                            $class_name
1254
-                        )
1255
-                    );
1256
-                }
1257
-            }
1258
-        }
1259
-        return $arguments;
1260
-    }
1261
-
1262
-
1263
-
1264
-    /**
1265
-     * @param string $class_name
1266
-     * @param string $param_class
1267
-     * @param array  $arguments
1268
-     * @param mixed  $index
1269
-     * @param array  $argument_keys
1270
-     * @return array
1271
-     * @throws EE_Error
1272
-     * @throws ReflectionException
1273
-     * @throws InvalidArgumentException
1274
-     * @throws InvalidInterfaceException
1275
-     * @throws InvalidDataTypeException
1276
-     */
1277
-    protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys)
1278
-    {
1279
-        $dependency = null;
1280
-        // should dependency be loaded from cache ?
1281
-        $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1282
-            $class_name,
1283
-            $param_class
1284
-        );
1285
-        $cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1286
-        // we might have a dependency...
1287
-        // let's MAYBE try and find it in our cache if that's what's been requested
1288
-        $cached_class = $cache_on
1289
-            ? $this->_get_cached_class($param_class)
1290
-            : null;
1291
-        // and grab it if it exists
1292
-        if ($cached_class instanceof $param_class) {
1293
-            $dependency = $cached_class;
1294
-        } else if ($param_class !== $class_name) {
1295
-            // obtain the loader method from the dependency map
1296
-            $loader = $this->_dependency_map->class_loader($param_class);
1297
-            // is loader a custom closure ?
1298
-            if ($loader instanceof Closure) {
1299
-                $dependency = $loader($arguments);
1300
-            } else {
1301
-                // set the cache on property for the recursive loading call
1302
-                $this->_cache_on = $cache_on;
1303
-                // if not, then let's try and load it via the registry
1304
-                if ($loader && method_exists($this, $loader)) {
1305
-                    $dependency = $this->{$loader}($param_class);
1306
-                } else {
1307
-                    $dependency = LoaderFactory::getLoader()->load(
1308
-                        $param_class,
1309
-                        array(),
1310
-                        $cache_on
1311
-                    );
1312
-                }
1313
-            }
1314
-        }
1315
-        // did we successfully find the correct dependency ?
1316
-        if ($dependency instanceof $param_class) {
1317
-            // then let's inject it into the incoming array of arguments at the correct location
1318
-            $arguments[$index] = $dependency;
1319
-        }
1320
-        return $arguments;
1321
-    }
1322
-
1323
-
1324
-
1325
-    /**
1326
-     * _set_cached_class
1327
-     * attempts to cache the instantiated class locally
1328
-     * in one of the following places, in the following order:
1329
-     *        $this->{class_abbreviation}   ie:    $this->CART
1330
-     *        $this->{$class_name}          ie:    $this->Some_Class
1331
-     *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1332
-     *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1333
-     *
1334
-     * @param object $class_obj
1335
-     * @param string $class_name
1336
-     * @param string $class_prefix
1337
-     * @param bool   $from_db
1338
-     * @return void
1339
-     * @throws OutOfBoundsException
1340
-     */
1341
-    protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1342
-    {
1343
-        if ($class_name === 'EE_Registry' || empty($class_obj)) {
1344
-            return;
1345
-        }
1346
-        // return newly instantiated class
1347
-        $class_abbreviation = $this->get_class_abbreviation($class_name, '');
1348
-        if ($class_abbreviation) {
1349
-            $this->{$class_abbreviation} = $class_obj;
1350
-            return;
1351
-        }
1352
-        $class_name = str_replace('\\', '_', $class_name);
1353
-        if (property_exists($this, $class_name)) {
1354
-            $this->{$class_name} = $class_obj;
1355
-            return;
1356
-        }
1357
-        if ($class_prefix === 'addon') {
1358
-            $this->addons->{$class_name} = $class_obj;
1359
-            return;
1360
-        }
1361
-        if (! $from_db) {
1362
-            $this->LIB->{$class_name} = $class_obj;
1363
-        }
1364
-    }
1365
-
1366
-
1367
-
1368
-    /**
1369
-     * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1370
-     *
1371
-     * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1372
-     *                          in the EE_Dependency_Map::$_class_loaders array,
1373
-     *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1374
-     * @param array  $arguments
1375
-     * @return object
1376
-     */
1377
-    public static function factory($classname, $arguments = array())
1378
-    {
1379
-        $loader = self::instance()->_dependency_map->class_loader($classname);
1380
-        if ($loader instanceof Closure) {
1381
-            return $loader($arguments);
1382
-        }
1383
-        if (method_exists(self::instance(), $loader)) {
1384
-            return self::instance()->{$loader}($classname, $arguments);
1385
-        }
1386
-        return null;
1387
-    }
1388
-
1389
-
1390
-
1391
-    /**
1392
-     * Gets the addon by its class name
1393
-     *
1394
-     * @param string $class_name
1395
-     * @return EE_Addon
1396
-     * @throws OutOfBoundsException
1397
-     */
1398
-    public function getAddon($class_name)
1399
-    {
1400
-        $class_name = str_replace('\\', '_', $class_name);
1401
-        return $this->addons->{$class_name};
1402
-    }
1403
-
1404
-
1405
-    /**
1406
-     * removes the addon from the internal cache
1407
-     *
1408
-     * @param string $class_name
1409
-     * @return void
1410
-     */
1411
-    public function removeAddon($class_name)
1412
-    {
1413
-        $class_name = str_replace('\\', '_', $class_name);
1414
-        unset($this->addons->{$class_name});
1415
-    }
1416
-
1417
-
1418
-
1419
-    /**
1420
-     * Gets the addon by its name/slug (not classname. For that, just
1421
-     * use the get_addon() method above
1422
-     *
1423
-     * @param string $name
1424
-     * @return EE_Addon
1425
-     */
1426
-    public function get_addon_by_name($name)
1427
-    {
1428
-        foreach ($this->addons as $addon) {
1429
-            if ($addon->name() === $name) {
1430
-                return $addon;
1431
-            }
1432
-        }
1433
-        return null;
1434
-    }
1435
-
1436
-
1437
-
1438
-    /**
1439
-     * Gets an array of all the registered addons, where the keys are their names.
1440
-     * (ie, what each returns for their name() function)
1441
-     * They're already available on EE_Registry::instance()->addons as properties,
1442
-     * where each property's name is the addon's classname,
1443
-     * So if you just want to get the addon by classname,
1444
-     * OR use the get_addon() method above.
1445
-     * PLEASE  NOTE:
1446
-     * addons with Fully Qualified Class Names
1447
-     * have had the namespace separators converted to underscores,
1448
-     * so a classname like Fully\Qualified\ClassName
1449
-     * would have been converted to Fully_Qualified_ClassName
1450
-     *
1451
-     * @return EE_Addon[] where the KEYS are the addon's name()
1452
-     */
1453
-    public function get_addons_by_name()
1454
-    {
1455
-        $addons = array();
1456
-        foreach ($this->addons as $addon) {
1457
-            $addons[$addon->name()] = $addon;
1458
-        }
1459
-        return $addons;
1460
-    }
1461
-
1462
-
1463
-    /**
1464
-     * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1465
-     * a stale copy of it around
1466
-     *
1467
-     * @param string $model_name
1468
-     * @return \EEM_Base
1469
-     * @throws \EE_Error
1470
-     */
1471
-    public function reset_model($model_name)
1472
-    {
1473
-        $model_class_name = strpos($model_name, 'EEM_') !== 0
1474
-            ? "EEM_{$model_name}"
1475
-            : $model_name;
1476
-        if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1477
-            return null;
1478
-        }
1479
-        //get that model reset it and make sure we nuke the old reference to it
1480
-        if ($this->LIB->{$model_class_name} instanceof $model_class_name
1481
-            && is_callable(
1482
-                array($model_class_name, 'reset')
1483
-            )) {
1484
-            $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1485
-        } else {
1486
-            throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1487
-        }
1488
-        return $this->LIB->{$model_class_name};
1489
-    }
1490
-
1491
-
1492
-
1493
-    /**
1494
-     * Resets the registry.
1495
-     * The criteria for what gets reset is based on what can be shared between sites on the same request when
1496
-     * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1497
-     * - $_dependency_map
1498
-     * - $_class_abbreviations
1499
-     * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1500
-     * - $REQ:  Still on the same request so no need to change.
1501
-     * - $CAP: There is no site specific state in the EE_Capability class.
1502
-     * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1503
-     * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1504
-     * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1505
-     *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1506
-     *             switch or on the restore.
1507
-     * - $modules
1508
-     * - $shortcodes
1509
-     * - $widgets
1510
-     *
1511
-     * @param boolean $hard             [deprecated]
1512
-     * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1513
-     *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1514
-     *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1515
-     * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1516
-     *                                  client
1517
-     *                                  code instead can just change the model context to a different blog id if
1518
-     *                                  necessary
1519
-     * @return EE_Registry
1520
-     * @throws EE_Error
1521
-     * @throws ReflectionException
1522
-     */
1523
-    public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1524
-    {
1525
-        $instance = self::instance();
1526
-        $instance->_cache_on = true;
1527
-        // reset some "special" classes
1528
-        EEH_Activation::reset();
1529
-        $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1530
-        $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1531
-        $instance->CART = null;
1532
-        $instance->MRM = null;
1533
-        $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1534
-        //messages reset
1535
-        EED_Messages::reset();
1536
-        //handle of objects cached on LIB
1537
-        foreach (array('LIB', 'modules') as $cache) {
1538
-            foreach ($instance->{$cache} as $class_name => $class) {
1539
-                if (self::_reset_and_unset_object($class, $reset_models)) {
1540
-                    unset($instance->{$cache}->{$class_name});
1541
-                }
1542
-            }
1543
-        }
1544
-        return $instance;
1545
-    }
1546
-
1547
-
1548
-
1549
-    /**
1550
-     * if passed object implements ResettableInterface, then call it's reset() method
1551
-     * if passed object implements InterminableInterface, then return false,
1552
-     * to indicate that it should NOT be cleared from the Registry cache
1553
-     *
1554
-     * @param      $object
1555
-     * @param bool $reset_models
1556
-     * @return bool returns true if cached object should be unset
1557
-     */
1558
-    private static function _reset_and_unset_object($object, $reset_models)
1559
-    {
1560
-        if (! is_object($object)) {
1561
-            // don't unset anything that's not an object
1562
-            return false;
1563
-        }
1564
-        if ($object instanceof EED_Module) {
1565
-            $object::reset();
1566
-            // don't unset modules
1567
-            return false;
1568
-        }
1569
-        if ($object instanceof ResettableInterface) {
1570
-            if ($object instanceof EEM_Base) {
1571
-                if ($reset_models) {
1572
-                    $object->reset();
1573
-                    return true;
1574
-                }
1575
-                return false;
1576
-            }
1577
-            $object->reset();
1578
-            return true;
1579
-        }
1580
-        if (! $object instanceof InterminableInterface) {
1581
-            return true;
1582
-        }
1583
-        return false;
1584
-    }
1585
-
1586
-
1587
-
1588
-    /**
1589
-     * Gets all the custom post type models defined
1590
-     *
1591
-     * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1592
-     */
1593
-    public function cpt_models()
1594
-    {
1595
-        $cpt_models = array();
1596
-        foreach ($this->non_abstract_db_models as $short_name => $classname) {
1597
-            if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1598
-                $cpt_models[$short_name] = $classname;
1599
-            }
1600
-        }
1601
-        return $cpt_models;
1602
-    }
1603
-
1604
-
1605
-
1606
-    /**
1607
-     * @return \EE_Config
1608
-     */
1609
-    public static function CFG()
1610
-    {
1611
-        return self::instance()->CFG;
1612
-    }
26
+	/**
27
+	 * @var EE_Registry $_instance
28
+	 */
29
+	private static $_instance;
30
+
31
+	/**
32
+	 * @var EE_Dependency_Map $_dependency_map
33
+	 */
34
+	protected $_dependency_map;
35
+
36
+	/**
37
+	 * @var array $_class_abbreviations
38
+	 */
39
+	protected $_class_abbreviations = array();
40
+
41
+	/**
42
+	 * @var CommandBusInterface $BUS
43
+	 */
44
+	public $BUS;
45
+
46
+	/**
47
+	 * @var EE_Cart $CART
48
+	 */
49
+	public $CART;
50
+
51
+	/**
52
+	 * @var EE_Config $CFG
53
+	 */
54
+	public $CFG;
55
+
56
+	/**
57
+	 * @var EE_Network_Config $NET_CFG
58
+	 */
59
+	public $NET_CFG;
60
+
61
+	/**
62
+	 * StdClass object for storing library classes in
63
+	 *
64
+	 * @var StdClass $LIB
65
+	 */
66
+	public $LIB;
67
+
68
+	/**
69
+	 * @var EE_Request_Handler $REQ
70
+	 */
71
+	public $REQ;
72
+
73
+	/**
74
+	 * @var EE_Session $SSN
75
+	 */
76
+	public $SSN;
77
+
78
+	/**
79
+	 * @since 4.5.0
80
+	 * @var EE_Capabilities $CAP
81
+	 */
82
+	public $CAP;
83
+
84
+	/**
85
+	 * @since 4.9.0
86
+	 * @var EE_Message_Resource_Manager $MRM
87
+	 */
88
+	public $MRM;
89
+
90
+
91
+	/**
92
+	 * @var Registry $AssetsRegistry
93
+	 */
94
+	public $AssetsRegistry;
95
+
96
+	/**
97
+	 * StdClass object for holding addons which have registered themselves to work with EE core
98
+	 *
99
+	 * @var EE_Addon[] $addons
100
+	 */
101
+	public $addons;
102
+
103
+	/**
104
+	 * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
105
+	 *
106
+	 * @var EEM_Base[] $models
107
+	 */
108
+	public $models = array();
109
+
110
+	/**
111
+	 * @var EED_Module[] $modules
112
+	 */
113
+	public $modules;
114
+
115
+	/**
116
+	 * @var EES_Shortcode[] $shortcodes
117
+	 */
118
+	public $shortcodes;
119
+
120
+	/**
121
+	 * @var WP_Widget[] $widgets
122
+	 */
123
+	public $widgets;
124
+
125
+	/**
126
+	 * this is an array of all implemented model names (i.e. not the parent abstract models, or models
127
+	 * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
128
+	 * Keys are model "short names" (eg "Event") as used in model relations, and values are
129
+	 * classnames (eg "EEM_Event")
130
+	 *
131
+	 * @var array $non_abstract_db_models
132
+	 */
133
+	public $non_abstract_db_models = array();
134
+
135
+
136
+	/**
137
+	 * internationalization for JS strings
138
+	 *    usage:   EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' );
139
+	 *    in js file:  var translatedString = eei18n.string_key;
140
+	 *
141
+	 * @var array $i18n_js_strings
142
+	 */
143
+	public static $i18n_js_strings = array();
144
+
145
+
146
+	/**
147
+	 * $main_file - path to espresso.php
148
+	 *
149
+	 * @var array $main_file
150
+	 */
151
+	public $main_file;
152
+
153
+	/**
154
+	 * array of ReflectionClass objects where the key is the class name
155
+	 *
156
+	 * @var ReflectionClass[] $_reflectors
157
+	 */
158
+	public $_reflectors;
159
+
160
+	/**
161
+	 * boolean flag to indicate whether or not to load/save dependencies from/to the cache
162
+	 *
163
+	 * @var boolean $_cache_on
164
+	 */
165
+	protected $_cache_on = true;
166
+
167
+
168
+
169
+	/**
170
+	 * @singleton method used to instantiate class object
171
+	 * @param  EE_Dependency_Map $dependency_map
172
+	 * @return EE_Registry instance
173
+	 * @throws InvalidArgumentException
174
+	 * @throws InvalidInterfaceException
175
+	 * @throws InvalidDataTypeException
176
+	 */
177
+	public static function instance(EE_Dependency_Map $dependency_map = null)
178
+	{
179
+		// check if class object is instantiated
180
+		if (! self::$_instance instanceof EE_Registry) {
181
+			self::$_instance = new self($dependency_map);
182
+		}
183
+		return self::$_instance;
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * protected constructor to prevent direct creation
190
+	 *
191
+	 * @Constructor
192
+	 * @param  EE_Dependency_Map $dependency_map
193
+	 * @throws InvalidDataTypeException
194
+	 * @throws InvalidInterfaceException
195
+	 * @throws InvalidArgumentException
196
+	 */
197
+	protected function __construct(EE_Dependency_Map $dependency_map)
198
+	{
199
+		$this->_dependency_map = $dependency_map;
200
+		// $registry_container = new RegistryContainer();
201
+		$this->LIB = new RegistryContainer();
202
+		$this->addons = new RegistryContainer();
203
+		$this->modules = new RegistryContainer();
204
+		$this->shortcodes = new RegistryContainer();
205
+		$this->widgets = new RegistryContainer();
206
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
207
+	}
208
+
209
+
210
+
211
+	/**
212
+	 * initialize
213
+	 *
214
+	 * @throws EE_Error
215
+	 * @throws ReflectionException
216
+	 */
217
+	public function initialize()
218
+	{
219
+		$this->_class_abbreviations = apply_filters(
220
+			'FHEE__EE_Registry____construct___class_abbreviations',
221
+			array(
222
+				'EE_Config'                                       => 'CFG',
223
+				'EE_Session'                                      => 'SSN',
224
+				'EE_Capabilities'                                 => 'CAP',
225
+				'EE_Cart'                                         => 'CART',
226
+				'EE_Network_Config'                               => 'NET_CFG',
227
+				'EE_Request_Handler'                              => 'REQ',
228
+				'EE_Message_Resource_Manager'                     => 'MRM',
229
+				'EventEspresso\core\services\commands\CommandBus' => 'BUS',
230
+				'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
231
+			)
232
+		);
233
+		$this->load_core('Base', array(), true);
234
+		// add our request and response objects to the cache
235
+		$request_loader = $this->_dependency_map->class_loader(
236
+			'EventEspresso\core\services\request\Request'
237
+		);
238
+		$this->_set_cached_class(
239
+			$request_loader(),
240
+			'EventEspresso\core\services\request\Request'
241
+		);
242
+		$response_loader = $this->_dependency_map->class_loader(
243
+			'EventEspresso\core\services\request\Response'
244
+		);
245
+		$this->_set_cached_class(
246
+			$response_loader(),
247
+			'EventEspresso\core\services\request\Response'
248
+		);
249
+		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
250
+	}
251
+
252
+
253
+
254
+	/**
255
+	 * @return void
256
+	 */
257
+	public function init()
258
+	{
259
+		// Get current page protocol
260
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
261
+		// Output admin-ajax.php URL with same protocol as current page
262
+		self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
263
+		self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
264
+	}
265
+
266
+
267
+
268
+	/**
269
+	 * localize_i18n_js_strings
270
+	 *
271
+	 * @return string
272
+	 */
273
+	public static function localize_i18n_js_strings()
274
+	{
275
+		$i18n_js_strings = (array)self::$i18n_js_strings;
276
+		foreach ($i18n_js_strings as $key => $value) {
277
+			if (is_scalar($value)) {
278
+				$i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
279
+			}
280
+		}
281
+		return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * @param mixed string | EED_Module $module
288
+	 * @throws EE_Error
289
+	 * @throws ReflectionException
290
+	 */
291
+	public function add_module($module)
292
+	{
293
+		if ($module instanceof EED_Module) {
294
+			$module_class = get_class($module);
295
+			$this->modules->{$module_class} = $module;
296
+		} else {
297
+			if ( ! class_exists('EE_Module_Request_Router', false)) {
298
+				$this->load_core('Module_Request_Router');
299
+			}
300
+			EE_Module_Request_Router::module_factory($module);
301
+		}
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * @param string $module_name
308
+	 * @return mixed EED_Module | NULL
309
+	 */
310
+	public function get_module($module_name = '')
311
+	{
312
+		return isset($this->modules->{$module_name})
313
+			? $this->modules->{$module_name}
314
+			: null;
315
+	}
316
+
317
+
318
+
319
+	/**
320
+	 * loads core classes - must be singletons
321
+	 *
322
+	 * @param string $class_name - simple class name ie: session
323
+	 * @param mixed  $arguments
324
+	 * @param bool   $load_only
325
+	 * @return mixed
326
+	 * @throws EE_Error
327
+	 * @throws ReflectionException
328
+	 */
329
+	public function load_core($class_name, $arguments = array(), $load_only = false)
330
+	{
331
+		$core_paths = apply_filters(
332
+			'FHEE__EE_Registry__load_core__core_paths',
333
+			array(
334
+				EE_CORE,
335
+				EE_ADMIN,
336
+				EE_CPTS,
337
+				EE_CORE . 'data_migration_scripts' . DS,
338
+				EE_CORE . 'capabilities' . DS,
339
+				EE_CORE . 'request_stack' . DS,
340
+				EE_CORE . 'middleware' . DS,
341
+			)
342
+		);
343
+		// retrieve instantiated class
344
+		return $this->_load(
345
+			$core_paths,
346
+			'EE_',
347
+			$class_name,
348
+			'core',
349
+			$arguments,
350
+			false,
351
+			true,
352
+			$load_only
353
+		);
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * loads service classes
360
+	 *
361
+	 * @param string $class_name - simple class name ie: session
362
+	 * @param mixed  $arguments
363
+	 * @param bool   $load_only
364
+	 * @return mixed
365
+	 * @throws EE_Error
366
+	 * @throws ReflectionException
367
+	 */
368
+	public function load_service($class_name, $arguments = array(), $load_only = false)
369
+	{
370
+		$service_paths = apply_filters(
371
+			'FHEE__EE_Registry__load_service__service_paths',
372
+			array(
373
+				EE_CORE . 'services' . DS,
374
+			)
375
+		);
376
+		// retrieve instantiated class
377
+		return $this->_load(
378
+			$service_paths,
379
+			'EE_',
380
+			$class_name,
381
+			'class',
382
+			$arguments,
383
+			false,
384
+			true,
385
+			$load_only
386
+		);
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 * loads data_migration_scripts
393
+	 *
394
+	 * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
395
+	 * @param mixed  $arguments
396
+	 * @return EE_Data_Migration_Script_Base|mixed
397
+	 * @throws EE_Error
398
+	 * @throws ReflectionException
399
+	 */
400
+	public function load_dms($class_name, $arguments = array())
401
+	{
402
+		// retrieve instantiated class
403
+		return $this->_load(
404
+			EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(),
405
+			'EE_DMS_',
406
+			$class_name,
407
+			'dms',
408
+			$arguments,
409
+			false,
410
+			false
411
+		);
412
+	}
413
+
414
+
415
+
416
+	/**
417
+	 * loads object creating classes - must be singletons
418
+	 *
419
+	 * @param string $class_name - simple class name ie: attendee
420
+	 * @param mixed  $arguments  - an array of arguments to pass to the class
421
+	 * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to
422
+	 *                           instantiate
423
+	 * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then
424
+	 *                           set this to FALSE (ie. when instantiating model objects from client in a loop)
425
+	 * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate
426
+	 *                           (default)
427
+	 * @return EE_Base_Class | bool
428
+	 * @throws EE_Error
429
+	 * @throws ReflectionException
430
+	 */
431
+	public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
432
+	{
433
+		$paths = apply_filters(
434
+			'FHEE__EE_Registry__load_class__paths', array(
435
+			EE_CORE,
436
+			EE_CLASSES,
437
+			EE_BUSINESS,
438
+		)
439
+		);
440
+		// retrieve instantiated class
441
+		return $this->_load(
442
+			$paths,
443
+			'EE_',
444
+			$class_name,
445
+			'class',
446
+			$arguments,
447
+			$from_db,
448
+			$cache,
449
+			$load_only
450
+		);
451
+	}
452
+
453
+
454
+
455
+	/**
456
+	 * loads helper classes - must be singletons
457
+	 *
458
+	 * @param string $class_name - simple class name ie: price
459
+	 * @param mixed  $arguments
460
+	 * @param bool   $load_only
461
+	 * @return EEH_Base | bool
462
+	 * @throws EE_Error
463
+	 * @throws ReflectionException
464
+	 */
465
+	public function load_helper($class_name, $arguments = array(), $load_only = true)
466
+	{
467
+		// todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
468
+		$helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
469
+		// retrieve instantiated class
470
+		return $this->_load(
471
+			$helper_paths,
472
+			'EEH_',
473
+			$class_name,
474
+			'helper',
475
+			$arguments,
476
+			false,
477
+			true,
478
+			$load_only
479
+		);
480
+	}
481
+
482
+
483
+
484
+	/**
485
+	 * loads core classes - must be singletons
486
+	 *
487
+	 * @param string $class_name - simple class name ie: session
488
+	 * @param mixed  $arguments
489
+	 * @param bool   $load_only
490
+	 * @param bool   $cache      whether to cache the object or not.
491
+	 * @return mixed
492
+	 * @throws EE_Error
493
+	 * @throws ReflectionException
494
+	 */
495
+	public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
496
+	{
497
+		$paths = array(
498
+			EE_LIBRARIES,
499
+			EE_LIBRARIES . 'messages' . DS,
500
+			EE_LIBRARIES . 'shortcodes' . DS,
501
+			EE_LIBRARIES . 'qtips' . DS,
502
+			EE_LIBRARIES . 'payment_methods' . DS,
503
+		);
504
+		// retrieve instantiated class
505
+		return $this->_load(
506
+			$paths,
507
+			'EE_',
508
+			$class_name,
509
+			'lib',
510
+			$arguments,
511
+			false,
512
+			$cache,
513
+			$load_only
514
+		);
515
+	}
516
+
517
+
518
+
519
+	/**
520
+	 * loads model classes - must be singletons
521
+	 *
522
+	 * @param string $class_name - simple class name ie: price
523
+	 * @param mixed  $arguments
524
+	 * @param bool   $load_only
525
+	 * @return EEM_Base | bool
526
+	 * @throws EE_Error
527
+	 * @throws ReflectionException
528
+	 */
529
+	public function load_model($class_name, $arguments = array(), $load_only = false)
530
+	{
531
+		$paths = apply_filters(
532
+			'FHEE__EE_Registry__load_model__paths', array(
533
+			EE_MODELS,
534
+			EE_CORE,
535
+		)
536
+		);
537
+		// retrieve instantiated class
538
+		return $this->_load(
539
+			$paths,
540
+			'EEM_',
541
+			$class_name,
542
+			'model',
543
+			$arguments,
544
+			false,
545
+			true,
546
+			$load_only
547
+		);
548
+	}
549
+
550
+
551
+
552
+	/**
553
+	 * loads model classes - must be singletons
554
+	 *
555
+	 * @param string $class_name - simple class name ie: price
556
+	 * @param mixed  $arguments
557
+	 * @param bool   $load_only
558
+	 * @return mixed | bool
559
+	 * @throws EE_Error
560
+	 * @throws ReflectionException
561
+	 */
562
+	public function load_model_class($class_name, $arguments = array(), $load_only = true)
563
+	{
564
+		$paths = array(
565
+			EE_MODELS . 'fields' . DS,
566
+			EE_MODELS . 'helpers' . DS,
567
+			EE_MODELS . 'relations' . DS,
568
+			EE_MODELS . 'strategies' . DS,
569
+		);
570
+		// retrieve instantiated class
571
+		return $this->_load(
572
+			$paths,
573
+			'EE_',
574
+			$class_name,
575
+			'',
576
+			$arguments,
577
+			false,
578
+			true,
579
+			$load_only
580
+		);
581
+	}
582
+
583
+
584
+
585
+	/**
586
+	 * Determines if $model_name is the name of an actual EE model.
587
+	 *
588
+	 * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
589
+	 * @return boolean
590
+	 */
591
+	public function is_model_name($model_name)
592
+	{
593
+		return isset($this->models[$model_name]);
594
+	}
595
+
596
+
597
+
598
+	/**
599
+	 * generic class loader
600
+	 *
601
+	 * @param string $path_to_file - directory path to file location, not including filename
602
+	 * @param string $file_name    - file name  ie:  my_file.php, including extension
603
+	 * @param string $type         - file type - core? class? helper? model?
604
+	 * @param mixed  $arguments
605
+	 * @param bool   $load_only
606
+	 * @return mixed
607
+	 * @throws EE_Error
608
+	 * @throws ReflectionException
609
+	 */
610
+	public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
611
+	{
612
+		// retrieve instantiated class
613
+		return $this->_load(
614
+			$path_to_file,
615
+			'',
616
+			$file_name,
617
+			$type,
618
+			$arguments,
619
+			false,
620
+			true,
621
+			$load_only
622
+		);
623
+	}
624
+
625
+
626
+
627
+	/**
628
+	 * @param string $path_to_file - directory path to file location, not including filename
629
+	 * @param string $class_name   - full class name  ie:  My_Class
630
+	 * @param string $type         - file type - core? class? helper? model?
631
+	 * @param mixed  $arguments
632
+	 * @param bool   $load_only
633
+	 * @return bool|EE_Addon|object
634
+	 * @throws EE_Error
635
+	 * @throws ReflectionException
636
+	 */
637
+	public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
638
+	{
639
+		// retrieve instantiated class
640
+		return $this->_load(
641
+			$path_to_file,
642
+			'addon',
643
+			$class_name,
644
+			$type,
645
+			$arguments,
646
+			false,
647
+			true,
648
+			$load_only
649
+		);
650
+	}
651
+
652
+
653
+
654
+	/**
655
+	 * instantiates, caches, and automatically resolves dependencies
656
+	 * for classes that use a Fully Qualified Class Name.
657
+	 * if the class is not capable of being loaded using PSR-4 autoloading,
658
+	 * then you need to use one of the existing load_*() methods
659
+	 * which can resolve the classname and filepath from the passed arguments
660
+	 *
661
+	 * @param bool|string $class_name   Fully Qualified Class Name
662
+	 * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
663
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
664
+	 * @param bool        $from_db      some classes are instantiated from the db
665
+	 *                                  and thus call a different method to instantiate
666
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
667
+	 * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
668
+	 * @return bool|null|mixed          null = failure to load or instantiate class object.
669
+	 *                                  object = class loaded and instantiated successfully.
670
+	 *                                  bool = fail or success when $load_only is true
671
+	 * @throws EE_Error
672
+	 * @throws ReflectionException
673
+	 */
674
+	public function create(
675
+		$class_name = false,
676
+		$arguments = array(),
677
+		$cache = false,
678
+		$from_db = false,
679
+		$load_only = false,
680
+		$addon = false
681
+	) {
682
+		$class_name = ltrim($class_name, '\\');
683
+		$class_name = $this->_dependency_map->get_alias($class_name);
684
+		$class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
685
+		// if a non-FQCN was passed, then verifyClassExists() might return an object
686
+		// or it could return null if the class just could not be found anywhere
687
+		if ($class_exists instanceof $class_name || $class_exists === null){
688
+			// either way, return the results
689
+			return $class_exists;
690
+		}
691
+		$class_name = $class_exists;
692
+		// if we're only loading the class and it already exists, then let's just return true immediately
693
+		if ($load_only) {
694
+			return true;
695
+		}
696
+		$addon = $addon
697
+			? 'addon'
698
+			: '';
699
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
700
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
701
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
702
+		if ($this->_cache_on && $cache && ! $load_only) {
703
+			// return object if it's already cached
704
+			$cached_class = $this->_get_cached_class($class_name, $addon);
705
+			if ($cached_class !== null) {
706
+				return $cached_class;
707
+			}
708
+		}
709
+		// obtain the loader method from the dependency map
710
+		$loader = $this->_dependency_map->class_loader($class_name);
711
+		// instantiate the requested object
712
+		if ($loader instanceof Closure) {
713
+			$class_obj = $loader($arguments);
714
+		} else if ($loader && method_exists($this, $loader)) {
715
+			$class_obj = $this->{$loader}($class_name, $arguments);
716
+		} else {
717
+			$class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
718
+		}
719
+		if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) {
720
+			// save it for later... kinda like gum  { : $
721
+			$this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
722
+		}
723
+		$this->_cache_on = true;
724
+		return $class_obj;
725
+	}
726
+
727
+
728
+
729
+	/**
730
+	 * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
731
+	 *
732
+	 * @param string $class_name
733
+	 * @param array  $arguments
734
+	 * @param int    $attempt
735
+	 * @return mixed
736
+	 */
737
+	private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) {
738
+		if (is_object($class_name) || class_exists($class_name)) {
739
+			return $class_name;
740
+		}
741
+		switch ($attempt) {
742
+			case 1:
743
+				// if it's a FQCN then maybe the class is registered with a preceding \
744
+				$class_name = strpos($class_name, '\\') !== false
745
+					? '\\' . ltrim($class_name, '\\')
746
+					: $class_name;
747
+				break;
748
+			case 2:
749
+				//
750
+				$loader = $this->_dependency_map->class_loader($class_name);
751
+				if ($loader && method_exists($this, $loader)) {
752
+					return $this->{$loader}($class_name, $arguments);
753
+				}
754
+				break;
755
+			case 3:
756
+			default;
757
+				return null;
758
+		}
759
+		$attempt++;
760
+		return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
761
+	}
762
+
763
+
764
+
765
+	/**
766
+	 * instantiates, caches, and injects dependencies for classes
767
+	 *
768
+	 * @param array       $file_paths   an array of paths to folders to look in
769
+	 * @param string      $class_prefix EE  or EEM or... ???
770
+	 * @param bool|string $class_name   $class name
771
+	 * @param string      $type         file type - core? class? helper? model?
772
+	 * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
773
+	 * @param bool        $from_db      some classes are instantiated from the db
774
+	 *                                  and thus call a different method to instantiate
775
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
776
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
777
+	 * @return bool|null|object null = failure to load or instantiate class object.
778
+	 *                                  object = class loaded and instantiated successfully.
779
+	 *                                  bool = fail or success when $load_only is true
780
+	 * @throws EE_Error
781
+	 * @throws ReflectionException
782
+	 */
783
+	protected function _load(
784
+		$file_paths = array(),
785
+		$class_prefix = 'EE_',
786
+		$class_name = false,
787
+		$type = 'class',
788
+		$arguments = array(),
789
+		$from_db = false,
790
+		$cache = true,
791
+		$load_only = false
792
+	) {
793
+		$class_name = ltrim($class_name, '\\');
794
+		// strip php file extension
795
+		$class_name = str_replace('.php', '', trim($class_name));
796
+		// does the class have a prefix ?
797
+		if (! empty($class_prefix) && $class_prefix !== 'addon') {
798
+			// make sure $class_prefix is uppercase
799
+			$class_prefix = strtoupper(trim($class_prefix));
800
+			// add class prefix ONCE!!!
801
+			$class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
802
+		}
803
+		$class_name = $this->_dependency_map->get_alias($class_name);
804
+		$class_exists = class_exists($class_name, false);
805
+		// if we're only loading the class and it already exists, then let's just return true immediately
806
+		if ($load_only && $class_exists) {
807
+			return true;
808
+		}
809
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
810
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
811
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
812
+		if ($this->_cache_on && $cache && ! $load_only) {
813
+			// return object if it's already cached
814
+			$cached_class = $this->_get_cached_class($class_name, $class_prefix);
815
+			if ($cached_class !== null) {
816
+				return $cached_class;
817
+			}
818
+		}
819
+		// if the class doesn't already exist.. then we need to try and find the file and load it
820
+		if (! $class_exists) {
821
+			// get full path to file
822
+			$path = $this->_resolve_path($class_name, $type, $file_paths);
823
+			// load the file
824
+			$loaded = $this->_require_file($path, $class_name, $type, $file_paths);
825
+			// if loading failed, or we are only loading a file but NOT instantiating an object
826
+			if (! $loaded || $load_only) {
827
+				// return boolean if only loading, or null if an object was expected
828
+				return $load_only
829
+					? $loaded
830
+					: null;
831
+			}
832
+		}
833
+		// instantiate the requested object
834
+		$class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
835
+		if ($this->_cache_on && $cache) {
836
+			// save it for later... kinda like gum  { : $
837
+			$this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
838
+		}
839
+		$this->_cache_on = true;
840
+		return $class_obj;
841
+	}
842
+
843
+
844
+
845
+	/**
846
+	 * @param string $class_name
847
+	 * @param string $default have to specify something, but not anything that will conflict
848
+	 * @return mixed|string
849
+	 */
850
+	protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
851
+	{
852
+		return isset($this->_class_abbreviations[$class_name])
853
+			? $this->_class_abbreviations[$class_name]
854
+			: $default;
855
+	}
856
+
857
+	/**
858
+	 * attempts to find a cached version of the requested class
859
+	 * by looking in the following places:
860
+	 *        $this->{$class_abbreviation}            ie:    $this->CART
861
+	 *        $this->{$class_name}                        ie:    $this->Some_Class
862
+	 *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
863
+	 *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
864
+	 *
865
+	 * @param string $class_name
866
+	 * @param string $class_prefix
867
+	 * @return mixed
868
+	 * @throws OutOfBoundsException
869
+	 */
870
+	protected function _get_cached_class($class_name, $class_prefix = '')
871
+	{
872
+		if ($class_name === 'EE_Registry') {
873
+			return $this;
874
+		}
875
+		$class_abbreviation = $this->get_class_abbreviation($class_name);
876
+		$class_name = str_replace('\\', '_', $class_name);
877
+		// check if class has already been loaded, and return it if it has been
878
+		if (isset($this->{$class_abbreviation})) {
879
+			return $this->{$class_abbreviation};
880
+		}
881
+		if (isset ($this->{$class_name})) {
882
+			return $this->{$class_name};
883
+		}
884
+		if (isset ($this->LIB->{$class_name})) {
885
+			return $this->LIB->{$class_name};
886
+		}
887
+		if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
888
+			return $this->addons->{$class_name};
889
+		}
890
+		return null;
891
+	}
892
+
893
+
894
+
895
+	/**
896
+	 * removes a cached version of the requested class
897
+	 *
898
+	 * @param string  $class_name
899
+	 * @param boolean $addon
900
+	 * @return boolean
901
+	 * @throws OutOfBoundsException
902
+	 */
903
+	public function clear_cached_class($class_name, $addon = false)
904
+	{
905
+		$class_abbreviation = $this->get_class_abbreviation($class_name);
906
+		$class_name = str_replace('\\', '_', $class_name);
907
+		// check if class has already been loaded, and return it if it has been
908
+		if (isset($this->{$class_abbreviation})) {
909
+			$this->{$class_abbreviation} = null;
910
+			return true;
911
+		}
912
+		if (isset($this->{$class_name})) {
913
+			$this->{$class_name} = null;
914
+			return true;
915
+		}
916
+		if (isset($this->LIB->{$class_name})) {
917
+			unset($this->LIB->{$class_name});
918
+			return true;
919
+		}
920
+		if ($addon && isset($this->addons->{$class_name})) {
921
+			unset($this->addons->{$class_name});
922
+			return true;
923
+		}
924
+		return false;
925
+	}
926
+
927
+
928
+
929
+	/**
930
+	 * attempts to find a full valid filepath for the requested class.
931
+	 * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
932
+	 * then returns that path if the target file has been found and is readable
933
+	 *
934
+	 * @param string $class_name
935
+	 * @param string $type
936
+	 * @param array  $file_paths
937
+	 * @return string | bool
938
+	 */
939
+	protected function _resolve_path($class_name, $type = '', $file_paths = array())
940
+	{
941
+		// make sure $file_paths is an array
942
+		$file_paths = is_array($file_paths)
943
+			? $file_paths
944
+			: array($file_paths);
945
+		// cycle thru paths
946
+		foreach ($file_paths as $key => $file_path) {
947
+			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
948
+			$file_path = $file_path
949
+				? str_replace(array('/', '\\'), DS, $file_path)
950
+				: EE_CLASSES;
951
+			// prep file type
952
+			$type = ! empty($type)
953
+				? trim($type, '.') . '.'
954
+				: '';
955
+			// build full file path
956
+			$file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
957
+			//does the file exist and can be read ?
958
+			if (is_readable($file_paths[$key])) {
959
+				return $file_paths[$key];
960
+			}
961
+		}
962
+		return false;
963
+	}
964
+
965
+
966
+
967
+	/**
968
+	 * basically just performs a require_once()
969
+	 * but with some error handling
970
+	 *
971
+	 * @param  string $path
972
+	 * @param  string $class_name
973
+	 * @param  string $type
974
+	 * @param  array  $file_paths
975
+	 * @return bool
976
+	 * @throws EE_Error
977
+	 * @throws ReflectionException
978
+	 */
979
+	protected function _require_file($path, $class_name, $type = '', $file_paths = array())
980
+	{
981
+		$this->resolve_legacy_class_parent($class_name);
982
+		// don't give up! you gotta...
983
+		try {
984
+			//does the file exist and can it be read ?
985
+			if (! $path) {
986
+				// just in case the file has already been autoloaded,
987
+				// but discrepancies in the naming schema are preventing it from
988
+				// being loaded via one of the EE_Registry::load_*() methods,
989
+				// then let's try one last hail mary before throwing an exception
990
+				// and call class_exists() again, but with autoloading turned ON
991
+				if(class_exists($class_name)) {
992
+					return true;
993
+				}
994
+				// so sorry, can't find the file
995
+				throw new EE_Error (
996
+					sprintf(
997
+						esc_html__(
998
+							'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',
999
+							'event_espresso'
1000
+						),
1001
+						trim($type, '.'),
1002
+						$class_name,
1003
+						'<br />' . implode(',<br />', $file_paths)
1004
+					)
1005
+				);
1006
+			}
1007
+			// get the file
1008
+			require_once($path);
1009
+			// if the class isn't already declared somewhere
1010
+			if (class_exists($class_name, false) === false) {
1011
+				// so sorry, not a class
1012
+				throw new EE_Error(
1013
+					sprintf(
1014
+						esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
1015
+						$type,
1016
+						$path,
1017
+						$class_name
1018
+					)
1019
+				);
1020
+			}
1021
+		} catch (EE_Error $e) {
1022
+			$e->get_error();
1023
+			return false;
1024
+		}
1025
+		return true;
1026
+	}
1027
+
1028
+
1029
+
1030
+	/**
1031
+	 * Some of our legacy classes that extended a parent class would simply use a require() statement
1032
+	 * before their class declaration in order to ensure that the parent class was loaded.
1033
+	 * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class,
1034
+	 * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist.
1035
+	 *
1036
+	 * @param string $class_name
1037
+	 */
1038
+	protected function resolve_legacy_class_parent($class_name = '')
1039
+	{
1040
+		try {
1041
+			$legacy_parent_class_map = array(
1042
+				'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php'
1043
+			);
1044
+			if(isset($legacy_parent_class_map[$class_name])) {
1045
+				require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name];
1046
+			}
1047
+		} catch (Exception $exception) {
1048
+		}
1049
+	}
1050
+
1051
+
1052
+
1053
+	/**
1054
+	 * _create_object
1055
+	 * Attempts to instantiate the requested class via any of the
1056
+	 * commonly used instantiation methods employed throughout EE.
1057
+	 * The priority for instantiation is as follows:
1058
+	 *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
1059
+	 *        - model objects via their 'new_instance_from_db' method
1060
+	 *        - model objects via their 'new_instance' method
1061
+	 *        - "singleton" classes" via their 'instance' method
1062
+	 *    - standard instantiable classes via their __constructor
1063
+	 * Prior to instantiation, if the classname exists in the dependency_map,
1064
+	 * then the constructor for the requested class will be examined to determine
1065
+	 * if any dependencies exist, and if they can be injected.
1066
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1067
+	 *
1068
+	 * @param string $class_name
1069
+	 * @param array  $arguments
1070
+	 * @param string $type
1071
+	 * @param bool   $from_db
1072
+	 * @return null|object
1073
+	 * @throws EE_Error
1074
+	 * @throws ReflectionException
1075
+	 */
1076
+	protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
1077
+	{
1078
+		// create reflection
1079
+		$reflector = $this->get_ReflectionClass($class_name);
1080
+		// make sure arguments are an array
1081
+		$arguments = is_array($arguments)
1082
+			? $arguments
1083
+			: array($arguments);
1084
+		// and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1085
+		// else wrap it in an additional array so that it doesn't get split into multiple parameters
1086
+		$arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1087
+			? $arguments
1088
+			: array($arguments);
1089
+		// attempt to inject dependencies ?
1090
+		if ($this->_dependency_map->has($class_name)) {
1091
+			$arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1092
+		}
1093
+		// instantiate the class if possible
1094
+		if ($reflector->isAbstract()) {
1095
+			// nothing to instantiate, loading file was enough
1096
+			// does not throw an exception so $instantiation_mode is unused
1097
+			// $instantiation_mode = "1) no constructor abstract class";
1098
+			return true;
1099
+		}
1100
+		if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) {
1101
+			// no constructor = static methods only... nothing to instantiate, loading file was enough
1102
+			// $instantiation_mode = "2) no constructor but instantiable";
1103
+			return $reflector->newInstance();
1104
+		}
1105
+		if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1106
+			// $instantiation_mode = "3) new_instance_from_db()";
1107
+			return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1108
+		}
1109
+		if (method_exists($class_name, 'new_instance')) {
1110
+			// $instantiation_mode = "4) new_instance()";
1111
+			return call_user_func_array(array($class_name, 'new_instance'), $arguments);
1112
+		}
1113
+		if (method_exists($class_name, 'instance')) {
1114
+			// $instantiation_mode = "5) instance()";
1115
+			return call_user_func_array(array($class_name, 'instance'), $arguments);
1116
+		}
1117
+		if ($reflector->isInstantiable()) {
1118
+			// $instantiation_mode = "6) constructor";
1119
+			return $reflector->newInstanceArgs($arguments);
1120
+		}
1121
+		// heh ? something's not right !
1122
+		throw new EE_Error(
1123
+			sprintf(
1124
+				__('The %s file %s could not be instantiated.', 'event_espresso'),
1125
+				$type,
1126
+				$class_name
1127
+			)
1128
+		);
1129
+	}
1130
+
1131
+
1132
+
1133
+	/**
1134
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1135
+	 * @param array $array
1136
+	 * @return bool
1137
+	 */
1138
+	protected function _array_is_numerically_and_sequentially_indexed(array $array)
1139
+	{
1140
+		return ! empty($array)
1141
+			? array_keys($array) === range(0, count($array) - 1)
1142
+			: true;
1143
+	}
1144
+
1145
+
1146
+
1147
+	/**
1148
+	 * getReflectionClass
1149
+	 * checks if a ReflectionClass object has already been generated for a class
1150
+	 * and returns that instead of creating a new one
1151
+	 *
1152
+	 * @param string $class_name
1153
+	 * @return ReflectionClass
1154
+	 * @throws ReflectionException
1155
+	 */
1156
+	public function get_ReflectionClass($class_name)
1157
+	{
1158
+		if (
1159
+			! isset($this->_reflectors[$class_name])
1160
+			|| ! $this->_reflectors[$class_name] instanceof ReflectionClass
1161
+		) {
1162
+			$this->_reflectors[$class_name] = new ReflectionClass($class_name);
1163
+		}
1164
+		return $this->_reflectors[$class_name];
1165
+	}
1166
+
1167
+
1168
+
1169
+	/**
1170
+	 * _resolve_dependencies
1171
+	 * examines the constructor for the requested class to determine
1172
+	 * if any dependencies exist, and if they can be injected.
1173
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1174
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
1175
+	 * For example:
1176
+	 *        if attempting to load a class "Foo" with the following constructor:
1177
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
1178
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
1179
+	 *        but only IF they are NOT already present in the incoming arguments array,
1180
+	 *        and the correct classes can be loaded
1181
+	 *
1182
+	 * @param ReflectionClass $reflector
1183
+	 * @param string          $class_name
1184
+	 * @param array           $arguments
1185
+	 * @return array
1186
+	 * @throws EE_Error
1187
+	 * @throws ReflectionException
1188
+	 */
1189
+	protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1190
+	{
1191
+		// let's examine the constructor
1192
+		$constructor = $reflector->getConstructor();
1193
+		// whu? huh? nothing?
1194
+		if (! $constructor) {
1195
+			return $arguments;
1196
+		}
1197
+		// get constructor parameters
1198
+		$params = $constructor->getParameters();
1199
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1200
+		$argument_keys = array_keys($arguments);
1201
+		// now loop thru all of the constructors expected parameters
1202
+		foreach ($params as $index => $param) {
1203
+			// is this a dependency for a specific class ?
1204
+			$param_class = $param->getClass()
1205
+				? $param->getClass()->name
1206
+				: null;
1207
+			// BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1208
+			$param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1209
+				? $this->_dependency_map->get_alias($param_class, $class_name)
1210
+				: $param_class;
1211
+			if (
1212
+				// param is not even a class
1213
+				$param_class === null
1214
+				// and something already exists in the incoming arguments for this param
1215
+				&& array_key_exists($index, $argument_keys)
1216
+				&& array_key_exists($argument_keys[$index], $arguments)
1217
+			) {
1218
+				// so let's skip this argument and move on to the next
1219
+				continue;
1220
+			}
1221
+			if (
1222
+				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1223
+				$param_class !== null
1224
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1225
+				&& $arguments[$argument_keys[$index]] instanceof $param_class
1226
+			) {
1227
+				// skip this argument and move on to the next
1228
+				continue;
1229
+			}
1230
+			if (
1231
+				// parameter is type hinted as a class, and should be injected
1232
+				$param_class !== null
1233
+				&& $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1234
+			) {
1235
+				$arguments = $this->_resolve_dependency(
1236
+					$class_name,
1237
+					$param_class,
1238
+					$arguments,
1239
+					$index,
1240
+					$argument_keys
1241
+				);
1242
+			} else {
1243
+				try {
1244
+					$arguments[$index] = $param->isDefaultValueAvailable()
1245
+						? $param->getDefaultValue()
1246
+						: null;
1247
+				} catch (ReflectionException $e) {
1248
+					throw new ReflectionException(
1249
+						sprintf(
1250
+							esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'),
1251
+							$e->getMessage(),
1252
+							$param->getName(),
1253
+							$class_name
1254
+						)
1255
+					);
1256
+				}
1257
+			}
1258
+		}
1259
+		return $arguments;
1260
+	}
1261
+
1262
+
1263
+
1264
+	/**
1265
+	 * @param string $class_name
1266
+	 * @param string $param_class
1267
+	 * @param array  $arguments
1268
+	 * @param mixed  $index
1269
+	 * @param array  $argument_keys
1270
+	 * @return array
1271
+	 * @throws EE_Error
1272
+	 * @throws ReflectionException
1273
+	 * @throws InvalidArgumentException
1274
+	 * @throws InvalidInterfaceException
1275
+	 * @throws InvalidDataTypeException
1276
+	 */
1277
+	protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys)
1278
+	{
1279
+		$dependency = null;
1280
+		// should dependency be loaded from cache ?
1281
+		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1282
+			$class_name,
1283
+			$param_class
1284
+		);
1285
+		$cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1286
+		// we might have a dependency...
1287
+		// let's MAYBE try and find it in our cache if that's what's been requested
1288
+		$cached_class = $cache_on
1289
+			? $this->_get_cached_class($param_class)
1290
+			: null;
1291
+		// and grab it if it exists
1292
+		if ($cached_class instanceof $param_class) {
1293
+			$dependency = $cached_class;
1294
+		} else if ($param_class !== $class_name) {
1295
+			// obtain the loader method from the dependency map
1296
+			$loader = $this->_dependency_map->class_loader($param_class);
1297
+			// is loader a custom closure ?
1298
+			if ($loader instanceof Closure) {
1299
+				$dependency = $loader($arguments);
1300
+			} else {
1301
+				// set the cache on property for the recursive loading call
1302
+				$this->_cache_on = $cache_on;
1303
+				// if not, then let's try and load it via the registry
1304
+				if ($loader && method_exists($this, $loader)) {
1305
+					$dependency = $this->{$loader}($param_class);
1306
+				} else {
1307
+					$dependency = LoaderFactory::getLoader()->load(
1308
+						$param_class,
1309
+						array(),
1310
+						$cache_on
1311
+					);
1312
+				}
1313
+			}
1314
+		}
1315
+		// did we successfully find the correct dependency ?
1316
+		if ($dependency instanceof $param_class) {
1317
+			// then let's inject it into the incoming array of arguments at the correct location
1318
+			$arguments[$index] = $dependency;
1319
+		}
1320
+		return $arguments;
1321
+	}
1322
+
1323
+
1324
+
1325
+	/**
1326
+	 * _set_cached_class
1327
+	 * attempts to cache the instantiated class locally
1328
+	 * in one of the following places, in the following order:
1329
+	 *        $this->{class_abbreviation}   ie:    $this->CART
1330
+	 *        $this->{$class_name}          ie:    $this->Some_Class
1331
+	 *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1332
+	 *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1333
+	 *
1334
+	 * @param object $class_obj
1335
+	 * @param string $class_name
1336
+	 * @param string $class_prefix
1337
+	 * @param bool   $from_db
1338
+	 * @return void
1339
+	 * @throws OutOfBoundsException
1340
+	 */
1341
+	protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1342
+	{
1343
+		if ($class_name === 'EE_Registry' || empty($class_obj)) {
1344
+			return;
1345
+		}
1346
+		// return newly instantiated class
1347
+		$class_abbreviation = $this->get_class_abbreviation($class_name, '');
1348
+		if ($class_abbreviation) {
1349
+			$this->{$class_abbreviation} = $class_obj;
1350
+			return;
1351
+		}
1352
+		$class_name = str_replace('\\', '_', $class_name);
1353
+		if (property_exists($this, $class_name)) {
1354
+			$this->{$class_name} = $class_obj;
1355
+			return;
1356
+		}
1357
+		if ($class_prefix === 'addon') {
1358
+			$this->addons->{$class_name} = $class_obj;
1359
+			return;
1360
+		}
1361
+		if (! $from_db) {
1362
+			$this->LIB->{$class_name} = $class_obj;
1363
+		}
1364
+	}
1365
+
1366
+
1367
+
1368
+	/**
1369
+	 * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1370
+	 *
1371
+	 * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1372
+	 *                          in the EE_Dependency_Map::$_class_loaders array,
1373
+	 *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1374
+	 * @param array  $arguments
1375
+	 * @return object
1376
+	 */
1377
+	public static function factory($classname, $arguments = array())
1378
+	{
1379
+		$loader = self::instance()->_dependency_map->class_loader($classname);
1380
+		if ($loader instanceof Closure) {
1381
+			return $loader($arguments);
1382
+		}
1383
+		if (method_exists(self::instance(), $loader)) {
1384
+			return self::instance()->{$loader}($classname, $arguments);
1385
+		}
1386
+		return null;
1387
+	}
1388
+
1389
+
1390
+
1391
+	/**
1392
+	 * Gets the addon by its class name
1393
+	 *
1394
+	 * @param string $class_name
1395
+	 * @return EE_Addon
1396
+	 * @throws OutOfBoundsException
1397
+	 */
1398
+	public function getAddon($class_name)
1399
+	{
1400
+		$class_name = str_replace('\\', '_', $class_name);
1401
+		return $this->addons->{$class_name};
1402
+	}
1403
+
1404
+
1405
+	/**
1406
+	 * removes the addon from the internal cache
1407
+	 *
1408
+	 * @param string $class_name
1409
+	 * @return void
1410
+	 */
1411
+	public function removeAddon($class_name)
1412
+	{
1413
+		$class_name = str_replace('\\', '_', $class_name);
1414
+		unset($this->addons->{$class_name});
1415
+	}
1416
+
1417
+
1418
+
1419
+	/**
1420
+	 * Gets the addon by its name/slug (not classname. For that, just
1421
+	 * use the get_addon() method above
1422
+	 *
1423
+	 * @param string $name
1424
+	 * @return EE_Addon
1425
+	 */
1426
+	public function get_addon_by_name($name)
1427
+	{
1428
+		foreach ($this->addons as $addon) {
1429
+			if ($addon->name() === $name) {
1430
+				return $addon;
1431
+			}
1432
+		}
1433
+		return null;
1434
+	}
1435
+
1436
+
1437
+
1438
+	/**
1439
+	 * Gets an array of all the registered addons, where the keys are their names.
1440
+	 * (ie, what each returns for their name() function)
1441
+	 * They're already available on EE_Registry::instance()->addons as properties,
1442
+	 * where each property's name is the addon's classname,
1443
+	 * So if you just want to get the addon by classname,
1444
+	 * OR use the get_addon() method above.
1445
+	 * PLEASE  NOTE:
1446
+	 * addons with Fully Qualified Class Names
1447
+	 * have had the namespace separators converted to underscores,
1448
+	 * so a classname like Fully\Qualified\ClassName
1449
+	 * would have been converted to Fully_Qualified_ClassName
1450
+	 *
1451
+	 * @return EE_Addon[] where the KEYS are the addon's name()
1452
+	 */
1453
+	public function get_addons_by_name()
1454
+	{
1455
+		$addons = array();
1456
+		foreach ($this->addons as $addon) {
1457
+			$addons[$addon->name()] = $addon;
1458
+		}
1459
+		return $addons;
1460
+	}
1461
+
1462
+
1463
+	/**
1464
+	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1465
+	 * a stale copy of it around
1466
+	 *
1467
+	 * @param string $model_name
1468
+	 * @return \EEM_Base
1469
+	 * @throws \EE_Error
1470
+	 */
1471
+	public function reset_model($model_name)
1472
+	{
1473
+		$model_class_name = strpos($model_name, 'EEM_') !== 0
1474
+			? "EEM_{$model_name}"
1475
+			: $model_name;
1476
+		if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1477
+			return null;
1478
+		}
1479
+		//get that model reset it and make sure we nuke the old reference to it
1480
+		if ($this->LIB->{$model_class_name} instanceof $model_class_name
1481
+			&& is_callable(
1482
+				array($model_class_name, 'reset')
1483
+			)) {
1484
+			$this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1485
+		} else {
1486
+			throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1487
+		}
1488
+		return $this->LIB->{$model_class_name};
1489
+	}
1490
+
1491
+
1492
+
1493
+	/**
1494
+	 * Resets the registry.
1495
+	 * The criteria for what gets reset is based on what can be shared between sites on the same request when
1496
+	 * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1497
+	 * - $_dependency_map
1498
+	 * - $_class_abbreviations
1499
+	 * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1500
+	 * - $REQ:  Still on the same request so no need to change.
1501
+	 * - $CAP: There is no site specific state in the EE_Capability class.
1502
+	 * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1503
+	 * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1504
+	 * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1505
+	 *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1506
+	 *             switch or on the restore.
1507
+	 * - $modules
1508
+	 * - $shortcodes
1509
+	 * - $widgets
1510
+	 *
1511
+	 * @param boolean $hard             [deprecated]
1512
+	 * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1513
+	 *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1514
+	 *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1515
+	 * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1516
+	 *                                  client
1517
+	 *                                  code instead can just change the model context to a different blog id if
1518
+	 *                                  necessary
1519
+	 * @return EE_Registry
1520
+	 * @throws EE_Error
1521
+	 * @throws ReflectionException
1522
+	 */
1523
+	public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1524
+	{
1525
+		$instance = self::instance();
1526
+		$instance->_cache_on = true;
1527
+		// reset some "special" classes
1528
+		EEH_Activation::reset();
1529
+		$hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1530
+		$instance->CFG = EE_Config::reset($hard, $reinstantiate);
1531
+		$instance->CART = null;
1532
+		$instance->MRM = null;
1533
+		$instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1534
+		//messages reset
1535
+		EED_Messages::reset();
1536
+		//handle of objects cached on LIB
1537
+		foreach (array('LIB', 'modules') as $cache) {
1538
+			foreach ($instance->{$cache} as $class_name => $class) {
1539
+				if (self::_reset_and_unset_object($class, $reset_models)) {
1540
+					unset($instance->{$cache}->{$class_name});
1541
+				}
1542
+			}
1543
+		}
1544
+		return $instance;
1545
+	}
1546
+
1547
+
1548
+
1549
+	/**
1550
+	 * if passed object implements ResettableInterface, then call it's reset() method
1551
+	 * if passed object implements InterminableInterface, then return false,
1552
+	 * to indicate that it should NOT be cleared from the Registry cache
1553
+	 *
1554
+	 * @param      $object
1555
+	 * @param bool $reset_models
1556
+	 * @return bool returns true if cached object should be unset
1557
+	 */
1558
+	private static function _reset_and_unset_object($object, $reset_models)
1559
+	{
1560
+		if (! is_object($object)) {
1561
+			// don't unset anything that's not an object
1562
+			return false;
1563
+		}
1564
+		if ($object instanceof EED_Module) {
1565
+			$object::reset();
1566
+			// don't unset modules
1567
+			return false;
1568
+		}
1569
+		if ($object instanceof ResettableInterface) {
1570
+			if ($object instanceof EEM_Base) {
1571
+				if ($reset_models) {
1572
+					$object->reset();
1573
+					return true;
1574
+				}
1575
+				return false;
1576
+			}
1577
+			$object->reset();
1578
+			return true;
1579
+		}
1580
+		if (! $object instanceof InterminableInterface) {
1581
+			return true;
1582
+		}
1583
+		return false;
1584
+	}
1585
+
1586
+
1587
+
1588
+	/**
1589
+	 * Gets all the custom post type models defined
1590
+	 *
1591
+	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1592
+	 */
1593
+	public function cpt_models()
1594
+	{
1595
+		$cpt_models = array();
1596
+		foreach ($this->non_abstract_db_models as $short_name => $classname) {
1597
+			if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1598
+				$cpt_models[$short_name] = $classname;
1599
+			}
1600
+		}
1601
+		return $cpt_models;
1602
+	}
1603
+
1604
+
1605
+
1606
+	/**
1607
+	 * @return \EE_Config
1608
+	 */
1609
+	public static function CFG()
1610
+	{
1611
+		return self::instance()->CFG;
1612
+	}
1613 1613
 
1614 1614
 
1615 1615
 }
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorIframe.php 2 patches
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 use ReflectionException;
12 12
 
13 13
 if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
14
-    exit( 'No direct script access allowed' );
14
+	exit( 'No direct script access allowed' );
15 15
 }
16 16
 
17 17
 
@@ -28,83 +28,83 @@  discard block
 block discarded – undo
28 28
 class TicketSelectorIframe extends Iframe
29 29
 {
30 30
 
31
-    /**
32
-     * TicketSelectorIframe constructor.
33
-     *
34
-     * @throws InvalidArgumentException
35
-     * @throws InvalidInterfaceException
36
-     * @throws InvalidDataTypeException
37
-     * @throws DomainException
38
-     * @throws EE_Error
39
-     * @throws ReflectionException
40
-     */
41
-    public function __construct()
42
-    {
43
-        EE_Registry::instance()->REQ->set_espresso_page( true );
44
-        /** @type \EEM_Event $EEM_Event */
45
-        $EEM_Event = EE_Registry::instance()->load_model( 'Event' );
46
-        $event = $EEM_Event->get_one_by_ID(
47
-            EE_Registry::instance()->REQ->get( 'event', 0 )
48
-        );
49
-        $ticket_selector = new DisplayTicketSelector();
50
-        $ticket_selector->setIframe( true );
51
-        parent::__construct(
52
-            esc_html__( 'Ticket Selector', 'event_espresso' ),
53
-            $ticket_selector->display( $event )
54
-        );
55
-        $this->addStylesheets(
56
-            apply_filters(
57
-                'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
58
-                array(
59
-                    'ticket_selector_embed' => TICKET_SELECTOR_ASSETS_URL
60
-                                               . 'ticket_selector_embed.css?ver='
61
-                                               . EVENT_ESPRESSO_VERSION,
62
-                    'ticket_selector'       => TICKET_SELECTOR_ASSETS_URL
63
-                                               . 'ticket_selector.css?ver='
64
-                                               . EVENT_ESPRESSO_VERSION,
65
-                ),
66
-                $this
67
-            )
68
-        );
69
-        if ( ! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) {
70
-            $this->addStylesheets( array('site_theme' => '' ) );
71
-        }
72
-        $this->addScripts(
73
-            apply_filters(
74
-                'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
75
-                array(
76
-                    'ticket_selector_iframe_embed' => TICKET_SELECTOR_ASSETS_URL
77
-                                                      . 'ticket_selector_iframe_embed.js?ver='
78
-                                                      . EVENT_ESPRESSO_VERSION,
79
-                ),
80
-                $this
81
-            )
82
-        );
83
-        $js_attributes = apply_filters(
84
-            'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes',
85
-            array(),
86
-            $this
87
-        );
88
-        if(! empty($js_attributes)) {
89
-            $this->addScriptAttributes($js_attributes);
90
-        }
91
-        $this->addLocalizedVars(
92
-            apply_filters(
93
-                'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__localized_vars',
94
-                array(
95
-                    'ticket_selector_iframe' => true,
96
-                    'EEDTicketSelectorMsg'   => __(
97
-                        'Please choose at least one ticket before continuing.',
98
-                        'event_espresso'
99
-                    ),
100
-                )
101
-            )
102
-        );
103
-        do_action(
104
-            'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete',
105
-            $this
106
-        );
107
-    }
31
+	/**
32
+	 * TicketSelectorIframe constructor.
33
+	 *
34
+	 * @throws InvalidArgumentException
35
+	 * @throws InvalidInterfaceException
36
+	 * @throws InvalidDataTypeException
37
+	 * @throws DomainException
38
+	 * @throws EE_Error
39
+	 * @throws ReflectionException
40
+	 */
41
+	public function __construct()
42
+	{
43
+		EE_Registry::instance()->REQ->set_espresso_page( true );
44
+		/** @type \EEM_Event $EEM_Event */
45
+		$EEM_Event = EE_Registry::instance()->load_model( 'Event' );
46
+		$event = $EEM_Event->get_one_by_ID(
47
+			EE_Registry::instance()->REQ->get( 'event', 0 )
48
+		);
49
+		$ticket_selector = new DisplayTicketSelector();
50
+		$ticket_selector->setIframe( true );
51
+		parent::__construct(
52
+			esc_html__( 'Ticket Selector', 'event_espresso' ),
53
+			$ticket_selector->display( $event )
54
+		);
55
+		$this->addStylesheets(
56
+			apply_filters(
57
+				'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
58
+				array(
59
+					'ticket_selector_embed' => TICKET_SELECTOR_ASSETS_URL
60
+											   . 'ticket_selector_embed.css?ver='
61
+											   . EVENT_ESPRESSO_VERSION,
62
+					'ticket_selector'       => TICKET_SELECTOR_ASSETS_URL
63
+											   . 'ticket_selector.css?ver='
64
+											   . EVENT_ESPRESSO_VERSION,
65
+				),
66
+				$this
67
+			)
68
+		);
69
+		if ( ! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) {
70
+			$this->addStylesheets( array('site_theme' => '' ) );
71
+		}
72
+		$this->addScripts(
73
+			apply_filters(
74
+				'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
75
+				array(
76
+					'ticket_selector_iframe_embed' => TICKET_SELECTOR_ASSETS_URL
77
+													  . 'ticket_selector_iframe_embed.js?ver='
78
+													  . EVENT_ESPRESSO_VERSION,
79
+				),
80
+				$this
81
+			)
82
+		);
83
+		$js_attributes = apply_filters(
84
+			'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes',
85
+			array(),
86
+			$this
87
+		);
88
+		if(! empty($js_attributes)) {
89
+			$this->addScriptAttributes($js_attributes);
90
+		}
91
+		$this->addLocalizedVars(
92
+			apply_filters(
93
+				'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__localized_vars',
94
+				array(
95
+					'ticket_selector_iframe' => true,
96
+					'EEDTicketSelectorMsg'   => __(
97
+						'Please choose at least one ticket before continuing.',
98
+						'event_espresso'
99
+					),
100
+				)
101
+			)
102
+		);
103
+		do_action(
104
+			'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete',
105
+			$this
106
+		);
107
+	}
108 108
 
109 109
 }
110 110
 // End of file TicketSelectorIframe.php
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@  discard block
 block discarded – undo
10 10
 use InvalidArgumentException;
11 11
 use ReflectionException;
12 12
 
13
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
14
-    exit( 'No direct script access allowed' );
13
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
14
+    exit('No direct script access allowed');
15 15
 }
16 16
 
17 17
 
@@ -40,17 +40,17 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public function __construct()
42 42
     {
43
-        EE_Registry::instance()->REQ->set_espresso_page( true );
43
+        EE_Registry::instance()->REQ->set_espresso_page(true);
44 44
         /** @type \EEM_Event $EEM_Event */
45
-        $EEM_Event = EE_Registry::instance()->load_model( 'Event' );
45
+        $EEM_Event = EE_Registry::instance()->load_model('Event');
46 46
         $event = $EEM_Event->get_one_by_ID(
47
-            EE_Registry::instance()->REQ->get( 'event', 0 )
47
+            EE_Registry::instance()->REQ->get('event', 0)
48 48
         );
49 49
         $ticket_selector = new DisplayTicketSelector();
50
-        $ticket_selector->setIframe( true );
50
+        $ticket_selector->setIframe(true);
51 51
         parent::__construct(
52
-            esc_html__( 'Ticket Selector', 'event_espresso' ),
53
-            $ticket_selector->display( $event )
52
+            esc_html__('Ticket Selector', 'event_espresso'),
53
+            $ticket_selector->display($event)
54 54
         );
55 55
         $this->addStylesheets(
56 56
             apply_filters(
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             )
68 68
         );
69 69
         if ( ! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) {
70
-            $this->addStylesheets( array('site_theme' => '' ) );
70
+            $this->addStylesheets(array('site_theme' => ''));
71 71
         }
72 72
         $this->addScripts(
73 73
             apply_filters(
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
             array(),
86 86
             $this
87 87
         );
88
-        if(! empty($js_attributes)) {
88
+        if ( ! empty($js_attributes)) {
89 89
             $this->addScriptAttributes($js_attributes);
90 90
         }
91 91
         $this->addLocalizedVars(
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Invisible_Recaptcha_Input.input.php 2 patches
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -19,224 +19,224 @@
 block discarded – undo
19 19
 class EE_Invisible_Recaptcha_Input extends EE_Form_Input_Base
20 20
 {
21 21
 
22
-    const SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA   = 'google_invisible_recaptcha';
23
-
24
-    const SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA = 'espresso_invisible_recaptcha';
25
-
26
-    /**
27
-     * @var EE_Registration_Config $config
28
-     */
29
-    private $config;
30
-
31
-    /**
32
-     * @var string $recaptcha_id
33
-     */
34
-    private $recaptcha_id;
35
-
36
-    /**
37
-     * @var string $submit_button_id
38
-     */
39
-    private $submit_button_id;
40
-
41
-
42
-    /**
43
-     * @param array                  $input_settings
44
-     * @param EE_Registration_Config $registration_config
45
-     * @throws InvalidArgumentException
46
-     * @throws InvalidDataTypeException
47
-     * @throws InvalidInterfaceException
48
-     * @throws DomainException
49
-     */
50
-    public function __construct(array $input_settings = array(), EE_Registration_Config $registration_config = null)
51
-    {
52
-        $this->_set_display_strategy(new EE_Invisible_Recaptcha_Display_Strategy());
53
-        parent::__construct($input_settings);
54
-        $registration_config    = $registration_config instanceof EE_Registration_Config
55
-            ? $registration_config
56
-            : EE_Registry::instance()->CFG->registration;
57
-        $this->config           = $registration_config;
58
-        $this->recaptcha_id     = isset($input_settings['recaptcha_id'])
59
-            ? $input_settings['recaptcha_id']
60
-            : substr(spl_object_hash($this), 8, 8);
61
-        $this->submit_button_id = isset($input_settings['submit_button_id'])
62
-            ? $input_settings['submit_button_id']
63
-            : '';
64
-        if(
65
-            isset($input_settings['localized_vars'])
66
-            && filter_var($input_settings['iframe'], FILTER_VALIDATE_BOOLEAN)
67
-        ) {
68
-            $this->addIframeAssets($input_settings['localized_vars']);
69
-        } else {
70
-            $this->registerScripts();
71
-        }
72
-    }
73
-
74
-
75
-    /**
76
-     * @return bool
77
-     */
78
-    public function useCaptcha()
79
-    {
80
-        return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
81
-    }
82
-
83
-
84
-    /**
85
-     * @return string
86
-     */
87
-    public function badge()
88
-    {
89
-        return $this->config->recaptcha_badge;
90
-    }
91
-
92
-
93
-    /**
94
-     * @return string
95
-     */
96
-    public function language()
97
-    {
98
-        return $this->config->recaptcha_language;
99
-    }
100
-
101
-
102
-    /**
103
-     * @return string
104
-     */
105
-    public function siteKey()
106
-    {
107
-        return $this->config->recaptcha_publickey;
108
-    }
109
-
110
-
111
-    /**
112
-     * @return string
113
-     */
114
-    public function secretKey()
115
-    {
116
-        return $this->config->recaptcha_privatekey;
117
-    }
118
-
119
-
120
-    /**
121
-     * @return string
122
-     */
123
-    public function recaptchaId()
124
-    {
125
-        return $this->recaptcha_id;
126
-    }
127
-
128
-
129
-    /**
130
-     * @return string
131
-     */
132
-    public function submitButtonId()
133
-    {
134
-        return $this->submit_button_id;
135
-    }
136
-
137
-
138
-    /**
139
-     * @param array $localized_vars
140
-     * @throws DomainException
141
-     */
142
-    private function addIframeAssets(array $localized_vars)
143
-    {
144
-        if (! $this->useCaptcha()) {
145
-            return;
146
-        }
147
-        add_filter(
148
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
149
-            function(array $iframe_assets) {
150
-                $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA ] =
151
-                    EED_Recaptcha_Invisible::assetsUrl()
152
-                    . 'espresso_invisible_recaptcha.js?ver='
153
-                    . EVENT_ESPRESSO_VERSION;
154
-                $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] =
155
-                    add_query_arg(
156
-                        array(
157
-                            'onload' => 'espressoLoadRecaptcha',
158
-                            'render' => 'explicit',
159
-                            'hl'     => $this->language(),
160
-                        ),
161
-                        'https://www.google.com/recaptcha/api.js?'
162
-                    );
163
-                return $iframe_assets;
164
-            }
165
-        );
166
-        add_filter(
167
-            'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes',
168
-            function (array $iframe_asset_attributes)
169
-            {
170
-                $iframe_asset_attributes[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ]
171
-                    = ' async="async" defer="defer"';
172
-                return $iframe_asset_attributes;
173
-            }
174
-        );
175
-        add_action(
176
-            'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete',
177
-            function (EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars)
178
-            {
179
-                $ticket_selector_iframe->addLocalizedVars($localized_vars, 'eeRecaptcha');
180
-            }
181
-        );
182
-    }
183
-
184
-
185
-    /**
186
-     * @return void
187
-     */
188
-    private function registerScripts()
189
-    {
190
-        if (! $this->useCaptcha()) {
191
-            return;
192
-        }
193
-        add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2);
194
-        wp_register_script(
195
-            EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA,
196
-            EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js',
197
-            array('espresso_core'),
198
-            EVENT_ESPRESSO_VERSION,
199
-            true
200
-        );
201
-        wp_register_script(
202
-            EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA,
203
-            add_query_arg(
204
-                array(
205
-                    'onload' => 'espressoLoadRecaptcha',
206
-                    'render' => 'explicit',
207
-                    'hl'     => $this->language(),
208
-                ),
209
-                'https://www.google.com/recaptcha/api.js?'
210
-            ),
211
-            array(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA),
212
-            false,
213
-            true
214
-        );
215
-    }
216
-
217
-
218
-    /**
219
-     * @param string $tag
220
-     * @param string $handle
221
-     * @return string
222
-     */
223
-    public function addScriptAttributes($tag, $handle)
224
-    {
225
-        if ($handle === EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA) {
226
-            $tag = str_replace('></script>', ' async="async" defer="defer"></script>', $tag);
227
-        }
228
-        return $tag;
229
-    }
230
-
231
-
232
-    /**
233
-     * Gets the HTML for displaying the label for this form input
234
-     * according to the form section's layout strategy
235
-     *
236
-     * @return string
237
-     */
238
-    public function get_html_for_label()
239
-    {
240
-        return '';
241
-    }
22
+	const SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA   = 'google_invisible_recaptcha';
23
+
24
+	const SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA = 'espresso_invisible_recaptcha';
25
+
26
+	/**
27
+	 * @var EE_Registration_Config $config
28
+	 */
29
+	private $config;
30
+
31
+	/**
32
+	 * @var string $recaptcha_id
33
+	 */
34
+	private $recaptcha_id;
35
+
36
+	/**
37
+	 * @var string $submit_button_id
38
+	 */
39
+	private $submit_button_id;
40
+
41
+
42
+	/**
43
+	 * @param array                  $input_settings
44
+	 * @param EE_Registration_Config $registration_config
45
+	 * @throws InvalidArgumentException
46
+	 * @throws InvalidDataTypeException
47
+	 * @throws InvalidInterfaceException
48
+	 * @throws DomainException
49
+	 */
50
+	public function __construct(array $input_settings = array(), EE_Registration_Config $registration_config = null)
51
+	{
52
+		$this->_set_display_strategy(new EE_Invisible_Recaptcha_Display_Strategy());
53
+		parent::__construct($input_settings);
54
+		$registration_config    = $registration_config instanceof EE_Registration_Config
55
+			? $registration_config
56
+			: EE_Registry::instance()->CFG->registration;
57
+		$this->config           = $registration_config;
58
+		$this->recaptcha_id     = isset($input_settings['recaptcha_id'])
59
+			? $input_settings['recaptcha_id']
60
+			: substr(spl_object_hash($this), 8, 8);
61
+		$this->submit_button_id = isset($input_settings['submit_button_id'])
62
+			? $input_settings['submit_button_id']
63
+			: '';
64
+		if(
65
+			isset($input_settings['localized_vars'])
66
+			&& filter_var($input_settings['iframe'], FILTER_VALIDATE_BOOLEAN)
67
+		) {
68
+			$this->addIframeAssets($input_settings['localized_vars']);
69
+		} else {
70
+			$this->registerScripts();
71
+		}
72
+	}
73
+
74
+
75
+	/**
76
+	 * @return bool
77
+	 */
78
+	public function useCaptcha()
79
+	{
80
+		return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
81
+	}
82
+
83
+
84
+	/**
85
+	 * @return string
86
+	 */
87
+	public function badge()
88
+	{
89
+		return $this->config->recaptcha_badge;
90
+	}
91
+
92
+
93
+	/**
94
+	 * @return string
95
+	 */
96
+	public function language()
97
+	{
98
+		return $this->config->recaptcha_language;
99
+	}
100
+
101
+
102
+	/**
103
+	 * @return string
104
+	 */
105
+	public function siteKey()
106
+	{
107
+		return $this->config->recaptcha_publickey;
108
+	}
109
+
110
+
111
+	/**
112
+	 * @return string
113
+	 */
114
+	public function secretKey()
115
+	{
116
+		return $this->config->recaptcha_privatekey;
117
+	}
118
+
119
+
120
+	/**
121
+	 * @return string
122
+	 */
123
+	public function recaptchaId()
124
+	{
125
+		return $this->recaptcha_id;
126
+	}
127
+
128
+
129
+	/**
130
+	 * @return string
131
+	 */
132
+	public function submitButtonId()
133
+	{
134
+		return $this->submit_button_id;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @param array $localized_vars
140
+	 * @throws DomainException
141
+	 */
142
+	private function addIframeAssets(array $localized_vars)
143
+	{
144
+		if (! $this->useCaptcha()) {
145
+			return;
146
+		}
147
+		add_filter(
148
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
149
+			function(array $iframe_assets) {
150
+				$iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA ] =
151
+					EED_Recaptcha_Invisible::assetsUrl()
152
+					. 'espresso_invisible_recaptcha.js?ver='
153
+					. EVENT_ESPRESSO_VERSION;
154
+				$iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] =
155
+					add_query_arg(
156
+						array(
157
+							'onload' => 'espressoLoadRecaptcha',
158
+							'render' => 'explicit',
159
+							'hl'     => $this->language(),
160
+						),
161
+						'https://www.google.com/recaptcha/api.js?'
162
+					);
163
+				return $iframe_assets;
164
+			}
165
+		);
166
+		add_filter(
167
+			'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes',
168
+			function (array $iframe_asset_attributes)
169
+			{
170
+				$iframe_asset_attributes[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ]
171
+					= ' async="async" defer="defer"';
172
+				return $iframe_asset_attributes;
173
+			}
174
+		);
175
+		add_action(
176
+			'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete',
177
+			function (EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars)
178
+			{
179
+				$ticket_selector_iframe->addLocalizedVars($localized_vars, 'eeRecaptcha');
180
+			}
181
+		);
182
+	}
183
+
184
+
185
+	/**
186
+	 * @return void
187
+	 */
188
+	private function registerScripts()
189
+	{
190
+		if (! $this->useCaptcha()) {
191
+			return;
192
+		}
193
+		add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2);
194
+		wp_register_script(
195
+			EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA,
196
+			EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js',
197
+			array('espresso_core'),
198
+			EVENT_ESPRESSO_VERSION,
199
+			true
200
+		);
201
+		wp_register_script(
202
+			EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA,
203
+			add_query_arg(
204
+				array(
205
+					'onload' => 'espressoLoadRecaptcha',
206
+					'render' => 'explicit',
207
+					'hl'     => $this->language(),
208
+				),
209
+				'https://www.google.com/recaptcha/api.js?'
210
+			),
211
+			array(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA),
212
+			false,
213
+			true
214
+		);
215
+	}
216
+
217
+
218
+	/**
219
+	 * @param string $tag
220
+	 * @param string $handle
221
+	 * @return string
222
+	 */
223
+	public function addScriptAttributes($tag, $handle)
224
+	{
225
+		if ($handle === EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA) {
226
+			$tag = str_replace('></script>', ' async="async" defer="defer"></script>', $tag);
227
+		}
228
+		return $tag;
229
+	}
230
+
231
+
232
+	/**
233
+	 * Gets the HTML for displaying the label for this form input
234
+	 * according to the form section's layout strategy
235
+	 *
236
+	 * @return string
237
+	 */
238
+	public function get_html_for_label()
239
+	{
240
+		return '';
241
+	}
242 242
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
         $this->submit_button_id = isset($input_settings['submit_button_id'])
62 62
             ? $input_settings['submit_button_id']
63 63
             : '';
64
-        if(
64
+        if (
65 65
             isset($input_settings['localized_vars'])
66 66
             && filter_var($input_settings['iframe'], FILTER_VALIDATE_BOOLEAN)
67 67
         ) {
@@ -141,17 +141,17 @@  discard block
 block discarded – undo
141 141
      */
142 142
     private function addIframeAssets(array $localized_vars)
143 143
     {
144
-        if (! $this->useCaptcha()) {
144
+        if ( ! $this->useCaptcha()) {
145 145
             return;
146 146
         }
147 147
         add_filter(
148 148
             'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
149 149
             function(array $iframe_assets) {
150
-                $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA ] =
150
+                $iframe_assets[EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA] =
151 151
                     EED_Recaptcha_Invisible::assetsUrl()
152 152
                     . 'espresso_invisible_recaptcha.js?ver='
153 153
                     . EVENT_ESPRESSO_VERSION;
154
-                $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] =
154
+                $iframe_assets[EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA] =
155 155
                     add_query_arg(
156 156
                         array(
157 157
                             'onload' => 'espressoLoadRecaptcha',
@@ -165,16 +165,16 @@  discard block
 block discarded – undo
165 165
         );
166 166
         add_filter(
167 167
             'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes',
168
-            function (array $iframe_asset_attributes)
168
+            function(array $iframe_asset_attributes)
169 169
             {
170
-                $iframe_asset_attributes[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ]
170
+                $iframe_asset_attributes[EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA]
171 171
                     = ' async="async" defer="defer"';
172 172
                 return $iframe_asset_attributes;
173 173
             }
174 174
         );
175 175
         add_action(
176 176
             'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete',
177
-            function (EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars)
177
+            function(EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars)
178 178
             {
179 179
                 $ticket_selector_iframe->addLocalizedVars($localized_vars, 'eeRecaptcha');
180 180
             }
@@ -187,13 +187,13 @@  discard block
 block discarded – undo
187 187
      */
188 188
     private function registerScripts()
189 189
     {
190
-        if (! $this->useCaptcha()) {
190
+        if ( ! $this->useCaptcha()) {
191 191
             return;
192 192
         }
193 193
         add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2);
194 194
         wp_register_script(
195 195
             EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA,
196
-            EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js',
196
+            EED_Recaptcha_Invisible::assetsUrl().'espresso_invisible_recaptcha.js',
197 197
             array('espresso_core'),
198 198
             EVENT_ESPRESSO_VERSION,
199 199
             true
Please login to merge, or discard this patch.
core/libraries/iframe_display/iframe_wrapper.template.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -22,17 +22,17 @@  discard block
 block discarded – undo
22 22
 <html>
23 23
 <head>
24 24
 	<title><?php echo $title; ?></title>
25
-<?php if ( $enqueue_wp_assets ) : ?>
25
+<?php if ($enqueue_wp_assets) : ?>
26 26
 	<?php wp_head(); ?>
27 27
 <?php else : ?>
28
-	<?php foreach ( $css as $url ) : ?>
29
-	<link rel="stylesheet" type="text/css" href="<?php echo $url;?>">
28
+	<?php foreach ($css as $url) : ?>
29
+	<link rel="stylesheet" type="text/css" href="<?php echo $url; ?>">
30 30
 	<?php endforeach; ?>
31 31
 	<script type="text/javascript">
32 32
 		<?php echo $eei18n; ?>
33 33
 	</script>
34
-	<?php foreach ( $header_js as $key => $url ) : ?>
35
-    <?php $header_attributes = isset($header_js_attributes[ $key ]) ? $header_js_attributes[ $key ] : ''; ?>
34
+	<?php foreach ($header_js as $key => $url) : ?>
35
+    <?php $header_attributes = isset($header_js_attributes[$key]) ? $header_js_attributes[$key] : ''; ?>
36 36
     <script type="text/javascript" src="<?php echo $url; ?>"<?php echo $header_attributes; ?>></script>
37 37
 	<?php endforeach; ?>
38 38
 <?php endif; ?>
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
     <div style="padding: 1em;">
43 43
         <?php echo $content; ?>
44 44
     </div>
45
-    <?php foreach ( $footer_js as $key => $url ) : ?>
46
-        <?php $footer_attributes = isset($footer_js_attributes[$key]) ? $footer_js_attributes[ $key ] : '';  ?>
47
-		<script type="text/javascript" src="<?php echo $url; ?>"<?php echo $footer_attributes;?>></script>
45
+    <?php foreach ($footer_js as $key => $url) : ?>
46
+        <?php $footer_attributes = isset($footer_js_attributes[$key]) ? $footer_js_attributes[$key] : ''; ?>
47
+		<script type="text/javascript" src="<?php echo $url; ?>"<?php echo $footer_attributes; ?>></script>
48 48
 	<?php endforeach; ?>
49
-<?php if ( $enqueue_wp_assets ) : ?>
49
+<?php if ($enqueue_wp_assets) : ?>
50 50
 	<?php wp_footer(); ?>
51 51
 <?php endif; ?>
52 52
 </body>
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha_invisible/InvisibleRecaptcha.php 2 patches
Indentation   +237 added lines, -237 removed lines patch added patch discarded remove patch
@@ -31,241 +31,241 @@
 block discarded – undo
31 31
 class InvisibleRecaptcha
32 32
 {
33 33
 
34
-    const URL_GOOGLE_RECAPTCHA_API          = 'https://www.google.com/recaptcha/api/siteverify';
35
-
36
-    const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed';
37
-
38
-    /**
39
-     * @var EE_Registration_Config $config
40
-     */
41
-    private $config;
42
-
43
-    /**
44
-     * @var EE_Session $session
45
-     */
46
-    private $session;
47
-
48
-    /**
49
-     * @var boolean $recaptcha_passed
50
-     */
51
-    private $recaptcha_passed;
52
-
53
-
54
-    /**
55
-     * InvisibleRecaptcha constructor.
56
-     *
57
-     * @param EE_Registration_Config $registration_config
58
-     * @param EE_Session             $session
59
-     */
60
-    public function __construct(EE_Registration_Config $registration_config, EE_Session $session)
61
-    {
62
-        $this->config = $registration_config;
63
-        $this->session = $session;
64
-    }
65
-
66
-
67
-    /**
68
-     * @return boolean
69
-     */
70
-    public function useInvisibleRecaptcha()
71
-    {
72
-        return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
73
-    }
74
-
75
-
76
-    /**
77
-     * @param array $input_settings
78
-     * @return EE_Invisible_Recaptcha_Input
79
-     * @throws InvalidDataTypeException
80
-     * @throws InvalidInterfaceException
81
-     * @throws InvalidArgumentException
82
-     * @throws DomainException
83
-     */
84
-    public function getInput(array $input_settings = array())
85
-    {
86
-        return new EE_Invisible_Recaptcha_Input(
87
-            $input_settings,
88
-            $this->config
89
-        );
90
-    }
91
-
92
-
93
-    /**
94
-     * @param array $input_settings
95
-     * @return string
96
-     * @throws EE_Error
97
-     * @throws InvalidDataTypeException
98
-     * @throws InvalidInterfaceException
99
-     * @throws InvalidArgumentException
100
-     * @throws DomainException
101
-     */
102
-    public function getInputHtml(array $input_settings = array())
103
-    {
104
-        return $this->getInput($input_settings)->get_html_for_input();
105
-    }
106
-
107
-
108
-    /**
109
-     * @param EE_Form_Section_Proper $form
110
-     * @param array                  $input_settings
111
-     * @throws EE_Error
112
-     * @throws InvalidArgumentException
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     * @throws DomainException
116
-     */
117
-    public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array())
118
-    {
119
-        $form->add_subsections(
120
-            array(
121
-                'espresso_recaptcha' => $this->getInput($input_settings),
122
-            ),
123
-            null,
124
-            false
125
-        );
126
-    }
127
-
128
-
129
-    /**
130
-     * @param EE_Request $request
131
-     * @return boolean
132
-     * @throws RuntimeException
133
-     */
134
-    public function verifyToken(EE_Request $request)
135
-    {
136
-        static $previous_recaptcha_response = array();
137
-        $grecaptcha_response = $request->get('g-recaptcha-response');
138
-        // if this token has already been verified, then return previous response
139
-        if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
140
-            return $previous_recaptcha_response[ $grecaptcha_response ];
141
-        }
142
-        // will update to true if everything passes
143
-        $previous_recaptcha_response[ $grecaptcha_response ] = false;
144
-        $response                                            = wp_safe_remote_post(
145
-            InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
146
-            array(
147
-                'body' => array(
148
-                    'secret'   => $this->config->recaptcha_privatekey,
149
-                    'response' => $grecaptcha_response,
150
-                    'remoteip' => $request->ip_address(),
151
-                ),
152
-            )
153
-        );
154
-        if ($response instanceof WP_Error) {
155
-            $this->generateError($response->get_error_messages());
156
-            return false;
157
-        }
158
-        $results = json_decode(wp_remote_retrieve_body($response), true);
159
-        if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
160
-            $errors   = array_map(
161
-                array($this, 'getErrorCode'),
162
-                $results['error-codes']
163
-            );
164
-            if(isset($results['challenge_ts'])) {
165
-                $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
166
-            }
167
-            $this->generateError(implode(' ', $errors));
168
-        }
169
-        $previous_recaptcha_response[ $grecaptcha_response ] = true;
170
-        add_action('shutdown', array($this, 'setSessionData'));
171
-        return true;
172
-    }
173
-
174
-
175
-    /**
176
-     * @param string $error_response
177
-     * @return void
178
-     * @throws RuntimeException
179
-     */
180
-    public function generateError($error_response = '')
181
-    {
182
-        throw new RuntimeException(
183
-            sprintf(
184
-                esc_html__(
185
-                    'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.',
186
-                    'event_espresso'
187
-                ),
188
-                '<br />',
189
-                current_user_can('manage_options') ? $error_response : ''
190
-            )
191
-        );
192
-    }
193
-
194
-
195
-    /**
196
-     * @param string $error_code
197
-     * @return string
198
-     */
199
-    public function getErrorCode(&$error_code)
200
-    {
201
-        $error_codes = array(
202
-            'missing-input-secret'   => 'The secret parameter is missing.',
203
-            'invalid-input-secret'   => 'The secret parameter is invalid or malformed.',
204
-            'missing-input-response' => 'The response parameter is missing.',
205
-            'invalid-input-response' => 'The response parameter is invalid or malformed.',
206
-            'bad-request'            => 'The request is invalid or malformed.',
207
-            'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
208
-        );
209
-        return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
210
-    }
211
-
212
-
213
-    /**
214
-     * @return array
215
-     * @throws InvalidInterfaceException
216
-     * @throws InvalidDataTypeException
217
-     * @throws InvalidArgumentException
218
-     */
219
-    public function getLocalizedVars()
220
-    {
221
-        return (array) apply_filters(
222
-            'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars',
223
-            array(
224
-                'siteKey'          => $this->config->recaptcha_publickey,
225
-                'recaptcha_passed' => $this->recaptchaPassed(),
226
-                'wp_debug'         => WP_DEBUG,
227
-                'disable_submit'   => defined('EE_EVENT_QUEUE_BASE_URL'),
228
-            )
229
-        );
230
-    }
231
-
232
-
233
-    /**
234
-     * @return boolean
235
-     * @throws InvalidInterfaceException
236
-     * @throws InvalidDataTypeException
237
-     * @throws InvalidArgumentException
238
-     */
239
-    public function recaptchaPassed()
240
-    {
241
-        if ($this->recaptcha_passed !== null) {
242
-            return $this->recaptcha_passed;
243
-        }
244
-        // logged in means you have already passed a turing test of sorts
245
-        if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) {
246
-            $this->recaptcha_passed = true;
247
-            return $this->recaptcha_passed;
248
-        }
249
-        // was test already passed?
250
-        $this->recaptcha_passed = filter_var(
251
-            $this->session->get_session_data(
252
-                InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED
253
-            ),
254
-            FILTER_VALIDATE_BOOLEAN
255
-        );
256
-        return $this->recaptcha_passed;
257
-    }
258
-
259
-
260
-    /**
261
-     * @throws InvalidArgumentException
262
-     * @throws InvalidDataTypeException
263
-     * @throws InvalidInterfaceException
264
-     */
265
-    public function setSessionData()
266
-    {
267
-        $this->session->set_session_data(
268
-            array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true)
269
-        );
270
-    }
34
+	const URL_GOOGLE_RECAPTCHA_API          = 'https://www.google.com/recaptcha/api/siteverify';
35
+
36
+	const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed';
37
+
38
+	/**
39
+	 * @var EE_Registration_Config $config
40
+	 */
41
+	private $config;
42
+
43
+	/**
44
+	 * @var EE_Session $session
45
+	 */
46
+	private $session;
47
+
48
+	/**
49
+	 * @var boolean $recaptcha_passed
50
+	 */
51
+	private $recaptcha_passed;
52
+
53
+
54
+	/**
55
+	 * InvisibleRecaptcha constructor.
56
+	 *
57
+	 * @param EE_Registration_Config $registration_config
58
+	 * @param EE_Session             $session
59
+	 */
60
+	public function __construct(EE_Registration_Config $registration_config, EE_Session $session)
61
+	{
62
+		$this->config = $registration_config;
63
+		$this->session = $session;
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return boolean
69
+	 */
70
+	public function useInvisibleRecaptcha()
71
+	{
72
+		return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible';
73
+	}
74
+
75
+
76
+	/**
77
+	 * @param array $input_settings
78
+	 * @return EE_Invisible_Recaptcha_Input
79
+	 * @throws InvalidDataTypeException
80
+	 * @throws InvalidInterfaceException
81
+	 * @throws InvalidArgumentException
82
+	 * @throws DomainException
83
+	 */
84
+	public function getInput(array $input_settings = array())
85
+	{
86
+		return new EE_Invisible_Recaptcha_Input(
87
+			$input_settings,
88
+			$this->config
89
+		);
90
+	}
91
+
92
+
93
+	/**
94
+	 * @param array $input_settings
95
+	 * @return string
96
+	 * @throws EE_Error
97
+	 * @throws InvalidDataTypeException
98
+	 * @throws InvalidInterfaceException
99
+	 * @throws InvalidArgumentException
100
+	 * @throws DomainException
101
+	 */
102
+	public function getInputHtml(array $input_settings = array())
103
+	{
104
+		return $this->getInput($input_settings)->get_html_for_input();
105
+	}
106
+
107
+
108
+	/**
109
+	 * @param EE_Form_Section_Proper $form
110
+	 * @param array                  $input_settings
111
+	 * @throws EE_Error
112
+	 * @throws InvalidArgumentException
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 * @throws DomainException
116
+	 */
117
+	public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array())
118
+	{
119
+		$form->add_subsections(
120
+			array(
121
+				'espresso_recaptcha' => $this->getInput($input_settings),
122
+			),
123
+			null,
124
+			false
125
+		);
126
+	}
127
+
128
+
129
+	/**
130
+	 * @param EE_Request $request
131
+	 * @return boolean
132
+	 * @throws RuntimeException
133
+	 */
134
+	public function verifyToken(EE_Request $request)
135
+	{
136
+		static $previous_recaptcha_response = array();
137
+		$grecaptcha_response = $request->get('g-recaptcha-response');
138
+		// if this token has already been verified, then return previous response
139
+		if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
140
+			return $previous_recaptcha_response[ $grecaptcha_response ];
141
+		}
142
+		// will update to true if everything passes
143
+		$previous_recaptcha_response[ $grecaptcha_response ] = false;
144
+		$response                                            = wp_safe_remote_post(
145
+			InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
146
+			array(
147
+				'body' => array(
148
+					'secret'   => $this->config->recaptcha_privatekey,
149
+					'response' => $grecaptcha_response,
150
+					'remoteip' => $request->ip_address(),
151
+				),
152
+			)
153
+		);
154
+		if ($response instanceof WP_Error) {
155
+			$this->generateError($response->get_error_messages());
156
+			return false;
157
+		}
158
+		$results = json_decode(wp_remote_retrieve_body($response), true);
159
+		if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
160
+			$errors   = array_map(
161
+				array($this, 'getErrorCode'),
162
+				$results['error-codes']
163
+			);
164
+			if(isset($results['challenge_ts'])) {
165
+				$errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
166
+			}
167
+			$this->generateError(implode(' ', $errors));
168
+		}
169
+		$previous_recaptcha_response[ $grecaptcha_response ] = true;
170
+		add_action('shutdown', array($this, 'setSessionData'));
171
+		return true;
172
+	}
173
+
174
+
175
+	/**
176
+	 * @param string $error_response
177
+	 * @return void
178
+	 * @throws RuntimeException
179
+	 */
180
+	public function generateError($error_response = '')
181
+	{
182
+		throw new RuntimeException(
183
+			sprintf(
184
+				esc_html__(
185
+					'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.',
186
+					'event_espresso'
187
+				),
188
+				'<br />',
189
+				current_user_can('manage_options') ? $error_response : ''
190
+			)
191
+		);
192
+	}
193
+
194
+
195
+	/**
196
+	 * @param string $error_code
197
+	 * @return string
198
+	 */
199
+	public function getErrorCode(&$error_code)
200
+	{
201
+		$error_codes = array(
202
+			'missing-input-secret'   => 'The secret parameter is missing.',
203
+			'invalid-input-secret'   => 'The secret parameter is invalid or malformed.',
204
+			'missing-input-response' => 'The response parameter is missing.',
205
+			'invalid-input-response' => 'The response parameter is invalid or malformed.',
206
+			'bad-request'            => 'The request is invalid or malformed.',
207
+			'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
208
+		);
209
+		return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
210
+	}
211
+
212
+
213
+	/**
214
+	 * @return array
215
+	 * @throws InvalidInterfaceException
216
+	 * @throws InvalidDataTypeException
217
+	 * @throws InvalidArgumentException
218
+	 */
219
+	public function getLocalizedVars()
220
+	{
221
+		return (array) apply_filters(
222
+			'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars',
223
+			array(
224
+				'siteKey'          => $this->config->recaptcha_publickey,
225
+				'recaptcha_passed' => $this->recaptchaPassed(),
226
+				'wp_debug'         => WP_DEBUG,
227
+				'disable_submit'   => defined('EE_EVENT_QUEUE_BASE_URL'),
228
+			)
229
+		);
230
+	}
231
+
232
+
233
+	/**
234
+	 * @return boolean
235
+	 * @throws InvalidInterfaceException
236
+	 * @throws InvalidDataTypeException
237
+	 * @throws InvalidArgumentException
238
+	 */
239
+	public function recaptchaPassed()
240
+	{
241
+		if ($this->recaptcha_passed !== null) {
242
+			return $this->recaptcha_passed;
243
+		}
244
+		// logged in means you have already passed a turing test of sorts
245
+		if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) {
246
+			$this->recaptcha_passed = true;
247
+			return $this->recaptcha_passed;
248
+		}
249
+		// was test already passed?
250
+		$this->recaptcha_passed = filter_var(
251
+			$this->session->get_session_data(
252
+				InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED
253
+			),
254
+			FILTER_VALIDATE_BOOLEAN
255
+		);
256
+		return $this->recaptcha_passed;
257
+	}
258
+
259
+
260
+	/**
261
+	 * @throws InvalidArgumentException
262
+	 * @throws InvalidDataTypeException
263
+	 * @throws InvalidInterfaceException
264
+	 */
265
+	public function setSessionData()
266
+	{
267
+		$this->session->set_session_data(
268
+			array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true)
269
+		);
270
+	}
271 271
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -136,11 +136,11 @@  discard block
 block discarded – undo
136 136
         static $previous_recaptcha_response = array();
137 137
         $grecaptcha_response = $request->get('g-recaptcha-response');
138 138
         // if this token has already been verified, then return previous response
139
-        if (isset($previous_recaptcha_response[ $grecaptcha_response ])) {
140
-            return $previous_recaptcha_response[ $grecaptcha_response ];
139
+        if (isset($previous_recaptcha_response[$grecaptcha_response])) {
140
+            return $previous_recaptcha_response[$grecaptcha_response];
141 141
         }
142 142
         // will update to true if everything passes
143
-        $previous_recaptcha_response[ $grecaptcha_response ] = false;
143
+        $previous_recaptcha_response[$grecaptcha_response] = false;
144 144
         $response                                            = wp_safe_remote_post(
145 145
             InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API,
146 146
             array(
@@ -157,16 +157,16 @@  discard block
 block discarded – undo
157 157
         }
158 158
         $results = json_decode(wp_remote_retrieve_body($response), true);
159 159
         if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) {
160
-            $errors   = array_map(
160
+            $errors = array_map(
161 161
                 array($this, 'getErrorCode'),
162 162
                 $results['error-codes']
163 163
             );
164
-            if(isset($results['challenge_ts'])) {
165
-                $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.';
164
+            if (isset($results['challenge_ts'])) {
165
+                $errors[] = 'challenge timestamp: '.$results['challenge_ts'].'.';
166 166
             }
167 167
             $this->generateError(implode(' ', $errors));
168 168
         }
169
-        $previous_recaptcha_response[ $grecaptcha_response ] = true;
169
+        $previous_recaptcha_response[$grecaptcha_response] = true;
170 170
         add_action('shutdown', array($this, 'setSessionData'));
171 171
         return true;
172 172
     }
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
             'bad-request'            => 'The request is invalid or malformed.',
207 207
             'timeout-or-duplicate'   => 'The request took too long to be sent or was a duplicate of a previous request.',
208 208
         );
209
-        return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : '';
209
+        return isset($error_codes[$error_code]) ? $error_codes[$error_code] : '';
210 210
     }
211 211
 
212 212
 
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha_invisible/RecaptchaFactory.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -23,35 +23,35 @@
 block discarded – undo
23 23
 class RecaptchaFactory implements FactoryInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @param array $arguments
28
-     * @return InvisibleRecaptcha
29
-     * @throws InvalidDataTypeException
30
-     * @throws InvalidInterfaceException
31
-     * @throws InvalidArgumentException
32
-     */
33
-    public static function create($arguments = array())
34
-    {
35
-        return LoaderFactory::getLoader()->getShared(
36
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha',
37
-            $arguments
38
-        );
39
-    }
40
-
41
-
42
-
43
-    /**
44
-     * @param array $arguments
45
-     * @return RecaptchaAdminSettings
46
-     * @throws InvalidDataTypeException
47
-     * @throws InvalidInterfaceException
48
-     * @throws InvalidArgumentException
49
-     */
50
-    public static function getAdminModule($arguments = array())
51
-    {
52
-        return LoaderFactory::getLoader()->getShared(
53
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings',
54
-            $arguments
55
-        );
56
-    }
26
+	/**
27
+	 * @param array $arguments
28
+	 * @return InvisibleRecaptcha
29
+	 * @throws InvalidDataTypeException
30
+	 * @throws InvalidInterfaceException
31
+	 * @throws InvalidArgumentException
32
+	 */
33
+	public static function create($arguments = array())
34
+	{
35
+		return LoaderFactory::getLoader()->getShared(
36
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha',
37
+			$arguments
38
+		);
39
+	}
40
+
41
+
42
+
43
+	/**
44
+	 * @param array $arguments
45
+	 * @return RecaptchaAdminSettings
46
+	 * @throws InvalidDataTypeException
47
+	 * @throws InvalidInterfaceException
48
+	 * @throws InvalidArgumentException
49
+	 */
50
+	public static function getAdminModule($arguments = array())
51
+	{
52
+		return LoaderFactory::getLoader()->getShared(
53
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings',
54
+			$arguments
55
+		);
56
+	}
57 57
 }
Please login to merge, or discard this patch.
core/services/licensing/LicenseService.php 2 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -14,94 +14,94 @@
 block discarded – undo
14 14
  */
15 15
 class LicenseService
16 16
 {
17
-    /**
18
-     * @var Config
19
-     */
20
-    private $config;
17
+	/**
18
+	 * @var Config
19
+	 */
20
+	private $config;
21 21
 
22 22
 
23
-    /**
24
-     * @var Stats
25
-     */
26
-    private $stats_collection;
23
+	/**
24
+	 * @var Stats
25
+	 */
26
+	private $stats_collection;
27 27
 
28
-    public function __construct(Stats $stats_collection, Config $config)
29
-    {
30
-        $this->config = $config;
31
-        $this->stats_collection = $stats_collection;
32
-        $this->loadPueClient();
33
-    }
28
+	public function __construct(Stats $stats_collection, Config $config)
29
+	{
30
+		$this->config = $config;
31
+		$this->stats_collection = $stats_collection;
32
+		$this->loadPueClient();
33
+	}
34 34
 
35
-    private function loadPueClient()
36
-    {
37
-        // PUE Auto Upgrades stuff
38
-        if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { //include the file
39
-            require_once(EE_THIRD_PARTY . 'pue/pue-client.php');
35
+	private function loadPueClient()
36
+	{
37
+		// PUE Auto Upgrades stuff
38
+		if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { //include the file
39
+			require_once(EE_THIRD_PARTY . 'pue/pue-client.php');
40 40
 
41
-            //$options needs to be an array with the included keys as listed.
42
-            $options = array(
43
-                //	'optionName' => '', //(optional) - used as the reference for saving update information in the
44
-                // clients options table.  Will be automatically set if left blank.
45
-                'apikey'                => $this->config->siteLicenseKey(),
46
-                //(required), you will need to obtain the apikey that the client gets from your site and
47
-                // then saves in their sites options table (see 'getting an api-key' below)
48
-                'lang_domain'           => $this->config->i18nDomain(),
49
-                //(optional) - put here whatever reference you are using for the localization of your plugin (if it's
50
-                // localized).  That way strings in this file will be included in the translation for your plugin.
51
-                'checkPeriod'           => $this->config->checkPeriod(),
52
-                //(optional) - use this parameter to indicate how often you want the client's install to ping your
53
-                // server for update checks.  The integer indicates hours.  If you don't include this parameter it will
54
-                // default to 12 hours.
55
-                'option_key'            => $this->config->optionKey(),
56
-                //this is what is used to reference the api_key in your plugin options.  PUE uses this to trigger
57
-                // updating your information message whenever this option_key is modified.
58
-                'options_page_slug'     => $this->config->optionsPageSlug(),
59
-                'plugin_basename'       => EE_PLUGIN_BASENAME,
60
-                'use_wp_update'         => true,
61
-                //if TRUE then you want FREE versions of the plugin to be updated from WP
62
-                'extra_stats'           => $this->stats_collection->statsCallback(),
63
-                'turn_on_notices_saved' => true,
64
-            );
65
-            //initiate the class and start the plugin update engine!
66
-            new PluginUpdateEngineChecker(
67
-                $this->config->hostServerUrl(),
68
-                $this->config->pluginSlug(),
69
-                $options
70
-            );
71
-        }
72
-    }
41
+			//$options needs to be an array with the included keys as listed.
42
+			$options = array(
43
+				//	'optionName' => '', //(optional) - used as the reference for saving update information in the
44
+				// clients options table.  Will be automatically set if left blank.
45
+				'apikey'                => $this->config->siteLicenseKey(),
46
+				//(required), you will need to obtain the apikey that the client gets from your site and
47
+				// then saves in their sites options table (see 'getting an api-key' below)
48
+				'lang_domain'           => $this->config->i18nDomain(),
49
+				//(optional) - put here whatever reference you are using for the localization of your plugin (if it's
50
+				// localized).  That way strings in this file will be included in the translation for your plugin.
51
+				'checkPeriod'           => $this->config->checkPeriod(),
52
+				//(optional) - use this parameter to indicate how often you want the client's install to ping your
53
+				// server for update checks.  The integer indicates hours.  If you don't include this parameter it will
54
+				// default to 12 hours.
55
+				'option_key'            => $this->config->optionKey(),
56
+				//this is what is used to reference the api_key in your plugin options.  PUE uses this to trigger
57
+				// updating your information message whenever this option_key is modified.
58
+				'options_page_slug'     => $this->config->optionsPageSlug(),
59
+				'plugin_basename'       => EE_PLUGIN_BASENAME,
60
+				'use_wp_update'         => true,
61
+				//if TRUE then you want FREE versions of the plugin to be updated from WP
62
+				'extra_stats'           => $this->stats_collection->statsCallback(),
63
+				'turn_on_notices_saved' => true,
64
+			);
65
+			//initiate the class and start the plugin update engine!
66
+			new PluginUpdateEngineChecker(
67
+				$this->config->hostServerUrl(),
68
+				$this->config->pluginSlug(),
69
+				$options
70
+			);
71
+		}
72
+	}
73 73
 
74 74
 
75
-    /**
76
-     * This is a handy helper method for retrieving whether there is an update available for the given plugin.
77
-     *
78
-     * @param  string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to
79
-     *                          identify plugins. Defaults to core update
80
-     * @return boolean           True if update available, false if not.
81
-     */
82
-    public static function isUpdateAvailable($basename = '')
83
-    {
84
-        $basename = ! empty($basename) ? $basename : EE_PLUGIN_BASENAME;
75
+	/**
76
+	 * This is a handy helper method for retrieving whether there is an update available for the given plugin.
77
+	 *
78
+	 * @param  string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to
79
+	 *                          identify plugins. Defaults to core update
80
+	 * @return boolean           True if update available, false if not.
81
+	 */
82
+	public static function isUpdateAvailable($basename = '')
83
+	{
84
+		$basename = ! empty($basename) ? $basename : EE_PLUGIN_BASENAME;
85 85
 
86
-        $update = false;
86
+		$update = false;
87 87
 
88
-        // should take "event-espresso-core/espresso.php" and change to "/event-espresso-core"
89
-        $folder = DS . dirname($basename);
88
+		// should take "event-espresso-core/espresso.php" and change to "/event-espresso-core"
89
+		$folder = DS . dirname($basename);
90 90
 
91
-        $plugins = get_plugins($folder);
92
-        $current = get_site_transient('update_plugins');
91
+		$plugins = get_plugins($folder);
92
+		$current = get_site_transient('update_plugins');
93 93
 
94
-        foreach ((array)$plugins as $plugin_file => $plugin_data) {
95
-            if (isset($current->response['plugin_file'])) {
96
-                $update = true;
97
-            }
98
-        }
94
+		foreach ((array)$plugins as $plugin_file => $plugin_data) {
95
+			if (isset($current->response['plugin_file'])) {
96
+				$update = true;
97
+			}
98
+		}
99 99
 
100
-        //it's possible that there is an update but an invalid site-license-key is in use
101
-        if (get_site_option('pue_json_error_' . $basename)) {
102
-            $update = true;
103
-        }
100
+		//it's possible that there is an update but an invalid site-license-key is in use
101
+		if (get_site_option('pue_json_error_' . $basename)) {
102
+			$update = true;
103
+		}
104 104
 
105
-        return $update;
106
-    }
105
+		return $update;
106
+	}
107 107
 }
108 108
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
     private function loadPueClient()
36 36
     {
37 37
         // PUE Auto Upgrades stuff
38
-        if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { //include the file
39
-            require_once(EE_THIRD_PARTY . 'pue/pue-client.php');
38
+        if (is_readable(EE_THIRD_PARTY.'pue/pue-client.php')) { //include the file
39
+            require_once(EE_THIRD_PARTY.'pue/pue-client.php');
40 40
 
41 41
             //$options needs to be an array with the included keys as listed.
42 42
             $options = array(
@@ -86,19 +86,19 @@  discard block
 block discarded – undo
86 86
         $update = false;
87 87
 
88 88
         // should take "event-espresso-core/espresso.php" and change to "/event-espresso-core"
89
-        $folder = DS . dirname($basename);
89
+        $folder = DS.dirname($basename);
90 90
 
91 91
         $plugins = get_plugins($folder);
92 92
         $current = get_site_transient('update_plugins');
93 93
 
94
-        foreach ((array)$plugins as $plugin_file => $plugin_data) {
94
+        foreach ((array) $plugins as $plugin_file => $plugin_data) {
95 95
             if (isset($current->response['plugin_file'])) {
96 96
                 $update = true;
97 97
             }
98 98
         }
99 99
 
100 100
         //it's possible that there is an update but an invalid site-license-key is in use
101
-        if (get_site_option('pue_json_error_' . $basename)) {
101
+        if (get_site_option('pue_json_error_'.$basename)) {
102 102
             $update = true;
103 103
         }
104 104
 
Please login to merge, or discard this patch.
core/domain/services/pue/StatsGatherer.php 2 patches
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -16,284 +16,284 @@
 block discarded – undo
16 16
 class StatsGatherer
17 17
 {
18 18
 
19
-    const COUNT_ALL_EVENTS = 'event';
20
-    const COUNT_ACTIVE_EVENTS = 'active_event';
21
-    const COUNT_DATETIMES = 'datetime';
22
-    const COUNT_TICKETS = 'ticket';
23
-    const COUNT_DATETIMES_SOLD = 'datetime_sold';
24
-    const COUNT_TICKETS_FREE = 'free_ticket';
25
-    const COUNT_TICKETS_PAID = 'paid_ticket';
26
-    const COUNT_TICKETS_SOLD = 'ticket_sold';
27
-    const COUNT_REGISTRATIONS_APPROVED = 'registrations_approved';
28
-    const COUNT_REGISTRATIONS_NOT_APPROVED = 'registrations_not_approved';
29
-    const COUNT_REGISTRATIONS_PENDING = 'registrations_pending';
30
-    const COUNT_REGISTRATIONS_INCOMPLETE = 'registrations_incomplete';
31
-    const COUNT_REGISTRATIONS_ALL = 'registrations_all';
32
-    const COUNT_REGISTRATIONS_CANCELLED = 'registrations_cancelled';
33
-    const COUNT_REGISTRATIONS_DECLINED = 'registrations_declined';
34
-    const SUM_TRANSACTIONS_COMPLETE_TOTAL = 'transactions_complete_total_sum';
35
-    const SUM_TRANSACTIONS_ALL_PAID = 'transactions_all_paid';
36
-    const INFO_SITE_CURRENCY = 'site_currency';
19
+	const COUNT_ALL_EVENTS = 'event';
20
+	const COUNT_ACTIVE_EVENTS = 'active_event';
21
+	const COUNT_DATETIMES = 'datetime';
22
+	const COUNT_TICKETS = 'ticket';
23
+	const COUNT_DATETIMES_SOLD = 'datetime_sold';
24
+	const COUNT_TICKETS_FREE = 'free_ticket';
25
+	const COUNT_TICKETS_PAID = 'paid_ticket';
26
+	const COUNT_TICKETS_SOLD = 'ticket_sold';
27
+	const COUNT_REGISTRATIONS_APPROVED = 'registrations_approved';
28
+	const COUNT_REGISTRATIONS_NOT_APPROVED = 'registrations_not_approved';
29
+	const COUNT_REGISTRATIONS_PENDING = 'registrations_pending';
30
+	const COUNT_REGISTRATIONS_INCOMPLETE = 'registrations_incomplete';
31
+	const COUNT_REGISTRATIONS_ALL = 'registrations_all';
32
+	const COUNT_REGISTRATIONS_CANCELLED = 'registrations_cancelled';
33
+	const COUNT_REGISTRATIONS_DECLINED = 'registrations_declined';
34
+	const SUM_TRANSACTIONS_COMPLETE_TOTAL = 'transactions_complete_total_sum';
35
+	const SUM_TRANSACTIONS_ALL_PAID = 'transactions_all_paid';
36
+	const INFO_SITE_CURRENCY = 'site_currency';
37 37
 
38 38
 
39
-    /**
40
-     * @var EEM_Payment_Method
41
-     */
42
-    private $payment_method_model;
39
+	/**
40
+	 * @var EEM_Payment_Method
41
+	 */
42
+	private $payment_method_model;
43 43
 
44 44
 
45
-    /**
46
-     * @var EEM_Event
47
-     */
48
-    private $event_model;
45
+	/**
46
+	 * @var EEM_Event
47
+	 */
48
+	private $event_model;
49 49
 
50
-    /**
51
-     * @var EEM_Datetime
52
-     */
53
-    private $datetime_model;
50
+	/**
51
+	 * @var EEM_Datetime
52
+	 */
53
+	private $datetime_model;
54 54
 
55 55
 
56
-    /**
57
-     * @var EEM_Ticket
58
-     */
59
-    private $ticket_model;
56
+	/**
57
+	 * @var EEM_Ticket
58
+	 */
59
+	private $ticket_model;
60 60
 
61 61
 
62
-    /**
63
-     * @var EEM_Registration
64
-     */
65
-    private $registration_model;
62
+	/**
63
+	 * @var EEM_Registration
64
+	 */
65
+	private $registration_model;
66 66
 
67 67
 
68
-    /**
69
-     * @var EEM_Transaction
70
-     */
71
-    private $transaction_model;
68
+	/**
69
+	 * @var EEM_Transaction
70
+	 */
71
+	private $transaction_model;
72 72
 
73 73
 
74
-    /**
75
-     * @var EE_Config
76
-     */
77
-    private $config;
74
+	/**
75
+	 * @var EE_Config
76
+	 */
77
+	private $config;
78 78
 
79 79
 
80
-    /**
81
-     * StatsGatherer constructor.
82
-     *
83
-     * @param EEM_Payment_Method $payment_method_model
84
-     * @param EEM_Event          $event_model
85
-     * @param EEM_Datetime       $datetime_model
86
-     * @param EEM_Ticket         $ticket_model
87
-     * @param EEM_Registration   $registration_model
88
-     * @param EEM_Transaction    $transaction_model
89
-     * @param EE_Config          $config
90
-     */
91
-    public function __construct(
92
-        EEM_Payment_Method $payment_method_model,
93
-        EEM_Event $event_model,
94
-        EEM_Datetime $datetime_model,
95
-        EEM_Ticket $ticket_model,
96
-        EEM_Registration $registration_model,
97
-        EEM_Transaction $transaction_model,
98
-        EE_Config $config
99
-    ) {
100
-        $this->payment_method_model = $payment_method_model;
101
-        $this->event_model = $event_model;
102
-        $this->datetime_model = $datetime_model;
103
-        $this->ticket_model = $ticket_model;
104
-        $this->registration_model = $registration_model;
105
-        $this->transaction_model = $transaction_model;
106
-        $this->config = $config;
107
-    }
80
+	/**
81
+	 * StatsGatherer constructor.
82
+	 *
83
+	 * @param EEM_Payment_Method $payment_method_model
84
+	 * @param EEM_Event          $event_model
85
+	 * @param EEM_Datetime       $datetime_model
86
+	 * @param EEM_Ticket         $ticket_model
87
+	 * @param EEM_Registration   $registration_model
88
+	 * @param EEM_Transaction    $transaction_model
89
+	 * @param EE_Config          $config
90
+	 */
91
+	public function __construct(
92
+		EEM_Payment_Method $payment_method_model,
93
+		EEM_Event $event_model,
94
+		EEM_Datetime $datetime_model,
95
+		EEM_Ticket $ticket_model,
96
+		EEM_Registration $registration_model,
97
+		EEM_Transaction $transaction_model,
98
+		EE_Config $config
99
+	) {
100
+		$this->payment_method_model = $payment_method_model;
101
+		$this->event_model = $event_model;
102
+		$this->datetime_model = $datetime_model;
103
+		$this->ticket_model = $ticket_model;
104
+		$this->registration_model = $registration_model;
105
+		$this->transaction_model = $transaction_model;
106
+		$this->config = $config;
107
+	}
108 108
 
109 109
 
110
-    /**
111
-     * Return the stats array for PUE UXIP stats.
112
-     * @return array
113
-     */
114
-    public function stats()
115
-    {
116
-        $stats = $this->paymentMethodStats();
117
-        //a-ok so let's setup our stats.
118
-        $stats = array_merge($stats, array(
119
-            'is_multisite' => is_multisite() && is_main_site(),
120
-            'active_theme' => $this->getActiveThemeStat(),
121
-            'ee4_all_events_count' => $this->getCountFor(self::COUNT_ALL_EVENTS),
122
-            'ee4_active_events_count' => $this->getCountFor(self::COUNT_ACTIVE_EVENTS),
123
-            'all_dtts_count' => $this->getCountFor(self::COUNT_DATETIMES),
124
-            'dtt_sold' => $this->getCountFor(self::COUNT_DATETIMES_SOLD),
125
-            'all_tkt_count' => $this->getCountFor(self::COUNT_TICKETS),
126
-            'free_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_FREE),
127
-            'paid_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_PAID),
128
-            'tkt_sold' => $this->getCountFor(self::COUNT_TICKETS_SOLD),
129
-            'approve_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_APPROVED),
130
-            'pending_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_PENDING),
131
-            'not_approved_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_NOT_APPROVED),
132
-            'incomplete_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_INCOMPLETE),
133
-            'cancelled_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_CANCELLED),
134
-            'declined_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_DECLINED),
135
-            'all_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_ALL),
136
-            'completed_transaction_total_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_COMPLETE_TOTAL),
137
-            'all_transaction_paid_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_ALL_PAID),
138
-            self::INFO_SITE_CURRENCY => $this->config->currency instanceof EE_Currency_Config
139
-                ? $this->config->currency->code
140
-                : 'unknown',
141
-            'phpversion' => implode('.', array(PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION))
142
-        ));
143
-        //remove any values that equal null.  This ensures any stats that weren't retrieved successfully are excluded.
144
-        return array_filter($stats, function ($value) {
145
-            return $value !== null;
146
-        });
147
-    }
110
+	/**
111
+	 * Return the stats array for PUE UXIP stats.
112
+	 * @return array
113
+	 */
114
+	public function stats()
115
+	{
116
+		$stats = $this->paymentMethodStats();
117
+		//a-ok so let's setup our stats.
118
+		$stats = array_merge($stats, array(
119
+			'is_multisite' => is_multisite() && is_main_site(),
120
+			'active_theme' => $this->getActiveThemeStat(),
121
+			'ee4_all_events_count' => $this->getCountFor(self::COUNT_ALL_EVENTS),
122
+			'ee4_active_events_count' => $this->getCountFor(self::COUNT_ACTIVE_EVENTS),
123
+			'all_dtts_count' => $this->getCountFor(self::COUNT_DATETIMES),
124
+			'dtt_sold' => $this->getCountFor(self::COUNT_DATETIMES_SOLD),
125
+			'all_tkt_count' => $this->getCountFor(self::COUNT_TICKETS),
126
+			'free_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_FREE),
127
+			'paid_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_PAID),
128
+			'tkt_sold' => $this->getCountFor(self::COUNT_TICKETS_SOLD),
129
+			'approve_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_APPROVED),
130
+			'pending_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_PENDING),
131
+			'not_approved_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_NOT_APPROVED),
132
+			'incomplete_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_INCOMPLETE),
133
+			'cancelled_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_CANCELLED),
134
+			'declined_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_DECLINED),
135
+			'all_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_ALL),
136
+			'completed_transaction_total_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_COMPLETE_TOTAL),
137
+			'all_transaction_paid_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_ALL_PAID),
138
+			self::INFO_SITE_CURRENCY => $this->config->currency instanceof EE_Currency_Config
139
+				? $this->config->currency->code
140
+				: 'unknown',
141
+			'phpversion' => implode('.', array(PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION))
142
+		));
143
+		//remove any values that equal null.  This ensures any stats that weren't retrieved successfully are excluded.
144
+		return array_filter($stats, function ($value) {
145
+			return $value !== null;
146
+		});
147
+	}
148 148
 
149
-    /**
150
-     * @param string $which enum (@see constants prefixed with COUNT)
151
-     * @return int|null
152
-     */
153
-    private function getCountFor($which)
154
-    {
155
-        try {
156
-            switch ($which) {
157
-                case self::COUNT_ALL_EVENTS:
158
-                    $count = $this->event_model->count();
159
-                    break;
160
-                case self::COUNT_TICKETS:
161
-                    $count = $this->ticket_model->count();
162
-                    break;
163
-                case self::COUNT_DATETIMES:
164
-                    $count = $this->datetime_model->count();
165
-                    break;
166
-                case self::COUNT_ACTIVE_EVENTS:
167
-                    $count = $this->event_model->get_active_events(array(), true);
168
-                    break;
169
-                case self::COUNT_DATETIMES_SOLD:
170
-                    $count = $this->datetime_model->sum(array(), 'DTT_sold');
171
-                    break;
172
-                case self::COUNT_TICKETS_FREE:
173
-                    $count = $this->ticket_model->count(array(array(
174
-                        'TKT_price' => 0
175
-                    )));
176
-                    break;
177
-                case self::COUNT_TICKETS_PAID:
178
-                    $count = $this->ticket_model->count(array(array(
179
-                        'TKT_price' => array('>', 0)
180
-                    )));
181
-                    break;
182
-                case self::COUNT_TICKETS_SOLD:
183
-                    $count = $this->ticket_model->sum(array(), 'TKT_sold');
184
-                    break;
185
-                case self::COUNT_REGISTRATIONS_ALL:
186
-                    $count = $this->registration_model->count();
187
-                    break;
188
-                case self::COUNT_REGISTRATIONS_CANCELLED:
189
-                    $count = $this->registration_model->count(
190
-                        array(
191
-                            array(
192
-                                'STS_ID' => EEM_Registration::status_id_cancelled
193
-                            )
194
-                        )
195
-                    );
196
-                    break;
197
-                case self::COUNT_REGISTRATIONS_INCOMPLETE:
198
-                    $count = $this->registration_model->count(
199
-                        array(
200
-                            array(
201
-                                'STS_ID' => EEM_Registration::status_id_incomplete
202
-                            )
203
-                        )
204
-                    );
205
-                    break;
206
-                case self::COUNT_REGISTRATIONS_NOT_APPROVED:
207
-                    $count = $this->registration_model->count(
208
-                        array(
209
-                            array(
210
-                                'STS_ID' => EEM_Registration::status_id_not_approved
211
-                            )
212
-                        )
213
-                    );
214
-                    break;
215
-                case self::COUNT_REGISTRATIONS_DECLINED:
216
-                    $count = $this->registration_model->count(
217
-                        array(
218
-                            array(
219
-                                'STS_ID' => EEM_Registration::status_id_declined
220
-                            )
221
-                        )
222
-                    );
223
-                    break;
224
-                case self::COUNT_REGISTRATIONS_PENDING:
225
-                    $count = $this->registration_model->count(
226
-                        array(
227
-                            array(
228
-                                'STS_ID' => EEM_Registration::status_id_pending_payment
229
-                            )
230
-                        )
231
-                    );
232
-                    break;
233
-                case self::COUNT_REGISTRATIONS_APPROVED:
234
-                    $count = $this->registration_model->count(
235
-                        array(
236
-                            array(
237
-                                'STS_ID' => EEM_Registration::status_id_approved
238
-                            )
239
-                        )
240
-                    );
241
-                    break;
242
-                case self::SUM_TRANSACTIONS_COMPLETE_TOTAL:
243
-                    $count = $this->transaction_model->sum(
244
-                        array(
245
-                            array(
246
-                                'STS_ID' => EEM_Transaction::complete_status_code
247
-                            )
248
-                        ),
249
-                        'TXN_total'
250
-                    );
251
-                    break;
252
-                case self::SUM_TRANSACTIONS_ALL_PAID:
253
-                    $count = $this->transaction_model->sum(
254
-                        array(),
255
-                        'TXN_paid'
256
-                    );
257
-                    break;
258
-                default:
259
-                    $count = null;
260
-                    break;
261
-            }
262
-        } catch (Exception $e) {
263
-            $count = null;
264
-        }
265
-        return $count;
266
-    }
149
+	/**
150
+	 * @param string $which enum (@see constants prefixed with COUNT)
151
+	 * @return int|null
152
+	 */
153
+	private function getCountFor($which)
154
+	{
155
+		try {
156
+			switch ($which) {
157
+				case self::COUNT_ALL_EVENTS:
158
+					$count = $this->event_model->count();
159
+					break;
160
+				case self::COUNT_TICKETS:
161
+					$count = $this->ticket_model->count();
162
+					break;
163
+				case self::COUNT_DATETIMES:
164
+					$count = $this->datetime_model->count();
165
+					break;
166
+				case self::COUNT_ACTIVE_EVENTS:
167
+					$count = $this->event_model->get_active_events(array(), true);
168
+					break;
169
+				case self::COUNT_DATETIMES_SOLD:
170
+					$count = $this->datetime_model->sum(array(), 'DTT_sold');
171
+					break;
172
+				case self::COUNT_TICKETS_FREE:
173
+					$count = $this->ticket_model->count(array(array(
174
+						'TKT_price' => 0
175
+					)));
176
+					break;
177
+				case self::COUNT_TICKETS_PAID:
178
+					$count = $this->ticket_model->count(array(array(
179
+						'TKT_price' => array('>', 0)
180
+					)));
181
+					break;
182
+				case self::COUNT_TICKETS_SOLD:
183
+					$count = $this->ticket_model->sum(array(), 'TKT_sold');
184
+					break;
185
+				case self::COUNT_REGISTRATIONS_ALL:
186
+					$count = $this->registration_model->count();
187
+					break;
188
+				case self::COUNT_REGISTRATIONS_CANCELLED:
189
+					$count = $this->registration_model->count(
190
+						array(
191
+							array(
192
+								'STS_ID' => EEM_Registration::status_id_cancelled
193
+							)
194
+						)
195
+					);
196
+					break;
197
+				case self::COUNT_REGISTRATIONS_INCOMPLETE:
198
+					$count = $this->registration_model->count(
199
+						array(
200
+							array(
201
+								'STS_ID' => EEM_Registration::status_id_incomplete
202
+							)
203
+						)
204
+					);
205
+					break;
206
+				case self::COUNT_REGISTRATIONS_NOT_APPROVED:
207
+					$count = $this->registration_model->count(
208
+						array(
209
+							array(
210
+								'STS_ID' => EEM_Registration::status_id_not_approved
211
+							)
212
+						)
213
+					);
214
+					break;
215
+				case self::COUNT_REGISTRATIONS_DECLINED:
216
+					$count = $this->registration_model->count(
217
+						array(
218
+							array(
219
+								'STS_ID' => EEM_Registration::status_id_declined
220
+							)
221
+						)
222
+					);
223
+					break;
224
+				case self::COUNT_REGISTRATIONS_PENDING:
225
+					$count = $this->registration_model->count(
226
+						array(
227
+							array(
228
+								'STS_ID' => EEM_Registration::status_id_pending_payment
229
+							)
230
+						)
231
+					);
232
+					break;
233
+				case self::COUNT_REGISTRATIONS_APPROVED:
234
+					$count = $this->registration_model->count(
235
+						array(
236
+							array(
237
+								'STS_ID' => EEM_Registration::status_id_approved
238
+							)
239
+						)
240
+					);
241
+					break;
242
+				case self::SUM_TRANSACTIONS_COMPLETE_TOTAL:
243
+					$count = $this->transaction_model->sum(
244
+						array(
245
+							array(
246
+								'STS_ID' => EEM_Transaction::complete_status_code
247
+							)
248
+						),
249
+						'TXN_total'
250
+					);
251
+					break;
252
+				case self::SUM_TRANSACTIONS_ALL_PAID:
253
+					$count = $this->transaction_model->sum(
254
+						array(),
255
+						'TXN_paid'
256
+					);
257
+					break;
258
+				default:
259
+					$count = null;
260
+					break;
261
+			}
262
+		} catch (Exception $e) {
263
+			$count = null;
264
+		}
265
+		return $count;
266
+	}
267 267
 
268
-    /**
269
-     * Return the active theme.
270
-     * @return false|string
271
-     */
272
-    private function getActiveThemeStat()
273
-    {
274
-        $theme = wp_get_theme();
275
-        return $theme->get('Name');
276
-    }
268
+	/**
269
+	 * Return the active theme.
270
+	 * @return false|string
271
+	 */
272
+	private function getActiveThemeStat()
273
+	{
274
+		$theme = wp_get_theme();
275
+		return $theme->get('Name');
276
+	}
277 277
 
278
-    /**
279
-     * @return array
280
-     */
281
-    private function paymentMethodStats()
282
-    {
283
-        $payment_method_stats = array();
284
-        try {
285
-            $active_payment_methods = $this->payment_method_model->get_all_active(
286
-                null,
287
-                array('group_by' => 'PMD_type')
288
-            );
289
-            if ($active_payment_methods) {
290
-                foreach ($active_payment_methods as $payment_method) {
291
-                    $payment_method_stats[$payment_method->name() . '_active_payment_method'] = 1;
292
-                }
293
-            }
294
-        } catch (Exception $e) {
295
-            //do nothing just prevents fatals.
296
-        }
297
-        return $payment_method_stats;
298
-    }
278
+	/**
279
+	 * @return array
280
+	 */
281
+	private function paymentMethodStats()
282
+	{
283
+		$payment_method_stats = array();
284
+		try {
285
+			$active_payment_methods = $this->payment_method_model->get_all_active(
286
+				null,
287
+				array('group_by' => 'PMD_type')
288
+			);
289
+			if ($active_payment_methods) {
290
+				foreach ($active_payment_methods as $payment_method) {
291
+					$payment_method_stats[$payment_method->name() . '_active_payment_method'] = 1;
292
+				}
293
+			}
294
+		} catch (Exception $e) {
295
+			//do nothing just prevents fatals.
296
+		}
297
+		return $payment_method_stats;
298
+	}
299 299
 }
300 300
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
             'phpversion' => implode('.', array(PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION))
142 142
         ));
143 143
         //remove any values that equal null.  This ensures any stats that weren't retrieved successfully are excluded.
144
-        return array_filter($stats, function ($value) {
144
+        return array_filter($stats, function($value) {
145 145
             return $value !== null;
146 146
         });
147 147
     }
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
             );
289 289
             if ($active_payment_methods) {
290 290
                 foreach ($active_payment_methods as $payment_method) {
291
-                    $payment_method_stats[$payment_method->name() . '_active_payment_method'] = 1;
291
+                    $payment_method_stats[$payment_method->name().'_active_payment_method'] = 1;
292 292
                 }
293 293
             }
294 294
         } catch (Exception $e) {
Please login to merge, or discard this patch.
core/domain/services/pue/Config.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -17,135 +17,135 @@
 block discarded – undo
17 17
  */
18 18
 class Config
19 19
 {
20
-    /**
21
-     * @var EE_Network_Config
22
-     */
23
-    private $network_config;
20
+	/**
21
+	 * @var EE_Network_Config
22
+	 */
23
+	private $network_config;
24 24
 
25 25
 
26
-    /**
27
-     * @var EE_Config
28
-     */
29
-    private $ee_config;
26
+	/**
27
+	 * @var EE_Config
28
+	 */
29
+	private $ee_config;
30 30
 
31 31
 
32 32
 
33
-    public function __construct(EE_Network_Config $network_config, EE_Config $ee_config)
34
-    {
35
-        $this->network_config = $network_config;
36
-        $this->ee_config = $ee_config;
37
-    }
33
+	public function __construct(EE_Network_Config $network_config, EE_Config $ee_config)
34
+	{
35
+		$this->network_config = $network_config;
36
+		$this->ee_config = $ee_config;
37
+	}
38 38
 
39 39
 
40
-    /**
41
-     * Get the site license key for the site.
42
-     */
43
-    public function siteLicenseKey()
44
-    {
45
-        return $this->network_config->core->site_license_key;
46
-    }
40
+	/**
41
+	 * Get the site license key for the site.
42
+	 */
43
+	public function siteLicenseKey()
44
+	{
45
+		return $this->network_config->core->site_license_key;
46
+	}
47 47
 
48 48
 
49 49
 
50
-    public function i18nDomain()
51
-    {
52
-        return 'event_espresso';
53
-    }
50
+	public function i18nDomain()
51
+	{
52
+		return 'event_espresso';
53
+	}
54 54
 
55 55
 
56 56
 
57
-    public function checkPeriod()
58
-    {
59
-        return 24;
60
-    }
57
+	public function checkPeriod()
58
+	{
59
+		return 24;
60
+	}
61 61
 
62 62
 
63 63
 
64
-    public function optionKey()
65
-    {
66
-        return 'site_license_key';
67
-    }
64
+	public function optionKey()
65
+	{
66
+		return 'site_license_key';
67
+	}
68 68
 
69 69
 
70 70
 
71
-    public function optionsPageSlug()
72
-    {
73
-        return 'espresso_general_settings';
74
-    }
71
+	public function optionsPageSlug()
72
+	{
73
+		return 'espresso_general_settings';
74
+	}
75 75
 
76 76
 
77
-    public function hostServerUrl()
78
-    {
79
-        return defined('PUE_UPDATES_ENDPOINT')
80
-            ? PUE_UPDATES_ENDPOINT
81
-            : 'https://eventespresso.com';
82
-    }
77
+	public function hostServerUrl()
78
+	{
79
+		return defined('PUE_UPDATES_ENDPOINT')
80
+			? PUE_UPDATES_ENDPOINT
81
+			: 'https://eventespresso.com';
82
+	}
83 83
 
84 84
 
85
-    public function pluginSlug()
86
-    {
87
-        //Note: PUE uses a simple preg_match to determine what type is currently installed based on version number.
88
-        //  So it's important that you use a key for the version type that is unique and not found in another key.
89
-        //For example:
90
-        //$plugin_slug['premium']['p'] = 'some-premium-slug';
91
-        //$plugin_slug['prerelease']['pr'] = 'some-pre-release-slug';
92
-        //The above would not work because "p" is found in both keys for the version type. ( i.e 1.0.p vs 1.0.pr )
93
-        // so doing something like:
94
-        //$plugin_slug['premium']['p'] = 'some-premium-slug';
95
-        //$plugin_slug['prerelease']['b'] = 'some-pre-release-slug';
96
-        //..WOULD work!
97
-        return array(
98
-            'free'       => array('decaf' => 'event-espresso-core-decaf'),
99
-            'premium'    => array('p' => 'event-espresso-core-reg'),
100
-            'prerelease' => array('beta' => 'event-espresso-core-pr'),
101
-        );
102
-    }
85
+	public function pluginSlug()
86
+	{
87
+		//Note: PUE uses a simple preg_match to determine what type is currently installed based on version number.
88
+		//  So it's important that you use a key for the version type that is unique and not found in another key.
89
+		//For example:
90
+		//$plugin_slug['premium']['p'] = 'some-premium-slug';
91
+		//$plugin_slug['prerelease']['pr'] = 'some-pre-release-slug';
92
+		//The above would not work because "p" is found in both keys for the version type. ( i.e 1.0.p vs 1.0.pr )
93
+		// so doing something like:
94
+		//$plugin_slug['premium']['p'] = 'some-premium-slug';
95
+		//$plugin_slug['prerelease']['b'] = 'some-pre-release-slug';
96
+		//..WOULD work!
97
+		return array(
98
+			'free'       => array('decaf' => 'event-espresso-core-decaf'),
99
+			'premium'    => array('p' => 'event-espresso-core-reg'),
100
+			'prerelease' => array('beta' => 'event-espresso-core-pr'),
101
+		);
102
+	}
103 103
 
104 104
 
105
-    /**
106
-     * Return whether the site is opted in for UXIP or not.
107
-     * @return bool
108
-     */
109
-    public function isOptedInForUxip()
110
-    {
111
-        return filter_var($this->ee_config->core->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN);
112
-    }
105
+	/**
106
+	 * Return whether the site is opted in for UXIP or not.
107
+	 * @return bool
108
+	 */
109
+	public function isOptedInForUxip()
110
+	{
111
+		return filter_var($this->ee_config->core->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN);
112
+	}
113 113
 
114 114
 
115
-    /**
116
-     * Return whether the site has been notified about UXIP or not.
117
-     * @return bool
118
-     */
119
-    public function hasNotifiedForUxip()
120
-    {
121
-        return filter_var($this->ee_config->core->ee_ueip_has_notified, FILTER_VALIDATE_BOOLEAN);
122
-    }
115
+	/**
116
+	 * Return whether the site has been notified about UXIP or not.
117
+	 * @return bool
118
+	 */
119
+	public function hasNotifiedForUxip()
120
+	{
121
+		return filter_var($this->ee_config->core->ee_ueip_has_notified, FILTER_VALIDATE_BOOLEAN);
122
+	}
123 123
 
124 124
 
125
-    /**
126
-     * Set the site opted in for UXIP.
127
-     */
128
-    public function setHasOptedInForUxip()
129
-    {
130
-        $this->ee_config->core->ee_ueip_optin = true;
131
-        $this->ee_config->update_espresso_config(false, false);
132
-    }
125
+	/**
126
+	 * Set the site opted in for UXIP.
127
+	 */
128
+	public function setHasOptedInForUxip()
129
+	{
130
+		$this->ee_config->core->ee_ueip_optin = true;
131
+		$this->ee_config->update_espresso_config(false, false);
132
+	}
133 133
 
134 134
 
135
-    /**
136
-     * Set the site opted out for UXIP
137
-     */
138
-    public function setHasOptedOutForUxip()
139
-    {
140
-        $this->ee_config->core->ee_ueip_optin = false;
141
-        $this->ee_config->update_espresso_config(false, false);
142
-    }
135
+	/**
136
+	 * Set the site opted out for UXIP
137
+	 */
138
+	public function setHasOptedOutForUxip()
139
+	{
140
+		$this->ee_config->core->ee_ueip_optin = false;
141
+		$this->ee_config->update_espresso_config(false, false);
142
+	}
143 143
 
144 144
 
145 145
 
146
-    public function setHasNotifiedAboutUxip()
147
-    {
148
-        $this->ee_config->core->ee_ueip_has_notified = true;
149
-        $this->ee_config->update_espresso_config(false, false);
150
-    }
146
+	public function setHasNotifiedAboutUxip()
147
+	{
148
+		$this->ee_config->core->ee_ueip_has_notified = true;
149
+		$this->ee_config->update_espresso_config(false, false);
150
+	}
151 151
 }
Please login to merge, or discard this patch.