Completed
Branch BUG/192/php-72-specific-warnin... (b9d261)
by
unknown
29:59 queued 21:02
created
core/EE_Session.core.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,6 @@
 block discarded – undo
6 6
 use EventEspresso\core\exceptions\InvalidInterfaceException;
7 7
 use EventEspresso\core\exceptions\InvalidSessionDataException;
8 8
 use EventEspresso\core\services\cache\CacheStorageInterface;
9
-use EventEspresso\core\services\loaders\LoaderFactory;
10 9
 use EventEspresso\core\services\request\RequestInterface;
11 10
 use EventEspresso\core\services\session\SessionStartHandler;
12 11
 
Please login to merge, or discard this patch.
Indentation   +1261 added lines, -1261 removed lines patch added patch discarded remove patch
@@ -25,1259 +25,1259 @@  discard block
 block discarded – undo
25 25
 class EE_Session implements SessionIdentifierInterface
26 26
 {
27 27
 
28
-    const session_id_prefix = 'ee_ssn_';
29
-
30
-    const hash_check_prefix = 'ee_shc_';
31
-
32
-    const OPTION_NAME_SETTINGS = 'ee_session_settings';
33
-
34
-    const STATUS_CLOSED = 0;
35
-
36
-    const STATUS_OPEN = 1;
37
-
38
-    /**
39
-     * instance of the EE_Session object
40
-     *
41
-     * @var EE_Session
42
-     */
43
-    private static $_instance;
44
-
45
-    /**
46
-     * @var CacheStorageInterface $cache_storage
47
-     */
48
-    protected $cache_storage;
49
-
50
-    /**
51
-     * @var EE_Encryption $encryption
52
-     */
53
-    protected $encryption;
54
-
55
-    /**
56
-     * @var SessionStartHandler $session_start_handler
57
-     */
58
-    protected $session_start_handler;
59
-
60
-    /**
61
-     * the session id
62
-     *
63
-     * @var string
64
-     */
65
-    private $_sid;
66
-
67
-    /**
68
-     * session id salt
69
-     *
70
-     * @var string
71
-     */
72
-    private $_sid_salt;
73
-
74
-    /**
75
-     * session data
76
-     *
77
-     * @var array
78
-     */
79
-    private $_session_data = array();
80
-
81
-    /**
82
-     * how long an EE session lasts
83
-     * default session lifespan of 1 hour (for not so instant IPNs)
84
-     *
85
-     * @var SessionLifespan $session_lifespan
86
-     */
87
-    private $session_lifespan;
88
-
89
-    /**
90
-     * session expiration time as Unix timestamp in GMT
91
-     *
92
-     * @var int
93
-     */
94
-    private $_expiration;
95
-
96
-    /**
97
-     * whether or not session has expired at some point
98
-     *
99
-     * @var boolean
100
-     */
101
-    private $_expired = false;
102
-
103
-    /**
104
-     * current time as Unix timestamp in GMT
105
-     *
106
-     * @var int
107
-     */
108
-    private $_time;
109
-
110
-    /**
111
-     * whether to encrypt session data
112
-     *
113
-     * @var bool
114
-     */
115
-    private $_use_encryption;
116
-
117
-    /**
118
-     * well... according to the server...
119
-     *
120
-     * @var null
121
-     */
122
-    private $_user_agent;
123
-
124
-    /**
125
-     * do you really trust the server ?
126
-     *
127
-     * @var null
128
-     */
129
-    private $_ip_address;
130
-
131
-    /**
132
-     * current WP user_id
133
-     *
134
-     * @var null
135
-     */
136
-    private $_wp_user_id;
137
-
138
-    /**
139
-     * array for defining default session vars
140
-     *
141
-     * @var array
142
-     */
143
-    private $_default_session_vars = array(
144
-        'id'            => null,
145
-        'user_id'       => null,
146
-        'ip_address'    => null,
147
-        'user_agent'    => null,
148
-        'init_access'   => null,
149
-        'last_access'   => null,
150
-        'expiration'    => null,
151
-        'pages_visited' => array(),
152
-    );
153
-
154
-    /**
155
-     * timestamp for when last garbage collection cycle was performed
156
-     *
157
-     * @var int $_last_gc
158
-     */
159
-    private $_last_gc;
160
-
161
-    /**
162
-     * @var RequestInterface $request
163
-     */
164
-    protected $request;
165
-
166
-    /**
167
-     * whether session is active or not
168
-     *
169
-     * @var int $status
170
-     */
171
-    private $status = EE_Session::STATUS_CLOSED;
172
-
173
-
174
-    /**
175
-     * @singleton method used to instantiate class object
176
-     * @param CacheStorageInterface $cache_storage
177
-     * @param SessionLifespan|null  $lifespan
178
-     * @param RequestInterface      $request
179
-     * @param SessionStartHandler   $session_start_handler
180
-     * @param EE_Encryption         $encryption
181
-     * @return EE_Session
182
-     * @throws InvalidArgumentException
183
-     * @throws InvalidDataTypeException
184
-     * @throws InvalidInterfaceException
185
-     */
186
-    public static function instance(
187
-        CacheStorageInterface $cache_storage = null,
188
-        SessionLifespan $lifespan = null,
189
-        RequestInterface $request = null,
190
-        SessionStartHandler $session_start_handler = null,
191
-        EE_Encryption $encryption = null
192
-    ) {
193
-        // check if class object is instantiated
194
-        // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
195
-        // add_filter( 'FHEE_load_EE_Session', '__return_false' );
196
-        if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
197
-            self::$_instance = new self(
198
-                $cache_storage,
199
-                $lifespan,
200
-                $request,
201
-                $session_start_handler,
202
-                $encryption
203
-            );
204
-        }
205
-        return self::$_instance;
206
-    }
207
-
208
-
209
-    /**
210
-     * protected constructor to prevent direct creation
211
-     *
212
-     * @param CacheStorageInterface $cache_storage
213
-     * @param SessionLifespan       $lifespan
214
-     * @param RequestInterface      $request
215
-     * @param SessionStartHandler   $session_start_handler
216
-     * @param EE_Encryption         $encryption
217
-     * @throws InvalidArgumentException
218
-     * @throws InvalidDataTypeException
219
-     * @throws InvalidInterfaceException
220
-     */
221
-    protected function __construct(
222
-        CacheStorageInterface $cache_storage,
223
-        SessionLifespan $lifespan,
224
-        RequestInterface $request,
225
-        SessionStartHandler $session_start_handler,
226
-        EE_Encryption $encryption = null
227
-    ) {
228
-        // session loading is turned ON by default,
229
-        // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook
230
-        // (which currently fires on the init hook at priority 9),
231
-        // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
232
-        if (! apply_filters('FHEE_load_EE_Session', true)) {
233
-            return;
234
-        }
235
-        $this->session_start_handler = $session_start_handler;
236
-        $this->session_lifespan = $lifespan;
237
-        $this->request = $request;
238
-        if (! defined('ESPRESSO_SESSION')) {
239
-            define('ESPRESSO_SESSION', true);
240
-        }
241
-        // retrieve session options from db
242
-        $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
243
-        if (! empty($session_settings)) {
244
-            // cycle though existing session options
245
-            foreach ($session_settings as $var_name => $session_setting) {
246
-                // set values for class properties
247
-                $var_name = '_' . $var_name;
248
-                $this->{$var_name} = $session_setting;
249
-            }
250
-        }
251
-        $this->cache_storage = $cache_storage;
252
-        // are we using encryption?
253
-        $this->_use_encryption = $encryption instanceof EE_Encryption
254
-                                 && EE_Registry::instance()->CFG->admin->encode_session_data();
255
-        // encrypt data via: $this->encryption->encrypt();
256
-        $this->encryption = $encryption;
257
-        // filter hook allows outside functions/classes/plugins to change default empty cart
258
-        $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
259
-        array_merge($this->_default_session_vars, $extra_default_session_vars);
260
-        // apply default session vars
261
-        $this->_set_defaults();
262
-        add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
263
-        // check request for 'clear_session' param
264
-        add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
265
-        // once everything is all said and done,
266
-        add_action('shutdown', array($this, 'update'), 100);
267
-        add_action('shutdown', array($this, 'garbageCollection'), 1000);
268
-        $this->configure_garbage_collection_filters();
269
-    }
270
-
271
-
272
-    /**
273
-     * @return bool
274
-     * @throws InvalidArgumentException
275
-     * @throws InvalidDataTypeException
276
-     * @throws InvalidInterfaceException
277
-     */
278
-    public static function isLoadedAndActive()
279
-    {
280
-        return did_action('AHEE__EE_System__core_loaded_and_ready')
281
-               && EE_Session::instance() instanceof EE_Session
282
-               && EE_Session::instance()->isActive();
283
-    }
284
-
285
-
286
-    /**
287
-     * @return bool
288
-     */
289
-    public function isActive()
290
-    {
291
-        return $this->status === EE_Session::STATUS_OPEN;
292
-    }
293
-
294
-
295
-    /**
296
-     * @return void
297
-     * @throws EE_Error
298
-     * @throws InvalidArgumentException
299
-     * @throws InvalidDataTypeException
300
-     * @throws InvalidInterfaceException
301
-     * @throws InvalidSessionDataException
302
-     */
303
-    public function open_session()
304
-    {
305
-        // check for existing session and retrieve it from db
306
-        if (! $this->_espresso_session()) {
307
-            // or just start a new one
308
-            $this->_create_espresso_session();
309
-        }
310
-    }
311
-
312
-
313
-    /**
314
-     * @return bool
315
-     */
316
-    public function expired()
317
-    {
318
-        return $this->_expired;
319
-    }
320
-
321
-
322
-    /**
323
-     * @return void
324
-     */
325
-    public function reset_expired()
326
-    {
327
-        $this->_expired = false;
328
-    }
329
-
330
-
331
-    /**
332
-     * @return int
333
-     */
334
-    public function expiration()
335
-    {
336
-        return $this->_expiration;
337
-    }
338
-
339
-
340
-    /**
341
-     * @return int
342
-     */
343
-    public function extension()
344
-    {
345
-        return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS);
346
-    }
347
-
348
-
349
-    /**
350
-     * @param int $time number of seconds to add to session expiration
351
-     */
352
-    public function extend_expiration($time = 0)
353
-    {
354
-        $time = $time ? $time : $this->extension();
355
-        $this->_expiration += absint($time);
356
-    }
357
-
358
-
359
-    /**
360
-     * @return int
361
-     */
362
-    public function lifespan()
363
-    {
364
-        return $this->session_lifespan->inSeconds();
365
-    }
366
-
367
-
368
-    /**
369
-     * This just sets some defaults for the _session data property
370
-     *
371
-     * @access private
372
-     * @return void
373
-     */
374
-    private function _set_defaults()
375
-    {
376
-        // set some defaults
377
-        foreach ($this->_default_session_vars as $key => $default_var) {
378
-            if (is_array($default_var)) {
379
-                $this->_session_data[ $key ] = array();
380
-            } else {
381
-                $this->_session_data[ $key ] = '';
382
-            }
383
-        }
384
-    }
385
-
386
-
387
-    /**
388
-     * @retrieve  session data
389
-     * @access    public
390
-     * @return    string
391
-     */
392
-    public function id()
393
-    {
394
-        return $this->_sid;
395
-    }
396
-
397
-
398
-    /**
399
-     * @param \EE_Cart $cart
400
-     * @return bool
401
-     */
402
-    public function set_cart(EE_Cart $cart)
403
-    {
404
-        $this->_session_data['cart'] = $cart;
405
-        return true;
406
-    }
407
-
408
-
409
-    /**
410
-     * reset_cart
411
-     */
412
-    public function reset_cart()
413
-    {
414
-        do_action('AHEE__EE_Session__reset_cart__before_reset', $this);
415
-        $this->_session_data['cart'] = null;
416
-    }
417
-
418
-
419
-    /**
420
-     * @return \EE_Cart
421
-     */
422
-    public function cart()
423
-    {
424
-        return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart
425
-            ? $this->_session_data['cart']
426
-            : null;
427
-    }
428
-
429
-
430
-    /**
431
-     * @param \EE_Checkout $checkout
432
-     * @return bool
433
-     */
434
-    public function set_checkout(EE_Checkout $checkout)
435
-    {
436
-        $this->_session_data['checkout'] = $checkout;
437
-        return true;
438
-    }
439
-
440
-
441
-    /**
442
-     * reset_checkout
443
-     */
444
-    public function reset_checkout()
445
-    {
446
-        do_action('AHEE__EE_Session__reset_checkout__before_reset', $this);
447
-        $this->_session_data['checkout'] = null;
448
-    }
449
-
450
-
451
-    /**
452
-     * @return \EE_Checkout
453
-     */
454
-    public function checkout()
455
-    {
456
-        return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout
457
-            ? $this->_session_data['checkout']
458
-            : null;
459
-    }
460
-
461
-
462
-    /**
463
-     * @param \EE_Transaction $transaction
464
-     * @return bool
465
-     * @throws EE_Error
466
-     */
467
-    public function set_transaction(EE_Transaction $transaction)
468
-    {
469
-        // first remove the session from the transaction before we save the transaction in the session
470
-        $transaction->set_txn_session_data(null);
471
-        $this->_session_data['transaction'] = $transaction;
472
-        return true;
473
-    }
474
-
475
-
476
-    /**
477
-     * reset_transaction
478
-     */
479
-    public function reset_transaction()
480
-    {
481
-        do_action('AHEE__EE_Session__reset_transaction__before_reset', $this);
482
-        $this->_session_data['transaction'] = null;
483
-    }
484
-
485
-
486
-    /**
487
-     * @return \EE_Transaction
488
-     */
489
-    public function transaction()
490
-    {
491
-        return isset($this->_session_data['transaction'])
492
-               && $this->_session_data['transaction'] instanceof EE_Transaction
493
-            ? $this->_session_data['transaction']
494
-            : null;
495
-    }
496
-
497
-
498
-    /**
499
-     * retrieve session data
500
-     *
501
-     * @param null $key
502
-     * @param bool $reset_cache
503
-     * @return array
504
-     */
505
-    public function get_session_data($key = null, $reset_cache = false)
506
-    {
507
-        if ($reset_cache) {
508
-            $this->reset_cart();
509
-            $this->reset_checkout();
510
-            $this->reset_transaction();
511
-        }
512
-        if (! empty($key)) {
513
-            return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
514
-        }
515
-        return $this->_session_data;
516
-    }
517
-
518
-
519
-    /**
520
-     * Returns TRUE on success, FALSE on fail
521
-     *
522
-     * @param array $data
523
-     * @return bool
524
-     */
525
-    public function set_session_data($data)
526
-    {
527
-        // nothing ??? bad data ??? go home!
528
-        if (empty($data) || ! is_array($data)) {
529
-            EE_Error::add_error(
530
-                esc_html__(
531
-                    'No session data or invalid session data was provided.',
532
-                    'event_espresso'
533
-                ),
534
-                __FILE__,
535
-                __FUNCTION__,
536
-                __LINE__
537
-            );
538
-            return false;
539
-        }
540
-        foreach ($data as $key => $value) {
541
-            if (isset($this->_default_session_vars[ $key ])) {
542
-                EE_Error::add_error(
543
-                    sprintf(
544
-                        esc_html__(
545
-                            'Sorry! %s is a default session datum and can not be reset.',
546
-                            'event_espresso'
547
-                        ),
548
-                        $key
549
-                    ),
550
-                    __FILE__,
551
-                    __FUNCTION__,
552
-                    __LINE__
553
-                );
554
-                return false;
555
-            }
556
-            $this->_session_data[ $key ] = $value;
557
-        }
558
-        return true;
559
-    }
560
-
561
-
562
-    /**
563
-     * @initiate session
564
-     * @access   private
565
-     * @return TRUE on success, FALSE on fail
566
-     * @throws EE_Error
567
-     * @throws InvalidArgumentException
568
-     * @throws InvalidDataTypeException
569
-     * @throws InvalidInterfaceException
570
-     * @throws InvalidSessionDataException
571
-     */
572
-    private function _espresso_session()
573
-    {
574
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
575
-        $this->session_start_handler->startSession();
576
-        $this->status = EE_Session::STATUS_OPEN;
577
-        // get our modified session ID
578
-        $this->_sid = $this->_generate_session_id();
579
-        // and the visitors IP
580
-        $this->_ip_address = $this->request->ipAddress();
581
-        // set the "user agent"
582
-        $this->_user_agent = $this->request->userAgent();
583
-        // now let's retrieve what's in the db
584
-        $session_data = $this->_retrieve_session_data();
585
-        if (! empty($session_data)) {
586
-            // get the current time in UTC
587
-            $this->_time = $this->_time !== null ? $this->_time : time();
588
-            // and reset the session expiration
589
-            $this->_expiration = isset($session_data['expiration'])
590
-                ? $session_data['expiration']
591
-                : $this->_time + $this->session_lifespan->inSeconds();
592
-        } else {
593
-            // set initial site access time and the session expiration
594
-            $this->_set_init_access_and_expiration();
595
-            // set referer
596
-            $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER'])
597
-                ? esc_attr($_SERVER['HTTP_REFERER'])
598
-                : '';
599
-            // no previous session = go back and create one (on top of the data above)
600
-            return false;
601
-        }
602
-        // now the user agent
603
-        if ($session_data['user_agent'] !== $this->_user_agent) {
604
-            return false;
605
-        }
606
-        // wait a minute... how old are you?
607
-        if ($this->_time > $this->_expiration) {
608
-            // yer too old fer me!
609
-            $this->_expired = true;
610
-            // wipe out everything that isn't a default session datum
611
-            $this->clear_session(__CLASS__, __FUNCTION__);
612
-        }
613
-        // make event espresso session data available to plugin
614
-        $this->_session_data = array_merge($this->_session_data, $session_data);
615
-        return true;
616
-    }
617
-
618
-
619
-    /**
620
-     * _get_session_data
621
-     * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup
622
-     * databases
623
-     *
624
-     * @return array
625
-     * @throws EE_Error
626
-     * @throws InvalidArgumentException
627
-     * @throws InvalidSessionDataException
628
-     * @throws InvalidDataTypeException
629
-     * @throws InvalidInterfaceException
630
-     */
631
-    protected function _retrieve_session_data()
632
-    {
633
-        $ssn_key = EE_Session::session_id_prefix . $this->_sid;
634
-        try {
635
-            // we're using WP's Transient API to store session data using the PHP session ID as the option name
636
-            $session_data = $this->cache_storage->get($ssn_key, false);
637
-            if (empty($session_data)) {
638
-                return array();
639
-            }
640
-            if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
641
-                $hash_check = $this->cache_storage->get(
642
-                    EE_Session::hash_check_prefix . $this->_sid,
643
-                    false
644
-                );
645
-                if ($hash_check && $hash_check !== md5($session_data)) {
646
-                    EE_Error::add_error(
647
-                        sprintf(
648
-                            __(
649
-                                'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
650
-                                'event_espresso'
651
-                            ),
652
-                            EE_Session::session_id_prefix . $this->_sid
653
-                        ),
654
-                        __FILE__,
655
-                        __FUNCTION__,
656
-                        __LINE__
657
-                    );
658
-                }
659
-            }
660
-        } catch (Exception $e) {
661
-            // let's just eat that error for now and attempt to correct any corrupted data
662
-            global $wpdb;
663
-            $row = $wpdb->get_row(
664
-                $wpdb->prepare(
665
-                    "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
666
-                    '_transient_' . $ssn_key
667
-                )
668
-            );
669
-            $session_data = is_object($row) ? $row->option_value : null;
670
-            if ($session_data) {
671
-                $session_data = preg_replace_callback(
672
-                    '!s:(d+):"(.*?)";!',
673
-                    function ($match) {
674
-                        return $match[1] === strlen($match[2])
675
-                            ? $match[0]
676
-                            : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
677
-                    },
678
-                    $session_data
679
-                );
680
-            }
681
-            $session_data = maybe_unserialize($session_data);
682
-        }
683
-        // in case the data is encoded... try to decode it
684
-        $session_data = $this->encryption instanceof EE_Encryption
685
-            ? $this->encryption->base64_string_decode($session_data)
686
-            : $session_data;
687
-        if (! is_array($session_data)) {
688
-            try {
689
-                $session_data = maybe_unserialize($session_data);
690
-            } catch (Exception $e) {
691
-                $msg = esc_html__(
692
-                    'An error occurred while attempting to unserialize the session data.',
693
-                    'event_espresso'
694
-                );
695
-                $msg .= WP_DEBUG
696
-                    ? '<br><pre>'
697
-                      . print_r($session_data, true)
698
-                      . '</pre><br>'
699
-                      . $this->find_serialize_error($session_data)
700
-                    : '';
701
-                $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
702
-                throw new InvalidSessionDataException($msg, 0, $e);
703
-            }
704
-        }
705
-        // just a check to make sure the session array is indeed an array
706
-        if (! is_array($session_data)) {
707
-            // no?!?! then something is wrong
708
-            $msg = esc_html__(
709
-                'The session data is missing, invalid, or corrupted.',
710
-                'event_espresso'
711
-            );
712
-            $msg .= WP_DEBUG
713
-                ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
714
-                : '';
715
-            $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
716
-            throw new InvalidSessionDataException($msg);
717
-        }
718
-        if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
719
-            $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
720
-                $session_data['transaction']
721
-            );
722
-        }
723
-        return $session_data;
724
-    }
725
-
726
-
727
-    /**
728
-     * _generate_session_id
729
-     * Retrieves the PHP session id either directly from the PHP session,
730
-     * or from the $_REQUEST array if it was passed in from an AJAX request.
731
-     * The session id is then salted and hashed (mmm sounds tasty)
732
-     * so that it can be safely used as a $_REQUEST param
733
-     *
734
-     * @return string
735
-     */
736
-    protected function _generate_session_id()
737
-    {
738
-        // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
739
-        if (isset($_REQUEST['EESID'])) {
740
-            $session_id = sanitize_text_field($_REQUEST['EESID']);
741
-        } else {
742
-            $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
743
-        }
744
-        return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
745
-    }
746
-
747
-
748
-    /**
749
-     * _get_sid_salt
750
-     *
751
-     * @return string
752
-     */
753
-    protected function _get_sid_salt()
754
-    {
755
-        // was session id salt already saved to db ?
756
-        if (empty($this->_sid_salt)) {
757
-            // no?  then maybe use WP defined constant
758
-            if (defined('AUTH_SALT')) {
759
-                $this->_sid_salt = AUTH_SALT;
760
-            }
761
-            // if salt doesn't exist or is too short
762
-            if (strlen($this->_sid_salt) < 32) {
763
-                // create a new one
764
-                $this->_sid_salt = wp_generate_password(64);
765
-            }
766
-            // and save it as a permanent session setting
767
-            $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt));
768
-        }
769
-        return $this->_sid_salt;
770
-    }
771
-
772
-
773
-    /**
774
-     * _set_init_access_and_expiration
775
-     *
776
-     * @return void
777
-     */
778
-    protected function _set_init_access_and_expiration()
779
-    {
780
-        $this->_time = time();
781
-        $this->_expiration = $this->_time + $this->session_lifespan->inSeconds();
782
-        // set initial site access time
783
-        $this->_session_data['init_access'] = $this->_time;
784
-        // and the session expiration
785
-        $this->_session_data['expiration'] = $this->_expiration;
786
-    }
787
-
788
-
789
-    /**
790
-     * @update session data  prior to saving to the db
791
-     * @access public
792
-     * @param bool $new_session
793
-     * @return TRUE on success, FALSE on fail
794
-     * @throws EE_Error
795
-     * @throws InvalidArgumentException
796
-     * @throws InvalidDataTypeException
797
-     * @throws InvalidInterfaceException
798
-     */
799
-    public function update($new_session = false)
800
-    {
801
-        $this->_session_data = $this->_session_data !== null
802
-                               && is_array($this->_session_data)
803
-                               && isset($this->_session_data['id'])
804
-            ? $this->_session_data
805
-            : array();
806
-        if (empty($this->_session_data)) {
807
-            $this->_set_defaults();
808
-        }
809
-        $session_data = array();
810
-        foreach ($this->_session_data as $key => $value) {
811
-            switch ($key) {
812
-                case 'id':
813
-                    // session ID
814
-                    $session_data['id'] = $this->_sid;
815
-                    break;
816
-                case 'ip_address':
817
-                    // visitor ip address
818
-                    $session_data['ip_address'] = $this->request->ipAddress();
819
-                    break;
820
-                case 'user_agent':
821
-                    // visitor user_agent
822
-                    $session_data['user_agent'] = $this->_user_agent;
823
-                    break;
824
-                case 'init_access':
825
-                    $session_data['init_access'] = absint($value);
826
-                    break;
827
-                case 'last_access':
828
-                    // current access time
829
-                    $session_data['last_access'] = $this->_time;
830
-                    break;
831
-                case 'expiration':
832
-                    // when the session expires
833
-                    $session_data['expiration'] = ! empty($this->_expiration)
834
-                        ? $this->_expiration
835
-                        : $session_data['init_access'] + $this->session_lifespan->inSeconds();
836
-                    break;
837
-                case 'user_id':
838
-                    // current user if logged in
839
-                    $session_data['user_id'] = $this->_wp_user_id();
840
-                    break;
841
-                case 'pages_visited':
842
-                    $page_visit = $this->_get_page_visit();
843
-                    if ($page_visit) {
844
-                        // set pages visited where the first will be the http referrer
845
-                        $this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
846
-                        // we'll only save the last 10 page visits.
847
-                        $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
848
-                    }
849
-                    break;
850
-                default:
851
-                    // carry any other data over
852
-                    $session_data[ $key ] = $this->_session_data[ $key ];
853
-            }
854
-        }
855
-        $this->_session_data = $session_data;
856
-        // creating a new session does not require saving to the db just yet
857
-        if (! $new_session) {
858
-            // ready? let's save
859
-            if ($this->_save_session_to_db()) {
860
-                return true;
861
-            }
862
-            return false;
863
-        }
864
-        // meh, why not?
865
-        return true;
866
-    }
867
-
868
-
869
-    /**
870
-     * @create session data array
871
-     * @access public
872
-     * @return bool
873
-     * @throws EE_Error
874
-     * @throws InvalidArgumentException
875
-     * @throws InvalidDataTypeException
876
-     * @throws InvalidInterfaceException
877
-     */
878
-    private function _create_espresso_session()
879
-    {
880
-        do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
881
-        // use the update function for now with $new_session arg set to TRUE
882
-        return $this->update(true) ? true : false;
883
-    }
884
-
885
-    /**
886
-     * Detects if there is anything worth saving in the session (eg the cart is a good one, notices are pretty good
887
-     * too). This is used when determining if we want to save the session or not.
888
-     * @since 4.9.67.p
889
-     * @return bool
890
-     */
891
-    private function sessionHasStuffWorthSaving()
892
-    {
893
-        return $this->cart() instanceof EE_Cart
894
-            || (
895
-                isset($this->_session_data['ee_notices'])
896
-                && (
897
-                    ! empty($this->_session_data['ee_notices']['attention'])
898
-                    || !empty($this->_session_data['ee_notices']['errors'])
899
-                    || !empty($this->_session_data['ee_notices']['success'])
900
-                )
901
-            );
902
-    }
903
-    /**
904
-     * _save_session_to_db
905
-     *
906
-     * @param bool $clear_session
907
-     * @return string
908
-     * @throws EE_Error
909
-     * @throws InvalidArgumentException
910
-     * @throws InvalidDataTypeException
911
-     * @throws InvalidInterfaceException
912
-     */
913
-    private function _save_session_to_db($clear_session = false)
914
-    {
915
-        // don't save sessions for crawlers
916
-        // and unless we're deleting the session data, don't save anything if there isn't a cart
917
-        if ($this->request->isBot()
918
-            || (
919
-                ! $clear_session
920
-                && ! $this->sessionHasStuffWorthSaving()
921
-                && apply_filters('FHEE__EE_Session___save_session_to_db__abort_session_save', true)
922
-            )
923
-        ) {
924
-            return false;
925
-        }
926
-        $transaction = $this->transaction();
927
-        if ($transaction instanceof EE_Transaction) {
928
-            if (! $transaction->ID()) {
929
-                $transaction->save();
930
-            }
931
-            $this->_session_data['transaction'] = $transaction->ID();
932
-        }
933
-        // then serialize all of our session data
934
-        $session_data = serialize($this->_session_data);
935
-        // do we need to also encode it to avoid corrupted data when saved to the db?
936
-        $session_data = $this->_use_encryption
937
-            ? $this->encryption->base64_string_encode($session_data)
938
-            : $session_data;
939
-        // maybe save hash check
940
-        if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
941
-            $this->cache_storage->add(
942
-                EE_Session::hash_check_prefix . $this->_sid,
943
-                md5($session_data),
944
-                $this->session_lifespan->inSeconds()
945
-            );
946
-        }
947
-        // we're using the Transient API for storing session data,
948
-        return $this->cache_storage->add(
949
-            EE_Session::session_id_prefix . $this->_sid,
950
-            $session_data,
951
-            $this->session_lifespan->inSeconds()
952
-        );
953
-    }
954
-
955
-
956
-    /**
957
-     * @get    the full page request the visitor is accessing
958
-     * @access public
959
-     * @return string
960
-     */
961
-    public function _get_page_visit()
962
-    {
963
-        $page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
964
-        // check for request url
965
-        if (isset($_SERVER['REQUEST_URI'])) {
966
-            $http_host = '';
967
-            $page_id = '?';
968
-            $e_reg = '';
969
-            $request_uri = esc_url($_SERVER['REQUEST_URI']);
970
-            $ru_bits = explode('?', $request_uri);
971
-            $request_uri = $ru_bits[0];
972
-            // check for and grab host as well
973
-            if (isset($_SERVER['HTTP_HOST'])) {
974
-                $http_host = esc_url($_SERVER['HTTP_HOST']);
975
-            }
976
-            // check for page_id in SERVER REQUEST
977
-            if (isset($_REQUEST['page_id'])) {
978
-                // rebuild $e_reg without any of the extra parameters
979
-                $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&amp;';
980
-            }
981
-            // check for $e_reg in SERVER REQUEST
982
-            if (isset($_REQUEST['ee'])) {
983
-                // rebuild $e_reg without any of the extra parameters
984
-                $e_reg = 'ee=' . esc_attr($_REQUEST['ee']);
985
-            }
986
-            $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?');
987
-        }
988
-        return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
989
-    }
990
-
991
-
992
-    /**
993
-     * @the    current wp user id
994
-     * @access public
995
-     * @return int
996
-     */
997
-    public function _wp_user_id()
998
-    {
999
-        // if I need to explain the following lines of code, then you shouldn't be looking at this!
1000
-        $this->_wp_user_id = get_current_user_id();
1001
-        return $this->_wp_user_id;
1002
-    }
1003
-
1004
-
1005
-    /**
1006
-     * Clear EE_Session data
1007
-     *
1008
-     * @access public
1009
-     * @param string $class
1010
-     * @param string $function
1011
-     * @return void
1012
-     * @throws EE_Error
1013
-     * @throws InvalidArgumentException
1014
-     * @throws InvalidDataTypeException
1015
-     * @throws InvalidInterfaceException
1016
-     */
1017
-    public function clear_session($class = '', $function = '')
1018
-    {
28
+	const session_id_prefix = 'ee_ssn_';
29
+
30
+	const hash_check_prefix = 'ee_shc_';
31
+
32
+	const OPTION_NAME_SETTINGS = 'ee_session_settings';
33
+
34
+	const STATUS_CLOSED = 0;
35
+
36
+	const STATUS_OPEN = 1;
37
+
38
+	/**
39
+	 * instance of the EE_Session object
40
+	 *
41
+	 * @var EE_Session
42
+	 */
43
+	private static $_instance;
44
+
45
+	/**
46
+	 * @var CacheStorageInterface $cache_storage
47
+	 */
48
+	protected $cache_storage;
49
+
50
+	/**
51
+	 * @var EE_Encryption $encryption
52
+	 */
53
+	protected $encryption;
54
+
55
+	/**
56
+	 * @var SessionStartHandler $session_start_handler
57
+	 */
58
+	protected $session_start_handler;
59
+
60
+	/**
61
+	 * the session id
62
+	 *
63
+	 * @var string
64
+	 */
65
+	private $_sid;
66
+
67
+	/**
68
+	 * session id salt
69
+	 *
70
+	 * @var string
71
+	 */
72
+	private $_sid_salt;
73
+
74
+	/**
75
+	 * session data
76
+	 *
77
+	 * @var array
78
+	 */
79
+	private $_session_data = array();
80
+
81
+	/**
82
+	 * how long an EE session lasts
83
+	 * default session lifespan of 1 hour (for not so instant IPNs)
84
+	 *
85
+	 * @var SessionLifespan $session_lifespan
86
+	 */
87
+	private $session_lifespan;
88
+
89
+	/**
90
+	 * session expiration time as Unix timestamp in GMT
91
+	 *
92
+	 * @var int
93
+	 */
94
+	private $_expiration;
95
+
96
+	/**
97
+	 * whether or not session has expired at some point
98
+	 *
99
+	 * @var boolean
100
+	 */
101
+	private $_expired = false;
102
+
103
+	/**
104
+	 * current time as Unix timestamp in GMT
105
+	 *
106
+	 * @var int
107
+	 */
108
+	private $_time;
109
+
110
+	/**
111
+	 * whether to encrypt session data
112
+	 *
113
+	 * @var bool
114
+	 */
115
+	private $_use_encryption;
116
+
117
+	/**
118
+	 * well... according to the server...
119
+	 *
120
+	 * @var null
121
+	 */
122
+	private $_user_agent;
123
+
124
+	/**
125
+	 * do you really trust the server ?
126
+	 *
127
+	 * @var null
128
+	 */
129
+	private $_ip_address;
130
+
131
+	/**
132
+	 * current WP user_id
133
+	 *
134
+	 * @var null
135
+	 */
136
+	private $_wp_user_id;
137
+
138
+	/**
139
+	 * array for defining default session vars
140
+	 *
141
+	 * @var array
142
+	 */
143
+	private $_default_session_vars = array(
144
+		'id'            => null,
145
+		'user_id'       => null,
146
+		'ip_address'    => null,
147
+		'user_agent'    => null,
148
+		'init_access'   => null,
149
+		'last_access'   => null,
150
+		'expiration'    => null,
151
+		'pages_visited' => array(),
152
+	);
153
+
154
+	/**
155
+	 * timestamp for when last garbage collection cycle was performed
156
+	 *
157
+	 * @var int $_last_gc
158
+	 */
159
+	private $_last_gc;
160
+
161
+	/**
162
+	 * @var RequestInterface $request
163
+	 */
164
+	protected $request;
165
+
166
+	/**
167
+	 * whether session is active or not
168
+	 *
169
+	 * @var int $status
170
+	 */
171
+	private $status = EE_Session::STATUS_CLOSED;
172
+
173
+
174
+	/**
175
+	 * @singleton method used to instantiate class object
176
+	 * @param CacheStorageInterface $cache_storage
177
+	 * @param SessionLifespan|null  $lifespan
178
+	 * @param RequestInterface      $request
179
+	 * @param SessionStartHandler   $session_start_handler
180
+	 * @param EE_Encryption         $encryption
181
+	 * @return EE_Session
182
+	 * @throws InvalidArgumentException
183
+	 * @throws InvalidDataTypeException
184
+	 * @throws InvalidInterfaceException
185
+	 */
186
+	public static function instance(
187
+		CacheStorageInterface $cache_storage = null,
188
+		SessionLifespan $lifespan = null,
189
+		RequestInterface $request = null,
190
+		SessionStartHandler $session_start_handler = null,
191
+		EE_Encryption $encryption = null
192
+	) {
193
+		// check if class object is instantiated
194
+		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
195
+		// add_filter( 'FHEE_load_EE_Session', '__return_false' );
196
+		if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
197
+			self::$_instance = new self(
198
+				$cache_storage,
199
+				$lifespan,
200
+				$request,
201
+				$session_start_handler,
202
+				$encryption
203
+			);
204
+		}
205
+		return self::$_instance;
206
+	}
207
+
208
+
209
+	/**
210
+	 * protected constructor to prevent direct creation
211
+	 *
212
+	 * @param CacheStorageInterface $cache_storage
213
+	 * @param SessionLifespan       $lifespan
214
+	 * @param RequestInterface      $request
215
+	 * @param SessionStartHandler   $session_start_handler
216
+	 * @param EE_Encryption         $encryption
217
+	 * @throws InvalidArgumentException
218
+	 * @throws InvalidDataTypeException
219
+	 * @throws InvalidInterfaceException
220
+	 */
221
+	protected function __construct(
222
+		CacheStorageInterface $cache_storage,
223
+		SessionLifespan $lifespan,
224
+		RequestInterface $request,
225
+		SessionStartHandler $session_start_handler,
226
+		EE_Encryption $encryption = null
227
+	) {
228
+		// session loading is turned ON by default,
229
+		// but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook
230
+		// (which currently fires on the init hook at priority 9),
231
+		// can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
232
+		if (! apply_filters('FHEE_load_EE_Session', true)) {
233
+			return;
234
+		}
235
+		$this->session_start_handler = $session_start_handler;
236
+		$this->session_lifespan = $lifespan;
237
+		$this->request = $request;
238
+		if (! defined('ESPRESSO_SESSION')) {
239
+			define('ESPRESSO_SESSION', true);
240
+		}
241
+		// retrieve session options from db
242
+		$session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
243
+		if (! empty($session_settings)) {
244
+			// cycle though existing session options
245
+			foreach ($session_settings as $var_name => $session_setting) {
246
+				// set values for class properties
247
+				$var_name = '_' . $var_name;
248
+				$this->{$var_name} = $session_setting;
249
+			}
250
+		}
251
+		$this->cache_storage = $cache_storage;
252
+		// are we using encryption?
253
+		$this->_use_encryption = $encryption instanceof EE_Encryption
254
+								 && EE_Registry::instance()->CFG->admin->encode_session_data();
255
+		// encrypt data via: $this->encryption->encrypt();
256
+		$this->encryption = $encryption;
257
+		// filter hook allows outside functions/classes/plugins to change default empty cart
258
+		$extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
259
+		array_merge($this->_default_session_vars, $extra_default_session_vars);
260
+		// apply default session vars
261
+		$this->_set_defaults();
262
+		add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
263
+		// check request for 'clear_session' param
264
+		add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
265
+		// once everything is all said and done,
266
+		add_action('shutdown', array($this, 'update'), 100);
267
+		add_action('shutdown', array($this, 'garbageCollection'), 1000);
268
+		$this->configure_garbage_collection_filters();
269
+	}
270
+
271
+
272
+	/**
273
+	 * @return bool
274
+	 * @throws InvalidArgumentException
275
+	 * @throws InvalidDataTypeException
276
+	 * @throws InvalidInterfaceException
277
+	 */
278
+	public static function isLoadedAndActive()
279
+	{
280
+		return did_action('AHEE__EE_System__core_loaded_and_ready')
281
+			   && EE_Session::instance() instanceof EE_Session
282
+			   && EE_Session::instance()->isActive();
283
+	}
284
+
285
+
286
+	/**
287
+	 * @return bool
288
+	 */
289
+	public function isActive()
290
+	{
291
+		return $this->status === EE_Session::STATUS_OPEN;
292
+	}
293
+
294
+
295
+	/**
296
+	 * @return void
297
+	 * @throws EE_Error
298
+	 * @throws InvalidArgumentException
299
+	 * @throws InvalidDataTypeException
300
+	 * @throws InvalidInterfaceException
301
+	 * @throws InvalidSessionDataException
302
+	 */
303
+	public function open_session()
304
+	{
305
+		// check for existing session and retrieve it from db
306
+		if (! $this->_espresso_session()) {
307
+			// or just start a new one
308
+			$this->_create_espresso_session();
309
+		}
310
+	}
311
+
312
+
313
+	/**
314
+	 * @return bool
315
+	 */
316
+	public function expired()
317
+	{
318
+		return $this->_expired;
319
+	}
320
+
321
+
322
+	/**
323
+	 * @return void
324
+	 */
325
+	public function reset_expired()
326
+	{
327
+		$this->_expired = false;
328
+	}
329
+
330
+
331
+	/**
332
+	 * @return int
333
+	 */
334
+	public function expiration()
335
+	{
336
+		return $this->_expiration;
337
+	}
338
+
339
+
340
+	/**
341
+	 * @return int
342
+	 */
343
+	public function extension()
344
+	{
345
+		return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS);
346
+	}
347
+
348
+
349
+	/**
350
+	 * @param int $time number of seconds to add to session expiration
351
+	 */
352
+	public function extend_expiration($time = 0)
353
+	{
354
+		$time = $time ? $time : $this->extension();
355
+		$this->_expiration += absint($time);
356
+	}
357
+
358
+
359
+	/**
360
+	 * @return int
361
+	 */
362
+	public function lifespan()
363
+	{
364
+		return $this->session_lifespan->inSeconds();
365
+	}
366
+
367
+
368
+	/**
369
+	 * This just sets some defaults for the _session data property
370
+	 *
371
+	 * @access private
372
+	 * @return void
373
+	 */
374
+	private function _set_defaults()
375
+	{
376
+		// set some defaults
377
+		foreach ($this->_default_session_vars as $key => $default_var) {
378
+			if (is_array($default_var)) {
379
+				$this->_session_data[ $key ] = array();
380
+			} else {
381
+				$this->_session_data[ $key ] = '';
382
+			}
383
+		}
384
+	}
385
+
386
+
387
+	/**
388
+	 * @retrieve  session data
389
+	 * @access    public
390
+	 * @return    string
391
+	 */
392
+	public function id()
393
+	{
394
+		return $this->_sid;
395
+	}
396
+
397
+
398
+	/**
399
+	 * @param \EE_Cart $cart
400
+	 * @return bool
401
+	 */
402
+	public function set_cart(EE_Cart $cart)
403
+	{
404
+		$this->_session_data['cart'] = $cart;
405
+		return true;
406
+	}
407
+
408
+
409
+	/**
410
+	 * reset_cart
411
+	 */
412
+	public function reset_cart()
413
+	{
414
+		do_action('AHEE__EE_Session__reset_cart__before_reset', $this);
415
+		$this->_session_data['cart'] = null;
416
+	}
417
+
418
+
419
+	/**
420
+	 * @return \EE_Cart
421
+	 */
422
+	public function cart()
423
+	{
424
+		return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart
425
+			? $this->_session_data['cart']
426
+			: null;
427
+	}
428
+
429
+
430
+	/**
431
+	 * @param \EE_Checkout $checkout
432
+	 * @return bool
433
+	 */
434
+	public function set_checkout(EE_Checkout $checkout)
435
+	{
436
+		$this->_session_data['checkout'] = $checkout;
437
+		return true;
438
+	}
439
+
440
+
441
+	/**
442
+	 * reset_checkout
443
+	 */
444
+	public function reset_checkout()
445
+	{
446
+		do_action('AHEE__EE_Session__reset_checkout__before_reset', $this);
447
+		$this->_session_data['checkout'] = null;
448
+	}
449
+
450
+
451
+	/**
452
+	 * @return \EE_Checkout
453
+	 */
454
+	public function checkout()
455
+	{
456
+		return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout
457
+			? $this->_session_data['checkout']
458
+			: null;
459
+	}
460
+
461
+
462
+	/**
463
+	 * @param \EE_Transaction $transaction
464
+	 * @return bool
465
+	 * @throws EE_Error
466
+	 */
467
+	public function set_transaction(EE_Transaction $transaction)
468
+	{
469
+		// first remove the session from the transaction before we save the transaction in the session
470
+		$transaction->set_txn_session_data(null);
471
+		$this->_session_data['transaction'] = $transaction;
472
+		return true;
473
+	}
474
+
475
+
476
+	/**
477
+	 * reset_transaction
478
+	 */
479
+	public function reset_transaction()
480
+	{
481
+		do_action('AHEE__EE_Session__reset_transaction__before_reset', $this);
482
+		$this->_session_data['transaction'] = null;
483
+	}
484
+
485
+
486
+	/**
487
+	 * @return \EE_Transaction
488
+	 */
489
+	public function transaction()
490
+	{
491
+		return isset($this->_session_data['transaction'])
492
+			   && $this->_session_data['transaction'] instanceof EE_Transaction
493
+			? $this->_session_data['transaction']
494
+			: null;
495
+	}
496
+
497
+
498
+	/**
499
+	 * retrieve session data
500
+	 *
501
+	 * @param null $key
502
+	 * @param bool $reset_cache
503
+	 * @return array
504
+	 */
505
+	public function get_session_data($key = null, $reset_cache = false)
506
+	{
507
+		if ($reset_cache) {
508
+			$this->reset_cart();
509
+			$this->reset_checkout();
510
+			$this->reset_transaction();
511
+		}
512
+		if (! empty($key)) {
513
+			return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
514
+		}
515
+		return $this->_session_data;
516
+	}
517
+
518
+
519
+	/**
520
+	 * Returns TRUE on success, FALSE on fail
521
+	 *
522
+	 * @param array $data
523
+	 * @return bool
524
+	 */
525
+	public function set_session_data($data)
526
+	{
527
+		// nothing ??? bad data ??? go home!
528
+		if (empty($data) || ! is_array($data)) {
529
+			EE_Error::add_error(
530
+				esc_html__(
531
+					'No session data or invalid session data was provided.',
532
+					'event_espresso'
533
+				),
534
+				__FILE__,
535
+				__FUNCTION__,
536
+				__LINE__
537
+			);
538
+			return false;
539
+		}
540
+		foreach ($data as $key => $value) {
541
+			if (isset($this->_default_session_vars[ $key ])) {
542
+				EE_Error::add_error(
543
+					sprintf(
544
+						esc_html__(
545
+							'Sorry! %s is a default session datum and can not be reset.',
546
+							'event_espresso'
547
+						),
548
+						$key
549
+					),
550
+					__FILE__,
551
+					__FUNCTION__,
552
+					__LINE__
553
+				);
554
+				return false;
555
+			}
556
+			$this->_session_data[ $key ] = $value;
557
+		}
558
+		return true;
559
+	}
560
+
561
+
562
+	/**
563
+	 * @initiate session
564
+	 * @access   private
565
+	 * @return TRUE on success, FALSE on fail
566
+	 * @throws EE_Error
567
+	 * @throws InvalidArgumentException
568
+	 * @throws InvalidDataTypeException
569
+	 * @throws InvalidInterfaceException
570
+	 * @throws InvalidSessionDataException
571
+	 */
572
+	private function _espresso_session()
573
+	{
574
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
575
+		$this->session_start_handler->startSession();
576
+		$this->status = EE_Session::STATUS_OPEN;
577
+		// get our modified session ID
578
+		$this->_sid = $this->_generate_session_id();
579
+		// and the visitors IP
580
+		$this->_ip_address = $this->request->ipAddress();
581
+		// set the "user agent"
582
+		$this->_user_agent = $this->request->userAgent();
583
+		// now let's retrieve what's in the db
584
+		$session_data = $this->_retrieve_session_data();
585
+		if (! empty($session_data)) {
586
+			// get the current time in UTC
587
+			$this->_time = $this->_time !== null ? $this->_time : time();
588
+			// and reset the session expiration
589
+			$this->_expiration = isset($session_data['expiration'])
590
+				? $session_data['expiration']
591
+				: $this->_time + $this->session_lifespan->inSeconds();
592
+		} else {
593
+			// set initial site access time and the session expiration
594
+			$this->_set_init_access_and_expiration();
595
+			// set referer
596
+			$this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER'])
597
+				? esc_attr($_SERVER['HTTP_REFERER'])
598
+				: '';
599
+			// no previous session = go back and create one (on top of the data above)
600
+			return false;
601
+		}
602
+		// now the user agent
603
+		if ($session_data['user_agent'] !== $this->_user_agent) {
604
+			return false;
605
+		}
606
+		// wait a minute... how old are you?
607
+		if ($this->_time > $this->_expiration) {
608
+			// yer too old fer me!
609
+			$this->_expired = true;
610
+			// wipe out everything that isn't a default session datum
611
+			$this->clear_session(__CLASS__, __FUNCTION__);
612
+		}
613
+		// make event espresso session data available to plugin
614
+		$this->_session_data = array_merge($this->_session_data, $session_data);
615
+		return true;
616
+	}
617
+
618
+
619
+	/**
620
+	 * _get_session_data
621
+	 * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup
622
+	 * databases
623
+	 *
624
+	 * @return array
625
+	 * @throws EE_Error
626
+	 * @throws InvalidArgumentException
627
+	 * @throws InvalidSessionDataException
628
+	 * @throws InvalidDataTypeException
629
+	 * @throws InvalidInterfaceException
630
+	 */
631
+	protected function _retrieve_session_data()
632
+	{
633
+		$ssn_key = EE_Session::session_id_prefix . $this->_sid;
634
+		try {
635
+			// we're using WP's Transient API to store session data using the PHP session ID as the option name
636
+			$session_data = $this->cache_storage->get($ssn_key, false);
637
+			if (empty($session_data)) {
638
+				return array();
639
+			}
640
+			if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
641
+				$hash_check = $this->cache_storage->get(
642
+					EE_Session::hash_check_prefix . $this->_sid,
643
+					false
644
+				);
645
+				if ($hash_check && $hash_check !== md5($session_data)) {
646
+					EE_Error::add_error(
647
+						sprintf(
648
+							__(
649
+								'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
650
+								'event_espresso'
651
+							),
652
+							EE_Session::session_id_prefix . $this->_sid
653
+						),
654
+						__FILE__,
655
+						__FUNCTION__,
656
+						__LINE__
657
+					);
658
+				}
659
+			}
660
+		} catch (Exception $e) {
661
+			// let's just eat that error for now and attempt to correct any corrupted data
662
+			global $wpdb;
663
+			$row = $wpdb->get_row(
664
+				$wpdb->prepare(
665
+					"SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
666
+					'_transient_' . $ssn_key
667
+				)
668
+			);
669
+			$session_data = is_object($row) ? $row->option_value : null;
670
+			if ($session_data) {
671
+				$session_data = preg_replace_callback(
672
+					'!s:(d+):"(.*?)";!',
673
+					function ($match) {
674
+						return $match[1] === strlen($match[2])
675
+							? $match[0]
676
+							: 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
677
+					},
678
+					$session_data
679
+				);
680
+			}
681
+			$session_data = maybe_unserialize($session_data);
682
+		}
683
+		// in case the data is encoded... try to decode it
684
+		$session_data = $this->encryption instanceof EE_Encryption
685
+			? $this->encryption->base64_string_decode($session_data)
686
+			: $session_data;
687
+		if (! is_array($session_data)) {
688
+			try {
689
+				$session_data = maybe_unserialize($session_data);
690
+			} catch (Exception $e) {
691
+				$msg = esc_html__(
692
+					'An error occurred while attempting to unserialize the session data.',
693
+					'event_espresso'
694
+				);
695
+				$msg .= WP_DEBUG
696
+					? '<br><pre>'
697
+					  . print_r($session_data, true)
698
+					  . '</pre><br>'
699
+					  . $this->find_serialize_error($session_data)
700
+					: '';
701
+				$this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
702
+				throw new InvalidSessionDataException($msg, 0, $e);
703
+			}
704
+		}
705
+		// just a check to make sure the session array is indeed an array
706
+		if (! is_array($session_data)) {
707
+			// no?!?! then something is wrong
708
+			$msg = esc_html__(
709
+				'The session data is missing, invalid, or corrupted.',
710
+				'event_espresso'
711
+			);
712
+			$msg .= WP_DEBUG
713
+				? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
714
+				: '';
715
+			$this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
716
+			throw new InvalidSessionDataException($msg);
717
+		}
718
+		if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
719
+			$session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
720
+				$session_data['transaction']
721
+			);
722
+		}
723
+		return $session_data;
724
+	}
725
+
726
+
727
+	/**
728
+	 * _generate_session_id
729
+	 * Retrieves the PHP session id either directly from the PHP session,
730
+	 * or from the $_REQUEST array if it was passed in from an AJAX request.
731
+	 * The session id is then salted and hashed (mmm sounds tasty)
732
+	 * so that it can be safely used as a $_REQUEST param
733
+	 *
734
+	 * @return string
735
+	 */
736
+	protected function _generate_session_id()
737
+	{
738
+		// check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
739
+		if (isset($_REQUEST['EESID'])) {
740
+			$session_id = sanitize_text_field($_REQUEST['EESID']);
741
+		} else {
742
+			$session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
743
+		}
744
+		return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
745
+	}
746
+
747
+
748
+	/**
749
+	 * _get_sid_salt
750
+	 *
751
+	 * @return string
752
+	 */
753
+	protected function _get_sid_salt()
754
+	{
755
+		// was session id salt already saved to db ?
756
+		if (empty($this->_sid_salt)) {
757
+			// no?  then maybe use WP defined constant
758
+			if (defined('AUTH_SALT')) {
759
+				$this->_sid_salt = AUTH_SALT;
760
+			}
761
+			// if salt doesn't exist or is too short
762
+			if (strlen($this->_sid_salt) < 32) {
763
+				// create a new one
764
+				$this->_sid_salt = wp_generate_password(64);
765
+			}
766
+			// and save it as a permanent session setting
767
+			$this->updateSessionSettings(array('sid_salt' => $this->_sid_salt));
768
+		}
769
+		return $this->_sid_salt;
770
+	}
771
+
772
+
773
+	/**
774
+	 * _set_init_access_and_expiration
775
+	 *
776
+	 * @return void
777
+	 */
778
+	protected function _set_init_access_and_expiration()
779
+	{
780
+		$this->_time = time();
781
+		$this->_expiration = $this->_time + $this->session_lifespan->inSeconds();
782
+		// set initial site access time
783
+		$this->_session_data['init_access'] = $this->_time;
784
+		// and the session expiration
785
+		$this->_session_data['expiration'] = $this->_expiration;
786
+	}
787
+
788
+
789
+	/**
790
+	 * @update session data  prior to saving to the db
791
+	 * @access public
792
+	 * @param bool $new_session
793
+	 * @return TRUE on success, FALSE on fail
794
+	 * @throws EE_Error
795
+	 * @throws InvalidArgumentException
796
+	 * @throws InvalidDataTypeException
797
+	 * @throws InvalidInterfaceException
798
+	 */
799
+	public function update($new_session = false)
800
+	{
801
+		$this->_session_data = $this->_session_data !== null
802
+							   && is_array($this->_session_data)
803
+							   && isset($this->_session_data['id'])
804
+			? $this->_session_data
805
+			: array();
806
+		if (empty($this->_session_data)) {
807
+			$this->_set_defaults();
808
+		}
809
+		$session_data = array();
810
+		foreach ($this->_session_data as $key => $value) {
811
+			switch ($key) {
812
+				case 'id':
813
+					// session ID
814
+					$session_data['id'] = $this->_sid;
815
+					break;
816
+				case 'ip_address':
817
+					// visitor ip address
818
+					$session_data['ip_address'] = $this->request->ipAddress();
819
+					break;
820
+				case 'user_agent':
821
+					// visitor user_agent
822
+					$session_data['user_agent'] = $this->_user_agent;
823
+					break;
824
+				case 'init_access':
825
+					$session_data['init_access'] = absint($value);
826
+					break;
827
+				case 'last_access':
828
+					// current access time
829
+					$session_data['last_access'] = $this->_time;
830
+					break;
831
+				case 'expiration':
832
+					// when the session expires
833
+					$session_data['expiration'] = ! empty($this->_expiration)
834
+						? $this->_expiration
835
+						: $session_data['init_access'] + $this->session_lifespan->inSeconds();
836
+					break;
837
+				case 'user_id':
838
+					// current user if logged in
839
+					$session_data['user_id'] = $this->_wp_user_id();
840
+					break;
841
+				case 'pages_visited':
842
+					$page_visit = $this->_get_page_visit();
843
+					if ($page_visit) {
844
+						// set pages visited where the first will be the http referrer
845
+						$this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
846
+						// we'll only save the last 10 page visits.
847
+						$session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
848
+					}
849
+					break;
850
+				default:
851
+					// carry any other data over
852
+					$session_data[ $key ] = $this->_session_data[ $key ];
853
+			}
854
+		}
855
+		$this->_session_data = $session_data;
856
+		// creating a new session does not require saving to the db just yet
857
+		if (! $new_session) {
858
+			// ready? let's save
859
+			if ($this->_save_session_to_db()) {
860
+				return true;
861
+			}
862
+			return false;
863
+		}
864
+		// meh, why not?
865
+		return true;
866
+	}
867
+
868
+
869
+	/**
870
+	 * @create session data array
871
+	 * @access public
872
+	 * @return bool
873
+	 * @throws EE_Error
874
+	 * @throws InvalidArgumentException
875
+	 * @throws InvalidDataTypeException
876
+	 * @throws InvalidInterfaceException
877
+	 */
878
+	private function _create_espresso_session()
879
+	{
880
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
881
+		// use the update function for now with $new_session arg set to TRUE
882
+		return $this->update(true) ? true : false;
883
+	}
884
+
885
+	/**
886
+	 * Detects if there is anything worth saving in the session (eg the cart is a good one, notices are pretty good
887
+	 * too). This is used when determining if we want to save the session or not.
888
+	 * @since 4.9.67.p
889
+	 * @return bool
890
+	 */
891
+	private function sessionHasStuffWorthSaving()
892
+	{
893
+		return $this->cart() instanceof EE_Cart
894
+			|| (
895
+				isset($this->_session_data['ee_notices'])
896
+				&& (
897
+					! empty($this->_session_data['ee_notices']['attention'])
898
+					|| !empty($this->_session_data['ee_notices']['errors'])
899
+					|| !empty($this->_session_data['ee_notices']['success'])
900
+				)
901
+			);
902
+	}
903
+	/**
904
+	 * _save_session_to_db
905
+	 *
906
+	 * @param bool $clear_session
907
+	 * @return string
908
+	 * @throws EE_Error
909
+	 * @throws InvalidArgumentException
910
+	 * @throws InvalidDataTypeException
911
+	 * @throws InvalidInterfaceException
912
+	 */
913
+	private function _save_session_to_db($clear_session = false)
914
+	{
915
+		// don't save sessions for crawlers
916
+		// and unless we're deleting the session data, don't save anything if there isn't a cart
917
+		if ($this->request->isBot()
918
+			|| (
919
+				! $clear_session
920
+				&& ! $this->sessionHasStuffWorthSaving()
921
+				&& apply_filters('FHEE__EE_Session___save_session_to_db__abort_session_save', true)
922
+			)
923
+		) {
924
+			return false;
925
+		}
926
+		$transaction = $this->transaction();
927
+		if ($transaction instanceof EE_Transaction) {
928
+			if (! $transaction->ID()) {
929
+				$transaction->save();
930
+			}
931
+			$this->_session_data['transaction'] = $transaction->ID();
932
+		}
933
+		// then serialize all of our session data
934
+		$session_data = serialize($this->_session_data);
935
+		// do we need to also encode it to avoid corrupted data when saved to the db?
936
+		$session_data = $this->_use_encryption
937
+			? $this->encryption->base64_string_encode($session_data)
938
+			: $session_data;
939
+		// maybe save hash check
940
+		if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
941
+			$this->cache_storage->add(
942
+				EE_Session::hash_check_prefix . $this->_sid,
943
+				md5($session_data),
944
+				$this->session_lifespan->inSeconds()
945
+			);
946
+		}
947
+		// we're using the Transient API for storing session data,
948
+		return $this->cache_storage->add(
949
+			EE_Session::session_id_prefix . $this->_sid,
950
+			$session_data,
951
+			$this->session_lifespan->inSeconds()
952
+		);
953
+	}
954
+
955
+
956
+	/**
957
+	 * @get    the full page request the visitor is accessing
958
+	 * @access public
959
+	 * @return string
960
+	 */
961
+	public function _get_page_visit()
962
+	{
963
+		$page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
964
+		// check for request url
965
+		if (isset($_SERVER['REQUEST_URI'])) {
966
+			$http_host = '';
967
+			$page_id = '?';
968
+			$e_reg = '';
969
+			$request_uri = esc_url($_SERVER['REQUEST_URI']);
970
+			$ru_bits = explode('?', $request_uri);
971
+			$request_uri = $ru_bits[0];
972
+			// check for and grab host as well
973
+			if (isset($_SERVER['HTTP_HOST'])) {
974
+				$http_host = esc_url($_SERVER['HTTP_HOST']);
975
+			}
976
+			// check for page_id in SERVER REQUEST
977
+			if (isset($_REQUEST['page_id'])) {
978
+				// rebuild $e_reg without any of the extra parameters
979
+				$page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&amp;';
980
+			}
981
+			// check for $e_reg in SERVER REQUEST
982
+			if (isset($_REQUEST['ee'])) {
983
+				// rebuild $e_reg without any of the extra parameters
984
+				$e_reg = 'ee=' . esc_attr($_REQUEST['ee']);
985
+			}
986
+			$page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?');
987
+		}
988
+		return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
989
+	}
990
+
991
+
992
+	/**
993
+	 * @the    current wp user id
994
+	 * @access public
995
+	 * @return int
996
+	 */
997
+	public function _wp_user_id()
998
+	{
999
+		// if I need to explain the following lines of code, then you shouldn't be looking at this!
1000
+		$this->_wp_user_id = get_current_user_id();
1001
+		return $this->_wp_user_id;
1002
+	}
1003
+
1004
+
1005
+	/**
1006
+	 * Clear EE_Session data
1007
+	 *
1008
+	 * @access public
1009
+	 * @param string $class
1010
+	 * @param string $function
1011
+	 * @return void
1012
+	 * @throws EE_Error
1013
+	 * @throws InvalidArgumentException
1014
+	 * @throws InvalidDataTypeException
1015
+	 * @throws InvalidInterfaceException
1016
+	 */
1017
+	public function clear_session($class = '', $function = '')
1018
+	{
1019 1019
 //         echo '
1020 1020
 // <h3 style="color:#999;line-height:.9em;">
1021 1021
 // <span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/>
1022 1022
 // <span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b>
1023 1023
 // </h3>';
1024
-        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
1025
-        $this->reset_cart();
1026
-        $this->reset_checkout();
1027
-        $this->reset_transaction();
1028
-        // wipe out everything that isn't a default session datum
1029
-        $this->reset_data(array_keys($this->_session_data));
1030
-        // reset initial site access time and the session expiration
1031
-        $this->_set_init_access_and_expiration();
1032
-        $this->_save_session_to_db(true);
1033
-    }
1034
-
1035
-
1036
-    /**
1037
-     * resets all non-default session vars. Returns TRUE on success, FALSE on fail
1038
-     *
1039
-     * @param array|mixed $data_to_reset
1040
-     * @param bool        $show_all_notices
1041
-     * @return bool
1042
-     */
1043
-    public function reset_data($data_to_reset = array(), $show_all_notices = false)
1044
-    {
1045
-        // if $data_to_reset is not in an array, then put it in one
1046
-        if (! is_array($data_to_reset)) {
1047
-            $data_to_reset = array($data_to_reset);
1048
-        }
1049
-        // nothing ??? go home!
1050
-        if (empty($data_to_reset)) {
1051
-            EE_Error::add_error(
1052
-                __(
1053
-                    'No session data could be reset, because no session var name was provided.',
1054
-                    'event_espresso'
1055
-                ),
1056
-                __FILE__,
1057
-                __FUNCTION__,
1058
-                __LINE__
1059
-            );
1060
-            return false;
1061
-        }
1062
-        $return_value = true;
1063
-        // since $data_to_reset is an array, cycle through the values
1064
-        foreach ($data_to_reset as $reset) {
1065
-            // first check to make sure it is a valid session var
1066
-            if (isset($this->_session_data[ $reset ])) {
1067
-                // then check to make sure it is not a default var
1068
-                if (! array_key_exists($reset, $this->_default_session_vars)) {
1069
-                    // remove session var
1070
-                    unset($this->_session_data[ $reset ]);
1071
-                    if ($show_all_notices) {
1072
-                        EE_Error::add_success(
1073
-                            sprintf(
1074
-                                __('The session variable %s was removed.', 'event_espresso'),
1075
-                                $reset
1076
-                            ),
1077
-                            __FILE__,
1078
-                            __FUNCTION__,
1079
-                            __LINE__
1080
-                        );
1081
-                    }
1082
-                } else {
1083
-                    // yeeeeeeeeerrrrrrrrrrr OUT !!!!
1084
-                    if ($show_all_notices) {
1085
-                        EE_Error::add_error(
1086
-                            sprintf(
1087
-                                __(
1088
-                                    'Sorry! %s is a default session datum and can not be reset.',
1089
-                                    'event_espresso'
1090
-                                ),
1091
-                                $reset
1092
-                            ),
1093
-                            __FILE__,
1094
-                            __FUNCTION__,
1095
-                            __LINE__
1096
-                        );
1097
-                    }
1098
-                    $return_value = false;
1099
-                }
1100
-            } elseif ($show_all_notices) {
1101
-                // oops! that session var does not exist!
1102
-                EE_Error::add_error(
1103
-                    sprintf(
1104
-                        __(
1105
-                            'The session item provided, %s, is invalid or does not exist.',
1106
-                            'event_espresso'
1107
-                        ),
1108
-                        $reset
1109
-                    ),
1110
-                    __FILE__,
1111
-                    __FUNCTION__,
1112
-                    __LINE__
1113
-                );
1114
-                $return_value = false;
1115
-            }
1116
-        } // end of foreach
1117
-        return $return_value;
1118
-    }
1119
-
1120
-
1121
-    /**
1122
-     *   wp_loaded
1123
-     *
1124
-     * @access public
1125
-     * @throws EE_Error
1126
-     * @throws InvalidDataTypeException
1127
-     * @throws InvalidInterfaceException
1128
-     * @throws InvalidArgumentException
1129
-     */
1130
-    public function wp_loaded()
1131
-    {
1132
-        if ($this->request->requestParamIsSet('clear_session')) {
1133
-            $this->clear_session(__CLASS__, __FUNCTION__);
1134
-        }
1135
-    }
1136
-
1137
-
1138
-    /**
1139
-     * Used to reset the entire object (for tests).
1140
-     *
1141
-     * @since 4.3.0
1142
-     * @throws EE_Error
1143
-     * @throws InvalidDataTypeException
1144
-     * @throws InvalidInterfaceException
1145
-     * @throws InvalidArgumentException
1146
-     */
1147
-    public function reset_instance()
1148
-    {
1149
-        $this->clear_session();
1150
-        self::$_instance = null;
1151
-    }
1152
-
1153
-
1154
-    public function configure_garbage_collection_filters()
1155
-    {
1156
-        // run old filter we had for controlling session cleanup
1157
-        $expired_session_transient_delete_query_limit = absint(
1158
-            apply_filters(
1159
-                'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1160
-                50
1161
-            )
1162
-        );
1163
-        // is there a value? or one that is different than the default 50 records?
1164
-        if ($expired_session_transient_delete_query_limit === 0) {
1165
-            // hook into TransientCacheStorage in case Session cleanup was turned off
1166
-            add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero');
1167
-        } elseif ($expired_session_transient_delete_query_limit !== 50) {
1168
-            // or use that for the new transient cleanup query limit
1169
-            add_filter(
1170
-                'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1171
-                function () use ($expired_session_transient_delete_query_limit) {
1172
-                    return $expired_session_transient_delete_query_limit;
1173
-                }
1174
-            );
1175
-        }
1176
-    }
1177
-
1178
-
1179
-    /**
1180
-     * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996
1181
-     * @param $data1
1182
-     * @return string
1183
-     */
1184
-    private function find_serialize_error($data1)
1185
-    {
1186
-        $error = '<pre>';
1187
-        $data2 = preg_replace_callback(
1188
-            '!s:(\d+):"(.*?)";!',
1189
-            function ($match) {
1190
-                return ($match[1] === strlen($match[2]))
1191
-                    ? $match[0]
1192
-                    : 's:'
1193
-                      . strlen($match[2])
1194
-                      . ':"'
1195
-                      . $match[2]
1196
-                      . '";';
1197
-            },
1198
-            $data1
1199
-        );
1200
-        $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1201
-        $error .= $data1 . PHP_EOL;
1202
-        $error .= $data2 . PHP_EOL;
1203
-        for ($i = 0; $i < $max; $i++) {
1204
-            if (@$data1[ $i ] !== @$data2[ $i ]) {
1205
-                $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1206
-                $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1207
-                $error .= "\t-> Line Number = $i" . PHP_EOL;
1208
-                $start = ($i - 20);
1209
-                $start = ($start < 0) ? 0 : $start;
1210
-                $length = 40;
1211
-                $point = $max - $i;
1212
-                if ($point < 20) {
1213
-                    $rlength = 1;
1214
-                    $rpoint = -$point;
1215
-                } else {
1216
-                    $rpoint = $length - 20;
1217
-                    $rlength = 1;
1218
-                }
1219
-                $error .= "\t-> Section Data1  = ";
1220
-                $error .= substr_replace(
1221
-                    substr($data1, $start, $length),
1222
-                    "<b style=\"color:green\">{$data1[ $i ]}</b>",
1223
-                    $rpoint,
1224
-                    $rlength
1225
-                );
1226
-                $error .= PHP_EOL;
1227
-                $error .= "\t-> Section Data2  = ";
1228
-                $error .= substr_replace(
1229
-                    substr($data2, $start, $length),
1230
-                    "<b style=\"color:red\">{$data2[ $i ]}</b>",
1231
-                    $rpoint,
1232
-                    $rlength
1233
-                );
1234
-                $error .= PHP_EOL;
1235
-            }
1236
-        }
1237
-        $error .= '</pre>';
1238
-        return $error;
1239
-    }
1240
-
1241
-
1242
-    /**
1243
-     * Saves an  array of settings used for configuring aspects of session behaviour
1244
-     *
1245
-     * @param array $updated_settings
1246
-     */
1247
-    private function updateSessionSettings(array $updated_settings = array())
1248
-    {
1249
-        // add existing settings, but only if not included in incoming $updated_settings array
1250
-        $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array());
1251
-        update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings);
1252
-    }
1253
-
1254
-
1255
-    /**
1256
-     * garbage_collection
1257
-     */
1258
-    public function garbageCollection()
1259
-    {
1260
-        // only perform during regular requests if last garbage collection was over an hour ago
1261
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1262
-            $this->_last_gc = time();
1263
-            $this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1264
-            /** @type WPDB $wpdb */
1265
-            global $wpdb;
1266
-            // filter the query limit. Set to 0 to turn off garbage collection
1267
-            $expired_session_transient_delete_query_limit = absint(
1268
-                apply_filters(
1269
-                    'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1270
-                    50
1271
-                )
1272
-            );
1273
-            // non-zero LIMIT means take out the trash
1274
-            if ($expired_session_transient_delete_query_limit) {
1275
-                $session_key = str_replace('_', '\_', EE_Session::session_id_prefix);
1276
-                $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix);
1277
-                // since transient expiration timestamps are set in the future, we can compare against NOW
1278
-                // but we only want to pick up any trash that's been around for more than a day
1279
-                $expiration = time() - DAY_IN_SECONDS;
1280
-                $SQL = "
1024
+		do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
1025
+		$this->reset_cart();
1026
+		$this->reset_checkout();
1027
+		$this->reset_transaction();
1028
+		// wipe out everything that isn't a default session datum
1029
+		$this->reset_data(array_keys($this->_session_data));
1030
+		// reset initial site access time and the session expiration
1031
+		$this->_set_init_access_and_expiration();
1032
+		$this->_save_session_to_db(true);
1033
+	}
1034
+
1035
+
1036
+	/**
1037
+	 * resets all non-default session vars. Returns TRUE on success, FALSE on fail
1038
+	 *
1039
+	 * @param array|mixed $data_to_reset
1040
+	 * @param bool        $show_all_notices
1041
+	 * @return bool
1042
+	 */
1043
+	public function reset_data($data_to_reset = array(), $show_all_notices = false)
1044
+	{
1045
+		// if $data_to_reset is not in an array, then put it in one
1046
+		if (! is_array($data_to_reset)) {
1047
+			$data_to_reset = array($data_to_reset);
1048
+		}
1049
+		// nothing ??? go home!
1050
+		if (empty($data_to_reset)) {
1051
+			EE_Error::add_error(
1052
+				__(
1053
+					'No session data could be reset, because no session var name was provided.',
1054
+					'event_espresso'
1055
+				),
1056
+				__FILE__,
1057
+				__FUNCTION__,
1058
+				__LINE__
1059
+			);
1060
+			return false;
1061
+		}
1062
+		$return_value = true;
1063
+		// since $data_to_reset is an array, cycle through the values
1064
+		foreach ($data_to_reset as $reset) {
1065
+			// first check to make sure it is a valid session var
1066
+			if (isset($this->_session_data[ $reset ])) {
1067
+				// then check to make sure it is not a default var
1068
+				if (! array_key_exists($reset, $this->_default_session_vars)) {
1069
+					// remove session var
1070
+					unset($this->_session_data[ $reset ]);
1071
+					if ($show_all_notices) {
1072
+						EE_Error::add_success(
1073
+							sprintf(
1074
+								__('The session variable %s was removed.', 'event_espresso'),
1075
+								$reset
1076
+							),
1077
+							__FILE__,
1078
+							__FUNCTION__,
1079
+							__LINE__
1080
+						);
1081
+					}
1082
+				} else {
1083
+					// yeeeeeeeeerrrrrrrrrrr OUT !!!!
1084
+					if ($show_all_notices) {
1085
+						EE_Error::add_error(
1086
+							sprintf(
1087
+								__(
1088
+									'Sorry! %s is a default session datum and can not be reset.',
1089
+									'event_espresso'
1090
+								),
1091
+								$reset
1092
+							),
1093
+							__FILE__,
1094
+							__FUNCTION__,
1095
+							__LINE__
1096
+						);
1097
+					}
1098
+					$return_value = false;
1099
+				}
1100
+			} elseif ($show_all_notices) {
1101
+				// oops! that session var does not exist!
1102
+				EE_Error::add_error(
1103
+					sprintf(
1104
+						__(
1105
+							'The session item provided, %s, is invalid or does not exist.',
1106
+							'event_espresso'
1107
+						),
1108
+						$reset
1109
+					),
1110
+					__FILE__,
1111
+					__FUNCTION__,
1112
+					__LINE__
1113
+				);
1114
+				$return_value = false;
1115
+			}
1116
+		} // end of foreach
1117
+		return $return_value;
1118
+	}
1119
+
1120
+
1121
+	/**
1122
+	 *   wp_loaded
1123
+	 *
1124
+	 * @access public
1125
+	 * @throws EE_Error
1126
+	 * @throws InvalidDataTypeException
1127
+	 * @throws InvalidInterfaceException
1128
+	 * @throws InvalidArgumentException
1129
+	 */
1130
+	public function wp_loaded()
1131
+	{
1132
+		if ($this->request->requestParamIsSet('clear_session')) {
1133
+			$this->clear_session(__CLASS__, __FUNCTION__);
1134
+		}
1135
+	}
1136
+
1137
+
1138
+	/**
1139
+	 * Used to reset the entire object (for tests).
1140
+	 *
1141
+	 * @since 4.3.0
1142
+	 * @throws EE_Error
1143
+	 * @throws InvalidDataTypeException
1144
+	 * @throws InvalidInterfaceException
1145
+	 * @throws InvalidArgumentException
1146
+	 */
1147
+	public function reset_instance()
1148
+	{
1149
+		$this->clear_session();
1150
+		self::$_instance = null;
1151
+	}
1152
+
1153
+
1154
+	public function configure_garbage_collection_filters()
1155
+	{
1156
+		// run old filter we had for controlling session cleanup
1157
+		$expired_session_transient_delete_query_limit = absint(
1158
+			apply_filters(
1159
+				'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1160
+				50
1161
+			)
1162
+		);
1163
+		// is there a value? or one that is different than the default 50 records?
1164
+		if ($expired_session_transient_delete_query_limit === 0) {
1165
+			// hook into TransientCacheStorage in case Session cleanup was turned off
1166
+			add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero');
1167
+		} elseif ($expired_session_transient_delete_query_limit !== 50) {
1168
+			// or use that for the new transient cleanup query limit
1169
+			add_filter(
1170
+				'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1171
+				function () use ($expired_session_transient_delete_query_limit) {
1172
+					return $expired_session_transient_delete_query_limit;
1173
+				}
1174
+			);
1175
+		}
1176
+	}
1177
+
1178
+
1179
+	/**
1180
+	 * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996
1181
+	 * @param $data1
1182
+	 * @return string
1183
+	 */
1184
+	private function find_serialize_error($data1)
1185
+	{
1186
+		$error = '<pre>';
1187
+		$data2 = preg_replace_callback(
1188
+			'!s:(\d+):"(.*?)";!',
1189
+			function ($match) {
1190
+				return ($match[1] === strlen($match[2]))
1191
+					? $match[0]
1192
+					: 's:'
1193
+					  . strlen($match[2])
1194
+					  . ':"'
1195
+					  . $match[2]
1196
+					  . '";';
1197
+			},
1198
+			$data1
1199
+		);
1200
+		$max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1201
+		$error .= $data1 . PHP_EOL;
1202
+		$error .= $data2 . PHP_EOL;
1203
+		for ($i = 0; $i < $max; $i++) {
1204
+			if (@$data1[ $i ] !== @$data2[ $i ]) {
1205
+				$error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1206
+				$error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1207
+				$error .= "\t-> Line Number = $i" . PHP_EOL;
1208
+				$start = ($i - 20);
1209
+				$start = ($start < 0) ? 0 : $start;
1210
+				$length = 40;
1211
+				$point = $max - $i;
1212
+				if ($point < 20) {
1213
+					$rlength = 1;
1214
+					$rpoint = -$point;
1215
+				} else {
1216
+					$rpoint = $length - 20;
1217
+					$rlength = 1;
1218
+				}
1219
+				$error .= "\t-> Section Data1  = ";
1220
+				$error .= substr_replace(
1221
+					substr($data1, $start, $length),
1222
+					"<b style=\"color:green\">{$data1[ $i ]}</b>",
1223
+					$rpoint,
1224
+					$rlength
1225
+				);
1226
+				$error .= PHP_EOL;
1227
+				$error .= "\t-> Section Data2  = ";
1228
+				$error .= substr_replace(
1229
+					substr($data2, $start, $length),
1230
+					"<b style=\"color:red\">{$data2[ $i ]}</b>",
1231
+					$rpoint,
1232
+					$rlength
1233
+				);
1234
+				$error .= PHP_EOL;
1235
+			}
1236
+		}
1237
+		$error .= '</pre>';
1238
+		return $error;
1239
+	}
1240
+
1241
+
1242
+	/**
1243
+	 * Saves an  array of settings used for configuring aspects of session behaviour
1244
+	 *
1245
+	 * @param array $updated_settings
1246
+	 */
1247
+	private function updateSessionSettings(array $updated_settings = array())
1248
+	{
1249
+		// add existing settings, but only if not included in incoming $updated_settings array
1250
+		$updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array());
1251
+		update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings);
1252
+	}
1253
+
1254
+
1255
+	/**
1256
+	 * garbage_collection
1257
+	 */
1258
+	public function garbageCollection()
1259
+	{
1260
+		// only perform during regular requests if last garbage collection was over an hour ago
1261
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1262
+			$this->_last_gc = time();
1263
+			$this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1264
+			/** @type WPDB $wpdb */
1265
+			global $wpdb;
1266
+			// filter the query limit. Set to 0 to turn off garbage collection
1267
+			$expired_session_transient_delete_query_limit = absint(
1268
+				apply_filters(
1269
+					'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1270
+					50
1271
+				)
1272
+			);
1273
+			// non-zero LIMIT means take out the trash
1274
+			if ($expired_session_transient_delete_query_limit) {
1275
+				$session_key = str_replace('_', '\_', EE_Session::session_id_prefix);
1276
+				$hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix);
1277
+				// since transient expiration timestamps are set in the future, we can compare against NOW
1278
+				// but we only want to pick up any trash that's been around for more than a day
1279
+				$expiration = time() - DAY_IN_SECONDS;
1280
+				$SQL = "
1281 1281
                     SELECT option_name
1282 1282
                     FROM {$wpdb->options}
1283 1283
                     WHERE
@@ -1286,17 +1286,17 @@  discard block
 block discarded – undo
1286 1286
                     AND option_value < {$expiration}
1287 1287
                     LIMIT {$expired_session_transient_delete_query_limit}
1288 1288
                 ";
1289
-                // produces something like:
1290
-                // SELECT option_name FROM wp_options
1291
-                // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%'
1292
-                // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' )
1293
-                // AND option_value < 1508368198 LIMIT 50
1294
-                $expired_sessions = $wpdb->get_col($SQL);
1295
-                // valid results?
1296
-                if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1297
-                    $this->cache_storage->deleteMany($expired_sessions, true);
1298
-                }
1299
-            }
1300
-        }
1301
-    }
1289
+				// produces something like:
1290
+				// SELECT option_name FROM wp_options
1291
+				// WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%'
1292
+				// OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' )
1293
+				// AND option_value < 1508368198 LIMIT 50
1294
+				$expired_sessions = $wpdb->get_col($SQL);
1295
+				// valid results?
1296
+				if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1297
+					$this->cache_storage->deleteMany($expired_sessions, true);
1298
+				}
1299
+			}
1300
+		}
1301
+	}
1302 1302
 }
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
         // check if class object is instantiated
