Completed
Branch BUG/avoid-session-exception (04619c)
by
unknown
19:07 queued 10:18
created
core/EE_Session.core.php 4 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
     /**
543 543
      * @initiate session
544 544
      * @access   private
545
-     * @return TRUE on success, FALSE on fail
545
+     * @return boolean on success, FALSE on fail
546 546
      * @throws EE_Error
547 547
      * @throws InvalidArgumentException
548 548
      * @throws InvalidDataTypeException
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
      * @update session data  prior to saving to the db
779 779
      * @access public
780 780
      * @param bool $new_session
781
-     * @return TRUE on success, FALSE on fail
781
+     * @return boolean on success, FALSE on fail
782 782
      * @throws EE_Error
783 783
      * @throws InvalidArgumentException
784 784
      * @throws InvalidDataTypeException
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
      * _save_session_to_db
880 880
      *
881 881
      * @param bool $clear_session
882
-     * @return string
882
+     * @return boolean
883 883
      * @throws EE_Error
884 884
      * @throws InvalidArgumentException
885 885
      * @throws InvalidDataTypeException
Please login to merge, or discard this patch.
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   +1267 added lines, -1267 removed lines patch added patch discarded remove patch
@@ -25,1265 +25,1265 @@  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
197
-            && apply_filters('FHEE_load_EE_Session', true)
198
-            && $cache_storage instanceof CacheStorageInterface
199
-            && $lifespan instanceof SessionLifespan
200
-            && $request instanceof RequestInterface
201
-            && $session_start_handler instanceof SessionStartHandler
202
-        ) {
203
-            self::$_instance = new self(
204
-                $cache_storage,
205
-                $lifespan,
206
-                $request,
207
-                $session_start_handler,
208
-                $encryption
209
-            );
210
-        }
211
-        return self::$_instance;
212
-    }
213
-
214
-
215
-    /**
216
-     * protected constructor to prevent direct creation
217
-     *
218
-     * @param CacheStorageInterface $cache_storage
219
-     * @param SessionLifespan       $lifespan
220
-     * @param RequestInterface      $request
221
-     * @param SessionStartHandler   $session_start_handler
222
-     * @param EE_Encryption         $encryption
223
-     * @throws InvalidArgumentException
224
-     * @throws InvalidDataTypeException
225
-     * @throws InvalidInterfaceException
226
-     */
227
-    protected function __construct(
228
-        CacheStorageInterface $cache_storage,
229
-        SessionLifespan $lifespan,
230
-        RequestInterface $request,
231
-        SessionStartHandler $session_start_handler,
232
-        EE_Encryption $encryption = null
233
-    ) {
234
-        // session loading is turned ON by default,
235
-        // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook
236
-        // (which currently fires on the init hook at priority 9),
237
-        // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
238
-        if (! apply_filters('FHEE_load_EE_Session', true)) {
239
-            return;
240
-        }
241
-        $this->session_start_handler = $session_start_handler;
242
-        $this->session_lifespan = $lifespan;
243
-        $this->request = $request;
244
-        if (! defined('ESPRESSO_SESSION')) {
245
-            define('ESPRESSO_SESSION', true);
246
-        }
247
-        // retrieve session options from db
248
-        $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
249
-        if (! empty($session_settings)) {
250
-            // cycle though existing session options
251
-            foreach ($session_settings as $var_name => $session_setting) {
252
-                // set values for class properties
253
-                $var_name = '_' . $var_name;
254
-                $this->{$var_name} = $session_setting;
255
-            }
256
-        }
257
-        $this->cache_storage = $cache_storage;
258
-        // are we using encryption?
259
-        $this->_use_encryption = $encryption instanceof EE_Encryption
260
-                                 && EE_Registry::instance()->CFG->admin->encode_session_data();
261
-        // encrypt data via: $this->encryption->encrypt();
262
-        $this->encryption = $encryption;
263
-        // filter hook allows outside functions/classes/plugins to change default empty cart
264
-        $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
265
-        array_merge($this->_default_session_vars, $extra_default_session_vars);
266
-        // apply default session vars
267
-        $this->_set_defaults();
268
-        add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
269
-        // check request for 'clear_session' param
270
-        add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
271
-        // once everything is all said and done,
272
-        add_action('shutdown', array($this, 'update'), 100);
273
-        add_action('shutdown', array($this, 'garbageCollection'), 1000);
274
-        $this->configure_garbage_collection_filters();
275
-    }
276
-
277
-
278
-    /**
279
-     * @return bool
280
-     * @throws InvalidArgumentException
281
-     * @throws InvalidDataTypeException
282
-     * @throws InvalidInterfaceException
283
-     */
284
-    public static function isLoadedAndActive()
285
-    {
286
-        return did_action('AHEE__EE_System__core_loaded_and_ready')
287
-               && EE_Session::instance() instanceof EE_Session
288
-               && EE_Session::instance()->isActive();
289
-    }
290
-
291
-
292
-    /**
293
-     * @return bool
294
-     */
295
-    public function isActive()
296
-    {
297
-        return $this->status === EE_Session::STATUS_OPEN;
298
-    }
299
-
300
-
301
-    /**
302
-     * @return void
303
-     * @throws EE_Error
304
-     * @throws InvalidArgumentException
305
-     * @throws InvalidDataTypeException
306
-     * @throws InvalidInterfaceException
307
-     * @throws InvalidSessionDataException
308
-     */
309
-    public function open_session()
310
-    {
311
-        // check for existing session and retrieve it from db
312
-        if (! $this->_espresso_session()) {
313
-            // or just start a new one
314
-            $this->_create_espresso_session();
315
-        }
316
-    }
317
-
318
-
319
-    /**
320
-     * @return bool
321
-     */
322
-    public function expired()
323
-    {
324
-        return $this->_expired;
325
-    }
326
-
327
-
328
-    /**
329
-     * @return void
330
-     */
331
-    public function reset_expired()
332
-    {
333
-        $this->_expired = false;
334
-    }
335
-
336
-
337
-    /**
338
-     * @return int
339
-     */
340
-    public function expiration()
341
-    {
342
-        return $this->_expiration;
343
-    }
344
-
345
-
346
-    /**
347
-     * @return int
348
-     */
349
-    public function extension()
350
-    {
351
-        return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS);
352
-    }
353
-
354
-
355
-    /**
356
-     * @param int $time number of seconds to add to session expiration
357
-     */
358
-    public function extend_expiration($time = 0)
359
-    {
360
-        $time = $time ? $time : $this->extension();
361
-        $this->_expiration += absint($time);
362
-    }
363
-
364
-
365
-    /**
366
-     * @return int
367
-     */
368
-    public function lifespan()
369
-    {
370
-        return $this->session_lifespan->inSeconds();
371
-    }
372
-
373
-
374
-    /**
375
-     * This just sets some defaults for the _session data property
376
-     *
377
-     * @access private
378
-     * @return void
379
-     */
380
-    private function _set_defaults()
381
-    {
382
-        // set some defaults
383
-        foreach ($this->_default_session_vars as $key => $default_var) {
384
-            if (is_array($default_var)) {
385
-                $this->_session_data[ $key ] = array();
386
-            } else {
387
-                $this->_session_data[ $key ] = '';
388
-            }
389
-        }
390
-    }
391
-
392
-
393
-    /**
394
-     * @retrieve  session data
395
-     * @access    public
396
-     * @return    string
397
-     */
398
-    public function id()
399
-    {
400
-        return $this->_sid;
401
-    }
402
-
403
-
404
-    /**
405
-     * @param \EE_Cart $cart
406
-     * @return bool
407
-     */
408
-    public function set_cart(EE_Cart $cart)
409
-    {
410
-        $this->_session_data['cart'] = $cart;
411
-        return true;
412
-    }
413
-
414
-
415
-    /**
416
-     * reset_cart
417
-     */
418
-    public function reset_cart()
419
-    {
420
-        do_action('AHEE__EE_Session__reset_cart__before_reset', $this);
421
-        $this->_session_data['cart'] = null;
422
-    }
423
-
424
-
425
-    /**
426
-     * @return \EE_Cart
427
-     */
428
-    public function cart()
429
-    {
430
-        return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart
431
-            ? $this->_session_data['cart']
432
-            : null;
433
-    }
434
-
435
-
436
-    /**
437
-     * @param \EE_Checkout $checkout
438
-     * @return bool
439
-     */
440
-    public function set_checkout(EE_Checkout $checkout)
441
-    {
442
-        $this->_session_data['checkout'] = $checkout;
443
-        return true;
444
-    }
445
-
446
-
447
-    /**
448
-     * reset_checkout
449
-     */
450
-    public function reset_checkout()
451
-    {
452
-        do_action('AHEE__EE_Session__reset_checkout__before_reset', $this);
453
-        $this->_session_data['checkout'] = null;
454
-    }
455
-
456
-
457
-    /**
458
-     * @return \EE_Checkout
459
-     */
460
-    public function checkout()
461
-    {
462
-        return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout
463
-            ? $this->_session_data['checkout']
464
-            : null;
465
-    }
466
-
467
-
468
-    /**
469
-     * @param \EE_Transaction $transaction
470
-     * @return bool
471
-     * @throws EE_Error
472
-     */
473
-    public function set_transaction(EE_Transaction $transaction)
474
-    {
475
-        // first remove the session from the transaction before we save the transaction in the session
476
-        $transaction->set_txn_session_data(null);
477
-        $this->_session_data['transaction'] = $transaction;
478
-        return true;
479
-    }
480
-
481
-
482
-    /**
483
-     * reset_transaction
484
-     */
485
-    public function reset_transaction()
486
-    {
487
-        do_action('AHEE__EE_Session__reset_transaction__before_reset', $this);
488
-        $this->_session_data['transaction'] = null;
489
-    }
490
-
491
-
492
-    /**
493
-     * @return \EE_Transaction
494
-     */
495
-    public function transaction()
496
-    {
497
-        return isset($this->_session_data['transaction'])
498
-               && $this->_session_data['transaction'] instanceof EE_Transaction
499
-            ? $this->_session_data['transaction']
500
-            : null;
501
-    }
502
-
503
-
504
-    /**
505
-     * retrieve session data
506
-     *
507
-     * @param null $key
508
-     * @param bool $reset_cache
509
-     * @return array
510
-     */
511
-    public function get_session_data($key = null, $reset_cache = false)
512
-    {
513
-        if ($reset_cache) {
514
-            $this->reset_cart();
515
-            $this->reset_checkout();
516
-            $this->reset_transaction();
517
-        }
518
-        if (! empty($key)) {
519
-            return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
520
-        }
521
-        return $this->_session_data;
522
-    }
523
-
524
-
525
-    /**
526
-     * Returns TRUE on success, FALSE on fail
527
-     *
528
-     * @param array $data
529
-     * @return bool
530
-     */
531
-    public function set_session_data($data)
532
-    {
533
-        // nothing ??? bad data ??? go home!
534
-        if (empty($data) || ! is_array($data)) {
535
-            EE_Error::add_error(
536
-                esc_html__(
537
-                    'No session data or invalid session data was provided.',
538
-                    'event_espresso'
539
-                ),
540
-                __FILE__,
541
-                __FUNCTION__,
542
-                __LINE__
543
-            );
544
-            return false;
545
-        }
546
-        foreach ($data as $key => $value) {
547
-            if (isset($this->_default_session_vars[ $key ])) {
548
-                EE_Error::add_error(
549
-                    sprintf(
550
-                        esc_html__(
551
-                            'Sorry! %s is a default session datum and can not be reset.',
552
-                            'event_espresso'
553
-                        ),
554
-                        $key
555
-                    ),
556
-                    __FILE__,
557
-                    __FUNCTION__,
558
-                    __LINE__
559
-                );
560
-                return false;
561
-            }
562
-            $this->_session_data[ $key ] = $value;
563
-        }
564
-        return true;
565
-    }
566
-
567
-
568
-    /**
569
-     * @initiate session
570
-     * @access   private
571
-     * @return TRUE on success, FALSE on fail
572
-     * @throws EE_Error
573
-     * @throws InvalidArgumentException
574
-     * @throws InvalidDataTypeException
575
-     * @throws InvalidInterfaceException
576
-     * @throws InvalidSessionDataException
577
-     */
578
-    private function _espresso_session()
579
-    {
580
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
581
-        $this->session_start_handler->startSession();
582
-        $this->status = EE_Session::STATUS_OPEN;
583
-        // get our modified session ID
584
-        $this->_sid = $this->_generate_session_id();
585
-        // and the visitors IP
586
-        $this->_ip_address = $this->request->ipAddress();
587
-        // set the "user agent"
588
-        $this->_user_agent = $this->request->userAgent();
589
-        // now let's retrieve what's in the db
590
-        $session_data = $this->_retrieve_session_data();
591
-        if (! empty($session_data)) {
592
-            // get the current time in UTC
593
-            $this->_time = $this->_time !== null ? $this->_time : time();
594
-            // and reset the session expiration
595
-            $this->_expiration = isset($session_data['expiration'])
596
-                ? $session_data['expiration']
597
-                : $this->_time + $this->session_lifespan->inSeconds();
598
-        } else {
599
-            // set initial site access time and the session expiration
600
-            $this->_set_init_access_and_expiration();
601
-            // set referer
602
-            $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER'])
603
-                ? esc_attr($_SERVER['HTTP_REFERER'])
604
-                : '';
605
-            // no previous session = go back and create one (on top of the data above)
606
-            return false;
607
-        }
608
-        // now the user agent
609
-        if ($session_data['user_agent'] !== $this->_user_agent) {
610
-            return false;
611
-        }
612
-        // wait a minute... how old are you?
613
-        if ($this->_time > $this->_expiration) {
614
-            // yer too old fer me!
615
-            $this->_expired = true;
616
-            // wipe out everything that isn't a default session datum
617
-            $this->clear_session(__CLASS__, __FUNCTION__);
618
-        }
619
-        // make event espresso session data available to plugin
620
-        $this->_session_data = array_merge($this->_session_data, $session_data);
621
-        return true;
622
-    }
623
-
624
-
625
-    /**
626
-     * _get_session_data
627
-     * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup
628
-     * databases
629
-     *
630
-     * @return array
631
-     * @throws EE_Error
632
-     * @throws InvalidArgumentException
633
-     * @throws InvalidSessionDataException
634
-     * @throws InvalidDataTypeException
635
-     * @throws InvalidInterfaceException
636
-     */
637
-    protected function _retrieve_session_data()
638
-    {
639
-        $ssn_key = EE_Session::session_id_prefix . $this->_sid;
640
-        try {
641
-            // we're using WP's Transient API to store session data using the PHP session ID as the option name
642
-            $session_data = $this->cache_storage->get($ssn_key, false);
643
-            if (empty($session_data)) {
644
-                return array();
645
-            }
646
-            if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
647
-                $hash_check = $this->cache_storage->get(
648
-                    EE_Session::hash_check_prefix . $this->_sid,
649
-                    false
650
-                );
651
-                if ($hash_check && $hash_check !== md5($session_data)) {
652
-                    EE_Error::add_error(
653
-                        sprintf(
654
-                            __(
655
-                                'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
656
-                                'event_espresso'
657
-                            ),
658
-                            EE_Session::session_id_prefix . $this->_sid
659
-                        ),
660
-                        __FILE__,
661
-                        __FUNCTION__,
662
-                        __LINE__
663
-                    );
664
-                }
665
-            }
666
-        } catch (Exception $e) {
667
-            // let's just eat that error for now and attempt to correct any corrupted data
668
-            global $wpdb;
669
-            $row = $wpdb->get_row(
670
-                $wpdb->prepare(
671
-                    "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
672
-                    '_transient_' . $ssn_key
673
-                )
674
-            );
675
-            $session_data = is_object($row) ? $row->option_value : null;
676
-            if ($session_data) {
677
-                $session_data = preg_replace_callback(
678
-                    '!s:(d+):"(.*?)";!',
679
-                    function ($match) {
680
-                        return $match[1] === strlen($match[2])
681
-                            ? $match[0]
682
-                            : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
683
-                    },
684
-                    $session_data
685
-                );
686
-            }
687
-            $session_data = maybe_unserialize($session_data);
688
-        }
689
-        // in case the data is encoded... try to decode it
690
-        $session_data = $this->encryption instanceof EE_Encryption
691
-            ? $this->encryption->base64_string_decode($session_data)
692
-            : $session_data;
693
-        if (! is_array($session_data)) {
694
-            try {
695
-                $session_data = maybe_unserialize($session_data);
696
-            } catch (Exception $e) {
697
-                $msg = esc_html__(
698
-                    'An error occurred while attempting to unserialize the session data.',
699
-                    'event_espresso'
700
-                );
701
-                $msg .= WP_DEBUG
702
-                    ? '<br><pre>'
703
-                      . print_r($session_data, true)
704
-                      . '</pre><br>'
705
-                      . $this->find_serialize_error($session_data)
706
-                    : '';
707
-                $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
708
-                throw new InvalidSessionDataException($msg, 0, $e);
709
-            }
710
-        }
711
-        // just a check to make sure the session array is indeed an array
712
-        if (! is_array($session_data)) {
713
-            // no?!?! then something is wrong
714
-            $msg = esc_html__(
715
-                'The session data is missing, invalid, or corrupted.',
716
-                'event_espresso'
717
-            );
718
-            $msg .= WP_DEBUG
719
-                ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
720
-                : '';
721
-            $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
722
-            throw new InvalidSessionDataException($msg);
723
-        }
724
-        if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
725
-            $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
726
-                $session_data['transaction']
727
-            );
728
-        }
729
-        return $session_data;
730
-    }
731
-
732
-
733
-    /**
734
-     * _generate_session_id
735
-     * Retrieves the PHP session id either directly from the PHP session,
736
-     * or from the $_REQUEST array if it was passed in from an AJAX request.
737
-     * The session id is then salted and hashed (mmm sounds tasty)
738
-     * so that it can be safely used as a $_REQUEST param
739
-     *
740
-     * @return string
741
-     */
742
-    protected function _generate_session_id()
743
-    {
744
-        // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
745
-        if (isset($_REQUEST['EESID'])) {
746
-            $session_id = sanitize_text_field($_REQUEST['EESID']);
747
-        } else {
748
-            $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
749
-        }
750
-        return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
751
-    }
752
-
753
-
754
-    /**
755
-     * _get_sid_salt
756
-     *
757
-     * @return string
758
-     */
759
-    protected function _get_sid_salt()
760
-    {
761
-        // was session id salt already saved to db ?
762
-        if (empty($this->_sid_salt)) {
763
-            // no?  then maybe use WP defined constant
764
-            if (defined('AUTH_SALT')) {
765
-                $this->_sid_salt = AUTH_SALT;
766
-            }
767
-            // if salt doesn't exist or is too short
768
-            if (strlen($this->_sid_salt) < 32) {
769
-                // create a new one
770
-                $this->_sid_salt = wp_generate_password(64);
771
-            }
772
-            // and save it as a permanent session setting
773
-            $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt));
774
-        }
775
-        return $this->_sid_salt;
776
-    }
777
-
778
-
779
-    /**
780
-     * _set_init_access_and_expiration
781
-     *
782
-     * @return void
783
-     */
784
-    protected function _set_init_access_and_expiration()
785
-    {
786
-        $this->_time = time();
787
-        $this->_expiration = $this->_time + $this->session_lifespan->inSeconds();
788
-        // set initial site access time
789
-        $this->_session_data['init_access'] = $this->_time;
790
-        // and the session expiration
791
-        $this->_session_data['expiration'] = $this->_expiration;
792
-    }
793
-
794
-
795
-    /**
796
-     * @update session data  prior to saving to the db
797
-     * @access public
798
-     * @param bool $new_session
799
-     * @return TRUE on success, FALSE on fail
800
-     * @throws EE_Error
801
-     * @throws InvalidArgumentException
802
-     * @throws InvalidDataTypeException
803
-     * @throws InvalidInterfaceException
804
-     */
805
-    public function update($new_session = false)
806
-    {
807
-        $this->_session_data = $this->_session_data !== null
808
-                               && is_array($this->_session_data)
809
-                               && isset($this->_session_data['id'])
810
-            ? $this->_session_data
811
-            : array();
812
-        if (empty($this->_session_data)) {
813
-            $this->_set_defaults();
814
-        }
815
-        $session_data = array();
816
-        foreach ($this->_session_data as $key => $value) {
817
-            switch ($key) {
818
-                case 'id':
819
-                    // session ID
820
-                    $session_data['id'] = $this->_sid;
821
-                    break;
822
-                case 'ip_address':
823
-                    // visitor ip address
824
-                    $session_data['ip_address'] = $this->request->ipAddress();
825
-                    break;
826
-                case 'user_agent':
827
-                    // visitor user_agent
828
-                    $session_data['user_agent'] = $this->_user_agent;
829
-                    break;
830
-                case 'init_access':
831
-                    $session_data['init_access'] = absint($value);
832
-                    break;
833
-                case 'last_access':
834
-                    // current access time
835
-                    $session_data['last_access'] = $this->_time;
836
-                    break;
837
-                case 'expiration':
838
-                    // when the session expires
839
-                    $session_data['expiration'] = ! empty($this->_expiration)
840
-                        ? $this->_expiration
841
-                        : $session_data['init_access'] + $this->session_lifespan->inSeconds();
842
-                    break;
843
-                case 'user_id':
844
-                    // current user if logged in
845
-                    $session_data['user_id'] = $this->_wp_user_id();
846
-                    break;
847
-                case 'pages_visited':
848
-                    $page_visit = $this->_get_page_visit();
849
-                    if ($page_visit) {
850
-                        // set pages visited where the first will be the http referrer
851
-                        $this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
852
-                        // we'll only save the last 10 page visits.
853
-                        $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
854
-                    }
855
-                    break;
856
-                default:
857
-                    // carry any other data over
858
-                    $session_data[ $key ] = $this->_session_data[ $key ];
859
-            }
860
-        }
861
-        $this->_session_data = $session_data;
862
-        // creating a new session does not require saving to the db just yet
863
-        if (! $new_session) {
864
-            // ready? let's save
865
-            if ($this->_save_session_to_db()) {
866
-                return true;
867
-            }
868
-            return false;
869
-        }
870
-        // meh, why not?
871
-        return true;
872
-    }
873
-
874
-
875
-    /**
876
-     * @create session data array
877
-     * @access public
878
-     * @return bool
879
-     * @throws EE_Error
880
-     * @throws InvalidArgumentException
881
-     * @throws InvalidDataTypeException
882
-     * @throws InvalidInterfaceException
883
-     */
884
-    private function _create_espresso_session()
885
-    {
886
-        do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
887
-        // use the update function for now with $new_session arg set to TRUE
888
-        return $this->update(true) ? true : false;
889
-    }
890
-
891
-    /**
892
-     * Detects if there is anything worth saving in the session (eg the cart is a good one, notices are pretty good
893
-     * too). This is used when determining if we want to save the session or not.
894
-     * @since 4.9.67.p
895
-     * @return bool
896
-     */
897
-    private function sessionHasStuffWorthSaving()
898
-    {
899
-        return $this->cart() instanceof EE_Cart
900
-            || (
901
-                isset($this->_session_data['ee_notices'])
902
-                && (
903
-                    ! empty($this->_session_data['ee_notices']['attention'])
904
-                    || !empty($this->_session_data['ee_notices']['errors'])
905
-                    || !empty($this->_session_data['ee_notices']['success'])
906
-                )
907
-            );
908
-    }
909
-    /**
910
-     * _save_session_to_db
911
-     *
912
-     * @param bool $clear_session
913
-     * @return string
914
-     * @throws EE_Error
915
-     * @throws InvalidArgumentException
916
-     * @throws InvalidDataTypeException
917
-     * @throws InvalidInterfaceException
918
-     */
919
-    private function _save_session_to_db($clear_session = false)
920
-    {
921
-        // don't save sessions for crawlers
922
-        // and unless we're deleting the session data, don't save anything if there isn't a cart
923
-        if ($this->request->isBot()
924
-            || (
925
-                ! $clear_session
926
-                && ! $this->sessionHasStuffWorthSaving()
927
-                && apply_filters('FHEE__EE_Session___save_session_to_db__abort_session_save', true)
928
-            )
929
-        ) {
930
-            return false;
931
-        }
932
-        $transaction = $this->transaction();
933
-        if ($transaction instanceof EE_Transaction) {
934
-            if (! $transaction->ID()) {
935
-                $transaction->save();
936
-            }
937
-            $this->_session_data['transaction'] = $transaction->ID();
938
-        }
939
-        // then serialize all of our session data
940
-        $session_data = serialize($this->_session_data);
941
-        // do we need to also encode it to avoid corrupted data when saved to the db?
942
-        $session_data = $this->_use_encryption
943
-            ? $this->encryption->base64_string_encode($session_data)
944
-            : $session_data;
945
-        // maybe save hash check
946
-        if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
947
-            $this->cache_storage->add(
948
-                EE_Session::hash_check_prefix . $this->_sid,
949
-                md5($session_data),
950
-                $this->session_lifespan->inSeconds()
951
-            );
952
-        }
953
-        // we're using the Transient API for storing session data,
954
-        return $this->cache_storage->add(
955
-            EE_Session::session_id_prefix . $this->_sid,
956
-            $session_data,
957
-            $this->session_lifespan->inSeconds()
958
-        );
959
-    }
960
-
961
-
962
-    /**
963
-     * @get    the full page request the visitor is accessing
964
-     * @access public
965
-     * @return string
966
-     */
967
-    public function _get_page_visit()
968
-    {
969
-        $page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
970
-        // check for request url
971
-        if (isset($_SERVER['REQUEST_URI'])) {
972
-            $http_host = '';
973
-            $page_id = '?';
974
-            $e_reg = '';
975
-            $request_uri = esc_url($_SERVER['REQUEST_URI']);
976
-            $ru_bits = explode('?', $request_uri);
977
-            $request_uri = $ru_bits[0];
978
-            // check for and grab host as well
979
-            if (isset($_SERVER['HTTP_HOST'])) {
980
-                $http_host = esc_url($_SERVER['HTTP_HOST']);
981
-            }
982
-            // check for page_id in SERVER REQUEST
983
-            if (isset($_REQUEST['page_id'])) {
984
-                // rebuild $e_reg without any of the extra parameters
985
-                $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&amp;';
986
-            }
987
-            // check for $e_reg in SERVER REQUEST
988
-            if (isset($_REQUEST['ee'])) {
989
-                // rebuild $e_reg without any of the extra parameters
990
-                $e_reg = 'ee=' . esc_attr($_REQUEST['ee']);
991
-            }
992
-            $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?');
993
-        }
994
-        return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
995
-    }
996
-
997
-
998
-    /**
999
-     * @the    current wp user id
1000
-     * @access public
1001
-     * @return int
1002
-     */
1003
-    public function _wp_user_id()
1004
-    {
1005
-        // if I need to explain the following lines of code, then you shouldn't be looking at this!
1006
-        $this->_wp_user_id = get_current_user_id();
1007
-        return $this->_wp_user_id;
1008
-    }
1009
-
1010
-
1011
-    /**
1012
-     * Clear EE_Session data
1013
-     *
1014
-     * @access public
1015
-     * @param string $class
1016
-     * @param string $function
1017
-     * @return void
1018
-     * @throws EE_Error
1019
-     * @throws InvalidArgumentException
1020
-     * @throws InvalidDataTypeException
1021
-     * @throws InvalidInterfaceException
1022
-     */
1023
-    public function clear_session($class = '', $function = '')
1024
-    {
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
197
+			&& apply_filters('FHEE_load_EE_Session', true)
198
+			&& $cache_storage instanceof CacheStorageInterface
199
+			&& $lifespan instanceof SessionLifespan
200
+			&& $request instanceof RequestInterface
201
+			&& $session_start_handler instanceof SessionStartHandler
202
+		) {
203
+			self::$_instance = new self(
204
+				$cache_storage,
205
+				$lifespan,
206
+				$request,
207
+				$session_start_handler,
208
+				$encryption
209
+			);
210
+		}
211
+		return self::$_instance;
212
+	}
213
+
214
+
215
+	/**
216
+	 * protected constructor to prevent direct creation
217
+	 *
218
+	 * @param CacheStorageInterface $cache_storage
219
+	 * @param SessionLifespan       $lifespan
220
+	 * @param RequestInterface      $request
221
+	 * @param SessionStartHandler   $session_start_handler
222
+	 * @param EE_Encryption         $encryption
223
+	 * @throws InvalidArgumentException
224
+	 * @throws InvalidDataTypeException
225
+	 * @throws InvalidInterfaceException
226
+	 */
227
+	protected function __construct(
228
+		CacheStorageInterface $cache_storage,
229
+		SessionLifespan $lifespan,
230
+		RequestInterface $request,
231
+		SessionStartHandler $session_start_handler,
232
+		EE_Encryption $encryption = null
233
+	) {
234
+		// session loading is turned ON by default,
235
+		// but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook
236
+		// (which currently fires on the init hook at priority 9),
237
+		// can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
238
+		if (! apply_filters('FHEE_load_EE_Session', true)) {
239
+			return;
240
+		}
241
+		$this->session_start_handler = $session_start_handler;
242
+		$this->session_lifespan = $lifespan;
243
+		$this->request = $request;
244
+		if (! defined('ESPRESSO_SESSION')) {
245
+			define('ESPRESSO_SESSION', true);
246
+		}
247
+		// retrieve session options from db
248
+		$session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
249
+		if (! empty($session_settings)) {
250
+			// cycle though existing session options
251
+			foreach ($session_settings as $var_name => $session_setting) {
252
+				// set values for class properties
253
+				$var_name = '_' . $var_name;
254
+				$this->{$var_name} = $session_setting;
255
+			}
256
+		}
257
+		$this->cache_storage = $cache_storage;
258
+		// are we using encryption?
259
+		$this->_use_encryption = $encryption instanceof EE_Encryption
260
+								 && EE_Registry::instance()->CFG->admin->encode_session_data();
261
+		// encrypt data via: $this->encryption->encrypt();
262
+		$this->encryption = $encryption;
263
+		// filter hook allows outside functions/classes/plugins to change default empty cart
264
+		$extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
265
+		array_merge($this->_default_session_vars, $extra_default_session_vars);
266
+		// apply default session vars
267
+		$this->_set_defaults();
268
+		add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
269
+		// check request for 'clear_session' param
270
+		add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
271
+		// once everything is all said and done,
272
+		add_action('shutdown', array($this, 'update'), 100);
273
+		add_action('shutdown', array($this, 'garbageCollection'), 1000);
274
+		$this->configure_garbage_collection_filters();
275
+	}
276
+
277
+
278
+	/**
279
+	 * @return bool
280
+	 * @throws InvalidArgumentException
281
+	 * @throws InvalidDataTypeException
282
+	 * @throws InvalidInterfaceException
283
+	 */
284
+	public static function isLoadedAndActive()
285
+	{
286
+		return did_action('AHEE__EE_System__core_loaded_and_ready')
287
+			   && EE_Session::instance() instanceof EE_Session
288
+			   && EE_Session::instance()->isActive();
289
+	}
290
+
291
+
292
+	/**
293
+	 * @return bool
294
+	 */
295
+	public function isActive()
296
+	{
297
+		return $this->status === EE_Session::STATUS_OPEN;
298
+	}
299
+
300
+
301
+	/**
302
+	 * @return void
303
+	 * @throws EE_Error
304
+	 * @throws InvalidArgumentException
305
+	 * @throws InvalidDataTypeException
306
+	 * @throws InvalidInterfaceException
307
+	 * @throws InvalidSessionDataException
308
+	 */
309
+	public function open_session()
310
+	{
311
+		// check for existing session and retrieve it from db
312
+		if (! $this->_espresso_session()) {
313
+			// or just start a new one
314
+			$this->_create_espresso_session();
315
+		}
316
+	}
317
+
318
+
319
+	/**
320
+	 * @return bool
321
+	 */
322
+	public function expired()
323
+	{
324
+		return $this->_expired;
325
+	}
326
+
327
+
328
+	/**
329
+	 * @return void
330
+	 */
331
+	public function reset_expired()
332
+	{
333
+		$this->_expired = false;
334
+	}
335
+
336
+
337
+	/**
338
+	 * @return int
339
+	 */
340
+	public function expiration()
341
+	{
342
+		return $this->_expiration;
343
+	}
344
+
345
+
346
+	/**
347
+	 * @return int
348
+	 */
349
+	public function extension()
350
+	{
351
+		return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS);
352
+	}
353
+
354
+
355
+	/**
356
+	 * @param int $time number of seconds to add to session expiration
357
+	 */
358
+	public function extend_expiration($time = 0)
359
+	{
360
+		$time = $time ? $time : $this->extension();
361
+		$this->_expiration += absint($time);
362
+	}
363
+
364
+
365
+	/**
366
+	 * @return int
367
+	 */
368
+	public function lifespan()
369
+	{
370
+		return $this->session_lifespan->inSeconds();
371
+	}
372
+
373
+
374
+	/**
375
+	 * This just sets some defaults for the _session data property
376
+	 *
377
+	 * @access private
378
+	 * @return void
379
+	 */
380
+	private function _set_defaults()
381
+	{
382
+		// set some defaults
383
+		foreach ($this->_default_session_vars as $key => $default_var) {
384
+			if (is_array($default_var)) {
385
+				$this->_session_data[ $key ] = array();
386
+			} else {
387
+				$this->_session_data[ $key ] = '';
388
+			}
389
+		}
390
+	}
391
+
392
+
393
+	/**
394
+	 * @retrieve  session data
395
+	 * @access    public
396
+	 * @return    string
397
+	 */
398
+	public function id()
399
+	{
400
+		return $this->_sid;
401
+	}
402
+
403
+
404
+	/**
405
+	 * @param \EE_Cart $cart
406
+	 * @return bool
407
+	 */
408
+	public function set_cart(EE_Cart $cart)
409
+	{
410
+		$this->_session_data['cart'] = $cart;
411
+		return true;
412
+	}
413
+
414
+
415
+	/**
416
+	 * reset_cart
417
+	 */
418
+	public function reset_cart()
419
+	{
420
+		do_action('AHEE__EE_Session__reset_cart__before_reset', $this);
421
+		$this->_session_data['cart'] = null;
422
+	}
423
+
424
+
425
+	/**
426
+	 * @return \EE_Cart
427
+	 */
428
+	public function cart()
429
+	{
430
+		return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart
431
+			? $this->_session_data['cart']
432
+			: null;
433
+	}
434
+
435
+
436
+	/**
437
+	 * @param \EE_Checkout $checkout
438
+	 * @return bool
439
+	 */
440
+	public function set_checkout(EE_Checkout $checkout)
441
+	{
442
+		$this->_session_data['checkout'] = $checkout;
443
+		return true;
444
+	}
445
+
446
+
447
+	/**
448
+	 * reset_checkout
449
+	 */
450
+	public function reset_checkout()
451
+	{
452
+		do_action('AHEE__EE_Session__reset_checkout__before_reset', $this);
453
+		$this->_session_data['checkout'] = null;
454
+	}
455
+
456
+
457
+	/**
458
+	 * @return \EE_Checkout
459
+	 */
460
+	public function checkout()
461
+	{
462
+		return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout
463
+			? $this->_session_data['checkout']
464
+			: null;
465
+	}
466
+
467
+
468
+	/**
469
+	 * @param \EE_Transaction $transaction
470
+	 * @return bool
471
+	 * @throws EE_Error
472
+	 */
473
+	public function set_transaction(EE_Transaction $transaction)
474
+	{
475
+		// first remove the session from the transaction before we save the transaction in the session
476
+		$transaction->set_txn_session_data(null);
477
+		$this->_session_data['transaction'] = $transaction;
478
+		return true;
479
+	}
480
+
481
+
482
+	/**
483
+	 * reset_transaction
484
+	 */
485
+	public function reset_transaction()
486
+	{
487
+		do_action('AHEE__EE_Session__reset_transaction__before_reset', $this);
488
+		$this->_session_data['transaction'] = null;
489
+	}
490
+
491
+
492
+	/**
493
+	 * @return \EE_Transaction
494
+	 */
495
+	public function transaction()
496
+	{
497
+		return isset($this->_session_data['transaction'])
498
+			   && $this->_session_data['transaction'] instanceof EE_Transaction
499
+			? $this->_session_data['transaction']
500
+			: null;
501
+	}
502
+
503
+
504
+	/**
505
+	 * retrieve session data
506
+	 *
507
+	 * @param null $key
508
+	 * @param bool $reset_cache
509
+	 * @return array
510
+	 */
511
+	public function get_session_data($key = null, $reset_cache = false)
512
+	{
513
+		if ($reset_cache) {
514
+			$this->reset_cart();
515
+			$this->reset_checkout();
516
+			$this->reset_transaction();
517
+		}
518
+		if (! empty($key)) {
519
+			return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
520
+		}
521
+		return $this->_session_data;
522
+	}
523
+
524
+
525
+	/**
526
+	 * Returns TRUE on success, FALSE on fail
527
+	 *
528
+	 * @param array $data
529
+	 * @return bool
530
+	 */
531
+	public function set_session_data($data)
532
+	{
533
+		// nothing ??? bad data ??? go home!
534
+		if (empty($data) || ! is_array($data)) {
535
+			EE_Error::add_error(
536
+				esc_html__(
537
+					'No session data or invalid session data was provided.',
538
+					'event_espresso'
539
+				),
540
+				__FILE__,
541
+				__FUNCTION__,
542
+				__LINE__
543
+			);
544
+			return false;
545
+		}
546
+		foreach ($data as $key => $value) {
547
+			if (isset($this->_default_session_vars[ $key ])) {
548
+				EE_Error::add_error(
549
+					sprintf(
550
+						esc_html__(
551
+							'Sorry! %s is a default session datum and can not be reset.',
552
+							'event_espresso'
553
+						),
554
+						$key
555
+					),
556
+					__FILE__,
557
+					__FUNCTION__,
558
+					__LINE__
559
+				);
560
+				return false;
561
+			}
562
+			$this->_session_data[ $key ] = $value;
563
+		}
564
+		return true;
565
+	}
566
+
567
+
568
+	/**
569
+	 * @initiate session
570
+	 * @access   private
571
+	 * @return TRUE on success, FALSE on fail
572
+	 * @throws EE_Error
573
+	 * @throws InvalidArgumentException
574
+	 * @throws InvalidDataTypeException
575
+	 * @throws InvalidInterfaceException
576
+	 * @throws InvalidSessionDataException
577
+	 */
578
+	private function _espresso_session()
579
+	{
580
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
581
+		$this->session_start_handler->startSession();
582
+		$this->status = EE_Session::STATUS_OPEN;
583
+		// get our modified session ID
584
+		$this->_sid = $this->_generate_session_id();
585
+		// and the visitors IP
586
+		$this->_ip_address = $this->request->ipAddress();
587
+		// set the "user agent"
588
+		$this->_user_agent = $this->request->userAgent();
589
+		// now let's retrieve what's in the db
590
+		$session_data = $this->_retrieve_session_data();
591
+		if (! empty($session_data)) {
592
+			// get the current time in UTC
593
+			$this->_time = $this->_time !== null ? $this->_time : time();
594
+			// and reset the session expiration
595
+			$this->_expiration = isset($session_data['expiration'])
596
+				? $session_data['expiration']
597
+				: $this->_time + $this->session_lifespan->inSeconds();
598
+		} else {
599
+			// set initial site access time and the session expiration
600
+			$this->_set_init_access_and_expiration();
601
+			// set referer
602
+			$this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER'])
603
+				? esc_attr($_SERVER['HTTP_REFERER'])
604
+				: '';
605
+			// no previous session = go back and create one (on top of the data above)
606
+			return false;
607
+		}
608
+		// now the user agent
609
+		if ($session_data['user_agent'] !== $this->_user_agent) {
610
+			return false;
611
+		}
612
+		// wait a minute... how old are you?
613
+		if ($this->_time > $this->_expiration) {
614
+			// yer too old fer me!
615
+			$this->_expired = true;
616
+			// wipe out everything that isn't a default session datum
617
+			$this->clear_session(__CLASS__, __FUNCTION__);
618
+		}
619
+		// make event espresso session data available to plugin
620
+		$this->_session_data = array_merge($this->_session_data, $session_data);
621
+		return true;
622
+	}
623
+
624
+
625
+	/**
626
+	 * _get_session_data
627
+	 * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup
628
+	 * databases
629
+	 *
630
+	 * @return array
631
+	 * @throws EE_Error
632
+	 * @throws InvalidArgumentException
633
+	 * @throws InvalidSessionDataException
634
+	 * @throws InvalidDataTypeException
635
+	 * @throws InvalidInterfaceException
636
+	 */
637
+	protected function _retrieve_session_data()
638
+	{
639
+		$ssn_key = EE_Session::session_id_prefix . $this->_sid;
640
+		try {
641
+			// we're using WP's Transient API to store session data using the PHP session ID as the option name
642
+			$session_data = $this->cache_storage->get($ssn_key, false);
643
+			if (empty($session_data)) {
644
+				return array();
645
+			}
646
+			if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
647
+				$hash_check = $this->cache_storage->get(
648
+					EE_Session::hash_check_prefix . $this->_sid,
649
+					false
650
+				);
651
+				if ($hash_check && $hash_check !== md5($session_data)) {
652
+					EE_Error::add_error(
653
+						sprintf(
654
+							__(
655
+								'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
656
+								'event_espresso'
657
+							),
658
+							EE_Session::session_id_prefix . $this->_sid
659
+						),
660
+						__FILE__,
661
+						__FUNCTION__,
662
+						__LINE__
663
+					);
664
+				}
665
+			}
666
+		} catch (Exception $e) {
667
+			// let's just eat that error for now and attempt to correct any corrupted data
668
+			global $wpdb;
669
+			$row = $wpdb->get_row(
670
+				$wpdb->prepare(
671
+					"SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
672
+					'_transient_' . $ssn_key
673
+				)
674
+			);
675
+			$session_data = is_object($row) ? $row->option_value : null;
676
+			if ($session_data) {
677
+				$session_data = preg_replace_callback(
678
+					'!s:(d+):"(.*?)";!',
679
+					function ($match) {
680
+						return $match[1] === strlen($match[2])
681
+							? $match[0]
682
+							: 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
683
+					},
684
+					$session_data
685
+				);
686
+			}
687
+			$session_data = maybe_unserialize($session_data);
688
+		}
689
+		// in case the data is encoded... try to decode it
690
+		$session_data = $this->encryption instanceof EE_Encryption
691
+			? $this->encryption->base64_string_decode($session_data)
692
+			: $session_data;
693
+		if (! is_array($session_data)) {
694
+			try {
695
+				$session_data = maybe_unserialize($session_data);
696
+			} catch (Exception $e) {
697
+				$msg = esc_html__(
698
+					'An error occurred while attempting to unserialize the session data.',
699
+					'event_espresso'
700
+				);
701
+				$msg .= WP_DEBUG
702
+					? '<br><pre>'
703
+					  . print_r($session_data, true)
704
+					  . '</pre><br>'
705
+					  . $this->find_serialize_error($session_data)
706
+					: '';
707
+				$this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
708
+				throw new InvalidSessionDataException($msg, 0, $e);
709
+			}
710
+		}
711
+		// just a check to make sure the session array is indeed an array
712
+		if (! is_array($session_data)) {
713
+			// no?!?! then something is wrong
714
+			$msg = esc_html__(
715
+				'The session data is missing, invalid, or corrupted.',
716
+				'event_espresso'
717
+			);
718
+			$msg .= WP_DEBUG
719
+				? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
720
+				: '';
721
+			$this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
722
+			throw new InvalidSessionDataException($msg);
723
+		}
724
+		if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
725
+			$session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
726
+				$session_data['transaction']
727
+			);
728
+		}
729
+		return $session_data;
730
+	}
731
+
732
+
733
+	/**
734
+	 * _generate_session_id
735
+	 * Retrieves the PHP session id either directly from the PHP session,
736
+	 * or from the $_REQUEST array if it was passed in from an AJAX request.
737
+	 * The session id is then salted and hashed (mmm sounds tasty)
738
+	 * so that it can be safely used as a $_REQUEST param
739
+	 *
740
+	 * @return string
741
+	 */
742
+	protected function _generate_session_id()
743
+	{
744
+		// check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
745
+		if (isset($_REQUEST['EESID'])) {
746
+			$session_id = sanitize_text_field($_REQUEST['EESID']);
747
+		} else {
748
+			$session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
749
+		}
750
+		return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
751
+	}
752
+
753
+
754
+	/**
755
+	 * _get_sid_salt
756
+	 *
757
+	 * @return string
758
+	 */
759
+	protected function _get_sid_salt()
760
+	{
761
+		// was session id salt already saved to db ?
762
+		if (empty($this->_sid_salt)) {
763
+			// no?  then maybe use WP defined constant
764
+			if (defined('AUTH_SALT')) {
765
+				$this->_sid_salt = AUTH_SALT;
766
+			}
767
+			// if salt doesn't exist or is too short
768
+			if (strlen($this->_sid_salt) < 32) {
769
+				// create a new one
770
+				$this->_sid_salt = wp_generate_password(64);
771
+			}
772
+			// and save it as a permanent session setting
773
+			$this->updateSessionSettings(array('sid_salt' => $this->_sid_salt));
774
+		}
775
+		return $this->_sid_salt;
776
+	}
777
+
778
+
779
+	/**
780
+	 * _set_init_access_and_expiration
781
+	 *
782
+	 * @return void
783
+	 */
784
+	protected function _set_init_access_and_expiration()
785
+	{
786
+		$this->_time = time();
787
+		$this->_expiration = $this->_time + $this->session_lifespan->inSeconds();
788
+		// set initial site access time
789
+		$this->_session_data['init_access'] = $this->_time;
790
+		// and the session expiration
791
+		$this->_session_data['expiration'] = $this->_expiration;
792
+	}
793
+
794
+
795
+	/**
796
+	 * @update session data  prior to saving to the db
797
+	 * @access public
798
+	 * @param bool $new_session
799
+	 * @return TRUE on success, FALSE on fail
800
+	 * @throws EE_Error
801
+	 * @throws InvalidArgumentException
802
+	 * @throws InvalidDataTypeException
803
+	 * @throws InvalidInterfaceException
804
+	 */
805
+	public function update($new_session = false)
806
+	{
807
+		$this->_session_data = $this->_session_data !== null
808
+							   && is_array($this->_session_data)
809
+							   && isset($this->_session_data['id'])
810
+			? $this->_session_data
811
+			: array();
812
+		if (empty($this->_session_data)) {
813
+			$this->_set_defaults();
814
+		}
815
+		$session_data = array();
816
+		foreach ($this->_session_data as $key => $value) {
817
+			switch ($key) {
818
+				case 'id':
819
+					// session ID
820
+					$session_data['id'] = $this->_sid;
821
+					break;
822
+				case 'ip_address':
823
+					// visitor ip address
824
+					$session_data['ip_address'] = $this->request->ipAddress();
825
+					break;
826
+				case 'user_agent':
827
+					// visitor user_agent
828
+					$session_data['user_agent'] = $this->_user_agent;
829
+					break;
830
+				case 'init_access':
831
+					$session_data['init_access'] = absint($value);
832
+					break;
833
+				case 'last_access':
834
+					// current access time
835
+					$session_data['last_access'] = $this->_time;
836
+					break;
837
+				case 'expiration':
838
+					// when the session expires
839
+					$session_data['expiration'] = ! empty($this->_expiration)
840
+						? $this->_expiration
841
+						: $session_data['init_access'] + $this->session_lifespan->inSeconds();
842
+					break;
843
+				case 'user_id':
844
+					// current user if logged in
845
+					$session_data['user_id'] = $this->_wp_user_id();
846
+					break;
847
+				case 'pages_visited':
848
+					$page_visit = $this->_get_page_visit();
849
+					if ($page_visit) {
850
+						// set pages visited where the first will be the http referrer
851
+						$this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
852
+						// we'll only save the last 10 page visits.
853
+						$session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
854
+					}
855
+					break;
856
+				default:
857
+					// carry any other data over
858
+					$session_data[ $key ] = $this->_session_data[ $key ];
859
+			}
860
+		}
861
+		$this->_session_data = $session_data;
862
+		// creating a new session does not require saving to the db just yet
863
+		if (! $new_session) {
864
+			// ready? let's save
865
+			if ($this->_save_session_to_db()) {
866
+				return true;
867
+			}
868
+			return false;
869
+		}
870
+		// meh, why not?
871
+		return true;
872
+	}
873
+
874
+
875
+	/**
876
+	 * @create session data array
877
+	 * @access public
878
+	 * @return bool
879
+	 * @throws EE_Error
880
+	 * @throws InvalidArgumentException
881
+	 * @throws InvalidDataTypeException
882
+	 * @throws InvalidInterfaceException
883
+	 */
884
+	private function _create_espresso_session()
885
+	{
886
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
887
+		// use the update function for now with $new_session arg set to TRUE
888
+		return $this->update(true) ? true : false;
889
+	}
890
+
891
+	/**
892
+	 * Detects if there is anything worth saving in the session (eg the cart is a good one, notices are pretty good
893
+	 * too). This is used when determining if we want to save the session or not.
894
+	 * @since 4.9.67.p
895
+	 * @return bool
896
+	 */
897
+	private function sessionHasStuffWorthSaving()
898
+	{
899
+		return $this->cart() instanceof EE_Cart
900
+			|| (
901
+				isset($this->_session_data['ee_notices'])
902
+				&& (
903
+					! empty($this->_session_data['ee_notices']['attention'])
904
+					|| !empty($this->_session_data['ee_notices']['errors'])
905
+					|| !empty($this->_session_data['ee_notices']['success'])
906
+				)
907
+			);
908
+	}
909
+	/**
910
+	 * _save_session_to_db
911
+	 *
912
+	 * @param bool $clear_session
913
+	 * @return string
914
+	 * @throws EE_Error
915
+	 * @throws InvalidArgumentException
916
+	 * @throws InvalidDataTypeException
917
+	 * @throws InvalidInterfaceException
918
+	 */
919
+	private function _save_session_to_db($clear_session = false)
920
+	{
921
+		// don't save sessions for crawlers
922
+		// and unless we're deleting the session data, don't save anything if there isn't a cart
923
+		if ($this->request->isBot()
924
+			|| (
925
+				! $clear_session
926
+				&& ! $this->sessionHasStuffWorthSaving()
927
+				&& apply_filters('FHEE__EE_Session___save_session_to_db__abort_session_save', true)
928
+			)
929
+		) {
930
+			return false;
931
+		}
932
+		$transaction = $this->transaction();
933
+		if ($transaction instanceof EE_Transaction) {
934
+			if (! $transaction->ID()) {
935
+				$transaction->save();
936
+			}
937
+			$this->_session_data['transaction'] = $transaction->ID();
938
+		}
939
+		// then serialize all of our session data
940
+		$session_data = serialize($this->_session_data);
941
+		// do we need to also encode it to avoid corrupted data when saved to the db?
942
+		$session_data = $this->_use_encryption
943
+			? $this->encryption->base64_string_encode($session_data)
944
+			: $session_data;
945
+		// maybe save hash check
946
+		if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
947
+			$this->cache_storage->add(
948
+				EE_Session::hash_check_prefix . $this->_sid,
949
+				md5($session_data),
950
+				$this->session_lifespan->inSeconds()
951
+			);
952
+		}
953
+		// we're using the Transient API for storing session data,
954
+		return $this->cache_storage->add(
955
+			EE_Session::session_id_prefix . $this->_sid,
956
+			$session_data,
957
+			$this->session_lifespan->inSeconds()
958
+		);
959
+	}
960
+
961
+
962
+	/**
963
+	 * @get    the full page request the visitor is accessing
964
+	 * @access public
965
+	 * @return string
966
+	 */
967
+	public function _get_page_visit()
968
+	{
969
+		$page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
970
+		// check for request url
971
+		if (isset($_SERVER['REQUEST_URI'])) {
972
+			$http_host = '';
973
+			$page_id = '?';
974
+			$e_reg = '';
975
+			$request_uri = esc_url($_SERVER['REQUEST_URI']);
976
+			$ru_bits = explode('?', $request_uri);
977
+			$request_uri = $ru_bits[0];
978
+			// check for and grab host as well
979
+			if (isset($_SERVER['HTTP_HOST'])) {
980
+				$http_host = esc_url($_SERVER['HTTP_HOST']);
981
+			}
982
+			// check for page_id in SERVER REQUEST
983
+			if (isset($_REQUEST['page_id'])) {
984
+				// rebuild $e_reg without any of the extra parameters
985
+				$page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&amp;';
986
+			}
987
+			// check for $e_reg in SERVER REQUEST
988
+			if (isset($_REQUEST['ee'])) {
989
+				// rebuild $e_reg without any of the extra parameters
990
+				$e_reg = 'ee=' . esc_attr($_REQUEST['ee']);
991
+			}
992
+			$page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?');
993
+		}
994
+		return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
995
+	}
996
+
997
+
998
+	/**
999
+	 * @the    current wp user id
1000
+	 * @access public
1001
+	 * @return int
1002
+	 */
1003
+	public function _wp_user_id()
1004
+	{
1005
+		// if I need to explain the following lines of code, then you shouldn't be looking at this!
1006
+		$this->_wp_user_id = get_current_user_id();
1007
+		return $this->_wp_user_id;
1008
+	}
1009
+
1010
+
1011
+	/**
1012
+	 * Clear EE_Session data
1013
+	 *
1014
+	 * @access public
1015
+	 * @param string $class
1016
+	 * @param string $function
1017
+	 * @return void
1018
+	 * @throws EE_Error
1019
+	 * @throws InvalidArgumentException
1020
+	 * @throws InvalidDataTypeException
1021
+	 * @throws InvalidInterfaceException
1022
+	 */
1023
+	public function clear_session($class = '', $function = '')
1024
+	{
1025 1025
 //         echo '
1026 1026
 // <h3 style="color:#999;line-height:.9em;">
1027 1027
 // <span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/>
1028 1028
 // <span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b>
1029 1029
 // </h3>';
1030
-        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
1031
-        $this->reset_cart();
1032
-        $this->reset_checkout();
1033
-        $this->reset_transaction();
1034
-        // wipe out everything that isn't a default session datum
1035
-        $this->reset_data(array_keys($this->_session_data));
1036
-        // reset initial site access time and the session expiration
1037
-        $this->_set_init_access_and_expiration();
1038
-        $this->_save_session_to_db(true);
1039
-    }
1040
-
1041
-
1042
-    /**
1043
-     * resets all non-default session vars. Returns TRUE on success, FALSE on fail
1044
-     *
1045
-     * @param array|mixed $data_to_reset
1046
-     * @param bool        $show_all_notices
1047
-     * @return bool
1048
-     */
1049
-    public function reset_data($data_to_reset = array(), $show_all_notices = false)
1050
-    {
1051
-        // if $data_to_reset is not in an array, then put it in one
1052
-        if (! is_array($data_to_reset)) {
1053
-            $data_to_reset = array($data_to_reset);
1054
-        }
1055
-        // nothing ??? go home!
1056
-        if (empty($data_to_reset)) {
1057
-            EE_Error::add_error(
1058
-                __(
1059
-                    'No session data could be reset, because no session var name was provided.',
1060
-                    'event_espresso'
1061
-                ),
1062
-                __FILE__,
1063
-                __FUNCTION__,
1064
-                __LINE__
1065
-            );
1066
-            return false;
1067
-        }
1068
-        $return_value = true;
1069
-        // since $data_to_reset is an array, cycle through the values
1070
-        foreach ($data_to_reset as $reset) {
1071
-            // first check to make sure it is a valid session var
1072
-            if (isset($this->_session_data[ $reset ])) {
1073
-                // then check to make sure it is not a default var
1074
-                if (! array_key_exists($reset, $this->_default_session_vars)) {
1075
-                    // remove session var
1076
-                    unset($this->_session_data[ $reset ]);
1077
-                    if ($show_all_notices) {
1078
-                        EE_Error::add_success(
1079
-                            sprintf(
1080
-                                __('The session variable %s was removed.', 'event_espresso'),
1081
-                                $reset
1082
-                            ),
1083
-                            __FILE__,
1084
-                            __FUNCTION__,
1085
-                            __LINE__
1086
-                        );
1087
-                    }
1088
-                } else {
1089
-                    // yeeeeeeeeerrrrrrrrrrr OUT !!!!
1090
-                    if ($show_all_notices) {
1091
-                        EE_Error::add_error(
1092
-                            sprintf(
1093
-                                __(
1094
-                                    'Sorry! %s is a default session datum and can not be reset.',
1095
-                                    'event_espresso'
1096
-                                ),
1097
-                                $reset
1098
-                            ),
1099
-                            __FILE__,
1100
-                            __FUNCTION__,
1101
-                            __LINE__
1102
-                        );
1103
-                    }
1104
-                    $return_value = false;
1105
-                }
1106
-            } elseif ($show_all_notices) {
1107
-                // oops! that session var does not exist!
1108
-                EE_Error::add_error(
1109
-                    sprintf(
1110
-                        __(
1111
-                            'The session item provided, %s, is invalid or does not exist.',
1112
-                            'event_espresso'
1113
-                        ),
1114
-                        $reset
1115
-                    ),
1116
-                    __FILE__,
1117
-                    __FUNCTION__,
1118
-                    __LINE__
1119
-                );
1120
-                $return_value = false;
1121
-            }
1122
-        } // end of foreach
1123
-        return $return_value;
1124
-    }
1125
-
1126
-
1127
-    /**
1128
-     *   wp_loaded
1129
-     *
1130
-     * @access public
1131
-     * @throws EE_Error
1132
-     * @throws InvalidDataTypeException
1133
-     * @throws InvalidInterfaceException
1134
-     * @throws InvalidArgumentException
1135
-     */
1136
-    public function wp_loaded()
1137
-    {
1138
-        if ($this->request->requestParamIsSet('clear_session')) {
1139
-            $this->clear_session(__CLASS__, __FUNCTION__);
1140
-        }
1141
-    }
1142
-
1143
-
1144
-    /**
1145
-     * Used to reset the entire object (for tests).
1146
-     *
1147
-     * @since 4.3.0
1148
-     * @throws EE_Error
1149
-     * @throws InvalidDataTypeException
1150
-     * @throws InvalidInterfaceException
1151
-     * @throws InvalidArgumentException
1152
-     */
1153
-    public function reset_instance()
1154
-    {
1155
-        $this->clear_session();
1156
-        self::$_instance = null;
1157
-    }
1158
-
1159
-
1160
-    public function configure_garbage_collection_filters()
1161
-    {
1162
-        // run old filter we had for controlling session cleanup
1163
-        $expired_session_transient_delete_query_limit = absint(
1164
-            apply_filters(
1165
-                'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1166
-                50
1167
-            )
1168
-        );
1169
-        // is there a value? or one that is different than the default 50 records?
1170
-        if ($expired_session_transient_delete_query_limit === 0) {
1171
-            // hook into TransientCacheStorage in case Session cleanup was turned off
1172
-            add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero');
1173
-        } elseif ($expired_session_transient_delete_query_limit !== 50) {
1174
-            // or use that for the new transient cleanup query limit
1175
-            add_filter(
1176
-                'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1177
-                function () use ($expired_session_transient_delete_query_limit) {
1178
-                    return $expired_session_transient_delete_query_limit;
1179
-                }
1180
-            );
1181
-        }
1182
-    }
1183
-
1184
-
1185
-    /**
1186
-     * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996
1187
-     * @param $data1
1188
-     * @return string
1189
-     */
1190
-    private function find_serialize_error($data1)
1191
-    {
1192
-        $error = '<pre>';
1193
-        $data2 = preg_replace_callback(
1194
-            '!s:(\d+):"(.*?)";!',
1195
-            function ($match) {
1196
-                return ($match[1] === strlen($match[2]))
1197
-                    ? $match[0]
1198
-                    : 's:'
1199
-                      . strlen($match[2])
1200
-                      . ':"'
1201
-                      . $match[2]
1202
-                      . '";';
1203
-            },
1204
-            $data1
1205
-        );
1206
-        $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1207
-        $error .= $data1 . PHP_EOL;
1208
-        $error .= $data2 . PHP_EOL;
1209
-        for ($i = 0; $i < $max; $i++) {
1210
-            if (@$data1[ $i ] !== @$data2[ $i ]) {
1211
-                $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1212
-                $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1213
-                $error .= "\t-> Line Number = $i" . PHP_EOL;
1214
-                $start = ($i - 20);
1215
-                $start = ($start < 0) ? 0 : $start;
1216
-                $length = 40;
1217
-                $point = $max - $i;
1218
-                if ($point < 20) {
1219
-                    $rlength = 1;
1220
-                    $rpoint = -$point;
1221
-                } else {
1222
-                    $rpoint = $length - 20;
1223
-                    $rlength = 1;
1224
-                }
1225
-                $error .= "\t-> Section Data1  = ";
1226
-                $error .= substr_replace(
1227
-                    substr($data1, $start, $length),
1228
-                    "<b style=\"color:green\">{$data1[ $i ]}</b>",
1229
-                    $rpoint,
1230
-                    $rlength
1231
-                );
1232
-                $error .= PHP_EOL;
1233
-                $error .= "\t-> Section Data2  = ";
1234
-                $error .= substr_replace(
1235
-                    substr($data2, $start, $length),
1236
-                    "<b style=\"color:red\">{$data2[ $i ]}</b>",
1237
-                    $rpoint,
1238
-                    $rlength
1239
-                );
1240
-                $error .= PHP_EOL;
1241
-            }
1242
-        }
1243
-        $error .= '</pre>';
1244
-        return $error;
1245
-    }
1246
-
1247
-
1248
-    /**
1249
-     * Saves an  array of settings used for configuring aspects of session behaviour
1250
-     *
1251
-     * @param array $updated_settings
1252
-     */
1253
-    private function updateSessionSettings(array $updated_settings = array())
1254
-    {
1255
-        // add existing settings, but only if not included in incoming $updated_settings array
1256
-        $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array());
1257
-        update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings);
1258
-    }
1259
-
1260
-
1261
-    /**
1262
-     * garbage_collection
1263
-     */
1264
-    public function garbageCollection()
1265
-    {
1266
-        // only perform during regular requests if last garbage collection was over an hour ago
1267
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1268
-            $this->_last_gc = time();
1269
-            $this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1270
-            /** @type WPDB $wpdb */
1271
-            global $wpdb;
1272
-            // filter the query limit. Set to 0 to turn off garbage collection
1273
-            $expired_session_transient_delete_query_limit = absint(
1274
-                apply_filters(
1275
-                    'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1276
-                    50
1277
-                )
1278
-            );
1279
-            // non-zero LIMIT means take out the trash
1280
-            if ($expired_session_transient_delete_query_limit) {
1281
-                $session_key = str_replace('_', '\_', EE_Session::session_id_prefix);
1282
-                $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix);
1283
-                // since transient expiration timestamps are set in the future, we can compare against NOW
1284
-                // but we only want to pick up any trash that's been around for more than a day
1285
-                $expiration = time() - DAY_IN_SECONDS;
1286
-                $SQL = "
1030
+		do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
1031
+		$this->reset_cart();
1032
+		$this->reset_checkout();
1033
+		$this->reset_transaction();
1034
+		// wipe out everything that isn't a default session datum
1035
+		$this->reset_data(array_keys($this->_session_data));
1036
+		// reset initial site access time and the session expiration
1037
+		$this->_set_init_access_and_expiration();
1038
+		$this->_save_session_to_db(true);
1039
+	}
1040
+
1041
+
1042
+	/**
1043
+	 * resets all non-default session vars. Returns TRUE on success, FALSE on fail
1044
+	 *
1045
+	 * @param array|mixed $data_to_reset
1046
+	 * @param bool        $show_all_notices
1047
+	 * @return bool
1048
+	 */
1049
+	public function reset_data($data_to_reset = array(), $show_all_notices = false)
1050
+	{
1051
+		// if $data_to_reset is not in an array, then put it in one
1052
+		if (! is_array($data_to_reset)) {
1053
+			$data_to_reset = array($data_to_reset);
1054
+		}
1055
+		// nothing ??? go home!
1056
+		if (empty($data_to_reset)) {
1057
+			EE_Error::add_error(
1058
+				__(
1059
+					'No session data could be reset, because no session var name was provided.',
1060
+					'event_espresso'
1061
+				),
1062
+				__FILE__,
1063
+				__FUNCTION__,
1064
+				__LINE__
1065
+			);
1066
+			return false;
1067
+		}
1068
+		$return_value = true;
1069
+		// since $data_to_reset is an array, cycle through the values
1070
+		foreach ($data_to_reset as $reset) {
1071
+			// first check to make sure it is a valid session var
1072
+			if (isset($this->_session_data[ $reset ])) {
1073
+				// then check to make sure it is not a default var
1074
+				if (! array_key_exists($reset, $this->_default_session_vars)) {
1075
+					// remove session var
1076
+					unset($this->_session_data[ $reset ]);
1077
+					if ($show_all_notices) {
1078
+						EE_Error::add_success(
1079
+							sprintf(
1080
+								__('The session variable %s was removed.', 'event_espresso'),
1081
+								$reset
1082
+							),
1083
+							__FILE__,
1084
+							__FUNCTION__,
1085
+							__LINE__
1086
+						);
1087
+					}
1088
+				} else {
1089
+					// yeeeeeeeeerrrrrrrrrrr OUT !!!!
1090
+					if ($show_all_notices) {
1091
+						EE_Error::add_error(
1092
+							sprintf(
1093
+								__(
1094
+									'Sorry! %s is a default session datum and can not be reset.',
1095
+									'event_espresso'
1096
+								),
1097
+								$reset
1098
+							),
1099
+							__FILE__,
1100
+							__FUNCTION__,
1101
+							__LINE__
1102
+						);
1103
+					}
1104
+					$return_value = false;
1105
+				}
1106
+			} elseif ($show_all_notices) {
1107
+				// oops! that session var does not exist!
1108
+				EE_Error::add_error(
1109
+					sprintf(
1110
+						__(
1111
+							'The session item provided, %s, is invalid or does not exist.',
1112
+							'event_espresso'
1113
+						),
1114
+						$reset
1115
+					),
1116
+					__FILE__,
1117
+					__FUNCTION__,
1118
+					__LINE__
1119
+				);
1120
+				$return_value = false;
1121
+			}
1122
+		} // end of foreach
1123
+		return $return_value;
1124
+	}
1125
+
1126
+
1127
+	/**
1128
+	 *   wp_loaded
1129
+	 *
1130
+	 * @access public
1131
+	 * @throws EE_Error
1132
+	 * @throws InvalidDataTypeException
1133
+	 * @throws InvalidInterfaceException
1134
+	 * @throws InvalidArgumentException
1135
+	 */
1136
+	public function wp_loaded()
1137
+	{
1138
+		if ($this->request->requestParamIsSet('clear_session')) {
1139
+			$this->clear_session(__CLASS__, __FUNCTION__);
1140
+		}
1141
+	}
1142
+
1143
+
1144
+	/**
1145
+	 * Used to reset the entire object (for tests).
1146
+	 *
1147
+	 * @since 4.3.0
1148
+	 * @throws EE_Error
1149
+	 * @throws InvalidDataTypeException
1150
+	 * @throws InvalidInterfaceException
1151
+	 * @throws InvalidArgumentException
1152
+	 */
1153
+	public function reset_instance()
1154
+	{
1155
+		$this->clear_session();
1156
+		self::$_instance = null;
1157
+	}
1158
+
1159
+
1160
+	public function configure_garbage_collection_filters()
1161
+	{
1162
+		// run old filter we had for controlling session cleanup
1163
+		$expired_session_transient_delete_query_limit = absint(
1164
+			apply_filters(
1165
+				'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1166
+				50
1167
+			)
1168
+		);
1169
+		// is there a value? or one that is different than the default 50 records?
1170
+		if ($expired_session_transient_delete_query_limit === 0) {
1171
+			// hook into TransientCacheStorage in case Session cleanup was turned off
1172
+			add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero');
1173
+		} elseif ($expired_session_transient_delete_query_limit !== 50) {
1174
+			// or use that for the new transient cleanup query limit
1175
+			add_filter(
1176
+				'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1177
+				function () use ($expired_session_transient_delete_query_limit) {
1178
+					return $expired_session_transient_delete_query_limit;
1179
+				}
1180
+			);
1181
+		}
1182
+	}
1183
+
1184
+
1185
+	/**
1186
+	 * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996
1187
+	 * @param $data1
1188
+	 * @return string
1189
+	 */
1190
+	private function find_serialize_error($data1)
1191
+	{
1192
+		$error = '<pre>';
1193
+		$data2 = preg_replace_callback(
1194
+			'!s:(\d+):"(.*?)";!',
1195
+			function ($match) {
1196
+				return ($match[1] === strlen($match[2]))
1197
+					? $match[0]
1198
+					: 's:'
1199
+					  . strlen($match[2])
1200
+					  . ':"'
1201
+					  . $match[2]
1202
+					  . '";';
1203
+			},
1204
+			$data1
1205
+		);
1206
+		$max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1207
+		$error .= $data1 . PHP_EOL;
1208
+		$error .= $data2 . PHP_EOL;
1209
+		for ($i = 0; $i < $max; $i++) {
1210
+			if (@$data1[ $i ] !== @$data2[ $i ]) {
1211
+				$error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1212
+				$error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1213
+				$error .= "\t-> Line Number = $i" . PHP_EOL;
1214
+				$start = ($i - 20);
1215
+				$start = ($start < 0) ? 0 : $start;
1216
+				$length = 40;
1217
+				$point = $max - $i;
1218
+				if ($point < 20) {
1219
+					$rlength = 1;
1220
+					$rpoint = -$point;
1221
+				} else {
1222
+					$rpoint = $length - 20;
1223
+					$rlength = 1;
1224
+				}
1225
+				$error .= "\t-> Section Data1  = ";
1226
+				$error .= substr_replace(
1227
+					substr($data1, $start, $length),
1228
+					"<b style=\"color:green\">{$data1[ $i ]}</b>",
1229
+					$rpoint,
1230
+					$rlength
1231
+				);
1232
+				$error .= PHP_EOL;
1233
+				$error .= "\t-> Section Data2  = ";
1234
+				$error .= substr_replace(
1235
+					substr($data2, $start, $length),
1236
+					"<b style=\"color:red\">{$data2[ $i ]}</b>",
1237
+					$rpoint,
1238
+					$rlength
1239
+				);
1240
+				$error .= PHP_EOL;
1241
+			}
1242
+		}
1243
+		$error .= '</pre>';
1244
+		return $error;
1245
+	}
1246
+
1247
+
1248
+	/**
1249
+	 * Saves an  array of settings used for configuring aspects of session behaviour
1250
+	 *
1251
+	 * @param array $updated_settings
1252
+	 */
1253
+	private function updateSessionSettings(array $updated_settings = array())
1254
+	{
1255
+		// add existing settings, but only if not included in incoming $updated_settings array
1256
+		$updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array());
1257
+		update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings);
1258
+	}
1259
+
1260
+
1261
+	/**
1262
+	 * garbage_collection
1263
+	 */
1264
+	public function garbageCollection()
1265
+	{
1266
+		// only perform during regular requests if last garbage collection was over an hour ago
1267
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1268
+			$this->_last_gc = time();
1269
+			$this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1270
+			/** @type WPDB $wpdb */
1271
+			global $wpdb;
1272
+			// filter the query limit. Set to 0 to turn off garbage collection
1273
+			$expired_session_transient_delete_query_limit = absint(
1274
+				apply_filters(
1275
+					'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1276
+					50
1277
+				)
1278
+			);
1279
+			// non-zero LIMIT means take out the trash
1280
+			if ($expired_session_transient_delete_query_limit) {
1281
+				$session_key = str_replace('_', '\_', EE_Session::session_id_prefix);
1282
+				$hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix);
1283
+				// since transient expiration timestamps are set in the future, we can compare against NOW
1284
+				// but we only want to pick up any trash that's been around for more than a day
1285
+				$expiration = time() - DAY_IN_SECONDS;
1286
+				$SQL = "
1287 1287
                     SELECT option_name
1288 1288
                     FROM {$wpdb->options}
1289 1289
                     WHERE
@@ -1292,17 +1292,17 @@  discard block
 block discarded – undo
1292 1292
                     AND option_value < {$expiration}
1293 1293
                     LIMIT {$expired_session_transient_delete_query_limit}
1294 1294
                 ";
1295
-                // produces something like:
1296
-                // SELECT option_name FROM wp_options
1297
-                // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%'
1298
-                // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' )
1299
-                // AND option_value < 1508368198 LIMIT 50
1300
-                $expired_sessions = $wpdb->get_col($SQL);
1301
-                // valid results?
1302
-                if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1303
-                    $this->cache_storage->deleteMany($expired_sessions, true);
1304
-                }
1305
-            }
1306
-        }
1307
-    }
1295
+				// produces something like:
1296
+				// SELECT option_name FROM wp_options
1297
+				// WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%'
1298
+				// OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' )
1299
+				// AND option_value < 1508368198 LIMIT 50
1300
+				$expired_sessions = $wpdb->get_col($SQL);
1301
+				// valid results?
1302
+				if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1303
+					$this->cache_storage->deleteMany($expired_sessions, true);
1304
+				}
1305
+			}
1306
+		}
1307
+	}
1308 1308
 }
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
196
+        if ( ! self::$_instance instanceof EE_Session
197 197
             && apply_filters('FHEE_load_EE_Session', true)
198 198
             && $cache_storage instanceof CacheStorageInterface
199 199
             && $lifespan instanceof SessionLifespan
@@ -235,22 +235,22 @@  discard block
 block discarded – undo
235 235
         // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook
236 236
         // (which currently fires on the init hook at priority 9),
237 237
         // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
238
-        if (! apply_filters('FHEE_load_EE_Session', true)) {
238
+        if ( ! apply_filters('FHEE_load_EE_Session', true)) {
239 239
             return;
240 240
         }
241 241
         $this->session_start_handler = $session_start_handler;
242 242
         $this->session_lifespan = $lifespan;
243 243
         $this->request = $request;
244
-        if (! defined('ESPRESSO_SESSION')) {
244
+        if ( ! defined('ESPRESSO_SESSION')) {
245 245
             define('ESPRESSO_SESSION', true);
246 246
         }
247 247
         // retrieve session options from db
248 248
         $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
249
-        if (! empty($session_settings)) {
249
+        if ( ! empty($session_settings)) {
250 250
             // cycle though existing session options
251 251
             foreach ($session_settings as $var_name => $session_setting) {
252 252
                 // set values for class properties
253
-                $var_name = '_' . $var_name;
253
+                $var_name = '_'.$var_name;
254 254
                 $this->{$var_name} = $session_setting;
255 255
             }
256 256
         }
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
     public function open_session()
310 310
     {
311 311
         // check for existing session and retrieve it from db
312
-        if (! $this->_espresso_session()) {
312
+        if ( ! $this->_espresso_session()) {
313 313
             // or just start a new one
314 314
             $this->_create_espresso_session();
315 315
         }
@@ -382,9 +382,9 @@  discard block
 block discarded – undo
382 382
         // set some defaults
383 383
         foreach ($this->_default_session_vars as $key => $default_var) {
384 384
             if (is_array($default_var)) {
385
-                $this->_session_data[ $key ] = array();
385
+                $this->_session_data[$key] = array();
386 386
             } else {
387
-                $this->_session_data[ $key ] = '';
387
+                $this->_session_data[$key] = '';
388 388
             }
389 389
         }
390 390
     }
@@ -515,8 +515,8 @@  discard block
 block discarded – undo
515 515
             $this->reset_checkout();
516 516
             $this->reset_transaction();
517 517
         }
518
-        if (! empty($key)) {
519
-            return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
518
+        if ( ! empty($key)) {
519
+            return isset($this->_session_data[$key]) ? $this->_session_data[$key] : null;
520 520
         }
521 521
         return $this->_session_data;
522 522
     }
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
             return false;
545 545
         }
546 546
         foreach ($data as $key => $value) {
547
-            if (isset($this->_default_session_vars[ $key ])) {
547
+            if (isset($this->_default_session_vars[$key])) {
548 548
                 EE_Error::add_error(
549 549
                     sprintf(
550 550
                         esc_html__(
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
                 );
560 560
                 return false;
561 561
             }
562
-            $this->_session_data[ $key ] = $value;
562
+            $this->_session_data[$key] = $value;
563 563
         }
564 564
         return true;
565 565
     }
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
         $this->_user_agent = $this->request->userAgent();
589 589
         // now let's retrieve what's in the db
590 590
         $session_data = $this->_retrieve_session_data();
591
-        if (! empty($session_data)) {
591
+        if ( ! empty($session_data)) {
592 592
             // get the current time in UTC
593 593
             $this->_time = $this->_time !== null ? $this->_time : time();
594 594
             // and reset the session expiration
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
             // set initial site access time and the session expiration
600 600
             $this->_set_init_access_and_expiration();
601 601
             // set referer
602
-            $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER'])
602
+            $this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER'])
603 603
                 ? esc_attr($_SERVER['HTTP_REFERER'])
604 604
                 : '';
605 605
             // no previous session = go back and create one (on top of the data above)
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
      */
637 637
     protected function _retrieve_session_data()
638 638
     {
639
-        $ssn_key = EE_Session::session_id_prefix . $this->_sid;
639
+        $ssn_key = EE_Session::session_id_prefix.$this->_sid;
640 640
         try {
641 641
             // we're using WP's Transient API to store session data using the PHP session ID as the option name
642 642
             $session_data = $this->cache_storage->get($ssn_key, false);
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
             }
646 646
             if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
647 647
                 $hash_check = $this->cache_storage->get(
648
-                    EE_Session::hash_check_prefix . $this->_sid,
648
+                    EE_Session::hash_check_prefix.$this->_sid,
649 649
                     false
650 650
                 );
651 651
                 if ($hash_check && $hash_check !== md5($session_data)) {
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
                                 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
656 656
                                 'event_espresso'
657 657
                             ),
658
-                            EE_Session::session_id_prefix . $this->_sid
658
+                            EE_Session::session_id_prefix.$this->_sid
659 659
                         ),
660 660
                         __FILE__,
661 661
                         __FUNCTION__,
@@ -669,17 +669,17 @@  discard block
 block discarded – undo
669 669
             $row = $wpdb->get_row(
670 670
                 $wpdb->prepare(
671 671
                     "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
672
-                    '_transient_' . $ssn_key
672
+                    '_transient_'.$ssn_key
673 673
                 )
674 674
             );
675 675
             $session_data = is_object($row) ? $row->option_value : null;
676 676
             if ($session_data) {
677 677
                 $session_data = preg_replace_callback(
678 678
                     '!s:(d+):"(.*?)";!',
679
-                    function ($match) {
679
+                    function($match) {
680 680
                         return $match[1] === strlen($match[2])
681 681
                             ? $match[0]
682
-                            : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
682
+                            : 's:'.strlen($match[2]).':"'.$match[2].'";';
683 683
                     },
684 684
                     $session_data
685 685
                 );
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
         $session_data = $this->encryption instanceof EE_Encryption
691 691
             ? $this->encryption->base64_string_decode($session_data)
692 692
             : $session_data;
693
-        if (! is_array($session_data)) {
693
+        if ( ! is_array($session_data)) {
694 694
             try {
695 695
                 $session_data = maybe_unserialize($session_data);
696 696
             } catch (Exception $e) {
@@ -704,21 +704,21 @@  discard block
 block discarded – undo
704 704
                       . '</pre><br>'
705 705
                       . $this->find_serialize_error($session_data)
706 706
                     : '';
707
-                $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
707
+                $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid);
708 708
                 throw new InvalidSessionDataException($msg, 0, $e);
709 709
             }
710 710
         }
711 711
         // just a check to make sure the session array is indeed an array
712
-        if (! is_array($session_data)) {
712
+        if ( ! is_array($session_data)) {
713 713
             // no?!?! then something is wrong
714 714
             $msg = esc_html__(
715 715
                 'The session data is missing, invalid, or corrupted.',
716 716
                 'event_espresso'
717 717
             );
718 718
             $msg .= WP_DEBUG
719
-                ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
719
+                ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data)
720 720
                 : '';
721
-            $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
721
+            $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid);
722 722
             throw new InvalidSessionDataException($msg);
723 723
         }
724 724
         if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
         if (isset($_REQUEST['EESID'])) {
746 746
             $session_id = sanitize_text_field($_REQUEST['EESID']);
747 747
         } else {
748
-            $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
748
+            $session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt());
749 749
         }
750 750
         return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
751 751
     }
@@ -848,19 +848,19 @@  discard block
 block discarded – undo
848 848
                     $page_visit = $this->_get_page_visit();
849 849
                     if ($page_visit) {
850 850
                         // set pages visited where the first will be the http referrer
851
-                        $this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
851
+                        $this->_session_data['pages_visited'][$this->_time] = $page_visit;
852 852
                         // we'll only save the last 10 page visits.
853 853
                         $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
854 854
                     }
855 855
                     break;
856 856
                 default:
857 857
                     // carry any other data over
858
-                    $session_data[ $key ] = $this->_session_data[ $key ];
858
+                    $session_data[$key] = $this->_session_data[$key];
859 859
             }
860 860
         }
861 861
         $this->_session_data = $session_data;
862 862
         // creating a new session does not require saving to the db just yet
863
-        if (! $new_session) {
863
+        if ( ! $new_session) {
864 864
             // ready? let's save
865 865
             if ($this->_save_session_to_db()) {
866 866
                 return true;
@@ -901,8 +901,8 @@  discard block
 block discarded – undo
901 901
                 isset($this->_session_data['ee_notices'])
902 902
                 && (
903 903
                     ! empty($this->_session_data['ee_notices']['attention'])
904
-                    || !empty($this->_session_data['ee_notices']['errors'])
905
-                    || !empty($this->_session_data['ee_notices']['success'])
904
+                    || ! empty($this->_session_data['ee_notices']['errors'])
905
+                    || ! empty($this->_session_data['ee_notices']['success'])
906 906
                 )
907 907
             );
908 908
     }
@@ -931,7 +931,7 @@  discard block
 block discarded – undo
931 931
         }
932 932
         $transaction = $this->transaction();
933 933
         if ($transaction instanceof EE_Transaction) {
934
-            if (! $transaction->ID()) {
934
+            if ( ! $transaction->ID()) {
935 935
                 $transaction->save();
936 936
             }
937 937
             $this->_session_data['transaction'] = $transaction->ID();
@@ -945,14 +945,14 @@  discard block
 block discarded – undo
945 945
         // maybe save hash check
946 946
         if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
947 947
             $this->cache_storage->add(
948
-                EE_Session::hash_check_prefix . $this->_sid,
948
+                EE_Session::hash_check_prefix.$this->_sid,
949 949
                 md5($session_data),
950 950
                 $this->session_lifespan->inSeconds()
951 951
             );
952 952
         }
953 953
         // we're using the Transient API for storing session data,
954 954
         return $this->cache_storage->add(
955
-            EE_Session::session_id_prefix . $this->_sid,
955
+            EE_Session::session_id_prefix.$this->_sid,
956 956
             $session_data,
957 957
             $this->session_lifespan->inSeconds()
958 958
         );
@@ -966,7 +966,7 @@  discard block
 block discarded – undo
966 966
      */
967 967
     public function _get_page_visit()
968 968
     {
969
-        $page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
969
+        $page_visit = home_url('/').'wp-admin/admin-ajax.php';
970 970
         // check for request url
971 971
         if (isset($_SERVER['REQUEST_URI'])) {
972 972
             $http_host = '';
@@ -982,14 +982,14 @@  discard block
 block discarded – undo
982 982
             // check for page_id in SERVER REQUEST
983 983
             if (isset($_REQUEST['page_id'])) {
984 984
                 // rebuild $e_reg without any of the extra parameters
985
-                $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&amp;';
985
+                $page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&amp;';
986 986
             }
987 987
             // check for $e_reg in SERVER REQUEST
988 988
             if (isset($_REQUEST['ee'])) {
989 989
                 // rebuild $e_reg without any of the extra parameters
990
-                $e_reg = 'ee=' . esc_attr($_REQUEST['ee']);
990
+                $e_reg = 'ee='.esc_attr($_REQUEST['ee']);
991 991
             }
992
-            $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?');
992
+            $page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?');
993 993
         }
994 994
         return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
995 995
     }
@@ -1027,7 +1027,7 @@  discard block
 block discarded – undo
1027 1027
 // <span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/>
1028 1028
 // <span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b>
1029 1029
 // </h3>';
1030
-        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
1030
+        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()');
1031 1031
         $this->reset_cart();
1032 1032
         $this->reset_checkout();
1033 1033
         $this->reset_transaction();
@@ -1049,7 +1049,7 @@  discard block
 block discarded – undo
1049 1049
     public function reset_data($data_to_reset = array(), $show_all_notices = false)
1050 1050
     {
1051 1051
         // if $data_to_reset is not in an array, then put it in one
1052
-        if (! is_array($data_to_reset)) {
1052
+        if ( ! is_array($data_to_reset)) {
1053 1053
             $data_to_reset = array($data_to_reset);
1054 1054
         }
1055 1055
         // nothing ??? go home!
@@ -1069,11 +1069,11 @@  discard block
 block discarded – undo
1069 1069
         // since $data_to_reset is an array, cycle through the values
1070 1070
         foreach ($data_to_reset as $reset) {
1071 1071
             // first check to make sure it is a valid session var
1072
-            if (isset($this->_session_data[ $reset ])) {
1072
+            if (isset($this->_session_data[$reset])) {
1073 1073
                 // then check to make sure it is not a default var
1074
-                if (! array_key_exists($reset, $this->_default_session_vars)) {
1074
+                if ( ! array_key_exists($reset, $this->_default_session_vars)) {
1075 1075
                     // remove session var
1076
-                    unset($this->_session_data[ $reset ]);
1076
+                    unset($this->_session_data[$reset]);
1077 1077
                     if ($show_all_notices) {
1078 1078
                         EE_Error::add_success(
1079 1079
                             sprintf(
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
             // or use that for the new transient cleanup query limit
1175 1175
             add_filter(
1176 1176
                 'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1177
-                function () use ($expired_session_transient_delete_query_limit) {
1177
+                function() use ($expired_session_transient_delete_query_limit) {
1178 1178
                     return $expired_session_transient_delete_query_limit;
1179 1179
                 }
1180 1180
             );
@@ -1192,7 +1192,7 @@  discard block
 block discarded – undo
1192 1192
         $error = '<pre>';
1193 1193
         $data2 = preg_replace_callback(
1194 1194
             '!s:(\d+):"(.*?)";!',
1195
-            function ($match) {
1195
+            function($match) {
1196 1196
                 return ($match[1] === strlen($match[2]))
1197 1197
                     ? $match[0]
1198 1198
                     : 's:'
@@ -1204,13 +1204,13 @@  discard block
 block discarded – undo
1204 1204
             $data1
1205 1205
         );
1206 1206
         $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1207
-        $error .= $data1 . PHP_EOL;
1208
-        $error .= $data2 . PHP_EOL;
1207
+        $error .= $data1.PHP_EOL;
1208
+        $error .= $data2.PHP_EOL;
1209 1209
         for ($i = 0; $i < $max; $i++) {
1210
-            if (@$data1[ $i ] !== @$data2[ $i ]) {
1211
-                $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1212
-                $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1213
-                $error .= "\t-> Line Number = $i" . PHP_EOL;
1210
+            if (@$data1[$i] !== @$data2[$i]) {
1211
+                $error .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL;
1212
+                $error .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL;
1213
+                $error .= "\t-> Line Number = $i".PHP_EOL;
1214 1214
                 $start = ($i - 20);
1215 1215
                 $start = ($start < 0) ? 0 : $start;
1216 1216
                 $length = 40;
@@ -1225,7 +1225,7 @@  discard block
 block discarded – undo
1225 1225
                 $error .= "\t-> Section Data1  = ";
1226 1226
                 $error .= substr_replace(
1227 1227
                     substr($data1, $start, $length),
1228
-                    "<b style=\"color:green\">{$data1[ $i ]}</b>",
1228
+                    "<b style=\"color:green\">{$data1[$i]}</b>",
1229 1229
                     $rpoint,
1230 1230
                     $rlength
1231 1231
                 );
@@ -1233,7 +1233,7 @@  discard block
 block discarded – undo
1233 1233
                 $error .= "\t-> Section Data2  = ";
1234 1234
                 $error .= substr_replace(
1235 1235
                     substr($data2, $start, $length),
1236
-                    "<b style=\"color:red\">{$data2[ $i ]}</b>",
1236
+                    "<b style=\"color:red\">{$data2[$i]}</b>",
1237 1237
                     $rpoint,
1238 1238
                     $rlength
1239 1239
                 );
@@ -1264,7 +1264,7 @@  discard block
 block discarded – undo
1264 1264
     public function garbageCollection()
1265 1265
     {
1266 1266
         // only perform during regular requests if last garbage collection was over an hour ago
1267
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1267
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1268 1268
             $this->_last_gc = time();
1269 1269
             $this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1270 1270
             /** @type WPDB $wpdb */
@@ -1299,7 +1299,7 @@  discard block
 block discarded – undo
1299 1299
                 // AND option_value < 1508368198 LIMIT 50
1300 1300
                 $expired_sessions = $wpdb->get_col($SQL);
1301 1301
                 // valid results?
1302
-                if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1302
+                if ( ! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1303 1303
                     $this->cache_storage->deleteMany($expired_sessions, true);
1304 1304
                 }
1305 1305
             }
Please login to merge, or discard this patch.
core/services/request/RequestInterface.php 1 patch
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -20,139 +20,139 @@
 block discarded – undo
20 20
 interface RequestInterface extends RequestTypeContextCheckerInterface
21 21
 {
22 22
 
23
-    /**
24
-     * @param RequestTypeContextCheckerInterface $type
25
-     */
26
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type);
27
-
28
-    /**
29
-     * @return array
30
-     */
31
-    public function getParams();
32
-
33
-
34
-    /**
35
-     * @return array
36
-     */
37
-    public function postParams();
38
-
39
-
40
-    /**
41
-     * @return array
42
-     */
43
-    public function cookieParams();
44
-
45
-
46
-    /**
47
-     * @return array
48
-     */
49
-    public function serverParams();
50
-
51
-
52
-    /**
53
-     * returns contents of $_REQUEST
54
-     *
55
-     * @return array
56
-     */
57
-    public function requestParams();
23
+	/**
24
+	 * @param RequestTypeContextCheckerInterface $type
25
+	 */
26
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type);
27
+
28
+	/**
29
+	 * @return array
30
+	 */
31
+	public function getParams();
32
+
33
+
34
+	/**
35
+	 * @return array
36
+	 */
37
+	public function postParams();
38
+
39
+
40
+	/**
41
+	 * @return array
42
+	 */
43
+	public function cookieParams();
44
+
45
+
46
+	/**
47
+	 * @return array
48
+	 */
49
+	public function serverParams();
50
+
51
+
52
+	/**
53
+	 * returns contents of $_REQUEST
54
+	 *
55
+	 * @return array
56
+	 */
57
+	public function requestParams();
58 58
 
59 59
 
60
-    /**
61
-     * @param string $key
62
-     * @param string $value
63
-     * @param bool   $override_ee
64
-     * @return    void
65
-     */
66
-    public function setRequestParam($key, $value, $override_ee = false);
60
+	/**
61
+	 * @param string $key
62
+	 * @param string $value
63
+	 * @param bool   $override_ee
64
+	 * @return    void
65
+	 */
66
+	public function setRequestParam($key, $value, $override_ee = false);
67 67
 
68 68
 
69
-    /**
70
-     * returns the value for a request param if the given key exists
71
-     *
72
-     * @param string $key
73
-     * @param null   $default
74
-     * @return mixed
75
-     */
76
-    public function getRequestParam($key, $default = null);
69
+	/**
70
+	 * returns the value for a request param if the given key exists
71
+	 *
72
+	 * @param string $key
73
+	 * @param null   $default
74
+	 * @return mixed
75
+	 */
76
+	public function getRequestParam($key, $default = null);
77 77
 
78 78
 
79
-    /**
80
-     * check if param exists
81
-     *
82
-     * @param string $key
83
-     * @return bool
84
-     */
85
-    public function requestParamIsSet($key);
79
+	/**
80
+	 * check if param exists
81
+	 *
82
+	 * @param string $key
83
+	 * @return bool
84
+	 */
85
+	public function requestParamIsSet($key);
86 86
 
87 87
 
88
-    /**
89
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
90
-     * and return the value for the first match found
91
-     * wildcards can be either of the following:
92
-     *      ? to represent a single character of any type
93
-     *      * to represent one or more characters of any type
94
-     *
95
-     * @param string     $pattern
96
-     * @param null|mixed $default
97
-     * @return false|int
98
-     */
99
-    public function getMatch($pattern, $default = null);
88
+	/**
89
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
90
+	 * and return the value for the first match found
91
+	 * wildcards can be either of the following:
92
+	 *      ? to represent a single character of any type
93
+	 *      * to represent one or more characters of any type
94
+	 *
95
+	 * @param string     $pattern
96
+	 * @param null|mixed $default
97
+	 * @return false|int
98
+	 */
99
+	public function getMatch($pattern, $default = null);
100 100
 
101 101
 
102
-    /**
103
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
104
-     * wildcards can be either of the following:
105
-     *      ? to represent a single character of any type
106
-     *      * to represent one or more characters of any type
107
-     * returns true if a match is found or false if not
108
-     *
109
-     * @param string $pattern
110
-     * @return false|int
111
-     */
112
-    public function matches($pattern);
102
+	/**
103
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
104
+	 * wildcards can be either of the following:
105
+	 *      ? to represent a single character of any type
106
+	 *      * to represent one or more characters of any type
107
+	 * returns true if a match is found or false if not
108
+	 *
109
+	 * @param string $pattern
110
+	 * @return false|int
111
+	 */
112
+	public function matches($pattern);
113 113
 
114 114
 
115
-    /**
116
-     * remove param
117
-     *
118
-     * @param string $key
119
-     * @param bool   $unset_from_global_too
120
-     */
121
-    public function unSetRequestParam($key, $unset_from_global_too = false);
115
+	/**
116
+	 * remove param
117
+	 *
118
+	 * @param string $key
119
+	 * @param bool   $unset_from_global_too
120
+	 */
121
+	public function unSetRequestParam($key, $unset_from_global_too = false);
122 122
 
123 123
 
124
-    /**
125
-     * @return string
126
-     */
127
-    public function ipAddress();
124
+	/**
125
+	 * @return string
126
+	 */
127
+	public function ipAddress();
128 128
 
129 129
 
130
-    /**
131
-     * @return string
132
-     */
133
-    public function requestUri();
134
-
130
+	/**
131
+	 * @return string
132
+	 */
133
+	public function requestUri();
134
+
135 135
 
136
-    /**
137
-     * @return string
138
-     */
139
-    public function userAgent();
140
-
141
-
142
-    /**
143
-     * @param string $user_agent
144
-     */
145
-    public function setUserAgent($user_agent = '');
146
-
147
-
148
-    /**
149
-     * @return bool
150
-     */
151
-    public function isBot();
152
-
153
-
154
-    /**
155
-     * @param bool $is_bot
156
-     */
157
-    public function setIsBot($is_bot);
136
+	/**
137
+	 * @return string
138
+	 */
139
+	public function userAgent();
140
+
141
+
142
+	/**
143
+	 * @param string $user_agent
144
+	 */
145
+	public function setUserAgent($user_agent = '');
146
+
147
+
148
+	/**
149
+	 * @return bool
150
+	 */
151
+	public function isBot();
152
+
153
+
154
+	/**
155
+	 * @param bool $is_bot
156
+	 */
157
+	public function setIsBot($is_bot);
158 158
 }
Please login to merge, or discard this patch.
core/middleware/EE_Detect_File_Editor_Request.core.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -14,28 +14,28 @@
 block discarded – undo
14 14
 class EE_Detect_File_Editor_Request extends EE_Middleware
15 15
 {
16 16
 
17
-    /**
18
-     * @deprecated
19
-     * @param EE_Request  $request
20
-     * @param EE_Response $response
21
-     * @return EE_Response
22
-     */
23
-    public function handle_request(EE_Request $request, EE_Response $response)
24
-    {
25
-        EE_Error::doing_it_wrong(
26
-            __METHOD__,
27
-            sprintf(
28
-                esc_html__(
29
-                    'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace',
30
-                    'event_espresso'
31
-                ),
32
-                'EventEspresso\core\services\request\middleware\DetectFileEditorRequest',
33
-                '\core\services\request',
34
-                'EventEspresso\core\services\request'
35
-            ),
36
-            '4.9.52'
37
-        );
38
-        return $response;
39
-    }
17
+	/**
18
+	 * @deprecated
19
+	 * @param EE_Request  $request
20
+	 * @param EE_Response $response
21
+	 * @return EE_Response
22
+	 */
23
+	public function handle_request(EE_Request $request, EE_Response $response)
24
+	{
25
+		EE_Error::doing_it_wrong(
26
+			__METHOD__,
27
+			sprintf(
28
+				esc_html__(
29
+					'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace',
30
+					'event_espresso'
31
+				),
32
+				'EventEspresso\core\services\request\middleware\DetectFileEditorRequest',
33
+				'\core\services\request',
34
+				'EventEspresso\core\services\request'
35
+			),
36
+			'4.9.52'
37
+		);
38
+		return $response;
39
+	}
40 40
 
41 41
 }
Please login to merge, or discard this patch.
core/domain/services/admin/PluginUpsells.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -83,12 +83,12 @@
 block discarded – undo
83 83
                     <div class="notice inline notice-alt">
84 84
                         <div class="ee-upsell-container">
85 85
                             <div class="ee-upsell-inner-container">
86
-                                <a href="' . $button_url . '">
87
-                                    ' . $button_text . '
86
+                                <a href="' . $button_url.'">
87
+                                    ' . $button_text.'
88 88
                                 </a>
89 89
                             </div>
90 90
                             <div class="ee-upsell-inner-container">
91
-                                <p>' . $upsell_text . '</p>
91
+                                <p>' . $upsell_text.'</p>
92 92
                             </div>
93 93
                             <div style="clear:both"></div>
94 94
                         </div>
Please login to merge, or discard this patch.
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -17,47 +17,47 @@  discard block
 block discarded – undo
17 17
 class PluginUpsells
18 18
 {
19 19
 
20
-    /**
21
-     * @var DomainInterface
22
-     */
23
-    private $domain;
20
+	/**
21
+	 * @var DomainInterface
22
+	 */
23
+	private $domain;
24 24
 
25 25
 
26
-    /**
27
-     * PluginUpsells constructor.
28
-     *
29
-     * @param DomainInterface $domain
30
-     */
31
-    public function __construct(DomainInterface $domain)
32
-    {
33
-        $this->domain = $domain;
34
-    }
26
+	/**
27
+	 * PluginUpsells constructor.
28
+	 *
29
+	 * @param DomainInterface $domain
30
+	 */
31
+	public function __construct(DomainInterface $domain)
32
+	{
33
+		$this->domain = $domain;
34
+	}
35 35
 
36 36
 
37
-    /**
38
-     * Hook in various upsells for the decaf version of EE.
39
-     */
40
-    public function decafUpsells()
41
-    {
42
-        if ($this->domain instanceof CaffeinatedInterface && ! $this->domain->isCaffeinated()) {
43
-            add_action('after_plugin_row', array($this, 'doPremiumUpsell'), 10, 3);
44
-        }
45
-    }
37
+	/**
38
+	 * Hook in various upsells for the decaf version of EE.
39
+	 */
40
+	public function decafUpsells()
41
+	{
42
+		if ($this->domain instanceof CaffeinatedInterface && ! $this->domain->isCaffeinated()) {
43
+			add_action('after_plugin_row', array($this, 'doPremiumUpsell'), 10, 3);
44
+		}
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * Callback for `after_plugin_row` to add upsell info
50
-     *
51
-     * @param string $plugin_file
52
-     * @param array  $plugin_data
53
-     * @param string $status
54
-     * @throws DomainException
55
-     */
56
-    public function doPremiumUpsell($plugin_file, $plugin_data, $status)
57
-    {
58
-        if ($plugin_file === $this->domain->pluginBasename()) {
59
-            list($button_text, $button_url, $upsell_text) = $this->getAfterPluginRowDetails();
60
-            echo '<tr class="plugin-update-tr ee-upsell-plugin-list-table active">
48
+	/**
49
+	 * Callback for `after_plugin_row` to add upsell info
50
+	 *
51
+	 * @param string $plugin_file
52
+	 * @param array  $plugin_data
53
+	 * @param string $status
54
+	 * @throws DomainException
55
+	 */
56
+	public function doPremiumUpsell($plugin_file, $plugin_data, $status)
57
+	{
58
+		if ($plugin_file === $this->domain->pluginBasename()) {
59
+			list($button_text, $button_url, $upsell_text) = $this->getAfterPluginRowDetails();
60
+			echo '<tr class="plugin-update-tr ee-upsell-plugin-list-table active">
61 61
                 <td colspan="3" class="plugin-update colspanchange">
62 62
                     <div class="notice inline notice-alt">
63 63
                         <div class="ee-upsell-container">
@@ -74,27 +74,27 @@  discard block
 block discarded – undo
74 74
                     </div>
75 75
                 </td>
76 76
               </tr>';
77
-        }
78
-    }
77
+		}
78
+	}
79 79
 
80
-    /**
81
-     * Provide the details used for the upsell container.
82
-     *
83
-     * @return array
84
-     */
85
-    protected function getAfterPluginRowDetails()
86
-    {
87
-        return array(
88
-            esc_html__('Upgrade for Support', 'event_espresso'),
89
-            'https://eventespresso.com/purchase/?slug=ee4-license-personal&utm_source=wp_admin_plugins_screen&utm_medium=link&utm_campaign=plugins_screen_upgrade_link" class="button button-primary',
90
-            sprintf(
91
-                esc_html__(
92
-                    'You\'re missing out on %1$sexpert support%2$s and %1$sone-click updates%2$s! Don\'t have an Event Espresso support license key? Support the project and buy one today!',
93
-                    'event_espresso'
94
-                ),
95
-                '<strong>',
96
-                '</strong>'
97
-            ),
98
-        );
99
-    }
80
+	/**
81
+	 * Provide the details used for the upsell container.
82
+	 *
83
+	 * @return array
84
+	 */
85
+	protected function getAfterPluginRowDetails()
86
+	{
87
+		return array(
88
+			esc_html__('Upgrade for Support', 'event_espresso'),
89
+			'https://eventespresso.com/purchase/?slug=ee4-license-personal&utm_source=wp_admin_plugins_screen&utm_medium=link&utm_campaign=plugins_screen_upgrade_link" class="button button-primary',
90
+			sprintf(
91
+				esc_html__(
92
+					'You\'re missing out on %1$sexpert support%2$s and %1$sone-click updates%2$s! Don\'t have an Event Espresso support license key? Support the project and buy one today!',
93
+					'event_espresso'
94
+				),
95
+				'<strong>',
96
+				'</strong>'
97
+			),
98
+		);
99
+	}
100 100
 }
Please login to merge, or discard this patch.
core/domain/Domain.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@
 block discarded – undo
66 66
      */
67 67
     private function setCaffeinated()
68 68
     {
69
-        $this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true)
70
-            && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php');
69
+        $this->caffeinated = ( ! defined('EE_DECAF') || EE_DECAF !== true)
70
+            && is_readable($this->pluginPath().'caffeinated/brewing_regular.php');
71 71
     }
72 72
 }
Please login to merge, or discard this patch.
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -19,54 +19,54 @@
 block discarded – undo
19 19
 class Domain extends DomainBase implements CaffeinatedInterface
20 20
 {
21 21
 
22
-    /**
23
-     * URL path component used to denote an API request
24
-     */
25
-    const API_NAMESPACE = 'ee/v';
22
+	/**
23
+	 * URL path component used to denote an API request
24
+	 */
25
+	const API_NAMESPACE = 'ee/v';
26 26
 
27
-    /**
28
-     * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin
29
-     * Page ui.
30
-     */
31
-    const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN
32
-        = 'manual_registration_status_change_from_registration_admin';
27
+	/**
28
+	 * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin
29
+	 * Page ui.
30
+	 */
31
+	const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN
32
+		= 'manual_registration_status_change_from_registration_admin';
33 33
 
34
-    const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
35
-        = 'manual_registration_status_change_from_registration_admin_and_notify';
34
+	const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
35
+		= 'manual_registration_status_change_from_registration_admin_and_notify';
36 36
 
37 37
 
38
-    /**
39
-     * Whether or not EE core is the full premium version.
40
-     * @since 4.9.59.p
41
-     * @var bool
42
-     */
43
-    private $caffeinated;
38
+	/**
39
+	 * Whether or not EE core is the full premium version.
40
+	 * @since 4.9.59.p
41
+	 * @var bool
42
+	 */
43
+	private $caffeinated;
44 44
 
45 45
 
46
-    public function __construct(FilePath $plugin_file, Version $version)
47
-    {
48
-        parent::__construct($plugin_file, $version);
49
-        $this->setCaffeinated();
50
-    }
46
+	public function __construct(FilePath $plugin_file, Version $version)
47
+	{
48
+		parent::__construct($plugin_file, $version);
49
+		$this->setCaffeinated();
50
+	}
51 51
 
52
-    /**
53
-     * Whether or not EE core is the full premium version.
54
-     * @since 4.9.59.p
55
-     * @return bool
56
-     */
57
-    public function isCaffeinated()
58
-    {
59
-        return $this->caffeinated;
60
-    }
52
+	/**
53
+	 * Whether or not EE core is the full premium version.
54
+	 * @since 4.9.59.p
55
+	 * @return bool
56
+	 */
57
+	public function isCaffeinated()
58
+	{
59
+		return $this->caffeinated;
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * Setter for $is_caffeinated property.
65
-     * @since 4.9.59.p
66
-     */
67
-    private function setCaffeinated()
68
-    {
69
-        $this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true)
70
-            && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php');
71
-    }
63
+	/**
64
+	 * Setter for $is_caffeinated property.
65
+	 * @since 4.9.59.p
66
+	 */
67
+	private function setCaffeinated()
68
+	{
69
+		$this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true)
70
+			&& is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php');
71
+	}
72 72
 }
Please login to merge, or discard this patch.
core/services/loaders/Loader.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@
 block discarded – undo
101 101
 
102 102
 
103 103
     /**
104
-     * @param FullyQualifiedName|string $fqcn
104
+     * @param string $fqcn
105 105
      * @param array                     $arguments
106 106
      * @return mixed
107 107
      */
Please login to merge, or discard this patch.
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -15,115 +15,115 @@
 block discarded – undo
15 15
 class Loader implements LoaderInterface
16 16
 {
17 17
 
18
-    /**
19
-     * @var LoaderDecoratorInterface $new_loader
20
-     */
21
-    private $new_loader;
22
-
23
-    /**
24
-     * @var LoaderDecoratorInterface $shared_loader
25
-     */
26
-    private $shared_loader;
27
-
28
-    /**
29
-     * @var ClassInterfaceCache $class_cache
30
-     */
31
-    private $class_cache;
32
-
33
-    /**
34
-     * Loader constructor.
35
-     *
36
-     * @param LoaderDecoratorInterface        $new_loader
37
-     * @param CachingLoaderDecoratorInterface $shared_loader
38
-     * @param ClassInterfaceCache             $class_cache
39
-     */
40
-    public function __construct(
41
-        LoaderDecoratorInterface $new_loader,
42
-        CachingLoaderDecoratorInterface $shared_loader,
43
-        ClassInterfaceCache $class_cache
44
-    ) {
45
-        $this->new_loader    = $new_loader;
46
-        $this->shared_loader = $shared_loader;
47
-        $this->class_cache   = $class_cache;
48
-    }
49
-
50
-
51
-    /**
52
-     * @return LoaderDecoratorInterface
53
-     */
54
-    public function getNewLoader()
55
-    {
56
-        return $this->new_loader;
57
-    }
58
-
59
-
60
-    /**
61
-     * @return CachingLoaderDecoratorInterface
62
-     */
63
-    public function getSharedLoader()
64
-    {
65
-        return $this->shared_loader;
66
-    }
67
-
68
-
69
-    /**
70
-     * @param FullyQualifiedName|string $fqcn
71
-     * @param array                     $arguments
72
-     * @param bool                      $shared
73
-     * @return mixed
74
-     */
75
-    public function load($fqcn, array $arguments = array(), $shared = true)
76
-    {
77
-        $fqcn = $this->class_cache->getFqn($fqcn);
78
-        if ($this->class_cache->hasInterface($fqcn, 'EventEspresso\core\interfaces\ReservedInstanceInterface')) {
79
-            $shared = true;
80
-        }
81
-        return $shared
82
-            ? $this->getSharedLoader()->load($fqcn, $arguments, $shared)
83
-            : $this->getNewLoader()->load($fqcn, $arguments, $shared);
84
-    }
85
-
86
-
87
-    /**
88
-     * @param FullyQualifiedName|string $fqcn
89
-     * @param array                     $arguments
90
-     * @return mixed
91
-     */
92
-    public function getNew($fqcn, array $arguments = array())
93
-    {
94
-        return $this->load($fqcn, $arguments, false);
95
-    }
96
-
97
-
98
-    /**
99
-     * @param FullyQualifiedName|string $fqcn
100
-     * @param array                     $arguments
101
-     * @return mixed
102
-     */
103
-    public function getShared($fqcn, array $arguments = array())
104
-    {
105
-        return $this->load($fqcn, $arguments);
106
-    }
107
-
108
-
109
-    /**
110
-     * @param FullyQualifiedName|string $fqcn
111
-     * @param mixed                     $object
112
-     * @return bool
113
-     * @throws InvalidArgumentException
114
-     */
115
-    public function share($fqcn, $object)
116
-    {
117
-        $fqcn = $this->class_cache->getFqn($fqcn);
118
-        return $this->getSharedLoader()->share($fqcn, $object);
119
-    }
120
-
121
-
122
-    /**
123
-     * calls reset() on loaders if that method exists
124
-     */
125
-    public function reset()
126
-    {
127
-        $this->shared_loader->reset();
128
-    }
18
+	/**
19
+	 * @var LoaderDecoratorInterface $new_loader
20
+	 */
21
+	private $new_loader;
22
+
23
+	/**
24
+	 * @var LoaderDecoratorInterface $shared_loader
25
+	 */
26
+	private $shared_loader;
27
+
28
+	/**
29
+	 * @var ClassInterfaceCache $class_cache
30
+	 */
31
+	private $class_cache;
32
+
33
+	/**
34
+	 * Loader constructor.
35
+	 *
36
+	 * @param LoaderDecoratorInterface        $new_loader
37
+	 * @param CachingLoaderDecoratorInterface $shared_loader
38
+	 * @param ClassInterfaceCache             $class_cache
39
+	 */
40
+	public function __construct(
41
+		LoaderDecoratorInterface $new_loader,
42
+		CachingLoaderDecoratorInterface $shared_loader,
43
+		ClassInterfaceCache $class_cache
44
+	) {
45
+		$this->new_loader    = $new_loader;
46
+		$this->shared_loader = $shared_loader;
47
+		$this->class_cache   = $class_cache;
48
+	}
49
+
50
+
51
+	/**
52
+	 * @return LoaderDecoratorInterface
53
+	 */
54
+	public function getNewLoader()
55
+	{
56
+		return $this->new_loader;
57
+	}
58
+
59
+
60
+	/**
61
+	 * @return CachingLoaderDecoratorInterface
62
+	 */
63
+	public function getSharedLoader()
64
+	{
65
+		return $this->shared_loader;
66
+	}
67
+
68
+
69
+	/**
70
+	 * @param FullyQualifiedName|string $fqcn
71
+	 * @param array                     $arguments
72
+	 * @param bool                      $shared
73
+	 * @return mixed
74
+	 */
75
+	public function load($fqcn, array $arguments = array(), $shared = true)
76
+	{
77
+		$fqcn = $this->class_cache->getFqn($fqcn);
78
+		if ($this->class_cache->hasInterface($fqcn, 'EventEspresso\core\interfaces\ReservedInstanceInterface')) {
79
+			$shared = true;
80
+		}
81
+		return $shared
82
+			? $this->getSharedLoader()->load($fqcn, $arguments, $shared)
83
+			: $this->getNewLoader()->load($fqcn, $arguments, $shared);
84
+	}
85
+
86
+
87
+	/**
88
+	 * @param FullyQualifiedName|string $fqcn
89
+	 * @param array                     $arguments
90
+	 * @return mixed
91
+	 */
92
+	public function getNew($fqcn, array $arguments = array())
93
+	{
94
+		return $this->load($fqcn, $arguments, false);
95
+	}
96
+
97
+
98
+	/**
99
+	 * @param FullyQualifiedName|string $fqcn
100
+	 * @param array                     $arguments
101
+	 * @return mixed
102
+	 */
103
+	public function getShared($fqcn, array $arguments = array())
104
+	{
105
+		return $this->load($fqcn, $arguments);
106
+	}
107
+
108
+
109
+	/**
110
+	 * @param FullyQualifiedName|string $fqcn
111
+	 * @param mixed                     $object
112
+	 * @return bool
113
+	 * @throws InvalidArgumentException
114
+	 */
115
+	public function share($fqcn, $object)
116
+	{
117
+		$fqcn = $this->class_cache->getFqn($fqcn);
118
+		return $this->getSharedLoader()->share($fqcn, $object);
119
+	}
120
+
121
+
122
+	/**
123
+	 * calls reset() on loaders if that method exists
124
+	 */
125
+	public function reset()
126
+	{
127
+		$this->shared_loader->reset();
128
+	}
129 129
 }
Please login to merge, or discard this patch.
core/services/bootstrap/BootstrapDependencyInjectionContainer.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -78,13 +78,13 @@
 block discarded – undo
78 78
         // EE_Dependency_Map: info about how to load classes required by other classes
79 79
         espresso_load_required(
80 80
             'EE_Dependency_Map',
81
-            EE_CORE . 'EE_Dependency_Map.core.php'
81
+            EE_CORE.'EE_Dependency_Map.core.php'
82 82
         );
83 83
         $this->dependency_map = EE_Dependency_Map::instance($this->class_cache);
84 84
         // EE_Registry: central repository for classes (legacy)
85 85
         espresso_load_required(
86 86
             'EE_Registry',
87
-            EE_CORE . 'EE_Registry.core.php'
87
+            EE_CORE.'EE_Registry.core.php'
88 88
         );
89 89
         $this->registry = EE_Registry::instance(
90 90
             $this->dependency_map,
Please login to merge, or discard this patch.
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -25,123 +25,123 @@
 block discarded – undo
25 25
 class BootstrapDependencyInjectionContainer
26 26
 {
27 27
 
28
-    /**
29
-     * @var EE_Dependency_Map $dependency_map
30
-     */
31
-    protected $dependency_map;
32
-
33
-    /**
34
-     * @type LoaderInterface $loader
35
-     */
36
-    protected $loader;
37
-
38
-    /**
39
-     * @var EE_Registry $registry
40
-     */
41
-    protected $registry;
42
-
43
-    /**
44
-     * @var ClassInterfaceCache $class_cache
45
-     */
46
-    private $class_cache;
47
-
48
-    /**
49
-     * @var Mirror
50
-     */
51
-    private $mirror;
52
-
53
-    /**
54
-     * @var ObjectIdentifier
55
-     */
56
-    private $object_identifier;
57
-
58
-
59
-    /**
60
-     * Can't use this just yet until we exorcise some more of our singleton usage from core
61
-     */
62
-    public function buildDependencyInjectionContainer()
63
-    {
64
-        // build DI container
65
-        // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop();
66
-        // $OpenCoffeeShop->addRecipes();
67
-        // $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
68
-    }
69
-
70
-
71
-    /**
72
-     * Setups  EE_Registry and EE_Dependency_Map
73
-     *
74
-     * @throws EE_Error
75
-     */
76
-    public function buildLegacyDependencyInjectionContainer()
77
-    {
78
-        $this->class_cache = new ClassInterfaceCache();
79
-        $this->object_identifier = new ObjectIdentifier($this->class_cache);
80
-        $this->mirror = new Mirror();
81
-        // EE_Dependency_Map: info about how to load classes required by other classes
82
-        espresso_load_required(
83
-            'EE_Dependency_Map',
84
-            EE_CORE . 'EE_Dependency_Map.core.php'
85
-        );
86
-        $this->dependency_map = EE_Dependency_Map::instance($this->class_cache);
87
-        // EE_Registry: central repository for classes (legacy)
88
-        espresso_load_required(
89
-            'EE_Registry',
90
-            EE_CORE . 'EE_Registry.core.php'
91
-        );
92
-        $this->registry = EE_Registry::instance(
93
-            $this->dependency_map,
94
-            $this->mirror,
95
-            $this->class_cache,
96
-            $this->object_identifier
97
-        );
98
-    }
99
-
100
-
101
-    /**
102
-     * Performs initial setup for the generic Loader
103
-     *
104
-     * @throws InvalidDataTypeException
105
-     * @throws InvalidInterfaceException
106
-     * @throws InvalidArgumentException
107
-     */
108
-    public function buildLoader()
109
-    {
110
-        $this->loader = LoaderFactory::getLoader(
111
-            $this->registry,
112
-            $this->class_cache,
113
-            $this->object_identifier
114
-        );
115
-        $this->loader->share('EventEspresso\core\services\loaders\ClassInterfaceCache', $this->class_cache);
116
-        $this->loader->share('EventEspresso\core\services\loaders\ObjectIdentifier', $this->object_identifier);
117
-        $this->loader->share('EventEspresso\core\services\container\Mirror', $this->mirror);
118
-        $this->dependency_map->setLoader($this->loader);
119
-    }
120
-
121
-
122
-    /**
123
-     * @return EE_Dependency_Map
124
-     */
125
-    public function getDependencyMap()
126
-    {
127
-        return $this->dependency_map;
128
-    }
129
-
130
-
131
-    /**
132
-     * @return EE_Registry
133
-     */
134
-    public function getRegistry()
135
-    {
136
-        return $this->registry;
137
-    }
138
-
139
-
140
-    /**
141
-     * @return LoaderInterface
142
-     */
143
-    public function getLoader()
144
-    {
145
-        return $this->loader;
146
-    }
28
+	/**
29
+	 * @var EE_Dependency_Map $dependency_map
30
+	 */
31
+	protected $dependency_map;
32
+
33
+	/**
34
+	 * @type LoaderInterface $loader
35
+	 */
36
+	protected $loader;
37
+
38
+	/**
39
+	 * @var EE_Registry $registry
40
+	 */
41
+	protected $registry;
42
+
43
+	/**
44
+	 * @var ClassInterfaceCache $class_cache
45
+	 */
46
+	private $class_cache;
47
+
48
+	/**
49
+	 * @var Mirror
50
+	 */
51
+	private $mirror;
52
+
53
+	/**
54
+	 * @var ObjectIdentifier
55
+	 */
56
+	private $object_identifier;
57
+
58
+
59
+	/**
60
+	 * Can't use this just yet until we exorcise some more of our singleton usage from core
61
+	 */
62
+	public function buildDependencyInjectionContainer()
63
+	{
64
+		// build DI container
65
+		// $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop();
66
+		// $OpenCoffeeShop->addRecipes();
67
+		// $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
68
+	}
69
+
70
+
71
+	/**
72
+	 * Setups  EE_Registry and EE_Dependency_Map
73
+	 *
74
+	 * @throws EE_Error
75
+	 */
76
+	public function buildLegacyDependencyInjectionContainer()
77
+	{
78
+		$this->class_cache = new ClassInterfaceCache();
79
+		$this->object_identifier = new ObjectIdentifier($this->class_cache);
80
+		$this->mirror = new Mirror();
81
+		// EE_Dependency_Map: info about how to load classes required by other classes
82
+		espresso_load_required(
83
+			'EE_Dependency_Map',
84
+			EE_CORE . 'EE_Dependency_Map.core.php'
85
+		);
86
+		$this->dependency_map = EE_Dependency_Map::instance($this->class_cache);
87
+		// EE_Registry: central repository for classes (legacy)
88
+		espresso_load_required(
89
+			'EE_Registry',
90
+			EE_CORE . 'EE_Registry.core.php'
91
+		);
92
+		$this->registry = EE_Registry::instance(
93
+			$this->dependency_map,
94
+			$this->mirror,
95
+			$this->class_cache,
96
+			$this->object_identifier
97
+		);
98
+	}
99
+
100
+
101
+	/**
102
+	 * Performs initial setup for the generic Loader
103
+	 *
104
+	 * @throws InvalidDataTypeException
105
+	 * @throws InvalidInterfaceException
106
+	 * @throws InvalidArgumentException
107
+	 */
108
+	public function buildLoader()
109
+	{
110
+		$this->loader = LoaderFactory::getLoader(
111
+			$this->registry,
112
+			$this->class_cache,
113
+			$this->object_identifier
114
+		);
115
+		$this->loader->share('EventEspresso\core\services\loaders\ClassInterfaceCache', $this->class_cache);
116
+		$this->loader->share('EventEspresso\core\services\loaders\ObjectIdentifier', $this->object_identifier);
117
+		$this->loader->share('EventEspresso\core\services\container\Mirror', $this->mirror);
118
+		$this->dependency_map->setLoader($this->loader);
119
+	}
120
+
121
+
122
+	/**
123
+	 * @return EE_Dependency_Map
124
+	 */
125
+	public function getDependencyMap()
126
+	{
127
+		return $this->dependency_map;
128
+	}
129
+
130
+
131
+	/**
132
+	 * @return EE_Registry
133
+	 */
134
+	public function getRegistry()
135
+	{
136
+		return $this->registry;
137
+	}
138
+
139
+
140
+	/**
141
+	 * @return LoaderInterface
142
+	 */
143
+	public function getLoader()
144
+	{
145
+		return $this->loader;
146
+	}
147 147
 }
Please login to merge, or discard this patch.
core/services/container/Mirror.php 2 patches
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -25,226 +25,226 @@
 block discarded – undo
25 25
 class Mirror
26 26
 {
27 27
 
28
-    /**
29
-     * @var ReflectionClass[] $classes
30
-     */
31
-    private $classes = array();
32
-
33
-    /**
34
-     * @var ReflectionMethod[] $constructors
35
-     */
36
-    private $constructors = array();
37
-
38
-    /**
39
-     * @var ReflectionParameter[][] $parameters
40
-     */
41
-    private $parameters = array();
42
-
43
-    /**
44
-     * @var ReflectionParameter[][] $parameters
45
-     */
46
-    private $parameter_classes = array();
47
-
48
-    /**
49
-     * @var ReflectionProperty[][] $properties
50
-     */
51
-    private $properties = array();
52
-
53
-    /**
54
-     * @var ReflectionMethod[][] $methods
55
-     */
56
-    private $methods = array();
57
-
58
-
59
-    /**
60
-     * @param string $class_name
61
-     * @return ReflectionClass
62
-     * @throws ReflectionException
63
-     * @throws InvalidDataTypeException
64
-     */
65
-    public function getReflectionClass($class_name)
66
-    {
67
-        if (! is_string($class_name)) {
68
-            throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
69
-        }
70
-        if (! isset($this->classes[ $class_name ])) {
71
-            $this->classes[ $class_name ] = new ReflectionClass($class_name);
72
-        }
73
-        return $this->classes[ $class_name ];
74
-    }
75
-
76
-
77
-    /**
78
-     * @param string $class_name
79
-     * @return ReflectionMethod
80
-     * @throws InvalidDataTypeException
81
-     * @throws ReflectionException
82
-     */
83
-    public function getConstructor($class_name)
84
-    {
85
-        if (! is_string($class_name)) {
86
-            throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
87
-        }
88
-        if (! isset($this->constructors[ $class_name ])) {
89
-            $reflection_class                  = $this->getReflectionClass($class_name);
90
-            $this->constructors[ $class_name ] = $reflection_class->getConstructor();
91
-        }
92
-        return $this->constructors[ $class_name ];
93
-    }
94
-
95
-
96
-    /**
97
-     * @param ReflectionClass $reflection_class
98
-     * @return ReflectionMethod
99
-     * @throws InvalidDataTypeException
100
-     * @throws ReflectionException
101
-     */
102
-    public function getConstructorFromReflection(ReflectionClass $reflection_class)
103
-    {
104
-        return $this->getConstructor($reflection_class->getName());
105
-    }
106
-
107
-
108
-    /**
109
-     * @param string $class_name
110
-     * @return ReflectionParameter[]
111
-     * @throws InvalidDataTypeException
112
-     * @throws ReflectionException
113
-     */
114
-    public function getParameters($class_name)
115
-    {
116
-        if (! isset($this->parameters[ $class_name ])) {
117
-            $constructor                     = $this->getConstructor($class_name);
118
-            $this->parameters[ $class_name ] = $constructor->getParameters();
119
-        }
120
-        return $this->parameters[ $class_name ];
121
-    }
122
-
123
-
124
-    /**
125
-     * @param ReflectionClass $reflection_class
126
-     * @return ReflectionParameter[]
127
-     * @throws InvalidDataTypeException
128
-     * @throws ReflectionException
129
-     */
130
-    public function getParametersFromReflection(ReflectionClass $reflection_class)
131
-    {
132
-        return $this->getParameters($reflection_class->getName());
133
-    }
134
-
135
-
136
-    /**
137
-     * @param ReflectionMethod $constructor
138
-     * @return ReflectionParameter[]
139
-     * @throws InvalidDataTypeException
140
-     * @throws ReflectionException
141
-     */
142
-    public function getParametersFromReflectionConstructor(ReflectionMethod $constructor)
143
-    {
144
-        return $this->getParameters($constructor->getDeclaringClass());
145
-    }
146
-
147
-
148
-    /**
149
-     * @param ReflectionParameter $param
150
-     * @param string              $class_name
151
-     * @param string              $index
152
-     * @return string|null
153
-     */
154
-    public function getParameterClassName(ReflectionParameter $param, $class_name, $index)
155
-    {
156
-        if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) {
157
-            return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
158
-        }
159
-        if (! isset($this->parameter_classes[ $class_name ])) {
160
-            $this->parameter_classes[ $class_name ] = array();
161
-        }
162
-        if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
163
-            $this->parameter_classes[ $class_name ][ $index ] = array();
164
-        }
165
-        $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = $param->getClass()
166
-            ? $param->getClass()->name
167
-            : null;
168
-        return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
169
-    }
170
-
171
-
172
-    /**
173
-     * @param ReflectionParameter $param
174
-     * @param string              $class_name
175
-     * @param string              $index
176
-     * @return string|null
177
-     */
178
-    public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index)
179
-    {
180
-        if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) {
181
-            return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
182
-        }
183
-        if (! isset($this->parameter_classes[ $class_name ])) {
184
-            $this->parameter_classes[ $class_name ] = array();
185
-        }
186
-        if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
187
-            $this->parameter_classes[ $class_name ][ $index ] = array();
188
-        }
189
-        $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable()
190
-            ? $param->getDefaultValue()
191
-            : null;
192
-        return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
193
-    }
194
-
195
-
196
-    /**
197
-     * @param string $class_name
198
-     * @return ReflectionProperty[]
199
-     * @throws InvalidDataTypeException
200
-     * @throws ReflectionException
201
-     */
202
-    public function getProperties($class_name)
203
-    {
204
-        if (! isset($this->properties[ $class_name ])) {
205
-            $reflection_class                = $this->getReflectionClass($class_name);
206
-            $this->properties[ $class_name ] = $reflection_class->getProperties();
207
-        }
208
-        return $this->properties[ $class_name ];
209
-    }
210
-
211
-
212
-    /**
213
-     * @param ReflectionClass $reflection_class
214
-     * @return ReflectionProperty[]
215
-     * @throws InvalidDataTypeException
216
-     * @throws ReflectionException
217
-     */
218
-    public function getPropertiesFromReflection(ReflectionClass $reflection_class)
219
-    {
220
-        return $this->getProperties($reflection_class->getName());
221
-    }
222
-
223
-
224
-    /**
225
-     * @param string $class_name
226
-     * @return ReflectionMethod[]
227
-     * @throws InvalidDataTypeException
228
-     * @throws ReflectionException
229
-     */
230
-    public function getMethods($class_name)
231
-    {
232
-        if (! isset($this->methods[ $class_name ])) {
233
-            $reflection_class             = $this->getReflectionClass($class_name);
234
-            $this->methods[ $class_name ] = $reflection_class->getMethods();
235
-        }
236
-        return $this->methods[ $class_name ];
237
-    }
238
-
239
-
240
-    /**
241
-     * @param ReflectionClass $reflection_class )
242
-     * @return ReflectionMethod[]
243
-     * @throws InvalidDataTypeException
244
-     * @throws ReflectionException
245
-     */
246
-    public function getMethodsFromReflection(ReflectionClass $reflection_class)
247
-    {
248
-        return $this->getMethods($reflection_class->getName());
249
-    }
28
+	/**
29
+	 * @var ReflectionClass[] $classes
30
+	 */
31
+	private $classes = array();
32
+
33
+	/**
34
+	 * @var ReflectionMethod[] $constructors
35
+	 */
36
+	private $constructors = array();
37
+
38
+	/**
39
+	 * @var ReflectionParameter[][] $parameters
40
+	 */
41
+	private $parameters = array();
42
+
43
+	/**
44
+	 * @var ReflectionParameter[][] $parameters
45
+	 */
46
+	private $parameter_classes = array();
47
+
48
+	/**
49
+	 * @var ReflectionProperty[][] $properties
50
+	 */
51
+	private $properties = array();
52
+
53
+	/**
54
+	 * @var ReflectionMethod[][] $methods
55
+	 */
56
+	private $methods = array();
57
+
58
+
59
+	/**
60
+	 * @param string $class_name
61
+	 * @return ReflectionClass
62
+	 * @throws ReflectionException
63
+	 * @throws InvalidDataTypeException
64
+	 */
65
+	public function getReflectionClass($class_name)
66
+	{
67
+		if (! is_string($class_name)) {
68
+			throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
69
+		}
70
+		if (! isset($this->classes[ $class_name ])) {
71
+			$this->classes[ $class_name ] = new ReflectionClass($class_name);
72
+		}
73
+		return $this->classes[ $class_name ];
74
+	}
75
+
76
+
77
+	/**
78
+	 * @param string $class_name
79
+	 * @return ReflectionMethod
80
+	 * @throws InvalidDataTypeException
81
+	 * @throws ReflectionException
82
+	 */
83
+	public function getConstructor($class_name)
84
+	{
85
+		if (! is_string($class_name)) {
86
+			throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
87
+		}
88
+		if (! isset($this->constructors[ $class_name ])) {
89
+			$reflection_class                  = $this->getReflectionClass($class_name);
90
+			$this->constructors[ $class_name ] = $reflection_class->getConstructor();
91
+		}
92
+		return $this->constructors[ $class_name ];
93
+	}
94
+
95
+
96
+	/**
97
+	 * @param ReflectionClass $reflection_class
98
+	 * @return ReflectionMethod
99
+	 * @throws InvalidDataTypeException
100
+	 * @throws ReflectionException
101
+	 */
102
+	public function getConstructorFromReflection(ReflectionClass $reflection_class)
103
+	{
104
+		return $this->getConstructor($reflection_class->getName());
105
+	}
106
+
107
+
108
+	/**
109
+	 * @param string $class_name
110
+	 * @return ReflectionParameter[]
111
+	 * @throws InvalidDataTypeException
112
+	 * @throws ReflectionException
113
+	 */
114
+	public function getParameters($class_name)
115
+	{
116
+		if (! isset($this->parameters[ $class_name ])) {
117
+			$constructor                     = $this->getConstructor($class_name);
118
+			$this->parameters[ $class_name ] = $constructor->getParameters();
119
+		}
120
+		return $this->parameters[ $class_name ];
121
+	}
122
+
123
+
124
+	/**
125
+	 * @param ReflectionClass $reflection_class
126
+	 * @return ReflectionParameter[]
127
+	 * @throws InvalidDataTypeException
128
+	 * @throws ReflectionException
129
+	 */
130
+	public function getParametersFromReflection(ReflectionClass $reflection_class)
131
+	{
132
+		return $this->getParameters($reflection_class->getName());
133
+	}
134
+
135
+
136
+	/**
137
+	 * @param ReflectionMethod $constructor
138
+	 * @return ReflectionParameter[]
139
+	 * @throws InvalidDataTypeException
140
+	 * @throws ReflectionException
141
+	 */
142
+	public function getParametersFromReflectionConstructor(ReflectionMethod $constructor)
143
+	{
144
+		return $this->getParameters($constructor->getDeclaringClass());
145
+	}
146
+
147
+
148
+	/**
149
+	 * @param ReflectionParameter $param
150
+	 * @param string              $class_name
151
+	 * @param string              $index
152
+	 * @return string|null
153
+	 */
154
+	public function getParameterClassName(ReflectionParameter $param, $class_name, $index)
155
+	{
156
+		if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) {
157
+			return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
158
+		}
159
+		if (! isset($this->parameter_classes[ $class_name ])) {
160
+			$this->parameter_classes[ $class_name ] = array();
161
+		}
162
+		if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
163
+			$this->parameter_classes[ $class_name ][ $index ] = array();
164
+		}
165
+		$this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = $param->getClass()
166
+			? $param->getClass()->name
167
+			: null;
168
+		return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param ReflectionParameter $param
174
+	 * @param string              $class_name
175
+	 * @param string              $index
176
+	 * @return string|null
177
+	 */
178
+	public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index)
179
+	{
180
+		if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) {
181
+			return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
182
+		}
183
+		if (! isset($this->parameter_classes[ $class_name ])) {
184
+			$this->parameter_classes[ $class_name ] = array();
185
+		}
186
+		if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
187
+			$this->parameter_classes[ $class_name ][ $index ] = array();
188
+		}
189
+		$this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable()
190
+			? $param->getDefaultValue()
191
+			: null;
192
+		return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
193
+	}
194
+
195
+
196
+	/**
197
+	 * @param string $class_name
198
+	 * @return ReflectionProperty[]
199
+	 * @throws InvalidDataTypeException
200
+	 * @throws ReflectionException
201
+	 */
202
+	public function getProperties($class_name)
203
+	{
204
+		if (! isset($this->properties[ $class_name ])) {
205
+			$reflection_class                = $this->getReflectionClass($class_name);
206
+			$this->properties[ $class_name ] = $reflection_class->getProperties();
207
+		}
208
+		return $this->properties[ $class_name ];
209
+	}
210
+
211
+
212
+	/**
213
+	 * @param ReflectionClass $reflection_class
214
+	 * @return ReflectionProperty[]
215
+	 * @throws InvalidDataTypeException
216
+	 * @throws ReflectionException
217
+	 */
218
+	public function getPropertiesFromReflection(ReflectionClass $reflection_class)
219
+	{
220
+		return $this->getProperties($reflection_class->getName());
221
+	}
222
+
223
+
224
+	/**
225
+	 * @param string $class_name
226
+	 * @return ReflectionMethod[]
227
+	 * @throws InvalidDataTypeException
228
+	 * @throws ReflectionException
229
+	 */
230
+	public function getMethods($class_name)
231
+	{
232
+		if (! isset($this->methods[ $class_name ])) {
233
+			$reflection_class             = $this->getReflectionClass($class_name);
234
+			$this->methods[ $class_name ] = $reflection_class->getMethods();
235
+		}
236
+		return $this->methods[ $class_name ];
237
+	}
238
+
239
+
240
+	/**
241
+	 * @param ReflectionClass $reflection_class )
242
+	 * @return ReflectionMethod[]
243
+	 * @throws InvalidDataTypeException
244
+	 * @throws ReflectionException
245
+	 */
246
+	public function getMethodsFromReflection(ReflectionClass $reflection_class)
247
+	{
248
+		return $this->getMethods($reflection_class->getName());
249
+	}
250 250
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -64,13 +64,13 @@  discard block
 block discarded – undo
64 64
      */
65 65
     public function getReflectionClass($class_name)
66 66
     {
67
-        if (! is_string($class_name)) {
67
+        if ( ! is_string($class_name)) {
68 68
             throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
69 69
         }
70
-        if (! isset($this->classes[ $class_name ])) {
71
-            $this->classes[ $class_name ] = new ReflectionClass($class_name);
70
+        if ( ! isset($this->classes[$class_name])) {
71
+            $this->classes[$class_name] = new ReflectionClass($class_name);
72 72
         }
73
-        return $this->classes[ $class_name ];
73
+        return $this->classes[$class_name];
74 74
     }
75 75
 
76 76
 
@@ -82,14 +82,14 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function getConstructor($class_name)
84 84
     {
85
-        if (! is_string($class_name)) {
85
+        if ( ! is_string($class_name)) {
86 86
             throw new InvalidDataTypeException($class_name, '$class_name', 'string (fully qualified class name)');
87 87
         }
88
-        if (! isset($this->constructors[ $class_name ])) {
88
+        if ( ! isset($this->constructors[$class_name])) {
89 89
             $reflection_class                  = $this->getReflectionClass($class_name);
90
-            $this->constructors[ $class_name ] = $reflection_class->getConstructor();
90
+            $this->constructors[$class_name] = $reflection_class->getConstructor();
91 91
         }
92
-        return $this->constructors[ $class_name ];
92
+        return $this->constructors[$class_name];
93 93
     }
94 94
 
95 95
 
@@ -113,11 +113,11 @@  discard block
 block discarded – undo
113 113
      */
114 114
     public function getParameters($class_name)
115 115
     {
116
-        if (! isset($this->parameters[ $class_name ])) {
116
+        if ( ! isset($this->parameters[$class_name])) {
117 117
             $constructor                     = $this->getConstructor($class_name);
118
-            $this->parameters[ $class_name ] = $constructor->getParameters();
118
+            $this->parameters[$class_name] = $constructor->getParameters();
119 119
         }
120
-        return $this->parameters[ $class_name ];
120
+        return $this->parameters[$class_name];
121 121
     }
122 122
 
123 123
 
@@ -153,19 +153,19 @@  discard block
 block discarded – undo
153 153
      */
154 154
     public function getParameterClassName(ReflectionParameter $param, $class_name, $index)
155 155
     {
156
-        if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_name'])) {
157
-            return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
156
+        if (isset($this->parameter_classes[$class_name][$index]['param_class_name'])) {
157
+            return $this->parameter_classes[$class_name][$index]['param_class_name'];
158 158
         }
159
-        if (! isset($this->parameter_classes[ $class_name ])) {
160
-            $this->parameter_classes[ $class_name ] = array();
159
+        if ( ! isset($this->parameter_classes[$class_name])) {
160
+            $this->parameter_classes[$class_name] = array();
161 161
         }
162
-        if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
163
-            $this->parameter_classes[ $class_name ][ $index ] = array();
162
+        if ( ! isset($this->parameter_classes[$class_name][$index])) {
163
+            $this->parameter_classes[$class_name][$index] = array();
164 164
         }
165
-        $this->parameter_classes[ $class_name ][ $index ]['param_class_name'] = $param->getClass()
165
+        $this->parameter_classes[$class_name][$index]['param_class_name'] = $param->getClass()
166 166
             ? $param->getClass()->name
167 167
             : null;
168
-        return $this->parameter_classes[ $class_name ][ $index ]['param_class_name'];
168
+        return $this->parameter_classes[$class_name][$index]['param_class_name'];
169 169
     }
170 170
 
171 171
 
@@ -177,19 +177,19 @@  discard block
 block discarded – undo
177 177
      */
178 178
     public function getParameterDefaultValue(ReflectionParameter $param, $class_name, $index)
179 179
     {
180
-        if (isset($this->parameter_classes[ $class_name ][ $index ]['param_class_default'])) {
181
-            return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
180
+        if (isset($this->parameter_classes[$class_name][$index]['param_class_default'])) {
181
+            return $this->parameter_classes[$class_name][$index]['param_class_default'];
182 182
         }
183
-        if (! isset($this->parameter_classes[ $class_name ])) {
184
-            $this->parameter_classes[ $class_name ] = array();
183
+        if ( ! isset($this->parameter_classes[$class_name])) {
184
+            $this->parameter_classes[$class_name] = array();
185 185
         }
186
-        if (! isset($this->parameter_classes[ $class_name ][ $index ])) {
187
-            $this->parameter_classes[ $class_name ][ $index ] = array();
186
+        if ( ! isset($this->parameter_classes[$class_name][$index])) {
187
+            $this->parameter_classes[$class_name][$index] = array();
188 188
         }
189
-        $this->parameter_classes[ $class_name ][ $index ]['param_class_default'] = $param->isDefaultValueAvailable()
189
+        $this->parameter_classes[$class_name][$index]['param_class_default'] = $param->isDefaultValueAvailable()
190 190
             ? $param->getDefaultValue()
191 191
             : null;
192
-        return $this->parameter_classes[ $class_name ][ $index ]['param_class_default'];
192
+        return $this->parameter_classes[$class_name][$index]['param_class_default'];
193 193
     }
194 194
 
195 195
 
@@ -201,11 +201,11 @@  discard block
 block discarded – undo
201 201
      */
202 202
     public function getProperties($class_name)
203 203
     {
204
-        if (! isset($this->properties[ $class_name ])) {
204
+        if ( ! isset($this->properties[$class_name])) {
205 205
             $reflection_class                = $this->getReflectionClass($class_name);
206
-            $this->properties[ $class_name ] = $reflection_class->getProperties();
206
+            $this->properties[$class_name] = $reflection_class->getProperties();
207 207
         }
208
-        return $this->properties[ $class_name ];
208
+        return $this->properties[$class_name];
209 209
     }
210 210
 
211 211
 
@@ -229,11 +229,11 @@  discard block
 block discarded – undo
229 229
      */
230 230
     public function getMethods($class_name)
231 231
     {
232
-        if (! isset($this->methods[ $class_name ])) {
232
+        if ( ! isset($this->methods[$class_name])) {
233 233
             $reflection_class             = $this->getReflectionClass($class_name);
234
-            $this->methods[ $class_name ] = $reflection_class->getMethods();
234
+            $this->methods[$class_name] = $reflection_class->getMethods();
235 235
         }
236
-        return $this->methods[ $class_name ];
236
+        return $this->methods[$class_name];
237 237
     }
238 238
 
239 239
 
Please login to merge, or discard this patch.
core/db_models/EEM_Line_Item.model.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -416,7 +416,7 @@
 block discarded – undo
416 416
      * If $expired is set to true, then only line items for expired sessions will be returned.
417 417
      * If $expired is set to false, then only line items for active sessions will be returned.
418 418
      *
419
-     * @param null $expired
419
+     * @param boolean $expired
420 420
      * @return EE_Base_Class[]|EE_Line_Item[]
421 421
      * @throws EE_Error
422 422
      * @throws InvalidArgumentException
Please login to merge, or discard this patch.
Indentation   +436 added lines, -436 removed lines patch added patch discarded remove patch
@@ -32,443 +32,443 @@
 block discarded – undo
32 32
 class EEM_Line_Item extends EEM_Base
33 33
 {
34 34
 
35
-    /**
36
-     * Tax sub-total is just the total of all the taxes, which should be children
37
-     * of this line item. There should only ever be one tax sub-total, and it should
38
-     * be a direct child of. Its quantity and LIN_unit_price = 1.
39
-     */
40
-    const type_tax_sub_total = 'tax-sub-total';
41
-
42
-    /**
43
-     * Tax line items indicate a tax applied to all the taxable line items.
44
-     * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal
45
-     * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1.
46
-     */
47
-    const type_tax = 'tax';
48
-
49
-    /**
50
-     * Indicating individual items purchased, or discounts or surcharges.
51
-     * The sum of all the regular line items  plus the tax items should equal
52
-     * the grand total.
53
-     * Possible children are sub-line-items and cancellations.
54
-     * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children
55
-     * LIN_totals. Its LIN_percent = 0.
56
-     * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1).
57
-     * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1.
58
-     */
59
-    const type_line_item = 'line-item';
60
-
61
-    /**
62
-     * Line item indicating all the factors that make a single line item.
63
-     * Sub-line items should have NO children line items.
64
-     * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's
65
-     * contribution towards the price of ONE of their parent items, and its LIN_total should be
66
-     *  = LIN_quantity * LIN_unit_price. Its LIN_percent = 0.
67
-     * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should
68
-     * = LIN_percent / 100 * sum of lower-priority sibling line items..
69
-     */
70
-    const type_sub_line_item = 'sub-item';
71
-
72
-    /**
73
-     * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal).
74
-     * Direct children should be event subtotals.
75
-     * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals.
76
-     *
77
-     */
78
-    const type_sub_total = 'sub-total';
79
-
80
-    /**
81
-     * Line item for the grand total of an order. Its direct children
82
-     * should be tax subtotals and (pre-tax) subtotals, and possibly a regular line item
83
-     * indicating a transaction-wide discount/surcharge. Should have a quantity of 1, a LIN_total and LIN_unit_price of
84
-     * the entire order's mount.
85
-     */
86
-    const type_total = 'total';
87
-
88
-    /**
89
-     * When a line item is cancelled, a sub-line-item of type 'cancellation'
90
-     * should be created, indicating the quantity that were cancelled
91
-     * (because a line item could have a quantity of 1, and its cancellation item
92
-     * could be for 3, indicating that originally 4 were purchased, but 3 have been
93
-     * cancelled, and only one remains).
94
-     * When items are refunded, a cancellation line item should be made, which points
95
-     * to teh payment model object which actually refunded the payment.
96
-     * Cancellations should NOT have any children line items; the should NOT affect
97
-     * any calculations, and are only meant as a record that cancellations have occurred.
98
-     * Their LIN_percent should be 0.
99
-     */
100
-    const type_cancellation = 'cancellation';
101
-
102
-    // private instance of the EEM_Line_Item object
103
-    protected static $_instance = null;
104
-
105
-
106
-    /**
107
-     *        private constructor to prevent direct creation
108
-     * @Constructor
109
-     * @access protected
110
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
111
-     * @return \EEM_Line_Item
112
-     */
113
-    protected function __construct($timezone)
114
-    {
115
-        $this->singular_item = __('Line Item', 'event_espresso');
116
-        $this->plural_item = __('Line Items', 'event_espresso');
117
-
118
-        $this->_tables = array(
119
-            'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID')
120
-        );
121
-        $line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event'));
122
-        $this->_fields = array(
123
-            'Line_Item' => array(
124
-                'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")),
125
-                'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), true),
126
-                'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), true, null, 'Transaction'),
127
-                'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), false, ''),
128
-                'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), true),
129
-                'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), false, 0),
130
-                'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), false, 0),
131
-                'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), false, false),
132
-                'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), false, 1),
133
-                'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), false, 0),
134
-                'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), true, 1),
135
-                'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), true, null),
136
-                'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), false, 'line-item', array(
137
-                        self::type_line_item => __("Line Item", "event_espresso"),
138
-                        self::type_sub_line_item => __("Sub-Item", "event_espresso"),
139
-                        self::type_sub_total => __("Subtotal", "event_espresso"),
140
-                        self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"),
141
-                        self::type_tax => __("Tax", "event_espresso"),
142
-                        self::type_total => __("Total", "event_espresso"),
143
-                        self::type_cancellation => __('Cancellation', 'event_espresso')
144
-                    )),
145
-                'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), true, null, $line_items_can_be_for),
146
-                'OBJ_type' => new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), true, null, $line_items_can_be_for),
147
-                'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
148
-            )
149
-        );
150
-        $this->_model_relations = array(
151
-            'Transaction' => new EE_Belongs_To_Relation(),
152
-            'Ticket' => new EE_Belongs_To_Any_Relation(),
153
-            'Price' => new EE_Belongs_To_Any_Relation(),
154
-            'Event' => new EE_Belongs_To_Any_Relation()
155
-        );
156
-        $this->_model_chain_to_wp_user = 'Transaction.Registration.Event';
157
-        $this->_caps_slug = 'transactions';
158
-        parent::__construct($timezone);
159
-    }
160
-
161
-
162
-    /**
163
-     * Gets all the line items for this transaction of the given type
164
-     * @param string $line_item_type like one of EEM_Line_Item::type_*
165
-     * @param EE_Transaction|int $transaction
166
-     * @return EE_Line_Item[]
167
-     */
168
-    public function get_all_of_type_for_transaction($line_item_type, $transaction)
169
-    {
170
-        $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
171
-        return $this->get_all(array(array(
172
-            'LIN_type' => $line_item_type,
173
-            'TXN_ID' => $transaction
174
-        )));
175
-    }
176
-
177
-
178
-    /**
179
-     * Gets all line items unrelated to tickets that are normal line items
180
-     * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category)
181
-     * @param EE_Transaction|int $transaction
182
-     * @return EE_Line_Item[]
183
-     */
184
-    public function get_all_non_ticket_line_items_for_transaction($transaction)
185
-    {
186
-        $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
187
-        return $this->get_all(array(array(
188
-            'LIN_type' => self::type_line_item,
189
-            'TXN_ID' => $transaction,
190
-            'OR' => array(
191
-                'OBJ_type*notticket' => array('!=', 'Ticket'),
192
-                'OBJ_type*null' => array('IS_NULL'))
193
-        )));
194
-    }
195
-
196
-    /**
197
-     * Deletes line items with no transaction who have passed the transaction cutoff time.
198
-     * This needs to be very efficient
199
-     * because if there are spam bots afoot there will be LOTS of line items
200
-     * @return int count of how many deleted
201
-     */
202
-    public function delete_line_items_with_no_transaction()
203
-    {
204
-        /** @type WPDB $wpdb */
205
-        global $wpdb;
206
-        $time_to_leave_alone = apply_filters(
207
-            'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone',
208
-            WEEK_IN_SECONDS
209
-        );
210
-        $query = $wpdb->prepare(
211
-            'DELETE li
35
+	/**
36
+	 * Tax sub-total is just the total of all the taxes, which should be children
37
+	 * of this line item. There should only ever be one tax sub-total, and it should
38
+	 * be a direct child of. Its quantity and LIN_unit_price = 1.
39
+	 */
40
+	const type_tax_sub_total = 'tax-sub-total';
41
+
42
+	/**
43
+	 * Tax line items indicate a tax applied to all the taxable line items.
44
+	 * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal
45
+	 * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1.
46
+	 */
47
+	const type_tax = 'tax';
48
+
49
+	/**
50
+	 * Indicating individual items purchased, or discounts or surcharges.
51
+	 * The sum of all the regular line items  plus the tax items should equal
52
+	 * the grand total.
53
+	 * Possible children are sub-line-items and cancellations.
54
+	 * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children
55
+	 * LIN_totals. Its LIN_percent = 0.
56
+	 * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1).
57
+	 * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1.
58
+	 */
59
+	const type_line_item = 'line-item';
60
+
61
+	/**
62
+	 * Line item indicating all the factors that make a single line item.
63
+	 * Sub-line items should have NO children line items.
64
+	 * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's
65
+	 * contribution towards the price of ONE of their parent items, and its LIN_total should be
66
+	 *  = LIN_quantity * LIN_unit_price. Its LIN_percent = 0.
67
+	 * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should
68
+	 * = LIN_percent / 100 * sum of lower-priority sibling line items..
69
+	 */
70
+	const type_sub_line_item = 'sub-item';
71
+
72
+	/**
73
+	 * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal).
74
+	 * Direct children should be event subtotals.
75
+	 * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals.
76
+	 *
77
+	 */
78
+	const type_sub_total = 'sub-total';
79
+
80
+	/**
81
+	 * Line item for the grand total of an order. Its direct children
82
+	 * should be tax subtotals and (pre-tax) subtotals, and possibly a regular line item
83
+	 * indicating a transaction-wide discount/surcharge. Should have a quantity of 1, a LIN_total and LIN_unit_price of
84
+	 * the entire order's mount.
85
+	 */
86
+	const type_total = 'total';
87
+
88
+	/**
89
+	 * When a line item is cancelled, a sub-line-item of type 'cancellation'
90
+	 * should be created, indicating the quantity that were cancelled
91
+	 * (because a line item could have a quantity of 1, and its cancellation item
92
+	 * could be for 3, indicating that originally 4 were purchased, but 3 have been
93
+	 * cancelled, and only one remains).
94
+	 * When items are refunded, a cancellation line item should be made, which points
95
+	 * to teh payment model object which actually refunded the payment.
96
+	 * Cancellations should NOT have any children line items; the should NOT affect
97
+	 * any calculations, and are only meant as a record that cancellations have occurred.
98
+	 * Their LIN_percent should be 0.
99
+	 */
100
+	const type_cancellation = 'cancellation';
101
+
102
+	// private instance of the EEM_Line_Item object
103
+	protected static $_instance = null;
104
+
105
+
106
+	/**
107
+	 *        private constructor to prevent direct creation
108
+	 * @Constructor
109
+	 * @access protected
110
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
111
+	 * @return \EEM_Line_Item
112
+	 */
113
+	protected function __construct($timezone)
114
+	{
115
+		$this->singular_item = __('Line Item', 'event_espresso');
116
+		$this->plural_item = __('Line Items', 'event_espresso');
117
+
118
+		$this->_tables = array(
119
+			'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID')
120
+		);
121
+		$line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event'));
122
+		$this->_fields = array(
123
+			'Line_Item' => array(
124
+				'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")),
125
+				'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), true),
126
+				'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), true, null, 'Transaction'),
127
+				'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), false, ''),
128
+				'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), true),
129
+				'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), false, 0),
130
+				'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), false, 0),
131
+				'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), false, false),
132
+				'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), false, 1),
133
+				'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), false, 0),
134
+				'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), true, 1),
135
+				'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), true, null),
136
+				'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), false, 'line-item', array(
137
+						self::type_line_item => __("Line Item", "event_espresso"),
138
+						self::type_sub_line_item => __("Sub-Item", "event_espresso"),
139
+						self::type_sub_total => __("Subtotal", "event_espresso"),
140
+						self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"),
141
+						self::type_tax => __("Tax", "event_espresso"),
142
+						self::type_total => __("Total", "event_espresso"),
143
+						self::type_cancellation => __('Cancellation', 'event_espresso')
144
+					)),
145
+				'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), true, null, $line_items_can_be_for),
146
+				'OBJ_type' => new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), true, null, $line_items_can_be_for),
147
+				'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
148
+			)
149
+		);
150
+		$this->_model_relations = array(
151
+			'Transaction' => new EE_Belongs_To_Relation(),
152
+			'Ticket' => new EE_Belongs_To_Any_Relation(),
153
+			'Price' => new EE_Belongs_To_Any_Relation(),
154
+			'Event' => new EE_Belongs_To_Any_Relation()
155
+		);
156
+		$this->_model_chain_to_wp_user = 'Transaction.Registration.Event';
157
+		$this->_caps_slug = 'transactions';
158
+		parent::__construct($timezone);
159
+	}
160
+
161
+
162
+	/**
163
+	 * Gets all the line items for this transaction of the given type
164
+	 * @param string $line_item_type like one of EEM_Line_Item::type_*
165
+	 * @param EE_Transaction|int $transaction
166
+	 * @return EE_Line_Item[]
167
+	 */
168
+	public function get_all_of_type_for_transaction($line_item_type, $transaction)
169
+	{
170
+		$transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
171
+		return $this->get_all(array(array(
172
+			'LIN_type' => $line_item_type,
173
+			'TXN_ID' => $transaction
174
+		)));
175
+	}
176
+
177
+
178
+	/**
179
+	 * Gets all line items unrelated to tickets that are normal line items
180
+	 * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category)
181
+	 * @param EE_Transaction|int $transaction
182
+	 * @return EE_Line_Item[]
183
+	 */
184
+	public function get_all_non_ticket_line_items_for_transaction($transaction)
185
+	{
186
+		$transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
187
+		return $this->get_all(array(array(
188
+			'LIN_type' => self::type_line_item,
189
+			'TXN_ID' => $transaction,
190
+			'OR' => array(
191
+				'OBJ_type*notticket' => array('!=', 'Ticket'),
192
+				'OBJ_type*null' => array('IS_NULL'))
193
+		)));
194
+	}
195
+
196
+	/**
197
+	 * Deletes line items with no transaction who have passed the transaction cutoff time.
198
+	 * This needs to be very efficient
199
+	 * because if there are spam bots afoot there will be LOTS of line items
200
+	 * @return int count of how many deleted
201
+	 */
202
+	public function delete_line_items_with_no_transaction()
203
+	{
204
+		/** @type WPDB $wpdb */
205
+		global $wpdb;
206
+		$time_to_leave_alone = apply_filters(
207
+			'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone',
208
+			WEEK_IN_SECONDS
209
+		);
210
+		$query = $wpdb->prepare(
211
+			'DELETE li
212 212
 				FROM ' . $this->table() . ' li
213 213
 				LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID
214 214
 				WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s',
215
-            // use GMT time because that's what TXN_timestamps are in
216
-            date('Y-m-d H:i:s', time() - $time_to_leave_alone)
217
-        );
218
-        return $wpdb->query($query);
219
-    }
220
-
221
-
222
-    /**
223
-     * get_line_item_for_transaction_object
224
-     * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket
225
-     *
226
-     * @param int $TXN_ID
227
-     * @param \EE_Base_Class $object
228
-     * @return EE_Line_Item[]
229
-     */
230
-    public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object)
231
-    {
232
-        return $this->get_all(array(array(
233
-            'TXN_ID' => $TXN_ID,
234
-            'OBJ_type' => str_replace('EE_', '', get_class($object)),
235
-            'OBJ_ID' => $object->ID()
236
-        )));
237
-    }
238
-
239
-
240
-    /**
241
-     * get_object_line_items_for_transaction
242
-     * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs
243
-     *
244
-     * @param int $TXN_ID
245
-     * @param string $OBJ_type
246
-     * @param array $OBJ_IDs
247
-     * @return EE_Line_Item[]
248
-     */
249
-    public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array())
250
-    {
251
-        $query_params = array(
252
-            'OBJ_type' => $OBJ_type,
253
-            // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query
254
-            'OBJ_ID' => is_array($OBJ_IDs) && !isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs
255
-        );
256
-        if ($TXN_ID) {
257
-            $query_params['TXN_ID'] = $TXN_ID;
258
-        }
259
-        return $this->get_all(array($query_params));
260
-    }
261
-
262
-
263
-    /**
264
-     * get_all_ticket_line_items_for_transaction
265
-     *
266
-     * @param EE_Transaction $transaction
267
-     * @return EE_Line_Item[]
268
-     */
269
-    public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction)
270
-    {
271
-        return $this->get_all(array(
272
-            array(
273
-                'TXN_ID' => $transaction->ID(),
274
-                'OBJ_type' => 'Ticket',
275
-            )
276
-        ));
277
-    }
278
-
279
-
280
-    /**
281
-     * get_ticket_line_item_for_transaction
282
-     *
283
-     * @param int $TXN_ID
284
-     * @param int $TKT_ID
285
-     * @return \EE_Line_Item
286
-     */
287
-    public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID)
288
-    {
289
-        return $this->get_one(array(
290
-            array(
291
-                'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID),
292
-                'OBJ_ID' => $TKT_ID,
293
-                'OBJ_type' => 'Ticket',
294
-            )
295
-        ));
296
-    }
297
-
298
-
299
-    /**
300
-     * get_existing_promotion_line_item
301
-     * searches the cart for existing line items for the specified promotion
302
-     *
303
-     * @since   1.0.0
304
-     *
305
-     * @param EE_Line_Item $parent_line_item
306
-     * @param EE_Promotion $promotion
307
-     * @return EE_Line_Item
308
-     */
309
-    public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion)
310
-    {
311
-        return $this->get_one(array(
312
-            array(
313
-                'TXN_ID' => $parent_line_item->TXN_ID(),
314
-                'LIN_parent' => $parent_line_item->ID(),
315
-                'OBJ_type' => 'Promotion',
316
-                'OBJ_ID' => $promotion->ID()
317
-            )
318
-        ));
319
-    }
320
-
321
-
322
-    /**
323
-     * get_all_promotion_line_items
324
-     * searches the cart for any and all existing promotion line items
325
-     *
326
-     * @since   1.0.0
327
-     *
328
-     * @param EE_Line_Item $parent_line_item
329
-     * @return EE_Line_Item[]
330
-     */
331
-    public function get_all_promotion_line_items(EE_Line_Item $parent_line_item)
332
-    {
333
-        return $this->get_all(array(
334
-            array(
335
-                'TXN_ID' => $parent_line_item->TXN_ID(),
336
-                'LIN_parent' => $parent_line_item->ID(),
337
-                'OBJ_type' => 'Promotion'
338
-            )
339
-        ));
340
-    }
341
-
342
-    /**
343
-     * Gets the registration's corresponding line item.
344
-     * Note: basically does NOT support having multiple line items for a single ticket,
345
-     * which would happen if some of the registrations had a price modifier while others didn't.
346
-     * In order to support that, we'd probably need a LIN_ID on registrations or something.
347
-     * @param EE_Registration $registration
348
-     * @return EE_Line_ITem
349
-     */
350
-    public function get_line_item_for_registration(EE_Registration $registration)
351
-    {
352
-        return $this->get_one($this->line_item_for_registration_query_params($registration));
353
-    }
354
-
355
-    /**
356
-     * Gets the query params used to retrieve a specific line item for the given registration
357
-     * @param EE_Registration $registration
358
-     * @param array $original_query_params any extra query params you'd like to be merged with
359
-     * @return array like EEM_Base::get_all()'s $query_params
360
-     */
361
-    public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array())
362
-    {
363
-        return array_replace_recursive($original_query_params, array(
364
-            array(
365
-                'OBJ_ID' => $registration->ticket_ID(),
366
-                'OBJ_type' => 'Ticket',
367
-                'TXN_ID' => $registration->transaction_ID()
368
-            )
369
-        ));
370
-    }
371
-
372
-
373
-    /**
374
-     * @return EE_Base_Class[]|EE_Line_Item[]
375
-     * @throws InvalidInterfaceException
376
-     * @throws InvalidDataTypeException
377
-     * @throws EE_Error
378
-     * @throws InvalidArgumentException
379
-     */
380
-    public function get_total_line_items_with_no_transaction()
381
-    {
382
-        return $this->get_total_line_items_for_carts();
383
-    }
384
-
385
-
386
-    /**
387
-     * @return EE_Base_Class[]|EE_Line_Item[]
388
-     * @throws InvalidInterfaceException
389
-     * @throws InvalidDataTypeException
390
-     * @throws EE_Error
391
-     * @throws InvalidArgumentException
392
-     */
393
-    public function get_total_line_items_for_active_carts()
394
-    {
395
-        return $this->get_total_line_items_for_carts(false);
396
-    }
397
-
398
-
399
-    /**
400
-     * @return EE_Base_Class[]|EE_Line_Item[]
401
-     * @throws InvalidInterfaceException
402
-     * @throws InvalidDataTypeException
403
-     * @throws EE_Error
404
-     * @throws InvalidArgumentException
405
-     */
406
-    public function get_total_line_items_for_expired_carts()
407
-    {
408
-        return $this->get_total_line_items_for_carts(true);
409
-    }
410
-
411
-
412
-    /**
413
-     * Returns an array of grand total line items where the TXN_ID is 0.
414
-     * If $expired is set to true, then only line items for expired sessions will be returned.
415
-     * If $expired is set to false, then only line items for active sessions will be returned.
416
-     *
417
-     * @param null $expired
418
-     * @return EE_Base_Class[]|EE_Line_Item[]
419
-     * @throws EE_Error
420
-     * @throws InvalidArgumentException
421
-     * @throws InvalidDataTypeException
422
-     * @throws InvalidInterfaceException
423
-     */
424
-    private function get_total_line_items_for_carts($expired = null)
425
-    {
426
-        $where_params = array(
427
-            'TXN_ID' => 0,
428
-            'LIN_type' => 'total',
429
-        );
430
-        if ($expired !== null) {
431
-            /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
432
-            $session_lifespan = LoaderFactory::getLoader()->getShared(
433
-                'EventEspresso\core\domain\values\session\SessionLifespan'
434
-            );
435
-            $where_params['LIN_timestamp'] = array(
436
-                $expired ? '<=' : '>',
437
-                $session_lifespan->expiration(),
438
-            );
439
-        }
440
-        return $this->get_all(array($where_params));
441
-    }
442
-
443
-
444
-    /**
445
-     * Returns an array of ticket total line items where the TXN_ID is 0
446
-     * AND the timestamp is older than the session lifespan.
447
-     *
448
-     * @param int $timestamp
449
-     * @return EE_Base_Class[]|EE_Line_Item[]
450
-     * @throws EE_Error
451
-     * @throws InvalidArgumentException
452
-     * @throws InvalidDataTypeException
453
-     * @throws InvalidInterfaceException
454
-     */
455
-    public function getTicketLineItemsForExpiredCarts($timestamp = 0)
456
-    {
457
-        if (! absint($timestamp)) {
458
-            /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
459
-            $session_lifespan = LoaderFactory::getLoader()->getShared(
460
-                'EventEspresso\core\domain\values\session\SessionLifespan'
461
-            );
462
-            $timestamp = $session_lifespan->expiration();
463
-        }
464
-        return $this->get_all(
465
-            array(
466
-                array(
467
-                    'TXN_ID'        => 0,
468
-                    'OBJ_type'      => 'Ticket',
469
-                    'LIN_timestamp' => array('<=', $timestamp),
470
-                )
471
-            )
472
-        );
473
-    }
215
+			// use GMT time because that's what TXN_timestamps are in
216
+			date('Y-m-d H:i:s', time() - $time_to_leave_alone)
217
+		);
218
+		return $wpdb->query($query);
219
+	}
220
+
221
+
222
+	/**
223
+	 * get_line_item_for_transaction_object
224
+	 * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket
225
+	 *
226
+	 * @param int $TXN_ID
227
+	 * @param \EE_Base_Class $object
228
+	 * @return EE_Line_Item[]
229
+	 */
230
+	public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object)
231
+	{
232
+		return $this->get_all(array(array(
233
+			'TXN_ID' => $TXN_ID,
234
+			'OBJ_type' => str_replace('EE_', '', get_class($object)),
235
+			'OBJ_ID' => $object->ID()
236
+		)));
237
+	}
238
+
239
+
240
+	/**
241
+	 * get_object_line_items_for_transaction
242
+	 * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs
243
+	 *
244
+	 * @param int $TXN_ID
245
+	 * @param string $OBJ_type
246
+	 * @param array $OBJ_IDs
247
+	 * @return EE_Line_Item[]
248
+	 */
249
+	public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array())
250
+	{
251
+		$query_params = array(
252
+			'OBJ_type' => $OBJ_type,
253
+			// if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query
254
+			'OBJ_ID' => is_array($OBJ_IDs) && !isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs
255
+		);
256
+		if ($TXN_ID) {
257
+			$query_params['TXN_ID'] = $TXN_ID;
258
+		}
259
+		return $this->get_all(array($query_params));
260
+	}
261
+
262
+
263
+	/**
264
+	 * get_all_ticket_line_items_for_transaction
265
+	 *
266
+	 * @param EE_Transaction $transaction
267
+	 * @return EE_Line_Item[]
268
+	 */
269
+	public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction)
270
+	{
271
+		return $this->get_all(array(
272
+			array(
273
+				'TXN_ID' => $transaction->ID(),
274
+				'OBJ_type' => 'Ticket',
275
+			)
276
+		));
277
+	}
278
+
279
+
280
+	/**
281
+	 * get_ticket_line_item_for_transaction
282
+	 *
283
+	 * @param int $TXN_ID
284
+	 * @param int $TKT_ID
285
+	 * @return \EE_Line_Item
286
+	 */
287
+	public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID)
288
+	{
289
+		return $this->get_one(array(
290
+			array(
291
+				'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID),
292
+				'OBJ_ID' => $TKT_ID,
293
+				'OBJ_type' => 'Ticket',
294
+			)
295
+		));
296
+	}
297
+
298
+
299
+	/**
300
+	 * get_existing_promotion_line_item
301
+	 * searches the cart for existing line items for the specified promotion
302
+	 *
303
+	 * @since   1.0.0
304
+	 *
305
+	 * @param EE_Line_Item $parent_line_item
306
+	 * @param EE_Promotion $promotion
307
+	 * @return EE_Line_Item
308
+	 */
309
+	public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion)
310
+	{
311
+		return $this->get_one(array(
312
+			array(
313
+				'TXN_ID' => $parent_line_item->TXN_ID(),
314
+				'LIN_parent' => $parent_line_item->ID(),
315
+				'OBJ_type' => 'Promotion',
316
+				'OBJ_ID' => $promotion->ID()
317
+			)
318
+		));
319
+	}
320
+
321
+
322
+	/**
323
+	 * get_all_promotion_line_items
324
+	 * searches the cart for any and all existing promotion line items
325
+	 *
326
+	 * @since   1.0.0
327
+	 *
328
+	 * @param EE_Line_Item $parent_line_item
329
+	 * @return EE_Line_Item[]
330
+	 */
331
+	public function get_all_promotion_line_items(EE_Line_Item $parent_line_item)
332
+	{
333
+		return $this->get_all(array(
334
+			array(
335
+				'TXN_ID' => $parent_line_item->TXN_ID(),
336
+				'LIN_parent' => $parent_line_item->ID(),
337
+				'OBJ_type' => 'Promotion'
338
+			)
339
+		));
340
+	}
341
+
342
+	/**
343
+	 * Gets the registration's corresponding line item.
344
+	 * Note: basically does NOT support having multiple line items for a single ticket,
345
+	 * which would happen if some of the registrations had a price modifier while others didn't.
346
+	 * In order to support that, we'd probably need a LIN_ID on registrations or something.
347
+	 * @param EE_Registration $registration
348
+	 * @return EE_Line_ITem
349
+	 */
350
+	public function get_line_item_for_registration(EE_Registration $registration)
351
+	{
352
+		return $this->get_one($this->line_item_for_registration_query_params($registration));
353
+	}
354
+
355
+	/**
356
+	 * Gets the query params used to retrieve a specific line item for the given registration
357
+	 * @param EE_Registration $registration
358
+	 * @param array $original_query_params any extra query params you'd like to be merged with
359
+	 * @return array like EEM_Base::get_all()'s $query_params
360
+	 */
361
+	public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array())
362
+	{
363
+		return array_replace_recursive($original_query_params, array(
364
+			array(
365
+				'OBJ_ID' => $registration->ticket_ID(),
366
+				'OBJ_type' => 'Ticket',
367
+				'TXN_ID' => $registration->transaction_ID()
368
+			)
369
+		));
370
+	}
371
+
372
+
373
+	/**
374
+	 * @return EE_Base_Class[]|EE_Line_Item[]
375
+	 * @throws InvalidInterfaceException
376
+	 * @throws InvalidDataTypeException
377
+	 * @throws EE_Error
378
+	 * @throws InvalidArgumentException
379
+	 */
380
+	public function get_total_line_items_with_no_transaction()
381
+	{
382
+		return $this->get_total_line_items_for_carts();
383
+	}
384
+
385
+
386
+	/**
387
+	 * @return EE_Base_Class[]|EE_Line_Item[]
388
+	 * @throws InvalidInterfaceException
389
+	 * @throws InvalidDataTypeException
390
+	 * @throws EE_Error
391
+	 * @throws InvalidArgumentException
392
+	 */
393
+	public function get_total_line_items_for_active_carts()
394
+	{
395
+		return $this->get_total_line_items_for_carts(false);
396
+	}
397
+
398
+
399
+	/**
400
+	 * @return EE_Base_Class[]|EE_Line_Item[]
401
+	 * @throws InvalidInterfaceException
402
+	 * @throws InvalidDataTypeException
403
+	 * @throws EE_Error
404
+	 * @throws InvalidArgumentException
405
+	 */
406
+	public function get_total_line_items_for_expired_carts()
407
+	{
408
+		return $this->get_total_line_items_for_carts(true);
409
+	}
410
+
411
+
412
+	/**
413
+	 * Returns an array of grand total line items where the TXN_ID is 0.
414
+	 * If $expired is set to true, then only line items for expired sessions will be returned.
415
+	 * If $expired is set to false, then only line items for active sessions will be returned.
416
+	 *
417
+	 * @param null $expired
418
+	 * @return EE_Base_Class[]|EE_Line_Item[]
419
+	 * @throws EE_Error
420
+	 * @throws InvalidArgumentException
421
+	 * @throws InvalidDataTypeException
422
+	 * @throws InvalidInterfaceException
423
+	 */
424
+	private function get_total_line_items_for_carts($expired = null)
425
+	{
426
+		$where_params = array(
427
+			'TXN_ID' => 0,
428
+			'LIN_type' => 'total',
429
+		);
430
+		if ($expired !== null) {
431
+			/** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
432
+			$session_lifespan = LoaderFactory::getLoader()->getShared(
433
+				'EventEspresso\core\domain\values\session\SessionLifespan'
434
+			);
435
+			$where_params['LIN_timestamp'] = array(
436
+				$expired ? '<=' : '>',
437
+				$session_lifespan->expiration(),
438
+			);
439
+		}
440
+		return $this->get_all(array($where_params));
441
+	}
442
+
443
+
444
+	/**
445
+	 * Returns an array of ticket total line items where the TXN_ID is 0
446
+	 * AND the timestamp is older than the session lifespan.
447
+	 *
448
+	 * @param int $timestamp
449
+	 * @return EE_Base_Class[]|EE_Line_Item[]
450
+	 * @throws EE_Error
451
+	 * @throws InvalidArgumentException
452
+	 * @throws InvalidDataTypeException
453
+	 * @throws InvalidInterfaceException
454
+	 */
455
+	public function getTicketLineItemsForExpiredCarts($timestamp = 0)
456
+	{
457
+		if (! absint($timestamp)) {
458
+			/** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
459
+			$session_lifespan = LoaderFactory::getLoader()->getShared(
460
+				'EventEspresso\core\domain\values\session\SessionLifespan'
461
+			);
462
+			$timestamp = $session_lifespan->expiration();
463
+		}
464
+		return $this->get_all(
465
+			array(
466
+				array(
467
+					'TXN_ID'        => 0,
468
+					'OBJ_type'      => 'Ticket',
469
+					'LIN_timestamp' => array('<=', $timestamp),
470
+				)
471
+			)
472
+		);
473
+	}
474 474
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -209,8 +209,8 @@  discard block
 block discarded – undo
209 209
         );
210 210
         $query = $wpdb->prepare(
211 211
             'DELETE li
212
-				FROM ' . $this->table() . ' li
213
-				LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID
212
+				FROM ' . $this->table().' li
213
+				LEFT JOIN ' . EEM_Transaction::instance()->table().' t ON li.TXN_ID = t.TXN_ID
214 214
 				WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s',
215 215
             // use GMT time because that's what TXN_timestamps are in
216 216
             date('Y-m-d H:i:s', time() - $time_to_leave_alone)
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
         $query_params = array(
252 252
             'OBJ_type' => $OBJ_type,
253 253
             // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query
254
-            'OBJ_ID' => is_array($OBJ_IDs) && !isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs
254
+            'OBJ_ID' => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs
255 255
         );
256 256
         if ($TXN_ID) {
257 257
             $query_params['TXN_ID'] = $TXN_ID;
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
      */
455 455
     public function getTicketLineItemsForExpiredCarts($timestamp = 0)
456 456
     {
457
-        if (! absint($timestamp)) {
457
+        if ( ! absint($timestamp)) {
458 458
             /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
459 459
             $session_lifespan = LoaderFactory::getLoader()->getShared(
460 460
                 'EventEspresso\core\domain\values\session\SessionLifespan'
Please login to merge, or discard this patch.