194 194
         // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
195 195
         // add_filter( 'FHEE_load_EE_Session', '__return_false' );
196
-        if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
196
+        if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
197 197
             self::$_instance = new self(
198 198
                 $cache_storage,
199 199
                 $lifespan,
@@ -229,22 +229,22 @@  discard block
 block discarded – undo
229 229
         // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook
230 230
         // (which currently fires on the init hook at priority 9),
231 231
         // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
232
-        if (! apply_filters('FHEE_load_EE_Session', true)) {
232
+        if ( ! apply_filters('FHEE_load_EE_Session', true)) {
233 233
             return;
234 234
         }
235 235
         $this->session_start_handler = $session_start_handler;
236 236
         $this->session_lifespan = $lifespan;
237 237
         $this->request = $request;
238
-        if (! defined('ESPRESSO_SESSION')) {
238
+        if ( ! defined('ESPRESSO_SESSION')) {
239 239
             define('ESPRESSO_SESSION', true);
240 240
         }
241 241
         // retrieve session options from db
242 242
         $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
243
-        if (! empty($session_settings)) {
243
+        if ( ! empty($session_settings)) {
244 244
             // cycle though existing session options
245 245
             foreach ($session_settings as $var_name => $session_setting) {
246 246
                 // set values for class properties
247
-                $var_name = '_' . $var_name;
247
+                $var_name = '_'.$var_name;
248 248
                 $this->{$var_name} = $session_setting;
249 249
             }
250 250
         }
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
     public function open_session()
304 304
     {
305 305
         // check for existing session and retrieve it from db
306
-        if (! $this->_espresso_session()) {
306
+        if ( ! $this->_espresso_session()) {
307 307
             // or just start a new one
308 308
             $this->_create_espresso_session();
309 309
         }
@@ -376,9 +376,9 @@  discard block
 block discarded – undo
376 376
         // set some defaults
377 377
         foreach ($this->_default_session_vars as $key => $default_var) {
378 378
             if (is_array($default_var)) {
379
-                $this->_session_data[ $key ] = array();
379
+                $this->_session_data[$key] = array();
380 380
             } else {
381
-                $this->_session_data[ $key ] = '';
381
+                $this->_session_data[$key] = '';
382 382
             }
383 383
         }
384 384
     }
@@ -509,8 +509,8 @@  discard block
 block discarded – undo
509 509
             $this->reset_checkout();
510 510
             $this->reset_transaction();
511 511
         }
512
-        if (! empty($key)) {
513
-            return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
512
+        if ( ! empty($key)) {
513
+            return isset($this->_session_data[$key]) ? $this->_session_data[$key] : null;
514 514
         }
515 515
         return $this->_session_data;
516 516
     }
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
             return false;
539 539
         }
540 540
         foreach ($data as $key => $value) {
541
-            if (isset($this->_default_session_vars[ $key ])) {
541
+            if (isset($this->_default_session_vars[$key])) {
542 542
                 EE_Error::add_error(
543 543
                     sprintf(
544 544
                         esc_html__(
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
                 );
554 554
                 return false;
555 555
             }
556
-            $this->_session_data[ $key ] = $value;
556
+            $this->_session_data[$key] = $value;
557 557
         }
558 558
         return true;
559 559
     }
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
         $this->_user_agent = $this->request->userAgent();
583 583
         // now let's retrieve what's in the db
584 584
         $session_data = $this->_retrieve_session_data();
585
-        if (! empty($session_data)) {
585
+        if ( ! empty($session_data)) {
586 586
             // get the current time in UTC
587 587
             $this->_time = $this->_time !== null ? $this->_time : time();
588 588
             // and reset the session expiration
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
             // set initial site access time and the session expiration
594 594
             $this->_set_init_access_and_expiration();
595 595
             // set referer
596
-            $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER'])
596
+            $this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER'])
597 597
                 ? esc_attr($_SERVER['HTTP_REFERER'])
598 598
                 : '';
599 599
             // no previous session = go back and create one (on top of the data above)
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
      */
631 631
     protected function _retrieve_session_data()
632 632
     {
633
-        $ssn_key = EE_Session::session_id_prefix . $this->_sid;
633
+        $ssn_key = EE_Session::session_id_prefix.$this->_sid;
634 634
         try {
635 635
             // we're using WP's Transient API to store session data using the PHP session ID as the option name
636 636
             $session_data = $this->cache_storage->get($ssn_key, false);
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
             }
640 640
             if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
641 641
                 $hash_check = $this->cache_storage->get(
642
-                    EE_Session::hash_check_prefix . $this->_sid,
642
+                    EE_Session::hash_check_prefix.$this->_sid,
643 643
                     false
644 644
                 );
645 645
                 if ($hash_check && $hash_check !== md5($session_data)) {
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
                                 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
650 650
                                 'event_espresso'
651 651
                             ),
652
-                            EE_Session::session_id_prefix . $this->_sid
652
+                            EE_Session::session_id_prefix.$this->_sid
653 653
                         ),
654 654
                         __FILE__,
655 655
                         __FUNCTION__,
@@ -663,17 +663,17 @@  discard block
 block discarded – undo
663 663
             $row = $wpdb->get_row(
664 664
                 $wpdb->prepare(
665 665
                     "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
666
-                    '_transient_' . $ssn_key
666
+                    '_transient_'.$ssn_key
667 667
                 )
668 668
             );
669 669
             $session_data = is_object($row) ? $row->option_value : null;
670 670
             if ($session_data) {
671 671
                 $session_data = preg_replace_callback(
672 672
                     '!s:(d+):"(.*?)";!',
673
-                    function ($match) {
673
+                    function($match) {
674 674
                         return $match[1] === strlen($match[2])
675 675
                             ? $match[0]
676
-                            : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
676
+                            : 's:'.strlen($match[2]).':"'.$match[2].'";';
677 677
                     },
678 678
                     $session_data
679 679
                 );
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
         $session_data = $this->encryption instanceof EE_Encryption
685 685
             ? $this->encryption->base64_string_decode($session_data)
686 686
             : $session_data;
687
-        if (! is_array($session_data)) {
687
+        if ( ! is_array($session_data)) {
688 688
             try {
689 689
                 $session_data = maybe_unserialize($session_data);
690 690
             } catch (Exception $e) {
@@ -698,21 +698,21 @@  discard block
 block discarded – undo
698 698
                       . '</pre><br>'
699 699
                       . $this->find_serialize_error($session_data)
700 700
                     : '';
701
-                $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
701
+                $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid);
702 702
                 throw new InvalidSessionDataException($msg, 0, $e);
703 703
             }
704 704
         }
705 705
         // just a check to make sure the session array is indeed an array
706
-        if (! is_array($session_data)) {
706
+        if ( ! is_array($session_data)) {
707 707
             // no?!?! then something is wrong
708 708
             $msg = esc_html__(
709 709
                 'The session data is missing, invalid, or corrupted.',
710 710
                 'event_espresso'
711 711
             );
712 712
             $msg .= WP_DEBUG
713
-                ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
713
+                ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data)
714 714
                 : '';
715
-            $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
715
+            $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid);
716 716
             throw new InvalidSessionDataException($msg);
717 717
         }
718 718
         if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
         if (isset($_REQUEST['EESID'])) {
740 740
             $session_id = sanitize_text_field($_REQUEST['EESID']);
741 741
         } else {
742
-            $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
742
+            $session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt());
743 743
         }
744 744
         return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
745 745
     }
@@ -842,19 +842,19 @@  discard block
 block discarded – undo
842 842
                     $page_visit = $this->_get_page_visit();
843 843
                     if ($page_visit) {
844 844
                         // set pages visited where the first will be the http referrer
845
-                        $this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
845
+                        $this->_session_data['pages_visited'][$this->_time] = $page_visit;
846 846
                         // we'll only save the last 10 page visits.
847 847
                         $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
848 848
                     }
849 849
                     break;
850 850
                 default:
851 851
                     // carry any other data over
852
-                    $session_data[ $key ] = $this->_session_data[ $key ];
852
+                    $session_data[$key] = $this->_session_data[$key];
853 853
             }
854 854
         }
855 855
         $this->_session_data = $session_data;
856 856
         // creating a new session does not require saving to the db just yet
857
-        if (! $new_session) {
857
+        if ( ! $new_session) {
858 858
             // ready? let's save
859 859
             if ($this->_save_session_to_db()) {
860 860
                 return true;
@@ -895,8 +895,8 @@  discard block
 block discarded – undo
895 895
                 isset($this->_session_data['ee_notices'])
896 896
                 && (
897 897
                     ! empty($this->_session_data['ee_notices']['attention'])
898
-                    || !empty($this->_session_data['ee_notices']['errors'])
899
-                    || !empty($this->_session_data['ee_notices']['success'])
898
+                    || ! empty($this->_session_data['ee_notices']['errors'])
899
+                    || ! empty($this->_session_data['ee_notices']['success'])
900 900
                 )
901 901
             );
902 902
     }
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
         }
926 926
         $transaction = $this->transaction();
927 927
         if ($transaction instanceof EE_Transaction) {
928
-            if (! $transaction->ID()) {
928
+            if ( ! $transaction->ID()) {
929 929
                 $transaction->save();
930 930
             }
931 931
             $this->_session_data['transaction'] = $transaction->ID();
@@ -939,14 +939,14 @@  discard block
 block discarded – undo
939 939
         // maybe save hash check
940 940
         if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
941 941
             $this->cache_storage->add(
942
-                EE_Session::hash_check_prefix . $this->_sid,
942
+                EE_Session::hash_check_prefix.$this->_sid,
943 943
                 md5($session_data),
944 944
                 $this->session_lifespan->inSeconds()
945 945
             );
946 946
         }
947 947
         // we're using the Transient API for storing session data,
948 948
         return $this->cache_storage->add(
949
-            EE_Session::session_id_prefix . $this->_sid,
949
+            EE_Session::session_id_prefix.$this->_sid,
950 950
             $session_data,
951 951
             $this->session_lifespan->inSeconds()
952 952
         );
@@ -960,7 +960,7 @@  discard block
 block discarded – undo
960 960
      */
961 961
     public function _get_page_visit()
962 962
     {
963
-        $page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
963
+        $page_visit = home_url('/').'wp-admin/admin-ajax.php';
964 964
         // check for request url
965 965
         if (isset($_SERVER['REQUEST_URI'])) {
966 966
             $http_host = '';
@@ -976,14 +976,14 @@  discard block
 block discarded – undo
976 976
             // check for page_id in SERVER REQUEST
977 977
             if (isset($_REQUEST['page_id'])) {
978 978
                 // rebuild $e_reg without any of the extra parameters
979
-                $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&amp;';
979
+                $page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&amp;';
980 980
             }
981 981
             // check for $e_reg in SERVER REQUEST
982 982
             if (isset($_REQUEST['ee'])) {
983 983
                 // rebuild $e_reg without any of the extra parameters
984
-                $e_reg = 'ee=' . esc_attr($_REQUEST['ee']);
984
+                $e_reg = 'ee='.esc_attr($_REQUEST['ee']);
985 985
             }
986
-            $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?');
986
+            $page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?');
987 987
         }
988 988
         return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
989 989
     }
@@ -1021,7 +1021,7 @@  discard block
 block discarded – undo
1021 1021
 // <span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/>
1022 1022
 // <span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b>
1023 1023
 // </h3>';
1024
-        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
1024
+        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()');
1025 1025
         $this->reset_cart();
1026 1026
         $this->reset_checkout();
1027 1027
         $this->reset_transaction();
@@ -1043,7 +1043,7 @@  discard block
 block discarded – undo
1043 1043
     public function reset_data($data_to_reset = array(), $show_all_notices = false)
1044 1044
     {
1045 1045
         // if $data_to_reset is not in an array, then put it in one
1046
-        if (! is_array($data_to_reset)) {
1046
+        if ( ! is_array($data_to_reset)) {
1047 1047
             $data_to_reset = array($data_to_reset);
1048 1048
         }
1049 1049
         // nothing ??? go home!
@@ -1063,11 +1063,11 @@  discard block
 block discarded – undo
1063 1063
         // since $data_to_reset is an array, cycle through the values
1064 1064
         foreach ($data_to_reset as $reset) {
1065 1065
             // first check to make sure it is a valid session var
1066
-            if (isset($this->_session_data[ $reset ])) {
1066
+            if (isset($this->_session_data[$reset])) {
1067 1067
                 // then check to make sure it is not a default var
1068
-                if (! array_key_exists($reset, $this->_default_session_vars)) {
1068
+                if ( ! array_key_exists($reset, $this->_default_session_vars)) {
1069 1069
                     // remove session var
1070
-                    unset($this->_session_data[ $reset ]);
1070
+                    unset($this->_session_data[$reset]);
1071 1071
                     if ($show_all_notices) {
1072 1072
                         EE_Error::add_success(
1073 1073
                             sprintf(
@@ -1168,7 +1168,7 @@  discard block
 block discarded – undo
1168 1168
             // or use that for the new transient cleanup query limit
1169 1169
             add_filter(
1170 1170
                 'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1171
-                function () use ($expired_session_transient_delete_query_limit) {
1171
+                function() use ($expired_session_transient_delete_query_limit) {
1172 1172
                     return $expired_session_transient_delete_query_limit;
1173 1173
                 }
1174 1174
             );
@@ -1186,7 +1186,7 @@  discard block
 block discarded – undo
1186 1186
         $error = '<pre>';
1187 1187
         $data2 = preg_replace_callback(
1188 1188
             '!s:(\d+):"(.*?)";!',
1189
-            function ($match) {
1189
+            function($match) {
1190 1190
                 return ($match[1] === strlen($match[2]))
1191 1191
                     ? $match[0]
1192 1192
                     : 's:'
@@ -1198,13 +1198,13 @@  discard block
 block discarded – undo
1198 1198
             $data1
1199 1199
         );
1200 1200
         $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1201
-        $error .= $data1 . PHP_EOL;
1202
-        $error .= $data2 . PHP_EOL;
1201
+        $error .= $data1.PHP_EOL;
1202
+        $error .= $data2.PHP_EOL;
1203 1203
         for ($i = 0; $i < $max; $i++) {
1204
-            if (@$data1[ $i ] !== @$data2[ $i ]) {
1205
-                $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1206
-                $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1207
-                $error .= "\t-> Line Number = $i" . PHP_EOL;
1204
+            if (@$data1[$i] !== @$data2[$i]) {
1205
+                $error .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL;
1206
+                $error .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL;
1207
+                $error .= "\t-> Line Number = $i".PHP_EOL;
1208 1208
                 $start = ($i - 20);
1209 1209
                 $start = ($start < 0) ? 0 : $start;
1210 1210
                 $length = 40;
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
                 $error .= "\t-> Section Data1  = ";
1220 1220
                 $error .= substr_replace(
1221 1221
                     substr($data1, $start, $length),
1222
-                    "<b style=\"color:green\">{$data1[ $i ]}</b>",
1222
+                    "<b style=\"color:green\">{$data1[$i]}</b>",
1223 1223
                     $rpoint,
1224 1224
                     $rlength
1225 1225
                 );
@@ -1227,7 +1227,7 @@  discard block
 block discarded – undo
1227 1227
                 $error .= "\t-> Section Data2  = ";
1228 1228
                 $error .= substr_replace(
1229 1229
                     substr($data2, $start, $length),
1230
-                    "<b style=\"color:red\">{$data2[ $i ]}</b>",
1230
+                    "<b style=\"color:red\">{$data2[$i]}</b>",
1231 1231
                     $rpoint,
1232 1232
                     $rlength
1233 1233
                 );
@@ -1258,7 +1258,7 @@  discard block
 block discarded – undo
1258 1258
     public function garbageCollection()
1259 1259
     {
1260 1260
         // only perform during regular requests if last garbage collection was over an hour ago
1261
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1261
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1262 1262
             $this->_last_gc = time();
1263 1263
             $this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1264 1264
             /** @type WPDB $wpdb */
@@ -1293,7 +1293,7 @@  discard block
 block discarded – undo
1293 1293
                 // AND option_value < 1508368198 LIMIT 50
1294 1294
                 $expired_sessions = $wpdb->get_col($SQL);
1295 1295
                 // valid results?
1296
-                if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1296
+                if ( ! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1297 1297
                     $this->cache_storage->deleteMany($expired_sessions, true);
1298 1298
                 }
1299 1299
             }
Please login to merge, or discard this patch.
core/services/session/SessionStartHandler.php 2 patches
Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -27,234 +27,234 @@
 block discarded – undo
27 27
  */
28 28
 class SessionStartHandler
29 29
 {
30
-    const OPTION_NAME_SESSION_SAVE_HANDLER_STATUS = 'ee_session_save_handler_status';
31
-    const REQUEST_PARAM_RETRY_SESSION = 'ee_retry_session';
32
-    const SESSION_SAVE_HANDLER_STATUS_FAILED = 'session_save_handler_failed';
33
-    const SESSION_SAVE_HANDLER_STATUS_SUCCESS = 'session_save_handler_success';
34
-    const SESSION_SAVE_HANDLER_STATUS_UNKNOWN = 'session_save_handler_untested';
30
+	const OPTION_NAME_SESSION_SAVE_HANDLER_STATUS = 'ee_session_save_handler_status';
31
+	const REQUEST_PARAM_RETRY_SESSION = 'ee_retry_session';
32
+	const SESSION_SAVE_HANDLER_STATUS_FAILED = 'session_save_handler_failed';
33
+	const SESSION_SAVE_HANDLER_STATUS_SUCCESS = 'session_save_handler_success';
34
+	const SESSION_SAVE_HANDLER_STATUS_UNKNOWN = 'session_save_handler_untested';
35 35
 
36
-    /**
37
-     * @var RequestInterface $request
38
-     */
39
-    protected $request;
36
+	/**
37
+	 * @var RequestInterface $request
38
+	 */
39
+	protected $request;
40 40
 
41
-    /**
42
-     * StartSession constructor.
43
-     *
44
-     * @param RequestInterface $request
45
-     */
46
-    public function __construct(RequestInterface $request)
47
-    {
48
-        $this->request = $request;
49
-    }
41
+	/**
42
+	 * StartSession constructor.
43
+	 *
44
+	 * @param RequestInterface $request
45
+	 */
46
+	public function __construct(RequestInterface $request)
47
+	{
48
+		$this->request = $request;
49
+	}
50 50
 
51
-    /**
52
-     * Check if a custom session save handler is in play
53
-     * and attempt to start the PHP session
54
-     *
55
-     * @since $VID:$
56
-     */
57
-    public function startSession()
58
-    {
59
-        // check that session has started
60
-        if (session_id() === '') {
61
-            // starts a new session if one doesn't already exist, or re-initiates an existing one
62
-            if ($this->hasKnownCustomSessionSaveHandler()) {
63
-                $this->checkCustomSessionSaveHandler();
64
-            } else {
65
-                session_start();
66
-            }
67
-        }
68
-    }
51
+	/**
52
+	 * Check if a custom session save handler is in play
53
+	 * and attempt to start the PHP session
54
+	 *
55
+	 * @since $VID:$
56
+	 */
57
+	public function startSession()
58
+	{
59
+		// check that session has started
60
+		if (session_id() === '') {
61
+			// starts a new session if one doesn't already exist, or re-initiates an existing one
62
+			if ($this->hasKnownCustomSessionSaveHandler()) {
63
+				$this->checkCustomSessionSaveHandler();
64
+			} else {
65
+				session_start();
66
+			}
67
+		}
68
+	}
69 69
 
70
-    /**
71
-     * Returns `true` if the 'session.save_handler' ini setting matches a known custom handler
72
-     *
73
-     * @since $VID:$
74
-     * @return bool
75
-     */
76
-    private function hasKnownCustomSessionSaveHandler()
77
-    {
78
-        return in_array(
79
-            ini_get('session.save_handler'),
80
-            array(
81
-                'user',
82
-            ),
83
-            true
84
-        );
85
-    }
70
+	/**
71
+	 * Returns `true` if the 'session.save_handler' ini setting matches a known custom handler
72
+	 *
73
+	 * @since $VID:$
74
+	 * @return bool
75
+	 */
76
+	private function hasKnownCustomSessionSaveHandler()
77
+	{
78
+		return in_array(
79
+			ini_get('session.save_handler'),
80
+			array(
81
+				'user',
82
+			),
83
+			true
84
+		);
85
+	}
86 86
 
87
-    /**
88
-     * Attempt to start the PHP session when a custom Session Save Handler is known to be set.
89
-     *
90
-     * @since $VID:$
91
-     */
92
-    private function checkCustomSessionSaveHandler()
93
-    {
94
-        // If we've already successfully tested the session save handler
95
-        // on a previous request then just start the session
96
-        if ($this->sessionSaveHandlerIsValid()) {
97
-            session_start();
98
-            return;
99
-        }
100
-        // If not, then attempt to deal with any errors,
101
-        // otherwise, try to hobble along without the session
102
-        if (! $this->handleSessionSaveHandlerErrors()) {
103
-            return;
104
-        }
105
-        // there is no record of a fatal error while trying to start the session
106
-        // so let's see if there's a custom session save handler. Proceed with caution
107
-        $this->initializeSessionSaveHandlerStatus();
108
-        // hold your breath, the custom session save handler might cause a fatal here...
109
-        session_start();
110
-        // phew! we made it! the custom session handler is a-ok
111
-        $this->setSessionSaveHandlerStatusToValid();
112
-    }
87
+	/**
88
+	 * Attempt to start the PHP session when a custom Session Save Handler is known to be set.
89
+	 *
90
+	 * @since $VID:$
91
+	 */
92
+	private function checkCustomSessionSaveHandler()
93
+	{
94
+		// If we've already successfully tested the session save handler
95
+		// on a previous request then just start the session
96
+		if ($this->sessionSaveHandlerIsValid()) {
97
+			session_start();
98
+			return;
99
+		}
100
+		// If not, then attempt to deal with any errors,
101
+		// otherwise, try to hobble along without the session
102
+		if (! $this->handleSessionSaveHandlerErrors()) {
103
+			return;
104
+		}
105
+		// there is no record of a fatal error while trying to start the session
106
+		// so let's see if there's a custom session save handler. Proceed with caution
107
+		$this->initializeSessionSaveHandlerStatus();
108
+		// hold your breath, the custom session save handler might cause a fatal here...
109
+		session_start();
110
+		// phew! we made it! the custom session handler is a-ok
111
+		$this->setSessionSaveHandlerStatusToValid();
112
+	}
113 113
 
114 114
 
115
-    /**
116
-     * retrieves the value for the 'ee_session_save_handler_status' WP option.
117
-     * default value = 'session_save_handler_untested'
118
-     *
119
-     * @since $VID:$
120
-     * @return string
121
-     */
122
-    private function getSessionSaveHandlerStatus()
123
-    {
124
-        return get_option(
125
-            SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
126
-            SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN
127
-        );
128
-    }
115
+	/**
116
+	 * retrieves the value for the 'ee_session_save_handler_status' WP option.
117
+	 * default value = 'session_save_handler_untested'
118
+	 *
119
+	 * @since $VID:$
120
+	 * @return string
121
+	 */
122
+	private function getSessionSaveHandlerStatus()
123
+	{
124
+		return get_option(
125
+			SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
126
+			SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN
127
+		);
128
+	}
129 129
 
130
-    /**
131
-     * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_failed'
132
-     * which can then be upgraded is everything works correctly
133
-     *
134
-     * @since $VID:$
135
-     * @return bool
136
-     */
137
-    private function initializeSessionSaveHandlerStatus()
138
-    {
139
-        return update_option(
140
-            SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
141
-            SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED
142
-        );
143
-    }
130
+	/**
131
+	 * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_failed'
132
+	 * which can then be upgraded is everything works correctly
133
+	 *
134
+	 * @since $VID:$
135
+	 * @return bool
136
+	 */
137
+	private function initializeSessionSaveHandlerStatus()
138
+	{
139
+		return update_option(
140
+			SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
141
+			SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED
142
+		);
143
+	}
144 144
 
145
-    /**
146
-     * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_success'
147
-     *
148
-     * @since $VID:$
149
-     * @return bool
150
-     */
151
-    private function setSessionSaveHandlerStatusToValid()
152
-    {
153
-        return update_option(
154
-            SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
155
-            SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS
156
-        );
157
-    }
145
+	/**
146
+	 * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_success'
147
+	 *
148
+	 * @since $VID:$
149
+	 * @return bool
150
+	 */
151
+	private function setSessionSaveHandlerStatusToValid()
152
+	{
153
+		return update_option(
154
+			SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
155
+			SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS
156
+		);
157
+	}
158 158
 
159
-    /**
160
-     * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_untested'
161
-     *
162
-     * @since $VID:$
163
-     * @return bool
164
-     */
165
-    private function resetSessionSaveHandlerStatus()
166
-    {
167
-        return update_option(
168
-            SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
169
-            SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN
170
-        );
171
-    }
159
+	/**
160
+	 * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_untested'
161
+	 *
162
+	 * @since $VID:$
163
+	 * @return bool
164
+	 */
165
+	private function resetSessionSaveHandlerStatus()
166
+	{
167
+		return update_option(
168
+			SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS,
169
+			SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN
170
+		);
171
+	}
172 172
 
173
-    /**
174
-     * Returns `true` if the 'ee_session_save_handler_status' WP option value
175
-     * is equal to 'session_save_handler_success'
176
-     *
177
-     * @since $VID:$
178
-     * @return bool
179
-     */
180
-    private function sessionSaveHandlerIsValid()
181
-    {
182
-        return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS;
183
-    }
173
+	/**
174
+	 * Returns `true` if the 'ee_session_save_handler_status' WP option value
175
+	 * is equal to 'session_save_handler_success'
176
+	 *
177
+	 * @since $VID:$
178
+	 * @return bool
179
+	 */
180
+	private function sessionSaveHandlerIsValid()
181
+	{
182
+		return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS;
183
+	}
184 184
 
185
-    /**
186
-     * Returns `true` if the 'ee_session_save_handler_status' WP option value
187
-     * is equal to 'session_save_handler_failed'
188
-     *
189
-     * @since $VID:$
190
-     * @return bool
191
-     */
192
-    private function sessionSaveHandlerFailed()
193
-    {
194
-        return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED;
195
-    }
185
+	/**
186
+	 * Returns `true` if the 'ee_session_save_handler_status' WP option value
187
+	 * is equal to 'session_save_handler_failed'
188
+	 *
189
+	 * @since $VID:$
190
+	 * @return bool
191
+	 */
192
+	private function sessionSaveHandlerFailed()
193
+	{
194
+		return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED;
195
+	}
196 196
 
197
-    /**
198
-     * Returns `true` if no errors were detected with the session save handler,
199
-     * otherwise attempts to work notify the appropriate authorities
200
-     * with a suggestion for how to fix the issue, and returns `false`.
201
-     *
202
-     *
203
-     * @since $VID:$
204
-     * @return bool
205
-     */
206
-    private function handleSessionSaveHandlerErrors()
207
-    {
208
-        // Check if we had a fatal error last time while trying to start the session
209
-        if ($this->sessionSaveHandlerFailed()) {
210
-            // apparently, last time we tried using the custom session save handler there was a fatal
211
-            if ($this->request->requestParamIsSet(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION)) {
212
-                $this->resetSessionSaveHandlerStatus();
213
-                // remove "ee_retry_session", otherwise if the problem still isn't fixed,
214
-                // we'll just keep getting the fatal error over and over.
215
-                // Better to remove it and redirect, and try on the next request
216
-                EEH_URL::safeRedirectAndExit(
217
-                    remove_query_arg(
218
-                        array(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION),
219
-                        EEH_URL::current_url()
220
-                    )
221
-                );
222
-            }
223
-            // so the session is broken, don't try it again,
224
-            // just show a message to users that can fix it
225
-            $this->displaySessionSaveHandlerErrorNotice();
226
-            return false;
227
-        }
228
-        return true;
229
-    }
197
+	/**
198
+	 * Returns `true` if no errors were detected with the session save handler,
199
+	 * otherwise attempts to work notify the appropriate authorities
200
+	 * with a suggestion for how to fix the issue, and returns `false`.
201
+	 *
202
+	 *
203
+	 * @since $VID:$
204
+	 * @return bool
205
+	 */
206
+	private function handleSessionSaveHandlerErrors()
207
+	{
208
+		// Check if we had a fatal error last time while trying to start the session
209
+		if ($this->sessionSaveHandlerFailed()) {
210
+			// apparently, last time we tried using the custom session save handler there was a fatal
211
+			if ($this->request->requestParamIsSet(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION)) {
212
+				$this->resetSessionSaveHandlerStatus();
213
+				// remove "ee_retry_session", otherwise if the problem still isn't fixed,
214
+				// we'll just keep getting the fatal error over and over.
215
+				// Better to remove it and redirect, and try on the next request
216
+				EEH_URL::safeRedirectAndExit(
217
+					remove_query_arg(
218
+						array(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION),
219
+						EEH_URL::current_url()
220
+					)
221
+				);
222
+			}
223
+			// so the session is broken, don't try it again,
224
+			// just show a message to users that can fix it
225
+			$this->displaySessionSaveHandlerErrorNotice();
226
+			return false;
227
+		}
228
+		return true;
229
+	}
230 230
 
231
-    /**
232
-     * Generates an EE_Error notice regarding the current session woes
233
-     * but only if the current user is an admin with permission to 'install_plugins'.
234
-     *
235
-     * @since $VID:$
236
-     */
237
-    private function displaySessionSaveHandlerErrorNotice()
238
-    {
239
-        if (current_user_can('install_plugins')) {
240
-            $retry_session_url = add_query_arg(
241
-                array(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION => true),
242
-                EEH_URL::current_url()
243
-            );
244
-            EE_Error::add_error(
245
-                sprintf(
246
-                    esc_html__(
247
-                        'It appears there was a fatal error while starting the session, so Event Espresso is not able to process registrations normally. Some hosting companies, like Pantheon, require an extra plugin for Event Espresso to work. Please install the %1$sWordPress Native PHP Sessions plugin%2$s, then %3$sclick here to check if the problem is resolved.%2$s',
248
-                        'event_espresso'
249
-                    ),
250
-                    '<a href="https://wordpress.org/plugins/wp-native-php-sessions/">',
251
-                    '</a>',
252
-                    '<a href="' . $retry_session_url . '">'
253
-                ),
254
-                __FILE__,
255
-                __FUNCTION__,
256
-                __LINE__
257
-            );
258
-        }
259
-    }
231
+	/**
232
+	 * Generates an EE_Error notice regarding the current session woes
233
+	 * but only if the current user is an admin with permission to 'install_plugins'.
234
+	 *
235
+	 * @since $VID:$
236
+	 */
237
+	private function displaySessionSaveHandlerErrorNotice()
238
+	{
239
+		if (current_user_can('install_plugins')) {
240
+			$retry_session_url = add_query_arg(
241
+				array(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION => true),
242
+				EEH_URL::current_url()
243
+			);
244
+			EE_Error::add_error(
245
+				sprintf(
246
+					esc_html__(
247
+						'It appears there was a fatal error while starting the session, so Event Espresso is not able to process registrations normally. Some hosting companies, like Pantheon, require an extra plugin for Event Espresso to work. Please install the %1$sWordPress Native PHP Sessions plugin%2$s, then %3$sclick here to check if the problem is resolved.%2$s',
248
+						'event_espresso'
249
+					),
250
+					'<a href="https://wordpress.org/plugins/wp-native-php-sessions/">',
251
+					'</a>',
252
+					'<a href="' . $retry_session_url . '">'
253
+				),
254
+				__FILE__,
255
+				__FUNCTION__,
256
+				__LINE__
257
+			);
258
+		}
259
+	}
260 260
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         }
100 100
         // If not, then attempt to deal with any errors,
101 101
         // otherwise, try to hobble along without the session
102
-        if (! $this->handleSessionSaveHandlerErrors()) {
102
+        if ( ! $this->handleSessionSaveHandlerErrors()) {
103 103
             return;
104 104
         }
105 105
         // there is no record of a fatal error while trying to start the session
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
                     ),
250 250
                     '<a href="https://wordpress.org/plugins/wp-native-php-sessions/">',
251 251
                     '</a>',
252
-                    '<a href="' . $retry_session_url . '">'
252
+                    '<a href="'.$retry_session_url.'">'
253 253
                 ),
254 254
                 __FILE__,
255 255
                 __FUNCTION__,
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 1 patch
Indentation   +1023 added lines, -1023 removed lines patch added patch discarded remove patch
@@ -20,1027 +20,1027 @@
 block discarded – undo
20 20
 class EE_Dependency_Map
21 21
 {
22 22
 
23
-    /**
24
-     * This means that the requested class dependency is not present in the dependency map
25
-     */
26
-    const not_registered = 0;
27
-
28
-    /**
29
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
30
-     */
31
-    const load_new_object = 1;
32
-
33
-    /**
34
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
35
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
36
-     */
37
-    const load_from_cache = 2;
38
-
39
-    /**
40
-     * When registering a dependency,
41
-     * this indicates to keep any existing dependencies that already exist,
42
-     * and simply discard any new dependencies declared in the incoming data
43
-     */
44
-    const KEEP_EXISTING_DEPENDENCIES = 0;
45
-
46
-    /**
47
-     * When registering a dependency,
48
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
49
-     */
50
-    const OVERWRITE_DEPENDENCIES = 1;
51
-
52
-
53
-    /**
54
-     * @type EE_Dependency_Map $_instance
55
-     */
56
-    protected static $_instance;
57
-
58
-    /**
59
-     * @var ClassInterfaceCache $class_cache
60
-     */
61
-    private $class_cache;
62
-
63
-    /**
64
-     * @type RequestInterface $request
65
-     */
66
-    protected $request;
67
-
68
-    /**
69
-     * @type LegacyRequestInterface $legacy_request
70
-     */
71
-    protected $legacy_request;
72
-
73
-    /**
74
-     * @type ResponseInterface $response
75
-     */
76
-    protected $response;
77
-
78
-    /**
79
-     * @type LoaderInterface $loader
80
-     */
81
-    protected $loader;
82
-
83
-    /**
84
-     * @type array $_dependency_map
85
-     */
86
-    protected $_dependency_map = array();
87
-
88
-    /**
89
-     * @type array $_class_loaders
90
-     */
91
-    protected $_class_loaders = array();
92
-
93
-
94
-    /**
95
-     * EE_Dependency_Map constructor.
96
-     *
97
-     * @param ClassInterfaceCache $class_cache
98
-     */
99
-    protected function __construct(ClassInterfaceCache $class_cache)
100
-    {
101
-        $this->class_cache = $class_cache;
102
-        do_action('EE_Dependency_Map____construct', $this);
103
-    }
104
-
105
-
106
-    /**
107
-     * @return void
108
-     */
109
-    public function initialize()
110
-    {
111
-        $this->_register_core_dependencies();
112
-        $this->_register_core_class_loaders();
113
-        $this->_register_core_aliases();
114
-    }
115
-
116
-
117
-    /**
118
-     * @singleton method used to instantiate class object
119
-     * @param ClassInterfaceCache|null $class_cache
120
-     * @return EE_Dependency_Map
121
-     */
122
-    public static function instance(ClassInterfaceCache $class_cache = null)
123
-    {
124
-        // check if class object is instantiated, and instantiated properly
125
-        if (! self::$_instance instanceof EE_Dependency_Map
126
-            && $class_cache instanceof ClassInterfaceCache
127
-        ) {
128
-            self::$_instance = new EE_Dependency_Map($class_cache);
129
-        }
130
-        return self::$_instance;
131
-    }
132
-
133
-
134
-    /**
135
-     * @param RequestInterface $request
136
-     */
137
-    public function setRequest(RequestInterface $request)
138
-    {
139
-        $this->request = $request;
140
-    }
141
-
142
-
143
-    /**
144
-     * @param LegacyRequestInterface $legacy_request
145
-     */
146
-    public function setLegacyRequest(LegacyRequestInterface $legacy_request)
147
-    {
148
-        $this->legacy_request = $legacy_request;
149
-    }
150
-
151
-
152
-    /**
153
-     * @param ResponseInterface $response
154
-     */
155
-    public function setResponse(ResponseInterface $response)
156
-    {
157
-        $this->response = $response;
158
-    }
159
-
160
-
161
-    /**
162
-     * @param LoaderInterface $loader
163
-     */
164
-    public function setLoader(LoaderInterface $loader)
165
-    {
166
-        $this->loader = $loader;
167
-    }
168
-
169
-
170
-    /**
171
-     * @param string $class
172
-     * @param array  $dependencies
173
-     * @param int    $overwrite
174
-     * @return bool
175
-     */
176
-    public static function register_dependencies(
177
-        $class,
178
-        array $dependencies,
179
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
180
-    ) {
181
-        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
182
-    }
183
-
184
-
185
-    /**
186
-     * Assigns an array of class names and corresponding load sources (new or cached)
187
-     * to the class specified by the first parameter.
188
-     * IMPORTANT !!!
189
-     * The order of elements in the incoming $dependencies array MUST match
190
-     * the order of the constructor parameters for the class in question.
191
-     * This is especially important when overriding any existing dependencies that are registered.
192
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
193
-     *
194
-     * @param string $class
195
-     * @param array  $dependencies
196
-     * @param int    $overwrite
197
-     * @return bool
198
-     */
199
-    public function registerDependencies(
200
-        $class,
201
-        array $dependencies,
202
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
203
-    ) {
204
-        $class = trim($class, '\\');
205
-        $registered = false;
206
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
207
-            self::$_instance->_dependency_map[ $class ] = array();
208
-        }
209
-        // we need to make sure that any aliases used when registering a dependency
210
-        // get resolved to the correct class name
211
-        foreach ($dependencies as $dependency => $load_source) {
212
-            $alias = self::$_instance->getFqnForAlias($dependency);
213
-            if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
214
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
215
-            ) {
216
-                unset($dependencies[ $dependency ]);
217
-                $dependencies[ $alias ] = $load_source;
218
-                $registered = true;
219
-            }
220
-        }
221
-        // now add our two lists of dependencies together.
222
-        // using Union (+=) favours the arrays in precedence from left to right,
223
-        // so $dependencies is NOT overwritten because it is listed first
224
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
225
-        // Union is way faster than array_merge() but should be used with caution...
226
-        // especially with numerically indexed arrays
227
-        $dependencies += self::$_instance->_dependency_map[ $class ];
228
-        // now we need to ensure that the resulting dependencies
229
-        // array only has the entries that are required for the class
230
-        // so first count how many dependencies were originally registered for the class
231
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
232
-        // if that count is non-zero (meaning dependencies were already registered)
233
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
234
-            // then truncate the  final array to match that count
235
-            ? array_slice($dependencies, 0, $dependency_count)
236
-            // otherwise just take the incoming array because nothing previously existed
237
-            : $dependencies;
238
-        return $registered;
239
-    }
240
-
241
-
242
-    /**
243
-     * @param string $class_name
244
-     * @param string $loader
245
-     * @return bool
246
-     * @throws DomainException
247
-     */
248
-    public static function register_class_loader($class_name, $loader = 'load_core')
249
-    {
250
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
251
-            throw new DomainException(
252
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
253
-            );
254
-        }
255
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
256
-        if (! is_callable($loader)
257
-            && (
258
-                strpos($loader, 'load_') !== 0
259
-                || ! method_exists('EE_Registry', $loader)
260
-            )
261
-        ) {
262
-            throw new DomainException(
263
-                sprintf(
264
-                    esc_html__(
265
-                        '"%1$s" is not a valid loader method on EE_Registry.',
266
-                        'event_espresso'
267
-                    ),
268
-                    $loader
269
-                )
270
-            );
271
-        }
272
-        $class_name = self::$_instance->getFqnForAlias($class_name);
273
-        if (! isset(self::$_instance->_class_loaders[ $class_name ])) {
274
-            self::$_instance->_class_loaders[ $class_name ] = $loader;
275
-            return true;
276
-        }
277
-        return false;
278
-    }
279
-
280
-
281
-    /**
282
-     * @return array
283
-     */
284
-    public function dependency_map()
285
-    {
286
-        return $this->_dependency_map;
287
-    }
288
-
289
-
290
-    /**
291
-     * returns TRUE if dependency map contains a listing for the provided class name
292
-     *
293
-     * @param string $class_name
294
-     * @return boolean
295
-     */
296
-    public function has($class_name = '')
297
-    {
298
-        // all legacy models have the same dependencies
299
-        if (strpos($class_name, 'EEM_') === 0) {
300
-            $class_name = 'LEGACY_MODELS';
301
-        }
302
-        return isset($this->_dependency_map[ $class_name ]) ? true : false;
303
-    }
304
-
305
-
306
-    /**
307
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
308
-     *
309
-     * @param string $class_name
310
-     * @param string $dependency
311
-     * @return bool
312
-     */
313
-    public function has_dependency_for_class($class_name = '', $dependency = '')
314
-    {
315
-        // all legacy models have the same dependencies
316
-        if (strpos($class_name, 'EEM_') === 0) {
317
-            $class_name = 'LEGACY_MODELS';
318
-        }
319
-        $dependency = $this->getFqnForAlias($dependency, $class_name);
320
-        return isset($this->_dependency_map[ $class_name ][ $dependency ])
321
-            ? true
322
-            : false;
323
-    }
324
-
325
-
326
-    /**
327
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
328
-     *
329
-     * @param string $class_name
330
-     * @param string $dependency
331
-     * @return int
332
-     */
333
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
334
-    {
335
-        // all legacy models have the same dependencies
336
-        if (strpos($class_name, 'EEM_') === 0) {
337
-            $class_name = 'LEGACY_MODELS';
338
-        }
339
-        $dependency = $this->getFqnForAlias($dependency);
340
-        return $this->has_dependency_for_class($class_name, $dependency)
341
-            ? $this->_dependency_map[ $class_name ][ $dependency ]
342
-            : EE_Dependency_Map::not_registered;
343
-    }
344
-
345
-
346
-    /**
347
-     * @param string $class_name
348
-     * @return string | Closure
349
-     */
350
-    public function class_loader($class_name)
351
-    {
352
-        // all legacy models use load_model()
353
-        if (strpos($class_name, 'EEM_') === 0) {
354
-            return 'load_model';
355
-        }
356
-        // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc
357
-        // perform strpos() first to avoid loading regex every time we load a class
358
-        if (strpos($class_name, 'EE_CPT_') === 0
359
-            && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name)
360
-        ) {
361
-            return 'load_core';
362
-        }
363
-        $class_name = $this->getFqnForAlias($class_name);
364
-        return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : '';
365
-    }
366
-
367
-
368
-    /**
369
-     * @return array
370
-     */
371
-    public function class_loaders()
372
-    {
373
-        return $this->_class_loaders;
374
-    }
375
-
376
-
377
-    /**
378
-     * adds an alias for a classname
379
-     *
380
-     * @param string $fqcn      the class name that should be used (concrete class to replace interface)
381
-     * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
382
-     * @param string $for_class the class that has the dependency (is type hinting for the interface)
383
-     */
384
-    public function add_alias($fqcn, $alias, $for_class = '')
385
-    {
386
-        $this->class_cache->addAlias($fqcn, $alias, $for_class);
387
-    }
388
-
389
-
390
-    /**
391
-     * Returns TRUE if the provided fully qualified name IS an alias
392
-     * WHY?
393
-     * Because if a class is type hinting for a concretion,
394
-     * then why would we need to find another class to supply it?
395
-     * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
396
-     * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
397
-     * Don't go looking for some substitute.
398
-     * Whereas if a class is type hinting for an interface...
399
-     * then we need to find an actual class to use.
400
-     * So the interface IS the alias for some other FQN,
401
-     * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
402
-     * represents some other class.
403
-     *
404
-     * @param string $fqn
405
-     * @param string $for_class
406
-     * @return bool
407
-     */
408
-    public function isAlias($fqn = '', $for_class = '')
409
-    {
410
-        return $this->class_cache->isAlias($fqn, $for_class);
411
-    }
412
-
413
-
414
-    /**
415
-     * Returns a FQN for provided alias if one exists, otherwise returns the original $alias
416
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
417
-     *  for example:
418
-     *      if the following two entries were added to the _aliases array:
419
-     *          array(
420
-     *              'interface_alias'           => 'some\namespace\interface'
421
-     *              'some\namespace\interface'  => 'some\namespace\classname'
422
-     *          )
423
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
424
-     *      to load an instance of 'some\namespace\classname'
425
-     *
426
-     * @param string $alias
427
-     * @param string $for_class
428
-     * @return string
429
-     */
430
-    public function getFqnForAlias($alias = '', $for_class = '')
431
-    {
432
-        return (string) $this->class_cache->getFqnForAlias($alias, $for_class);
433
-    }
434
-
435
-
436
-    /**
437
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
438
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
439
-     * This is done by using the following class constants:
440
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
441
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
442
-     */
443
-    protected function _register_core_dependencies()
444
-    {
445
-        $this->_dependency_map = array(
446
-            'EE_Request_Handler'                                                                                          => array(
447
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
448
-            ),
449
-            'EE_System'                                                                                                   => array(
450
-                'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
451
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
452
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
453
-                'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
454
-            ),
455
-            'EE_Session'                                                                                                  => array(
456
-                'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
457
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
458
-                'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
459
-                'EventEspresso\core\services\session\SessionStartHandler'  => EE_Dependency_Map::load_from_cache,
460
-                'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
461
-            ),
462
-            'EE_Cart'                                                                                                     => array(
463
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
464
-            ),
465
-            'EE_Front_Controller'                                                                                         => array(
466
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
467
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
468
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
469
-            ),
470
-            'EE_Messenger_Collection_Loader'                                                                              => array(
471
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
472
-            ),
473
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
474
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
475
-            ),
476
-            'EE_Message_Resource_Manager'                                                                                 => array(
477
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
478
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
479
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
480
-            ),
481
-            'EE_Message_Factory'                                                                                          => array(
482
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
483
-            ),
484
-            'EE_messages'                                                                                                 => array(
485
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
486
-            ),
487
-            'EE_Messages_Generator'                                                                                       => array(
488
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
489
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
490
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
491
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
492
-            ),
493
-            'EE_Messages_Processor'                                                                                       => array(
494
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
495
-            ),
496
-            'EE_Messages_Queue'                                                                                           => array(
497
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
498
-            ),
499
-            'EE_Messages_Template_Defaults'                                                                               => array(
500
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
501
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
502
-            ),
503
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
504
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
505
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
506
-            ),
507
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
508
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
509
-            ),
510
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
511
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
512
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
513
-            ),
514
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
515
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
516
-            ),
517
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
518
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
519
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
520
-            ),
521
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
522
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
523
-            ),
524
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
525
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
526
-            ),
527
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
528
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
529
-            ),
530
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
531
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
532
-            ),
533
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
534
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
535
-            ),
536
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
537
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
538
-            ),
539
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
540
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
541
-            ),
542
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
543
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
544
-            ),
545
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
546
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
547
-            ),
548
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
549
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
550
-            ),
551
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
552
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
553
-            ),
554
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
555
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
556
-            ),
557
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
558
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
559
-            ),
560
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
561
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
562
-            ),
563
-            'EE_Data_Migration_Class_Base'                                                                                => array(
564
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
565
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
566
-            ),
567
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
568
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
569
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
570
-            ),
571
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
572
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
573
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
574
-            ),
575
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
576
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
577
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
578
-            ),
579
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
580
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
581
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
582
-            ),
583
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
584
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
585
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
586
-            ),
587
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
588
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
589
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
590
-            ),
591
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
592
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
593
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
594
-            ),
595
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
596
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
597
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
598
-            ),
599
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
600
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
601
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
602
-            ),
603
-            'EventEspresso\core\services\assets\I18nRegistry'                                                             => array(
604
-                array(),
605
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
606
-            ),
607
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
608
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
609
-                'EventEspresso\core\services\assets\I18nRegistry'    => EE_Dependency_Map::load_from_cache,
610
-            ),
611
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
612
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
613
-            ),
614
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
615
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
616
-            ),
617
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
618
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
619
-            ),
620
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
621
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
622
-            ),
623
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
624
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
625
-            ),
626
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
627
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
628
-            ),
629
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
630
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
631
-            ),
632
-            'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
633
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
634
-            ),
635
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
636
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
637
-            ),
638
-            'EventEspresso\core\domain\services\validation\email\EmailValidationService'                                  => array(
639
-                'EE_Registration_Config'                     => EE_Dependency_Map::load_from_cache,
640
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
641
-            ),
642
-            'EventEspresso\core\domain\values\EmailAddress'                                                               => array(
643
-                null,
644
-                'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
645
-            ),
646
-            'EventEspresso\core\services\orm\ModelFieldFactory'                                                           => array(
647
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
648
-            ),
649
-            'LEGACY_MODELS'                                                                                               => array(
650
-                null,
651
-                'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
652
-            ),
653
-            'EE_Module_Request_Router'                                                                                    => array(
654
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
655
-            ),
656
-            'EE_Registration_Processor'                                                                                   => array(
657
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
658
-            ),
659
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'                                      => array(
660
-                null,
661
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
662
-                'EventEspresso\core\services\request\Request'                         => EE_Dependency_Map::load_from_cache,
663
-            ),
664
-            'EventEspresso\core\services\licensing\LicenseService'                                                        => array(
665
-                'EventEspresso\core\domain\services\pue\Stats'  => EE_Dependency_Map::load_from_cache,
666
-                'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
667
-            ),
668
-            'EE_Admin_Transactions_List_Table'                                                                            => array(
669
-                null,
670
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
671
-            ),
672
-            'EventEspresso\core\domain\services\pue\Stats'                                                                => array(
673
-                'EventEspresso\core\domain\services\pue\Config'        => EE_Dependency_Map::load_from_cache,
674
-                'EE_Maintenance_Mode'                                  => EE_Dependency_Map::load_from_cache,
675
-                'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache,
676
-            ),
677
-            'EventEspresso\core\domain\services\pue\Config'                                                               => array(
678
-                'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
679
-                'EE_Config'         => EE_Dependency_Map::load_from_cache,
680
-            ),
681
-            'EventEspresso\core\domain\services\pue\StatsGatherer'                                                        => array(
682
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
683
-                'EEM_Event'          => EE_Dependency_Map::load_from_cache,
684
-                'EEM_Datetime'       => EE_Dependency_Map::load_from_cache,
685
-                'EEM_Ticket'         => EE_Dependency_Map::load_from_cache,
686
-                'EEM_Registration'   => EE_Dependency_Map::load_from_cache,
687
-                'EEM_Transaction'    => EE_Dependency_Map::load_from_cache,
688
-                'EE_Config'          => EE_Dependency_Map::load_from_cache,
689
-            ),
690
-            'EventEspresso\core\domain\services\admin\ExitModal'                                                          => array(
691
-                'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache,
692
-            ),
693
-            'EventEspresso\core\domain\services\admin\PluginUpsells'                                                      => array(
694
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
695
-            ),
696
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha'                                    => array(
697
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
698
-                'EE_Session'             => EE_Dependency_Map::load_from_cache,
699
-            ),
700
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings'                                => array(
701
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
702
-            ),
703
-            'EventEspresso\modules\ticket_selector\ProcessTicketSelector'                                                 => array(
704
-                'EE_Core_Config'                                                          => EE_Dependency_Map::load_from_cache,
705
-                'EventEspresso\core\services\request\Request'                             => EE_Dependency_Map::load_from_cache,
706
-                'EE_Session'                                                              => EE_Dependency_Map::load_from_cache,
707
-                'EEM_Ticket'                                                              => EE_Dependency_Map::load_from_cache,
708
-                'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
709
-            ),
710
-            'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'                                     => array(
711
-                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
712
-            ),
713
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'                              => array(
714
-                'EE_Core_Config'                             => EE_Dependency_Map::load_from_cache,
715
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
716
-            ),
717
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'                                => array(
718
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
719
-            ),
720
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'                               => array(
721
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
722
-            ),
723
-            'EE_CPT_Strategy'                                                                                             => array(
724
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
725
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
726
-            ),
727
-            'EventEspresso\core\services\loaders\ObjectIdentifier'                                                        => array(
728
-                'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache,
729
-            ),
730
-            'EventEspresso\core\domain\services\assets\CoreAssetManager'                                                  => array(
731
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
732
-                'EE_Currency_Config'                                 => EE_Dependency_Map::load_from_cache,
733
-                'EE_Template_Config'                                 => EE_Dependency_Map::load_from_cache,
734
-                'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
735
-                'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
736
-            ),
737
-            'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array(
738
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
739
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache
740
-            ),
741
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array(
742
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
743
-            ),
744
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array(
745
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
746
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache
747
-            ),
748
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array(
749
-                'EEM_Checkin' => EE_Dependency_Map::load_from_cache,
750
-            ),
751
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array(
752
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache,
753
-            ),
754
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array(
755
-                'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
756
-            ),
757
-            'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array(
758
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
759
-            ),
760
-            'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array(
761
-                'EEM_Answer' => EE_Dependency_Map::load_from_cache,
762
-                'EEM_Question' => EE_Dependency_Map::load_from_cache,
763
-            ),
764
-            'EventEspresso\core\CPTs\CptQueryModifier' => array(
765
-                null,
766
-                null,
767
-                null,
768
-                'EE_Request_Handler'                          => EE_Dependency_Map::load_from_cache,
769
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
770
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
771
-            ),
772
-            'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array(
773
-                'EE_Registry' => EE_Dependency_Map::load_from_cache,
774
-                'EE_Config' => EE_Dependency_Map::load_from_cache
775
-            ),
776
-            'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => array(
777
-                'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache
778
-            ),
779
-            'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => array(
780
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
781
-            ),
782
-            'EventEspresso\core\libraries\rest_api\controllers\model\Read' => array(
783
-                'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache
784
-            ),
785
-            'EventEspresso\core\libraries\rest_api\calculations\Datetime' => array(
786
-                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
787
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache
788
-            ),
789
-            'EventEspresso\core\libraries\rest_api\calculations\Event' => array(
790
-                'EEM_Event' => EE_Dependency_Map::load_from_cache,
791
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache
792
-            ),
793
-            'EventEspresso\core\libraries\rest_api\calculations\Registration' => array(
794
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache
795
-            ),
796
-            'EventEspresso\core\services\session\SessionStartHandler' => array(
797
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
798
-            ),
799
-            'EE_URL_Validation_Strategy' => array(
800
-                null,
801
-                null,
802
-                'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache
803
-            ),
804
-        );
805
-    }
806
-
807
-
808
-    /**
809
-     * Registers how core classes are loaded.
810
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
811
-     *        'EE_Request_Handler' => 'load_core'
812
-     *        'EE_Messages_Queue'  => 'load_lib'
813
-     *        'EEH_Debug_Tools'    => 'load_helper'
814
-     * or, if greater control is required, by providing a custom closure. For example:
815
-     *        'Some_Class' => function () {
816
-     *            return new Some_Class();
817
-     *        },
818
-     * This is required for instantiating dependencies
819
-     * where an interface has been type hinted in a class constructor. For example:
820
-     *        'Required_Interface' => function () {
821
-     *            return new A_Class_That_Implements_Required_Interface();
822
-     *        },
823
-     */
824
-    protected function _register_core_class_loaders()
825
-    {
826
-        // for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
827
-        // be used in a closure.
828
-        $request = &$this->request;
829
-        $response = &$this->response;
830
-        $legacy_request = &$this->legacy_request;
831
-        // $loader = &$this->loader;
832
-        $this->_class_loaders = array(
833
-            // load_core
834
-            'EE_Capabilities'                              => 'load_core',
835
-            'EE_Encryption'                                => 'load_core',
836
-            'EE_Front_Controller'                          => 'load_core',
837
-            'EE_Module_Request_Router'                     => 'load_core',
838
-            'EE_Registry'                                  => 'load_core',
839
-            'EE_Request'                                   => function () use (&$legacy_request) {
840
-                return $legacy_request;
841
-            },
842
-            'EventEspresso\core\services\request\Request'  => function () use (&$request) {
843
-                return $request;
844
-            },
845
-            'EventEspresso\core\services\request\Response' => function () use (&$response) {
846
-                return $response;
847
-            },
848
-            'EE_Base'                                      => 'load_core',
849
-            'EE_Request_Handler'                           => 'load_core',
850
-            'EE_Session'                                   => 'load_core',
851
-            'EE_Cron_Tasks'                                => 'load_core',
852
-            'EE_System'                                    => 'load_core',
853
-            'EE_Maintenance_Mode'                          => 'load_core',
854
-            'EE_Register_CPTs'                             => 'load_core',
855
-            'EE_Admin'                                     => 'load_core',
856
-            'EE_CPT_Strategy'                              => 'load_core',
857
-            // load_lib
858
-            'EE_Message_Resource_Manager'                  => 'load_lib',
859
-            'EE_Message_Type_Collection'                   => 'load_lib',
860
-            'EE_Message_Type_Collection_Loader'            => 'load_lib',
861
-            'EE_Messenger_Collection'                      => 'load_lib',
862
-            'EE_Messenger_Collection_Loader'               => 'load_lib',
863
-            'EE_Messages_Processor'                        => 'load_lib',
864
-            'EE_Message_Repository'                        => 'load_lib',
865
-            'EE_Messages_Queue'                            => 'load_lib',
866
-            'EE_Messages_Data_Handler_Collection'          => 'load_lib',
867
-            'EE_Message_Template_Group_Collection'         => 'load_lib',
868
-            'EE_Payment_Method_Manager'                    => 'load_lib',
869
-            'EE_Messages_Generator'                        => function () {
870
-                return EE_Registry::instance()->load_lib(
871
-                    'Messages_Generator',
872
-                    array(),
873
-                    false,
874
-                    false
875
-                );
876
-            },
877
-            'EE_Messages_Template_Defaults'                => function ($arguments = array()) {
878
-                return EE_Registry::instance()->load_lib(
879
-                    'Messages_Template_Defaults',
880
-                    $arguments,
881
-                    false,
882
-                    false
883
-                );
884
-            },
885
-            // load_helper
886
-            'EEH_Parse_Shortcodes'                         => function () {
887
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
888
-                    return new EEH_Parse_Shortcodes();
889
-                }
890
-                return null;
891
-            },
892
-            'EE_Template_Config'                           => function () {
893
-                return EE_Config::instance()->template_settings;
894
-            },
895
-            'EE_Currency_Config'                           => function () {
896
-                return EE_Config::instance()->currency;
897
-            },
898
-            'EE_Registration_Config'                       => function () {
899
-                return EE_Config::instance()->registration;
900
-            },
901
-            'EE_Core_Config'                               => function () {
902
-                return EE_Config::instance()->core;
903
-            },
904
-            'EventEspresso\core\services\loaders\Loader'   => function () {
905
-                return LoaderFactory::getLoader();
906
-            },
907
-            'EE_Network_Config'                            => function () {
908
-                return EE_Network_Config::instance();
909
-            },
910
-            'EE_Config'                                    => function () {
911
-                return EE_Config::instance();
912
-            },
913
-            'EventEspresso\core\domain\Domain'             => function () {
914
-                return DomainFactory::getEventEspressoCoreDomain();
915
-            },
916
-            'EE_Admin_Config'                              => function () {
917
-                return EE_Config::instance()->admin;
918
-            },
919
-        );
920
-    }
921
-
922
-
923
-    /**
924
-     * can be used for supplying alternate names for classes,
925
-     * or for connecting interface names to instantiable classes
926
-     */
927
-    protected function _register_core_aliases()
928
-    {
929
-        $aliases = array(
930
-            'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
931
-            'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
932
-            'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
933
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
934
-            'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
935
-            'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
936
-            'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
937
-            'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
938
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
939
-            'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
940
-            'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
941
-            'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
942
-            'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
943
-            'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
944
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
945
-            'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
946
-            'CreateTransactionCommandHandler'                                              => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
947
-            'CreateAttendeeCommandHandler'                                                 => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
948
-            'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
949
-            'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
950
-            'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
951
-            'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
952
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
953
-            'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
954
-            'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
955
-            'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
956
-            'CommandFactoryInterface'                                                      => 'EventEspresso\core\services\commands\CommandFactoryInterface',
957
-            'EventEspresso\core\services\commands\CommandFactoryInterface'                 => 'EventEspresso\core\services\commands\CommandFactory',
958
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface'        => 'EE_Session',
959
-            'EmailValidatorInterface'                                                      => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
960
-            'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface'  => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
961
-            'NoticeConverterInterface'                                                     => 'EventEspresso\core\services\notices\NoticeConverterInterface',
962
-            'EventEspresso\core\services\notices\NoticeConverterInterface'                 => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
963
-            'NoticesContainerInterface'                                                    => 'EventEspresso\core\services\notices\NoticesContainerInterface',
964
-            'EventEspresso\core\services\notices\NoticesContainerInterface'                => 'EventEspresso\core\services\notices\NoticesContainer',
965
-            'EventEspresso\core\services\request\RequestInterface'                         => 'EventEspresso\core\services\request\Request',
966
-            'EventEspresso\core\services\request\ResponseInterface'                        => 'EventEspresso\core\services\request\Response',
967
-            'EventEspresso\core\domain\DomainInterface'                                    => 'EventEspresso\core\domain\Domain',
968
-        );
969
-        foreach ($aliases as $alias => $fqn) {
970
-            if (is_array($fqn)) {
971
-                foreach ($fqn as $class => $for_class) {
972
-                    $this->class_cache->addAlias($class, $alias, $for_class);
973
-                }
974
-                continue;
975
-            }
976
-            $this->class_cache->addAlias($fqn, $alias);
977
-        }
978
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
979
-            $this->class_cache->addAlias(
980
-                'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
981
-                'EventEspresso\core\services\notices\NoticeConverterInterface'
982
-            );
983
-        }
984
-    }
985
-
986
-
987
-    /**
988
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
989
-     * request Primarily used by unit tests.
990
-     */
991
-    public function reset()
992
-    {
993
-        $this->_register_core_class_loaders();
994
-        $this->_register_core_dependencies();
995
-    }
996
-
997
-
998
-    /**
999
-     * PLZ NOTE: a better name for this method would be is_alias()
1000
-     * because it returns TRUE if the provided fully qualified name IS an alias
1001
-     * WHY?
1002
-     * Because if a class is type hinting for a concretion,
1003
-     * then why would we need to find another class to supply it?
1004
-     * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
1005
-     * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
1006
-     * Don't go looking for some substitute.
1007
-     * Whereas if a class is type hinting for an interface...
1008
-     * then we need to find an actual class to use.
1009
-     * So the interface IS the alias for some other FQN,
1010
-     * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
1011
-     * represents some other class.
1012
-     *
1013
-     * @deprecated 4.9.62.p
1014
-     * @param string $fqn
1015
-     * @param string $for_class
1016
-     * @return bool
1017
-     */
1018
-    public function has_alias($fqn = '', $for_class = '')
1019
-    {
1020
-        return $this->isAlias($fqn, $for_class);
1021
-    }
1022
-
1023
-
1024
-    /**
1025
-     * PLZ NOTE: a better name for this method would be get_fqn_for_alias()
1026
-     * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias
1027
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
1028
-     *  for example:
1029
-     *      if the following two entries were added to the _aliases array:
1030
-     *          array(
1031
-     *              'interface_alias'           => 'some\namespace\interface'
1032
-     *              'some\namespace\interface'  => 'some\namespace\classname'
1033
-     *          )
1034
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
1035
-     *      to load an instance of 'some\namespace\classname'
1036
-     *
1037
-     * @deprecated 4.9.62.p
1038
-     * @param string $alias
1039
-     * @param string $for_class
1040
-     * @return string
1041
-     */
1042
-    public function get_alias($alias = '', $for_class = '')
1043
-    {
1044
-        return $this->getFqnForAlias($alias, $for_class);
1045
-    }
23
+	/**
24
+	 * This means that the requested class dependency is not present in the dependency map
25
+	 */
26
+	const not_registered = 0;
27
+
28
+	/**
29
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
30
+	 */
31
+	const load_new_object = 1;
32
+
33
+	/**
34
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
35
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
36
+	 */
37
+	const load_from_cache = 2;
38
+
39
+	/**
40
+	 * When registering a dependency,
41
+	 * this indicates to keep any existing dependencies that already exist,
42
+	 * and simply discard any new dependencies declared in the incoming data
43
+	 */
44
+	const KEEP_EXISTING_DEPENDENCIES = 0;
45
+
46
+	/**
47
+	 * When registering a dependency,
48
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
49
+	 */
50
+	const OVERWRITE_DEPENDENCIES = 1;
51
+
52
+
53
+	/**
54
+	 * @type EE_Dependency_Map $_instance
55
+	 */
56
+	protected static $_instance;
57
+
58
+	/**
59
+	 * @var ClassInterfaceCache $class_cache
60
+	 */
61
+	private $class_cache;
62
+
63
+	/**
64
+	 * @type RequestInterface $request
65
+	 */
66
+	protected $request;
67
+
68
+	/**
69
+	 * @type LegacyRequestInterface $legacy_request
70
+	 */
71
+	protected $legacy_request;
72
+
73
+	/**
74
+	 * @type ResponseInterface $response
75
+	 */
76
+	protected $response;
77
+
78
+	/**
79
+	 * @type LoaderInterface $loader
80
+	 */
81
+	protected $loader;
82
+
83
+	/**
84
+	 * @type array $_dependency_map
85
+	 */
86
+	protected $_dependency_map = array();
87
+
88
+	/**
89
+	 * @type array $_class_loaders
90
+	 */
91
+	protected $_class_loaders = array();
92
+
93
+
94
+	/**
95
+	 * EE_Dependency_Map constructor.
96
+	 *
97
+	 * @param ClassInterfaceCache $class_cache
98
+	 */
99
+	protected function __construct(ClassInterfaceCache $class_cache)
100
+	{
101
+		$this->class_cache = $class_cache;
102
+		do_action('EE_Dependency_Map____construct', $this);
103
+	}
104
+
105
+
106
+	/**
107
+	 * @return void
108
+	 */
109
+	public function initialize()
110
+	{
111
+		$this->_register_core_dependencies();
112
+		$this->_register_core_class_loaders();
113
+		$this->_register_core_aliases();
114
+	}
115
+
116
+
117
+	/**
118
+	 * @singleton method used to instantiate class object
119
+	 * @param ClassInterfaceCache|null $class_cache
120
+	 * @return EE_Dependency_Map
121
+	 */
122
+	public static function instance(ClassInterfaceCache $class_cache = null)
123
+	{
124
+		// check if class object is instantiated, and instantiated properly
125
+		if (! self::$_instance instanceof EE_Dependency_Map
126
+			&& $class_cache instanceof ClassInterfaceCache
127
+		) {
128
+			self::$_instance = new EE_Dependency_Map($class_cache);
129
+		}
130
+		return self::$_instance;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @param RequestInterface $request
136
+	 */
137
+	public function setRequest(RequestInterface $request)
138
+	{
139
+		$this->request = $request;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @param LegacyRequestInterface $legacy_request
145
+	 */
146
+	public function setLegacyRequest(LegacyRequestInterface $legacy_request)
147
+	{
148
+		$this->legacy_request = $legacy_request;
149
+	}
150
+
151
+
152
+	/**
153
+	 * @param ResponseInterface $response
154
+	 */
155
+	public function setResponse(ResponseInterface $response)
156
+	{
157
+		$this->response = $response;
158
+	}
159
+
160
+
161
+	/**
162
+	 * @param LoaderInterface $loader
163
+	 */
164
+	public function setLoader(LoaderInterface $loader)
165
+	{
166
+		$this->loader = $loader;
167
+	}
168
+
169
+
170
+	/**
171
+	 * @param string $class
172
+	 * @param array  $dependencies
173
+	 * @param int    $overwrite
174
+	 * @return bool
175
+	 */
176
+	public static function register_dependencies(
177
+		$class,
178
+		array $dependencies,
179
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
180
+	) {
181
+		return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
182
+	}
183
+
184
+
185
+	/**
186
+	 * Assigns an array of class names and corresponding load sources (new or cached)
187
+	 * to the class specified by the first parameter.
188
+	 * IMPORTANT !!!
189
+	 * The order of elements in the incoming $dependencies array MUST match
190
+	 * the order of the constructor parameters for the class in question.
191
+	 * This is especially important when overriding any existing dependencies that are registered.
192
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
193
+	 *
194
+	 * @param string $class
195
+	 * @param array  $dependencies
196
+	 * @param int    $overwrite
197
+	 * @return bool
198
+	 */
199
+	public function registerDependencies(
200
+		$class,
201
+		array $dependencies,
202
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
203
+	) {
204
+		$class = trim($class, '\\');
205
+		$registered = false;
206
+		if (empty(self::$_instance->_dependency_map[ $class ])) {
207
+			self::$_instance->_dependency_map[ $class ] = array();
208
+		}
209
+		// we need to make sure that any aliases used when registering a dependency
210
+		// get resolved to the correct class name
211
+		foreach ($dependencies as $dependency => $load_source) {
212
+			$alias = self::$_instance->getFqnForAlias($dependency);
213
+			if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
214
+				|| ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
215
+			) {
216
+				unset($dependencies[ $dependency ]);
217
+				$dependencies[ $alias ] = $load_source;
218
+				$registered = true;
219
+			}
220
+		}
221
+		// now add our two lists of dependencies together.
222
+		// using Union (+=) favours the arrays in precedence from left to right,
223
+		// so $dependencies is NOT overwritten because it is listed first
224
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
225
+		// Union is way faster than array_merge() but should be used with caution...
226
+		// especially with numerically indexed arrays
227
+		$dependencies += self::$_instance->_dependency_map[ $class ];
228
+		// now we need to ensure that the resulting dependencies
229
+		// array only has the entries that are required for the class
230
+		// so first count how many dependencies were originally registered for the class
231
+		$dependency_count = count(self::$_instance->_dependency_map[ $class ]);
232
+		// if that count is non-zero (meaning dependencies were already registered)
233
+		self::$_instance->_dependency_map[ $class ] = $dependency_count
234
+			// then truncate the  final array to match that count
235
+			? array_slice($dependencies, 0, $dependency_count)
236
+			// otherwise just take the incoming array because nothing previously existed
237
+			: $dependencies;
238
+		return $registered;
239
+	}
240
+
241
+
242
+	/**
243
+	 * @param string $class_name
244
+	 * @param string $loader
245
+	 * @return bool
246
+	 * @throws DomainException
247
+	 */
248
+	public static function register_class_loader($class_name, $loader = 'load_core')
249
+	{
250
+		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
251
+			throw new DomainException(
252
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
253
+			);
254
+		}
255
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
256
+		if (! is_callable($loader)
257
+			&& (
258
+				strpos($loader, 'load_') !== 0
259
+				|| ! method_exists('EE_Registry', $loader)
260
+			)
261
+		) {
262
+			throw new DomainException(
263
+				sprintf(
264
+					esc_html__(
265
+						'"%1$s" is not a valid loader method on EE_Registry.',
266
+						'event_espresso'
267
+					),
268
+					$loader
269
+				)
270
+			);
271
+		}
272
+		$class_name = self::$_instance->getFqnForAlias($class_name);
273
+		if (! isset(self::$_instance->_class_loaders[ $class_name ])) {
274
+			self::$_instance->_class_loaders[ $class_name ] = $loader;
275
+			return true;
276
+		}
277
+		return false;
278
+	}
279
+
280
+
281
+	/**
282
+	 * @return array
283
+	 */
284
+	public function dependency_map()
285
+	{
286
+		return $this->_dependency_map;
287
+	}
288
+
289
+
290
+	/**
291
+	 * returns TRUE if dependency map contains a listing for the provided class name
292
+	 *
293
+	 * @param string $class_name
294
+	 * @return boolean
295
+	 */
296
+	public function has($class_name = '')
297
+	{
298
+		// all legacy models have the same dependencies
299
+		if (strpos($class_name, 'EEM_') === 0) {
300
+			$class_name = 'LEGACY_MODELS';
301
+		}
302
+		return isset($this->_dependency_map[ $class_name ]) ? true : false;
303
+	}
304
+
305
+
306
+	/**
307
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
308
+	 *
309
+	 * @param string $class_name
310
+	 * @param string $dependency
311
+	 * @return bool
312
+	 */
313
+	public function has_dependency_for_class($class_name = '', $dependency = '')
314
+	{
315
+		// all legacy models have the same dependencies
316
+		if (strpos($class_name, 'EEM_') === 0) {
317
+			$class_name = 'LEGACY_MODELS';
318
+		}
319
+		$dependency = $this->getFqnForAlias($dependency, $class_name);
320
+		return isset($this->_dependency_map[ $class_name ][ $dependency ])
321
+			? true
322
+			: false;
323
+	}
324
+
325
+
326
+	/**
327
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
328
+	 *
329
+	 * @param string $class_name
330
+	 * @param string $dependency
331
+	 * @return int
332
+	 */
333
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
334
+	{
335
+		// all legacy models have the same dependencies
336
+		if (strpos($class_name, 'EEM_') === 0) {
337
+			$class_name = 'LEGACY_MODELS';
338
+		}
339
+		$dependency = $this->getFqnForAlias($dependency);
340
+		return $this->has_dependency_for_class($class_name, $dependency)
341
+			? $this->_dependency_map[ $class_name ][ $dependency ]
342
+			: EE_Dependency_Map::not_registered;
343
+	}
344
+
345
+
346
+	/**
347
+	 * @param string $class_name
348
+	 * @return string | Closure
349
+	 */
350
+	public function class_loader($class_name)
351
+	{
352
+		// all legacy models use load_model()
353
+		if (strpos($class_name, 'EEM_') === 0) {
354
+			return 'load_model';
355
+		}
356
+		// EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc
357
+		// perform strpos() first to avoid loading regex every time we load a class
358
+		if (strpos($class_name, 'EE_CPT_') === 0
359
+			&& preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name)
360
+		) {
361
+			return 'load_core';
362
+		}
363
+		$class_name = $this->getFqnForAlias($class_name);
364
+		return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : '';
365
+	}
366
+
367
+
368
+	/**
369
+	 * @return array
370
+	 */
371
+	public function class_loaders()
372
+	{
373
+		return $this->_class_loaders;
374
+	}
375
+
376
+
377
+	/**
378
+	 * adds an alias for a classname
379
+	 *
380
+	 * @param string $fqcn      the class name that should be used (concrete class to replace interface)
381
+	 * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
382
+	 * @param string $for_class the class that has the dependency (is type hinting for the interface)
383
+	 */
384
+	public function add_alias($fqcn, $alias, $for_class = '')
385
+	{
386
+		$this->class_cache->addAlias($fqcn, $alias, $for_class);
387
+	}
388
+
389
+
390
+	/**
391
+	 * Returns TRUE if the provided fully qualified name IS an alias
392
+	 * WHY?
393
+	 * Because if a class is type hinting for a concretion,
394
+	 * then why would we need to find another class to supply it?
395
+	 * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
396
+	 * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
397
+	 * Don't go looking for some substitute.
398
+	 * Whereas if a class is type hinting for an interface...
399
+	 * then we need to find an actual class to use.
400
+	 * So the interface IS the alias for some other FQN,
401
+	 * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
402
+	 * represents some other class.
403
+	 *
404
+	 * @param string $fqn
405
+	 * @param string $for_class
406
+	 * @return bool
407
+	 */
408
+	public function isAlias($fqn = '', $for_class = '')
409
+	{
410
+		return $this->class_cache->isAlias($fqn, $for_class);
411
+	}
412
+
413
+
414
+	/**
415
+	 * Returns a FQN for provided alias if one exists, otherwise returns the original $alias
416
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
417
+	 *  for example:
418
+	 *      if the following two entries were added to the _aliases array:
419
+	 *          array(
420
+	 *              'interface_alias'           => 'some\namespace\interface'
421
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
422
+	 *          )
423
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
424
+	 *      to load an instance of 'some\namespace\classname'
425
+	 *
426
+	 * @param string $alias
427
+	 * @param string $for_class
428
+	 * @return string
429
+	 */
430
+	public function getFqnForAlias($alias = '', $for_class = '')
431
+	{
432
+		return (string) $this->class_cache->getFqnForAlias($alias, $for_class);
433
+	}
434
+
435
+
436
+	/**
437
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
438
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
439
+	 * This is done by using the following class constants:
440
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
441
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
442
+	 */
443
+	protected function _register_core_dependencies()
444
+	{
445
+		$this->_dependency_map = array(
446
+			'EE_Request_Handler'                                                                                          => array(
447
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
448
+			),
449
+			'EE_System'                                                                                                   => array(
450
+				'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
451
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
452
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
453
+				'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
454
+			),
455
+			'EE_Session'                                                                                                  => array(
456
+				'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
457
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
458
+				'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
459
+				'EventEspresso\core\services\session\SessionStartHandler'  => EE_Dependency_Map::load_from_cache,
460
+				'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
461
+			),
462
+			'EE_Cart'                                                                                                     => array(
463
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
464
+			),
465
+			'EE_Front_Controller'                                                                                         => array(
466
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
467
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
468
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
469
+			),
470
+			'EE_Messenger_Collection_Loader'                                                                              => array(
471
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
472
+			),
473
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
474
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
475
+			),
476
+			'EE_Message_Resource_Manager'                                                                                 => array(
477
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
478
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
479
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
480
+			),
481
+			'EE_Message_Factory'                                                                                          => array(
482
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
483
+			),
484
+			'EE_messages'                                                                                                 => array(
485
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
486
+			),
487
+			'EE_Messages_Generator'                                                                                       => array(
488
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
489
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
490
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
491
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
492
+			),
493
+			'EE_Messages_Processor'                                                                                       => array(
494
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
495
+			),
496
+			'EE_Messages_Queue'                                                                                           => array(
497
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
498
+			),
499
+			'EE_Messages_Template_Defaults'                                                                               => array(
500
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
501
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
502
+			),
503
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
504
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
505
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
506
+			),
507
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
508
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
509
+			),
510
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
511
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
512
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
513
+			),
514
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
515
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
516
+			),
517
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
518
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
519
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
520
+			),
521
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
522
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
523
+			),
524
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
525
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
526
+			),
527
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
528
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
529
+			),
530
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
531
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
532
+			),
533
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
534
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
535
+			),
536
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
537
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
538
+			),
539
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
540
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
541
+			),
542
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
543
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
544
+			),
545
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
546
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
547
+			),
548
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
549
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
550
+			),
551
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
552
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
553
+			),
554
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
555
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
556
+			),
557
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
558
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
559
+			),
560
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
561
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
562
+			),
563
+			'EE_Data_Migration_Class_Base'                                                                                => array(
564
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
565
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
566
+			),
567
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
568
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
569
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
570
+			),
571
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
572
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
573
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
574
+			),
575
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
576
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
577
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
578
+			),
579
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
580
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
581
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
582
+			),
583
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
584
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
585
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
586
+			),
587
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
588
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
589
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
590
+			),
591
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
592
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
593
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
594
+			),
595
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
596
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
597
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
598
+			),
599
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
600
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
601
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
602
+			),
603
+			'EventEspresso\core\services\assets\I18nRegistry'                                                             => array(
604
+				array(),
605
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
606
+			),
607
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
608
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
609
+				'EventEspresso\core\services\assets\I18nRegistry'    => EE_Dependency_Map::load_from_cache,
610
+			),
611
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
612
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
613
+			),
614
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
615
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
616
+			),
617
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
618
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
619
+			),
620
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
621
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
622
+			),
623
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
624
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
625
+			),
626
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
627
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
628
+			),
629
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
630
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
631
+			),
632
+			'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
633
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
634
+			),
635
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
636
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
637
+			),
638
+			'EventEspresso\core\domain\services\validation\email\EmailValidationService'                                  => array(
639
+				'EE_Registration_Config'                     => EE_Dependency_Map::load_from_cache,
640
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
641
+			),
642
+			'EventEspresso\core\domain\values\EmailAddress'                                                               => array(
643
+				null,
644
+				'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
645
+			),
646
+			'EventEspresso\core\services\orm\ModelFieldFactory'                                                           => array(
647
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
648
+			),
649
+			'LEGACY_MODELS'                                                                                               => array(
650
+				null,
651
+				'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
652
+			),
653
+			'EE_Module_Request_Router'                                                                                    => array(
654
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
655
+			),
656
+			'EE_Registration_Processor'                                                                                   => array(
657
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
658
+			),
659
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'                                      => array(
660
+				null,
661
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
662
+				'EventEspresso\core\services\request\Request'                         => EE_Dependency_Map::load_from_cache,
663
+			),
664
+			'EventEspresso\core\services\licensing\LicenseService'                                                        => array(
665
+				'EventEspresso\core\domain\services\pue\Stats'  => EE_Dependency_Map::load_from_cache,
666
+				'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
667
+			),
668
+			'EE_Admin_Transactions_List_Table'                                                                            => array(
669
+				null,
670
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
671
+			),
672
+			'EventEspresso\core\domain\services\pue\Stats'                                                                => array(
673
+				'EventEspresso\core\domain\services\pue\Config'        => EE_Dependency_Map::load_from_cache,
674
+				'EE_Maintenance_Mode'                                  => EE_Dependency_Map::load_from_cache,
675
+				'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache,
676
+			),
677
+			'EventEspresso\core\domain\services\pue\Config'                                                               => array(
678
+				'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
679
+				'EE_Config'         => EE_Dependency_Map::load_from_cache,
680
+			),
681
+			'EventEspresso\core\domain\services\pue\StatsGatherer'                                                        => array(
682
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
683
+				'EEM_Event'          => EE_Dependency_Map::load_from_cache,
684
+				'EEM_Datetime'       => EE_Dependency_Map::load_from_cache,
685
+				'EEM_Ticket'         => EE_Dependency_Map::load_from_cache,
686
+				'EEM_Registration'   => EE_Dependency_Map::load_from_cache,
687
+				'EEM_Transaction'    => EE_Dependency_Map::load_from_cache,
688
+				'EE_Config'          => EE_Dependency_Map::load_from_cache,
689
+			),
690
+			'EventEspresso\core\domain\services\admin\ExitModal'                                                          => array(
691
+				'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache,
692
+			),
693
+			'EventEspresso\core\domain\services\admin\PluginUpsells'                                                      => array(
694
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
695
+			),
696
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha'                                    => array(
697
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
698
+				'EE_Session'             => EE_Dependency_Map::load_from_cache,
699
+			),
700
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings'                                => array(
701
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
702
+			),
703
+			'EventEspresso\modules\ticket_selector\ProcessTicketSelector'                                                 => array(
704
+				'EE_Core_Config'                                                          => EE_Dependency_Map::load_from_cache,
705
+				'EventEspresso\core\services\request\Request'                             => EE_Dependency_Map::load_from_cache,
706
+				'EE_Session'                                                              => EE_Dependency_Map::load_from_cache,
707
+				'EEM_Ticket'                                                              => EE_Dependency_Map::load_from_cache,
708
+				'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
709
+			),
710
+			'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'                                     => array(
711
+				'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
712
+			),
713
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'                              => array(
714
+				'EE_Core_Config'                             => EE_Dependency_Map::load_from_cache,
715
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
716
+			),
717
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'                                => array(
718
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
719
+			),
720
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'                               => array(
721
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
722
+			),
723
+			'EE_CPT_Strategy'                                                                                             => array(
724
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
725
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
726
+			),
727
+			'EventEspresso\core\services\loaders\ObjectIdentifier'                                                        => array(
728
+				'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache,
729
+			),
730
+			'EventEspresso\core\domain\services\assets\CoreAssetManager'                                                  => array(
731
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
732
+				'EE_Currency_Config'                                 => EE_Dependency_Map::load_from_cache,
733
+				'EE_Template_Config'                                 => EE_Dependency_Map::load_from_cache,
734
+				'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
735
+				'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
736
+			),
737
+			'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array(
738
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
739
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache
740
+			),
741
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array(
742
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
743
+			),
744
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array(
745
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
746
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache
747
+			),
748
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array(
749
+				'EEM_Checkin' => EE_Dependency_Map::load_from_cache,
750
+			),
751
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array(
752
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache,
753
+			),
754
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array(
755
+				'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
756
+			),
757
+			'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array(
758
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
759
+			),
760
+			'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array(
761
+				'EEM_Answer' => EE_Dependency_Map::load_from_cache,
762
+				'EEM_Question' => EE_Dependency_Map::load_from_cache,
763
+			),
764
+			'EventEspresso\core\CPTs\CptQueryModifier' => array(
765
+				null,
766
+				null,
767
+				null,
768
+				'EE_Request_Handler'                          => EE_Dependency_Map::load_from_cache,
769
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
770
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
771
+			),
772
+			'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array(
773
+				'EE_Registry' => EE_Dependency_Map::load_from_cache,
774
+				'EE_Config' => EE_Dependency_Map::load_from_cache
775
+			),
776
+			'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => array(
777
+				'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache
778
+			),
779
+			'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => array(
780
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
781
+			),
782
+			'EventEspresso\core\libraries\rest_api\controllers\model\Read' => array(
783
+				'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache
784
+			),
785
+			'EventEspresso\core\libraries\rest_api\calculations\Datetime' => array(
786
+				'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
787
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache
788
+			),
789
+			'EventEspresso\core\libraries\rest_api\calculations\Event' => array(
790
+				'EEM_Event' => EE_Dependency_Map::load_from_cache,
791
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache
792
+			),
793
+			'EventEspresso\core\libraries\rest_api\calculations\Registration' => array(
794
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache
795
+			),
796
+			'EventEspresso\core\services\session\SessionStartHandler' => array(
797
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
798
+			),
799
+			'EE_URL_Validation_Strategy' => array(
800
+				null,
801
+				null,
802
+				'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache
803
+			),
804
+		);
805
+	}
806
+
807
+
808
+	/**
809
+	 * Registers how core classes are loaded.
810
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
811
+	 *        'EE_Request_Handler' => 'load_core'
812
+	 *        'EE_Messages_Queue'  => 'load_lib'
813
+	 *        'EEH_Debug_Tools'    => 'load_helper'
814
+	 * or, if greater control is required, by providing a custom closure. For example:
815
+	 *        'Some_Class' => function () {
816
+	 *            return new Some_Class();
817
+	 *        },
818
+	 * This is required for instantiating dependencies
819
+	 * where an interface has been type hinted in a class constructor. For example:
820
+	 *        'Required_Interface' => function () {
821
+	 *            return new A_Class_That_Implements_Required_Interface();
822
+	 *        },
823
+	 */
824
+	protected function _register_core_class_loaders()
825
+	{
826
+		// for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
827
+		// be used in a closure.
828
+		$request = &$this->request;
829
+		$response = &$this->response;
830
+		$legacy_request = &$this->legacy_request;
831
+		// $loader = &$this->loader;
832
+		$this->_class_loaders = array(
833
+			// load_core
834
+			'EE_Capabilities'                              => 'load_core',
835
+			'EE_Encryption'                                => 'load_core',
836
+			'EE_Front_Controller'                          => 'load_core',
837
+			'EE_Module_Request_Router'                     => 'load_core',
838
+			'EE_Registry'                                  => 'load_core',
839
+			'EE_Request'                                   => function () use (&$legacy_request) {
840
+				return $legacy_request;
841
+			},
842
+			'EventEspresso\core\services\request\Request'  => function () use (&$request) {
843
+				return $request;
844
+			},
845
+			'EventEspresso\core\services\request\Response' => function () use (&$response) {
846
+				return $response;
847
+			},
848
+			'EE_Base'                                      => 'load_core',
849
+			'EE_Request_Handler'                           => 'load_core',
850
+			'EE_Session'                                   => 'load_core',
851
+			'EE_Cron_Tasks'                                => 'load_core',
852
+			'EE_System'                                    => 'load_core',
853
+			'EE_Maintenance_Mode'                          => 'load_core',
854
+			'EE_Register_CPTs'                             => 'load_core',
855
+			'EE_Admin'                                     => 'load_core',
856
+			'EE_CPT_Strategy'                              => 'load_core',
857
+			// load_lib
858
+			'EE_Message_Resource_Manager'                  => 'load_lib',
859
+			'EE_Message_Type_Collection'                   => 'load_lib',
860
+			'EE_Message_Type_Collection_Loader'            => 'load_lib',
861
+			'EE_Messenger_Collection'                      => 'load_lib',
862
+			'EE_Messenger_Collection_Loader'               => 'load_lib',
863
+			'EE_Messages_Processor'                        => 'load_lib',
864
+			'EE_Message_Repository'                        => 'load_lib',
865
+			'EE_Messages_Queue'                            => 'load_lib',
866
+			'EE_Messages_Data_Handler_Collection'          => 'load_lib',
867
+			'EE_Message_Template_Group_Collection'         => 'load_lib',
868
+			'EE_Payment_Method_Manager'                    => 'load_lib',
869
+			'EE_Messages_Generator'                        => function () {
870
+				return EE_Registry::instance()->load_lib(
871
+					'Messages_Generator',
872
+					array(),
873
+					false,
874
+					false
875
+				);
876
+			},
877
+			'EE_Messages_Template_Defaults'                => function ($arguments = array()) {
878
+				return EE_Registry::instance()->load_lib(
879
+					'Messages_Template_Defaults',
880
+					$arguments,
881
+					false,
882
+					false
883
+				);
884
+			},
885
+			// load_helper
886
+			'EEH_Parse_Shortcodes'                         => function () {
887
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
888
+					return new EEH_Parse_Shortcodes();
889
+				}
890
+				return null;
891
+			},
892
+			'EE_Template_Config'                           => function () {
893
+				return EE_Config::instance()->template_settings;
894
+			},
895
+			'EE_Currency_Config'                           => function () {
896
+				return EE_Config::instance()->currency;
897
+			},
898
+			'EE_Registration_Config'                       => function () {
899
+				return EE_Config::instance()->registration;
900
+			},
901
+			'EE_Core_Config'                               => function () {
902
+				return EE_Config::instance()->core;
903
+			},
904
+			'EventEspresso\core\services\loaders\Loader'   => function () {
905
+				return LoaderFactory::getLoader();
906
+			},
907
+			'EE_Network_Config'                            => function () {
908
+				return EE_Network_Config::instance();
909
+			},
910
+			'EE_Config'                                    => function () {
911
+				return EE_Config::instance();
912
+			},
913
+			'EventEspresso\core\domain\Domain'             => function () {
914
+				return DomainFactory::getEventEspressoCoreDomain();
915
+			},
916
+			'EE_Admin_Config'                              => function () {
917
+				return EE_Config::instance()->admin;
918
+			},
919
+		);
920
+	}
921
+
922
+
923
+	/**
924
+	 * can be used for supplying alternate names for classes,
925
+	 * or for connecting interface names to instantiable classes
926
+	 */
927
+	protected function _register_core_aliases()
928
+	{
929
+		$aliases = array(
930
+			'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
931
+			'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
932
+			'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
933
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
934
+			'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
935
+			'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
936
+			'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
937
+			'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
938
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
939
+			'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
940
+			'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
941
+			'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
942
+			'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
943
+			'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
944
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
945
+			'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
946
+			'CreateTransactionCommandHandler'                                              => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
947
+			'CreateAttendeeCommandHandler'                                                 => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
948
+			'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
949
+			'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
950
+			'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
951
+			'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
952
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
953
+			'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
954
+			'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
955
+			'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
956
+			'CommandFactoryInterface'                                                      => 'EventEspresso\core\services\commands\CommandFactoryInterface',
957
+			'EventEspresso\core\services\commands\CommandFactoryInterface'                 => 'EventEspresso\core\services\commands\CommandFactory',
958
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface'        => 'EE_Session',
959
+			'EmailValidatorInterface'                                                      => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
960
+			'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface'  => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
961
+			'NoticeConverterInterface'                                                     => 'EventEspresso\core\services\notices\NoticeConverterInterface',
962
+			'EventEspresso\core\services\notices\NoticeConverterInterface'                 => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
963
+			'NoticesContainerInterface'                                                    => 'EventEspresso\core\services\notices\NoticesContainerInterface',
964
+			'EventEspresso\core\services\notices\NoticesContainerInterface'                => 'EventEspresso\core\services\notices\NoticesContainer',
965
+			'EventEspresso\core\services\request\RequestInterface'                         => 'EventEspresso\core\services\request\Request',
966
+			'EventEspresso\core\services\request\ResponseInterface'                        => 'EventEspresso\core\services\request\Response',
967
+			'EventEspresso\core\domain\DomainInterface'                                    => 'EventEspresso\core\domain\Domain',
968
+		);
969
+		foreach ($aliases as $alias => $fqn) {
970
+			if (is_array($fqn)) {
971
+				foreach ($fqn as $class => $for_class) {
972
+					$this->class_cache->addAlias($class, $alias, $for_class);
973
+				}
974
+				continue;
975
+			}
976
+			$this->class_cache->addAlias($fqn, $alias);
977
+		}
978
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
979
+			$this->class_cache->addAlias(
980
+				'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
981
+				'EventEspresso\core\services\notices\NoticeConverterInterface'
982
+			);
983
+		}
984
+	}
985
+
986
+
987
+	/**
988
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
989
+	 * request Primarily used by unit tests.
990
+	 */
991
+	public function reset()
992
+	{
993
+		$this->_register_core_class_loaders();
994
+		$this->_register_core_dependencies();
995
+	}
996
+
997
+
998
+	/**
999
+	 * PLZ NOTE: a better name for this method would be is_alias()
1000
+	 * because it returns TRUE if the provided fully qualified name IS an alias
1001
+	 * WHY?
1002
+	 * Because if a class is type hinting for a concretion,
1003
+	 * then why would we need to find another class to supply it?
1004
+	 * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
1005
+	 * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
1006
+	 * Don't go looking for some substitute.
1007
+	 * Whereas if a class is type hinting for an interface...
1008
+	 * then we need to find an actual class to use.
1009
+	 * So the interface IS the alias for some other FQN,
1010
+	 * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
1011
+	 * represents some other class.
1012
+	 *
1013
+	 * @deprecated 4.9.62.p
1014
+	 * @param string $fqn
1015
+	 * @param string $for_class
1016
+	 * @return bool
1017
+	 */
1018
+	public function has_alias($fqn = '', $for_class = '')
1019
+	{
1020
+		return $this->isAlias($fqn, $for_class);
1021
+	}
1022
+
1023
+
1024
+	/**
1025
+	 * PLZ NOTE: a better name for this method would be get_fqn_for_alias()
1026
+	 * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias
1027
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
1028
+	 *  for example:
1029
+	 *      if the following two entries were added to the _aliases array:
1030
+	 *          array(
1031
+	 *              'interface_alias'           => 'some\namespace\interface'
1032
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
1033
+	 *          )
1034
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
1035
+	 *      to load an instance of 'some\namespace\classname'
1036
+	 *
1037
+	 * @deprecated 4.9.62.p
1038
+	 * @param string $alias
1039
+	 * @param string $for_class
1040
+	 * @return string
1041
+	 */
1042
+	public function get_alias($alias = '', $for_class = '')
1043
+	{
1044
+		return $this->getFqnForAlias($alias, $for_class);
1045
+	}
1046 1046
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.68.rc.013');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.68.rc.013');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.