Completed
Branch decaf-fixes/sanitize-all-reque... (b7fe86)
by
unknown
06:39 queued 04:47
created
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 1 patch
Indentation   +1774 added lines, -1774 removed lines patch added patch discarded remove patch
@@ -19,1778 +19,1778 @@
 block discarded – undo
19 19
 class EED_Single_Page_Checkout extends EED_Module
20 20
 {
21 21
 
22
-    /**
23
-     * $_initialized - has the SPCO controller already been initialized ?
24
-     *
25
-     * @var bool $_initialized
26
-     */
27
-    private static $_initialized = false;
28
-
29
-
30
-    /**
31
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
32
-     *
33
-     * @var bool $_valid_checkout
34
-     */
35
-    private static $_checkout_verified = true;
36
-
37
-    /**
38
-     *    $_reg_steps_array - holds initial array of reg steps
39
-     *
40
-     * @var array $_reg_steps_array
41
-     */
42
-    private static $_reg_steps_array = array();
43
-
44
-    /**
45
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
46
-     *
47
-     * @var EE_Checkout $checkout
48
-     */
49
-    public $checkout;
50
-
51
-    /**
52
-     * @var RequestInterface $request
53
-     */
54
-    protected $request;
55
-
56
-
57
-    /**
58
-     * @return EED_Single_Page_Checkout|EED_Module
59
-     * @throws EE_Error
60
-     * @throws ReflectionException
61
-     */
62
-    public static function instance()
63
-    {
64
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
65
-        return parent::get_instance(__CLASS__);
66
-    }
67
-
68
-
69
-    /**
70
-     * @return EE_CART
71
-     */
72
-    public function cart()
73
-    {
74
-        return $this->checkout->cart;
75
-    }
76
-
77
-
78
-    /**
79
-     * @return RequestInterface
80
-     * @since   $VID:$
81
-     */
82
-    public static function getRequest()
83
-    {
84
-        return LoaderFactory::getLoader()->getShared(RequestInterface::class);
85
-    }
86
-
87
-
88
-    /**
89
-     * @return EE_Transaction
90
-     */
91
-    public function transaction()
92
-    {
93
-        return $this->checkout->transaction;
94
-    }
95
-
96
-
97
-    /**
98
-     *    set_hooks - for hooking into EE Core, other modules, etc
99
-     *
100
-     * @return    void
101
-     * @throws EE_Error
102
-     */
103
-    public static function set_hooks()
104
-    {
105
-        EED_Single_Page_Checkout::set_definitions();
106
-    }
107
-
108
-
109
-    /**
110
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
111
-     *
112
-     * @return    void
113
-     * @throws EE_Error
114
-     */
115
-    public static function set_hooks_admin()
116
-    {
117
-        EED_Single_Page_Checkout::set_definitions();
118
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
119
-            return;
120
-        }
121
-        // going to start an output buffer in case anything gets accidentally output
122
-        // that might disrupt our JSON response
123
-        ob_start();
124
-        EED_Single_Page_Checkout::load_reg_steps();
125
-        // set ajax hooks
126
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
127
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
128
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
129
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
130
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
131
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
132
-    }
133
-
134
-
135
-    /**
136
-     *    process ajax request
137
-     *
138
-     * @param string $ajax_action
139
-     * @throws EE_Error
140
-     * @throws ReflectionException
141
-     */
142
-    public static function process_ajax_request($ajax_action)
143
-    {
144
-        $request = EED_Single_Page_Checkout::getRequest();
145
-        $request->setRequestParam('action', $ajax_action);
146
-        EED_Single_Page_Checkout::instance()->_initialize();
147
-    }
148
-
149
-
150
-    /**
151
-     * ajax display registration step
152
-     *
153
-     * @throws EE_Error
154
-     * @throws ReflectionException
155
-     */
156
-    public static function display_reg_step()
157
-    {
158
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
159
-    }
160
-
161
-
162
-    /**
163
-     * ajax process registration step
164
-     *
165
-     * @throws EE_Error
166
-     * @throws ReflectionException
167
-     */
168
-    public static function process_reg_step()
169
-    {
170
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
171
-    }
172
-
173
-
174
-    /**
175
-     * ajax process registration step
176
-     *
177
-     * @throws EE_Error
178
-     * @throws ReflectionException
179
-     */
180
-    public static function update_reg_step()
181
-    {
182
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
183
-    }
184
-
185
-
186
-    /**
187
-     * update_checkout
188
-     *
189
-     * @return void
190
-     * @throws ReflectionException
191
-     * @throws EE_Error
192
-     */
193
-    public static function update_checkout()
194
-    {
195
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
196
-    }
197
-
198
-
199
-    /**
200
-     * @return void
201
-     * @deprecated $VID:$
202
-     */
203
-    public static function load_request_handler()
204
-    {
205
-    }
206
-
207
-
208
-    /**
209
-     *    set_definitions
210
-     *
211
-     * @return    void
212
-     * @throws EE_Error
213
-     */
214
-    public static function set_definitions()
215
-    {
216
-        if (defined('SPCO_BASE_PATH')) {
217
-            return;
218
-        }
219
-        define(
220
-            'SPCO_BASE_PATH',
221
-            rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
222
-        );
223
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css/');
224
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img/');
225
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js/');
226
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc/');
227
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps/');
228
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates/');
229
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
230
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
231
-        );
232
-    }
233
-
234
-
235
-    /**
236
-     * load_reg_steps
237
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
238
-     *
239
-     * @throws EE_Error
240
-     */
241
-    public static function load_reg_steps()
242
-    {
243
-        static $reg_steps_loaded = false;
244
-        if ($reg_steps_loaded) {
245
-            return;
246
-        }
247
-        // filter list of reg_steps
248
-        $reg_steps_to_load = (array) apply_filters(
249
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
250
-            EED_Single_Page_Checkout::get_reg_steps()
251
-        );
252
-        // sort by key (order)
253
-        ksort($reg_steps_to_load);
254
-        // loop through folders
255
-        foreach ($reg_steps_to_load as $order => $reg_step) {
256
-            // we need a
257
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
258
-                // copy over to the reg_steps_array
259
-                EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step;
260
-                // register custom key route for each reg step
261
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
262
-                EE_Config::register_route(
263
-                    $reg_step['slug'],
264
-                    'EED_Single_Page_Checkout',
265
-                    'run',
266
-                    'step'
267
-                );
268
-                // add AJAX or other hooks
269
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
270
-                    // setup autoloaders if necessary
271
-                    if (! class_exists($reg_step['class_name'])) {
272
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
273
-                            $reg_step['file_path'],
274
-                            true
275
-                        );
276
-                    }
277
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
278
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
279
-                    }
280
-                }
281
-            }
282
-        }
283
-        $reg_steps_loaded = true;
284
-    }
285
-
286
-
287
-    /**
288
-     *    get_reg_steps
289
-     *
290
-     * @return    array
291
-     */
292
-    public static function get_reg_steps()
293
-    {
294
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
295
-        if (empty($reg_steps)) {
296
-            $reg_steps = array(
297
-                10  => array(
298
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
299
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
300
-                    'slug'       => 'attendee_information',
301
-                    'has_hooks'  => false,
302
-                ),
303
-                30  => array(
304
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
305
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
306
-                    'slug'       => 'payment_options',
307
-                    'has_hooks'  => true,
308
-                ),
309
-                999 => array(
310
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
311
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
312
-                    'slug'       => 'finalize_registration',
313
-                    'has_hooks'  => false,
314
-                ),
315
-            );
316
-        }
317
-        return $reg_steps;
318
-    }
319
-
320
-
321
-    /**
322
-     *    registration_checkout_for_admin
323
-     *
324
-     * @return    string
325
-     * @throws EE_Error
326
-     * @throws ReflectionException
327
-     */
328
-    public static function registration_checkout_for_admin()
329
-    {
330
-        $request = EED_Single_Page_Checkout::getRequest();
331
-        $request->setRequestParam('step', 'attendee_information');
332
-        $request->setRequestParam('action', 'display_spco_reg_step');
333
-        $request->setRequestParam('process_form_submission', false);
334
-        EED_Single_Page_Checkout::instance()->_initialize();
335
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
336
-        return EED_Single_Page_Checkout::getResponse()->getOutput();
337
-    }
338
-
339
-
340
-    /**
341
-     * process_registration_from_admin
342
-     *
343
-     * @return EE_Transaction
344
-     * @throws EE_Error
345
-     * @throws ReflectionException
346
-     */
347
-    public static function process_registration_from_admin()
348
-    {
349
-        $request = EED_Single_Page_Checkout::getRequest();
350
-        $request->setRequestParam('step', 'attendee_information');
351
-        $request->setRequestParam('action', 'process_reg_step');
352
-        $request->setRequestParam('process_form_submission', true);
353
-        EED_Single_Page_Checkout::instance()->_initialize();
354
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
355
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
356
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
357
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
358
-                if ($final_reg_step->process_reg_step()) {
359
-                    $final_reg_step->set_completed();
360
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
361
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
362
-                }
363
-            }
364
-        }
365
-        return null;
366
-    }
367
-
368
-
369
-    /**
370
-     *    run
371
-     *
372
-     * @param WP_Query $WP
373
-     * @return    void
374
-     */
375
-    public function run($WP)
376
-    {
377
-        if ($WP instanceof WP_Query
378
-            && $WP->is_main_query()
379
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
380
-            && $this->_is_reg_checkout()
381
-        ) {
382
-            $this->_initialize();
383
-        }
384
-    }
385
-
386
-
387
-    /**
388
-     * determines whether current url matches reg page url
389
-     *
390
-     * @return bool
391
-     */
392
-    protected function _is_reg_checkout()
393
-    {
394
-        // get current permalink for reg page without any extra query args
395
-        $reg_page_url = get_permalink(EE_Config::instance()->core->reg_page_id);
396
-        // get request URI for current request, but without the scheme or host
397
-        $current_request_uri = EEH_URL::filter_input_server_url();
398
-        $current_request_uri = html_entity_decode($current_request_uri);
399
-        // get array of query args from the current request URI
400
-        $query_args = EEH_URL::get_query_string($current_request_uri);
401
-        // grab page id if it is set
402
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
403
-        // and remove the page id from the query args (we will re-add it later)
404
-        unset($query_args['page_id']);
405
-        // now strip all query args from current request URI
406
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
407
-        // and re-add the page id if it was set
408
-        if ($page_id) {
409
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
410
-        }
411
-        // remove slashes and ?
412
-        $current_request_uri = trim($current_request_uri, '?/');
413
-        // is current request URI part of the known full reg page URL ?
414
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
415
-    }
416
-
417
-
418
-    /**
419
-     * @param WP_Query $wp_query
420
-     * @return    void
421
-     * @throws EE_Error
422
-     * @throws ReflectionException
423
-     */
424
-    public static function init($wp_query)
425
-    {
426
-        EED_Single_Page_Checkout::instance()->run($wp_query);
427
-    }
428
-
429
-
430
-    /**
431
-     *    _initialize - initial module setup
432
-     *
433
-     * @return    void
434
-     */
435
-    private function _initialize()
436
-    {
437
-        // ensure SPCO doesn't run twice
438
-        if (EED_Single_Page_Checkout::$_initialized) {
439
-            return;
440
-        }
441
-        try {
442
-            $this->request = EED_Single_Page_Checkout::getRequest();
443
-            EED_Single_Page_Checkout::load_reg_steps();
444
-            $this->_verify_session();
445
-            // setup the EE_Checkout object
446
-            $this->checkout = $this->_initialize_checkout();
447
-            // filter checkout
448
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
449
-            // get the $_GET
450
-            $this->_get_request_vars();
451
-            if ($this->_block_bots()) {
452
-                return;
453
-            }
454
-            // filter continue_reg
455
-            $this->checkout->continue_reg = apply_filters(
456
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
457
-                true,
458
-                $this->checkout
459
-            );
460
-            // load the reg steps array
461
-            if (! $this->_load_and_instantiate_reg_steps()) {
462
-                EED_Single_Page_Checkout::$_initialized = true;
463
-                return;
464
-            }
465
-            // set the current step
466
-            $this->checkout->set_current_step($this->checkout->step);
467
-            // and the next step
468
-            $this->checkout->set_next_step();
469
-            // verify that everything has been setup correctly
470
-            if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
471
-                EED_Single_Page_Checkout::$_initialized = true;
472
-                return;
473
-            }
474
-            // lock the transaction
475
-            $this->checkout->transaction->lock();
476
-            // make sure all of our cached objects are added to their respective model entity mappers
477
-            $this->checkout->refresh_all_entities();
478
-            // set amount owing
479
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
480
-            // initialize each reg step, which gives them the chance to potentially alter the process
481
-            $this->_initialize_reg_steps();
482
-            // DEBUG LOG
483
-            // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
484
-            // get reg form
485
-            if (! $this->_check_form_submission()) {
486
-                EED_Single_Page_Checkout::$_initialized = true;
487
-                return;
488
-            }
489
-            // checkout the action!!!
490
-            $this->_process_form_action();
491
-            // add some style and make it dance
492
-            $this->add_styles_and_scripts($this);
493
-            // kk... SPCO has successfully run
494
-            EED_Single_Page_Checkout::$_initialized = true;
495
-            // set no cache headers and constants
496
-            EE_System::do_not_cache();
497
-            // add anchor
498
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
499
-            // remove transaction lock
500
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
501
-        } catch (Exception $e) {
502
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
503
-        }
504
-    }
505
-
506
-
507
-    /**
508
-     *    _verify_session
509
-     * checks that the session is valid and not expired
510
-     *
511
-     * @throws EE_Error
512
-     * @throws ReflectionException
513
-     */
514
-    private function _verify_session()
515
-    {
516
-        if (! EE_Registry::instance()->SSN instanceof EE_Session) {
517
-            throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso'));
518
-        }
519
-        $clear_session_requested = $this->request->getRequestParam('clear_session', false, 'bool');
520
-        // is session still valid ?
521
-        if (
522
-            $clear_session_requested
523
-            || (
524
-                EE_Registry::instance()->SSN->expired()
525
-                && $this->request->getRequestParam('e_reg_url_link') === ''
526
-            )
527
-        ) {
528
-            $this->checkout = new EE_Checkout();
529
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
530
-            // EE_Registry::instance()->SSN->reset_cart();
531
-            // EE_Registry::instance()->SSN->reset_checkout();
532
-            // EE_Registry::instance()->SSN->reset_transaction();
533
-            if (! $clear_session_requested) {
534
-                EE_Error::add_attention(
535
-                    EE_Registry::$i18n_js_strings['registration_expiration_notice'],
536
-                    __FILE__,
537
-                    __FUNCTION__,
538
-                    __LINE__
539
-                );
540
-            }
541
-            // EE_Registry::instance()->SSN->reset_expired();
542
-        }
543
-    }
544
-
545
-
546
-    /**
547
-     *    _initialize_checkout
548
-     * loads and instantiates EE_Checkout
549
-     *
550
-     * @return EE_Checkout
551
-     * @throws EE_Error
552
-     * @throws ReflectionException
553
-     */
554
-    private function _initialize_checkout()
555
-    {
556
-        // look in session for existing checkout
557
-        /** @type EE_Checkout $checkout */
558
-        $checkout = EE_Registry::instance()->SSN->checkout();
559
-        // verify
560
-        if (! $checkout instanceof EE_Checkout) {
561
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
562
-            $checkout = EE_Registry::instance()->load_file(
563
-                SPCO_INC_PATH,
564
-                'EE_Checkout',
565
-                'class',
566
-                array(),
567
-                false
568
-            );
569
-        } else {
570
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
571
-                $this->unlock_transaction();
572
-                wp_safe_redirect($checkout->redirect_url);
573
-                exit();
574
-            }
575
-        }
576
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
577
-        // verify again
578
-        if (! $checkout instanceof EE_Checkout) {
579
-            throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso'));
580
-        }
581
-        // reset anything that needs a clean slate for each request
582
-        $checkout->reset_for_current_request();
583
-        return $checkout;
584
-    }
585
-
586
-
587
-    /**
588
-     *    _get_request_vars
589
-     *
590
-     * @return    void
591
-     */
592
-    private function _get_request_vars()
593
-    {
594
-        // make sure this request is marked as belonging to EE
595
-        /** @var CurrentPage $current_page */
596
-        $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
597
-        $current_page->setEspressoPage(true);
598
-        // which step is being requested ?
599
-        $this->checkout->step = $this->request->getRequestParam('step', $this->_get_first_step());
600
-        // which step is being edited ?
601
-        $this->checkout->edit_step = $this->request->getRequestParam('edit_step');
602
-        // and what we're doing on the current step
603
-        $this->checkout->action = $this->request->getRequestParam('action', 'display_spco_reg_step');
604
-        // timestamp
605
-        $this->checkout->uts = $this->request->getRequestParam('uts', 0, 'int');
606
-        // returning to edit ?
607
-        $this->checkout->reg_url_link = $this->request->getRequestParam('e_reg_url_link');
608
-        // add reg url link to registration query params
609
-        if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
610
-            $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
611
-        }
612
-        // or some other kind of revisit ?
613
-        $this->checkout->revisit = $this->request->getRequestParam('revisit', false, 'bool');
614
-        // and whether or not to generate a reg form for this request
615
-        $this->checkout->generate_reg_form = $this->request->getRequestParam('generate_reg_form', true, 'bool');
616
-        // and whether or not to process a reg form submission for this request
617
-        $this->checkout->process_form_submission = $this->request->getRequestParam(
618
-            'process_form_submission',
619
-            $this->checkout->action === 'process_reg_step',
620
-            'bool'
621
-        );
622
-        $this->checkout->process_form_submission = filter_var(
623
-            $this->checkout->action !== 'display_spco_reg_step'
624
-                ? $this->checkout->process_form_submission
625
-                : false,
626
-            FILTER_VALIDATE_BOOLEAN
627
-        );
628
-        // $this->_display_request_vars();
629
-    }
630
-
631
-
632
-    /**
633
-     *  _display_request_vars
634
-     *
635
-     * @return    void
636
-     */
637
-    protected function _display_request_vars()
638
-    {
639
-        if (! WP_DEBUG) {
640
-            return;
641
-        }
642
-        EEH_Debug_Tools::printr($this->request->requestParams(), 'requestParams', __FILE__, __LINE__);
643
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
644
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
645
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
646
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
647
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
648
-        EEH_Debug_Tools::printr(
649
-            $this->checkout->generate_reg_form,
650
-            '$this->checkout->generate_reg_form',
651
-            __FILE__,
652
-            __LINE__
653
-        );
654
-        EEH_Debug_Tools::printr(
655
-            $this->checkout->process_form_submission,
656
-            '$this->checkout->process_form_submission',
657
-            __FILE__,
658
-            __LINE__
659
-        );
660
-    }
661
-
662
-
663
-    /**
664
-     * _block_bots
665
-     * checks that the incoming request has either of the following set:
666
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
667
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
668
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
669
-     * then where you coming from man?
670
-     *
671
-     * @return boolean
672
-     */
673
-    private function _block_bots()
674
-    {
675
-        $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
676
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
677
-            return true;
678
-        }
679
-        return false;
680
-    }
681
-
682
-
683
-    /**
684
-     *    _get_first_step
685
-     *  gets slug for first step in $_reg_steps_array
686
-     *
687
-     * @return    string
688
-     */
689
-    private function _get_first_step()
690
-    {
691
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
692
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
693
-    }
694
-
695
-
696
-    /**
697
-     * instantiates each reg step based on the loaded reg_steps array
698
-     *
699
-     * @return    bool
700
-     * @throws EE_Error
701
-     * @throws InvalidArgumentException
702
-     * @throws InvalidDataTypeException
703
-     * @throws InvalidInterfaceException
704
-     * @throws ReflectionException
705
-     */
706
-    private function _load_and_instantiate_reg_steps()
707
-    {
708
-        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
709
-        // have reg_steps already been instantiated ?
710
-        if (empty($this->checkout->reg_steps)
711
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
712
-        ) {
713
-            // if not, then loop through raw reg steps array
714
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
715
-                if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
716
-                    return false;
717
-                }
718
-            }
719
-            if (isset($this->checkout->reg_steps['registration_confirmation'])) {
720
-                // skip the registration_confirmation page ?
721
-                if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
722
-                    // just remove it from the reg steps array
723
-                    $this->checkout->remove_reg_step('registration_confirmation', false);
724
-                } elseif (EE_Registry::instance()->CFG->registration->reg_confirmation_last
725
-                ) {
726
-                    // set the order to something big like 100
727
-                    $this->checkout->set_reg_step_order('registration_confirmation');
728
-                }
729
-            }
730
-            // filter the array for good luck
731
-            $this->checkout->reg_steps = apply_filters(
732
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
733
-                $this->checkout->reg_steps
734
-            );
735
-            // finally re-sort based on the reg step class order properties
736
-            $this->checkout->sort_reg_steps();
737
-        } else {
738
-            foreach ($this->checkout->reg_steps as $reg_step) {
739
-                // set all current step stati to FALSE
740
-                $reg_step->set_is_current_step(false);
741
-            }
742
-        }
743
-        if (empty($this->checkout->reg_steps)) {
744
-            EE_Error::add_error(
745
-                esc_html__('No Reg Steps were loaded..', 'event_espresso'),
746
-                __FILE__,
747
-                __FUNCTION__,
748
-                __LINE__
749
-            );
750
-            return false;
751
-        }
752
-        // make reg step details available to JS
753
-        $this->checkout->set_reg_step_JSON_info();
754
-        return true;
755
-    }
756
-
757
-
758
-    /**
759
-     *     _load_and_instantiate_reg_step
760
-     *
761
-     * @param array $reg_step
762
-     * @param int   $order
763
-     * @return bool
764
-     * @throws EE_Error
765
-     * @throws ReflectionException
766
-     */
767
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
768
-    {
769
-        // we need a file_path, class_name, and slug to add a reg step
770
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
771
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
772
-            if ($this->checkout->reg_url_link
773
-                && $this->checkout->step !== $reg_step['slug']
774
-                && $reg_step['slug'] !== 'finalize_registration'
775
-                // normally at this point we would NOT load the reg step, but this filter can change that
776
-                && apply_filters(
777
-                    'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
778
-                    true,
779
-                    $reg_step,
780
-                    $this->checkout
781
-                )
782
-            ) {
783
-                return true;
784
-            }
785
-            // instantiate step class using file path and class name
786
-            $reg_step_obj = EE_Registry::instance()->load_file(
787
-                $reg_step['file_path'],
788
-                $reg_step['class_name'],
789
-                'class',
790
-                $this->checkout,
791
-                false
792
-            );
793
-            // did we gets the goods ?
794
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
795
-                // set reg step order based on config
796
-                $reg_step_obj->set_order($order);
797
-                // add instantiated reg step object to the master reg steps array
798
-                $this->checkout->add_reg_step($reg_step_obj);
799
-            } else {
800
-                EE_Error::add_error(
801
-                    esc_html__('The current step could not be set.', 'event_espresso'),
802
-                    __FILE__,
803
-                    __FUNCTION__,
804
-                    __LINE__
805
-                );
806
-                return false;
807
-            }
808
-        } else {
809
-            if (WP_DEBUG) {
810
-                EE_Error::add_error(
811
-                    sprintf(
812
-                        esc_html__(
813
-                            'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
814
-                            'event_espresso'
815
-                        ),
816
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
817
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
818
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
819
-                        '<ul>',
820
-                        '<li>',
821
-                        '</li>',
822
-                        '</ul>'
823
-                    ),
824
-                    __FILE__,
825
-                    __FUNCTION__,
826
-                    __LINE__
827
-                );
828
-            }
829
-            return false;
830
-        }
831
-        return true;
832
-    }
833
-
834
-
835
-    /**
836
-     * _verify_transaction_and_get_registrations
837
-     *
838
-     * @return bool
839
-     * @throws EE_Error
840
-     * @throws ReflectionException
841
-     */
842
-    private function _verify_transaction_and_get_registrations()
843
-    {
844
-        // was there already a valid transaction in the checkout from the session ?
845
-        if (! $this->checkout->transaction instanceof EE_Transaction) {
846
-            // get transaction from db or session
847
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
848
-                ? $this->_get_transaction_and_cart_for_previous_visit()
849
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
850
-            if (! $this->checkout->transaction instanceof EE_Transaction) {
851
-                EE_Error::add_error(
852
-                    esc_html__(
853
-                        'Your Registration and Transaction information could not be retrieved from the db.',
854
-                        'event_espresso'
855
-                    ),
856
-                    __FILE__,
857
-                    __FUNCTION__,
858
-                    __LINE__
859
-                );
860
-                $this->checkout->transaction = EE_Transaction::new_instance();
861
-                // add some style and make it dance
862
-                $this->add_styles_and_scripts($this);
863
-                EED_Single_Page_Checkout::$_initialized = true;
864
-                return false;
865
-            }
866
-            // and the registrations for the transaction
867
-            $this->_get_registrations($this->checkout->transaction);
868
-        }
869
-        return true;
870
-    }
871
-
872
-
873
-    /**
874
-     * _get_transaction_and_cart_for_previous_visit
875
-     *
876
-     * @return EE_Transaction|null
877
-     * @throws EE_Error
878
-     * @throws ReflectionException
879
-     */
880
-    private function _get_transaction_and_cart_for_previous_visit()
881
-    {
882
-        /** @var $TXN_model EEM_Transaction */
883
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
884
-        // because the reg_url_link is present in the request,
885
-        // this is a return visit to SPCO, so we'll get the transaction data from the db
886
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
887
-        // verify transaction
888
-        if ($transaction instanceof EE_Transaction) {
889
-            // and get the cart that was used for that transaction
890
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
891
-            return $transaction;
892
-        }
893
-        EE_Error::add_error(
894
-            esc_html__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
895
-            __FILE__,
896
-            __FUNCTION__,
897
-            __LINE__
898
-        );
899
-        return null;
900
-    }
901
-
902
-
903
-    /**
904
-     * _get_cart_for_transaction
905
-     *
906
-     * @param EE_Transaction $transaction
907
-     * @return EE_Cart
908
-     */
909
-    private function _get_cart_for_transaction($transaction)
910
-    {
911
-        return $this->checkout->get_cart_for_transaction($transaction);
912
-    }
913
-
914
-
915
-    /**
916
-     * get_cart_for_transaction
917
-     *
918
-     * @param EE_Transaction $transaction
919
-     * @return EE_Cart
920
-     */
921
-    public function get_cart_for_transaction(EE_Transaction $transaction)
922
-    {
923
-        return $this->checkout->get_cart_for_transaction($transaction);
924
-    }
925
-
926
-
927
-    /**
928
-     * _get_transaction_and_cart_for_current_session
929
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
930
-     *
931
-     * @return EE_Transaction
932
-     * @throws EE_Error
933
-     * @throws ReflectionException
934
-     */
935
-    private function _get_cart_for_current_session_and_setup_new_transaction()
936
-    {
937
-        //  if there's no transaction, then this is the FIRST visit to SPCO
938
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
939
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
940
-        // and then create a new transaction
941
-        $transaction = $this->_initialize_transaction();
942
-        // verify transaction
943
-        if ($transaction instanceof EE_Transaction) {
944
-            // save it so that we have an ID for other objects to use
945
-            $transaction->save();
946
-            // and save TXN data to the cart
947
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
948
-        } else {
949
-            EE_Error::add_error(
950
-                esc_html__('A Valid Transaction could not be initialized.', 'event_espresso'),
951
-                __FILE__,
952
-                __FUNCTION__,
953
-                __LINE__
954
-            );
955
-        }
956
-        return $transaction;
957
-    }
958
-
959
-
960
-    /**
961
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
962
-     *
963
-     * @return EE_Transaction|null
964
-     */
965
-    private function _initialize_transaction()
966
-    {
967
-        try {
968
-            // ensure cart totals have been calculated
969
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
970
-            // grab the cart grand total
971
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
972
-            // create new TXN
973
-            $transaction = EE_Transaction::new_instance(
974
-                array(
975
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
976
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
977
-                    'TXN_paid'      => 0,
978
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
979
-                )
980
-            );
981
-            // save it so that we have an ID for other objects to use
982
-            $transaction->save();
983
-            // set cron job for following up on TXNs after their session has expired
984
-            EE_Cron_Tasks::schedule_expired_transaction_check(
985
-                EE_Registry::instance()->SSN->expiration() + 1,
986
-                $transaction->ID()
987
-            );
988
-            return $transaction;
989
-        } catch (Exception $e) {
990
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
991
-        }
992
-        return null;
993
-    }
994
-
995
-
996
-    /**
997
-     * _get_registrations
998
-     *
999
-     * @param EE_Transaction $transaction
1000
-     * @return void
1001
-     * @throws EE_Error
1002
-     * @throws ReflectionException
1003
-     */
1004
-    private function _get_registrations(EE_Transaction $transaction)
1005
-    {
1006
-        // first step: grab the registrants  { : o
1007
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params);
1008
-        $this->checkout->total_ticket_count = count($registrations);
1009
-        // verify registrations have been set
1010
-        if (empty($registrations)) {
1011
-            // if no cached registrations, then check the db
1012
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params);
1013
-            // still nothing ? well as long as this isn't a revisit
1014
-            if (empty($registrations) && ! $this->checkout->revisit) {
1015
-                // generate new registrations from scratch
1016
-                $registrations = $this->_initialize_registrations($transaction);
1017
-            }
1018
-        }
1019
-        // sort by their original registration order
1020
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1021
-        // then loop thru the array
1022
-        foreach ($registrations as $registration) {
1023
-            // verify each registration
1024
-            if ($registration instanceof EE_Registration) {
1025
-                // we display all attendee info for the primary registrant
1026
-                if ($this->checkout->reg_url_link === $registration->reg_url_link()
1027
-                    && $registration->is_primary_registrant()
1028
-                ) {
1029
-                    $this->checkout->primary_revisit = true;
1030
-                    break;
1031
-                }
1032
-                if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1033
-                    // but hide info if it doesn't belong to you
1034
-                    $transaction->clear_cache('Registration', $registration->ID());
1035
-                    $this->checkout->total_ticket_count--;
1036
-                }
1037
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1038
-            }
1039
-        }
1040
-    }
1041
-
1042
-
1043
-    /**
1044
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1045
-     *
1046
-     * @param EE_Transaction $transaction
1047
-     * @return    array
1048
-     * @throws EE_Error
1049
-     * @throws ReflectionException
1050
-     */
1051
-    private function _initialize_registrations(EE_Transaction $transaction)
1052
-    {
1053
-        $att_nmbr = 0;
1054
-        $registrations = array();
1055
-        if ($transaction instanceof EE_Transaction) {
1056
-            /** @type EE_Registration_Processor $registration_processor */
1057
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1058
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1059
-            // now let's add the cart items to the $transaction
1060
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1061
-                // do the following for each ticket of this type they selected
1062
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1063
-                    $att_nmbr++;
1064
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1065
-                    $CreateRegistrationCommand = EE_Registry::instance()->create(
1066
-                        'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1067
-                        array(
1068
-                            $transaction,
1069
-                            $line_item,
1070
-                            $att_nmbr,
1071
-                            $this->checkout->total_ticket_count,
1072
-                        )
1073
-                    );
1074
-                    // override capabilities for frontend registrations
1075
-                    if (! is_admin()) {
1076
-                        $CreateRegistrationCommand->setCapCheck(
1077
-                            new PublicCapabilities('', 'create_new_registration')
1078
-                        );
1079
-                    }
1080
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1081
-                    if (! $registration instanceof EE_Registration) {
1082
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1083
-                    }
1084
-                    $registrations[ $registration->ID() ] = $registration;
1085
-                }
1086
-            }
1087
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1088
-        }
1089
-        return $registrations;
1090
-    }
1091
-
1092
-
1093
-    /**
1094
-     * sorts registrations by REG_count
1095
-     *
1096
-     * @param EE_Registration $reg_A
1097
-     * @param EE_Registration $reg_B
1098
-     * @return int
1099
-     */
1100
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1101
-    {
1102
-        // this shouldn't ever happen within the same TXN, but oh well
1103
-        if ($reg_A->count() === $reg_B->count()) {
1104
-            return 0;
1105
-        }
1106
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1107
-    }
1108
-
1109
-
1110
-    /**
1111
-     *    _final_verifications
1112
-     * just makes sure that everything is set up correctly before proceeding
1113
-     *
1114
-     * @return    bool
1115
-     * @throws EE_Error
1116
-     * @throws ReflectionException
1117
-     */
1118
-    private function _final_verifications()
1119
-    {
1120
-        // filter checkout
1121
-        $this->checkout = apply_filters(
1122
-            'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1123
-            $this->checkout
1124
-        );
1125
-        // verify that current step is still set correctly
1126
-        if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1127
-            EE_Error::add_error(
1128
-                esc_html__(
1129
-                    'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.',
1130
-                    'event_espresso'
1131
-                ),
1132
-                __FILE__,
1133
-                __FUNCTION__,
1134
-                __LINE__
1135
-            );
1136
-            return false;
1137
-        }
1138
-        // if returning to SPCO, then verify that primary registrant is set
1139
-        if (! empty($this->checkout->reg_url_link)) {
1140
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1141
-            if (! $valid_registrant instanceof EE_Registration) {
1142
-                EE_Error::add_error(
1143
-                    esc_html__(
1144
-                        'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.',
1145
-                        'event_espresso'
1146
-                    ),
1147
-                    __FILE__,
1148
-                    __FUNCTION__,
1149
-                    __LINE__
1150
-                );
1151
-                return false;
1152
-            }
1153
-            $valid_registrant = null;
1154
-            foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1155
-                if ($registration instanceof EE_Registration
1156
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1157
-                ) {
1158
-                    $valid_registrant = $registration;
1159
-                }
1160
-            }
1161
-            if (! $valid_registrant instanceof EE_Registration) {
1162
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1163
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1164
-                    // clear the session, mark the checkout as unverified, and try again
1165
-                    EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1166
-                    EED_Single_Page_Checkout::$_initialized = false;
1167
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1168
-                    $this->_initialize();
1169
-                    EE_Error::reset_notices();
1170
-                    return false;
1171
-                }
1172
-                EE_Error::add_error(
1173
-                    esc_html__(
1174
-                        'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1175
-                        'event_espresso'
1176
-                    ),
1177
-                    __FILE__,
1178
-                    __FUNCTION__,
1179
-                    __LINE__
1180
-                );
1181
-                return false;
1182
-            }
1183
-        }
1184
-        // now that things have been kinda sufficiently verified,
1185
-        // let's add the checkout to the session so that it's available to other systems
1186
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1187
-        return true;
1188
-    }
1189
-
1190
-
1191
-    /**
1192
-     *    _initialize_reg_steps
1193
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1194
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1195
-     *
1196
-     * @param bool $reinitializing
1197
-     * @throws EE_Error
1198
-     */
1199
-    private function _initialize_reg_steps($reinitializing = false)
1200
-    {
1201
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1202
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1203
-        foreach ($this->checkout->reg_steps as $reg_step) {
1204
-            if (! $reg_step->initialize_reg_step()) {
1205
-                // if not initialized then maybe this step is being removed...
1206
-                if (! $reinitializing && $reg_step->is_current_step()) {
1207
-                    // if it was the current step, then we need to start over here
1208
-                    $this->_initialize_reg_steps(true);
1209
-                    return;
1210
-                }
1211
-                continue;
1212
-            }
1213
-            // add css and JS for current step
1214
-            $this->add_styles_and_scripts($reg_step);
1215
-            if ($reg_step->is_current_step()) {
1216
-                // the text that appears on the reg step form submit button
1217
-                $reg_step->set_submit_button_text();
1218
-            }
1219
-        }
1220
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1221
-        do_action(
1222
-            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1223
-            $this->checkout->current_step
1224
-        );
1225
-    }
1226
-
1227
-
1228
-    /**
1229
-     * _check_form_submission
1230
-     *
1231
-     * @return boolean
1232
-     * @throws EE_Error
1233
-     * @throws ReflectionException
1234
-     */
1235
-    private function _check_form_submission()
1236
-    {
1237
-        // does this request require the reg form to be generated ?
1238
-        if ($this->checkout->generate_reg_form) {
1239
-            // ever heard that song by Blue Rodeo ?
1240
-            try {
1241
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1242
-                // if not displaying a form, then check for form submission
1243
-                if ($this->checkout->process_form_submission
1244
-                    && $this->checkout->current_step->reg_form->was_submitted()
1245
-                ) {
1246
-                    // clear out any old data in case this step is being run again
1247
-                    $this->checkout->current_step->set_valid_data(array());
1248
-                    // capture submitted form data
1249
-                    $request_data = $this->request->requestParams();
1250
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1251
-                        (array) apply_filters(
1252
-                            'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1253
-                            $request_data,
1254
-                            $this->checkout
1255
-                        )
1256
-                    );
1257
-                    // validate submitted form data
1258
-                    if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1259
-                        // thou shall not pass !!!
1260
-                        $this->checkout->continue_reg = false;
1261
-                        // any form validation errors?
1262
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1263
-                            EE_Error::add_error(
1264
-                                $this->checkout->current_step->reg_form->submission_error_message(),
1265
-                                __FILE__,
1266
-                                __FUNCTION__,
1267
-                                __LINE__
1268
-                            );
1269
-                        }
1270
-                        // well not really... what will happen is
1271
-                        // we'll just get redirected back to redo the current step
1272
-                        $this->go_to_next_step();
1273
-                        return false;
1274
-                    }
1275
-                }
1276
-            } catch (EE_Error $e) {
1277
-                $e->get_error();
1278
-            }
1279
-        }
1280
-        return true;
1281
-    }
1282
-
1283
-
1284
-    /**
1285
-     * _process_action
1286
-     *
1287
-     * @return void
1288
-     * @throws EE_Error
1289
-     * @throws ReflectionException
1290
-     */
1291
-    private function _process_form_action()
1292
-    {
1293
-        // what cha wanna do?
1294
-        switch ($this->checkout->action) {
1295
-            // AJAX next step reg form
1296
-            case 'display_spco_reg_step':
1297
-                $this->checkout->redirect = false;
1298
-                if ($this->request->isAjax()) {
1299
-                    $this->checkout->json_response->set_reg_step_html(
1300
-                        $this->checkout->current_step->display_reg_form()
1301
-                    );
1302
-                }
1303
-                break;
1304
-            default:
1305
-                // meh... do one of those other steps first
1306
-                if (! empty($this->checkout->action)
1307
-                    && is_callable(array($this->checkout->current_step, $this->checkout->action))
1308
-                ) {
1309
-                    // dynamically creates hook point like:
1310
-                    //   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1311
-                    do_action(
1312
-                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1313
-                        $this->checkout->current_step
1314
-                    );
1315
-                    $process_reg_step = apply_filters(
1316
-                        "AHEE__Single_Page_Checkout__process_reg_step__{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1317
-                        true,
1318
-                        $this->checkout->current_step,
1319
-                        $this
1320
-                    );
1321
-                    // call action on current step
1322
-                    if ($process_reg_step && call_user_func([$this->checkout->current_step, $this->checkout->action])) {
1323
-                        // good registrant, you get to proceed
1324
-                        if ($this->checkout->current_step->success_message() !== ''
1325
-                            && apply_filters(
1326
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1327
-                                false
1328
-                            )
1329
-                        ) {
1330
-                            EE_Error::add_success(
1331
-                                $this->checkout->current_step->success_message()
1332
-                                . '<br />' . $this->checkout->next_step->_instructions()
1333
-                            );
1334
-                        }
1335
-                        // pack it up, pack it in...
1336
-                        $this->_setup_redirect();
1337
-                    }
1338
-                    // dynamically creates hook point like:
1339
-                    //  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1340
-                    do_action(
1341
-                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1342
-                        $this->checkout->current_step
1343
-                    );
1344
-                } else {
1345
-                    EE_Error::add_error(
1346
-                        sprintf(
1347
-                            esc_html__(
1348
-                                'The requested form action "%s" does not exist for the current "%s" registration step.',
1349
-                                'event_espresso'
1350
-                            ),
1351
-                            $this->checkout->action,
1352
-                            $this->checkout->current_step->name()
1353
-                        ),
1354
-                        __FILE__,
1355
-                        __FUNCTION__,
1356
-                        __LINE__
1357
-                    );
1358
-                }
1359
-            // end default
1360
-        }
1361
-        // store our progress so far
1362
-        $this->checkout->stash_transaction_and_checkout();
1363
-        // advance to the next step! If you pass GO, collect $200
1364
-        $this->go_to_next_step();
1365
-    }
1366
-
1367
-
1368
-    /**
1369
-     * @param EED_Single_Page_Checkout|EE_SPCO_Reg_Step $target an object with the method `translate_js_strings` and
1370
-     *                                                          `enqueue_styles_and_scripts`.
1371
-     * @return        void
1372
-     */
1373
-    public function add_styles_and_scripts($target)
1374
-    {
1375
-        // i18n
1376
-        $target->translate_js_strings();
1377
-        if ($this->checkout->admin_request) {
1378
-            add_action('admin_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1379
-        } else {
1380
-            add_action('wp_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1381
-        }
1382
-    }
1383
-
1384
-    /**
1385
-     *        translate_js_strings
1386
-     *
1387
-     * @return        void
1388
-     */
1389
-    public function translate_js_strings()
1390
-    {
1391
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1392
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1393
-        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
1394
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1395
-            'event_espresso'
1396
-        );
1397
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = esc_html__(
1398
-            'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1399
-            'event_espresso'
1400
-        );
1401
-        EE_Registry::$i18n_js_strings['validation_error'] = esc_html__(
1402
-            'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1403
-            'event_espresso'
1404
-        );
1405
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
1406
-            'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1407
-            'event_espresso'
1408
-        );
1409
-        EE_Registry::$i18n_js_strings['reg_step_error'] = esc_html__(
1410
-            'This registration step could not be completed. Please refresh the page and try again.',
1411
-            'event_espresso'
1412
-        );
1413
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = esc_html__(
1414
-            'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1415
-            'event_espresso'
1416
-        );
1417
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1418
-            esc_html__(
1419
-                'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1420
-                'event_espresso'
1421
-            ),
1422
-            '<br/>',
1423
-            '<br/>'
1424
-        );
1425
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1426
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1427
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1428
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1429
-        EE_Registry::$i18n_js_strings['timer_years'] = esc_html__('years', 'event_espresso');
1430
-        EE_Registry::$i18n_js_strings['timer_months'] = esc_html__('months', 'event_espresso');
1431
-        EE_Registry::$i18n_js_strings['timer_weeks'] = esc_html__('weeks', 'event_espresso');
1432
-        EE_Registry::$i18n_js_strings['timer_days'] = esc_html__('days', 'event_espresso');
1433
-        EE_Registry::$i18n_js_strings['timer_hours'] = esc_html__('hours', 'event_espresso');
1434
-        EE_Registry::$i18n_js_strings['timer_minutes'] = esc_html__('minutes', 'event_espresso');
1435
-        EE_Registry::$i18n_js_strings['timer_seconds'] = esc_html__('seconds', 'event_espresso');
1436
-        EE_Registry::$i18n_js_strings['timer_year'] = esc_html__('year', 'event_espresso');
1437
-        EE_Registry::$i18n_js_strings['timer_month'] = esc_html__('month', 'event_espresso');
1438
-        EE_Registry::$i18n_js_strings['timer_week'] = esc_html__('week', 'event_espresso');
1439
-        EE_Registry::$i18n_js_strings['timer_day'] = esc_html__('day', 'event_espresso');
1440
-        EE_Registry::$i18n_js_strings['timer_hour'] = esc_html__('hour', 'event_espresso');
1441
-        EE_Registry::$i18n_js_strings['timer_minute'] = esc_html__('minute', 'event_espresso');
1442
-        EE_Registry::$i18n_js_strings['timer_second'] = esc_html__('second', 'event_espresso');
1443
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
1444
-        );
1445
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1446
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1447
-            true
1448
-        );
1449
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1450
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1451
-        );
1452
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1453
-            'M d, Y H:i:s',
1454
-            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1455
-        );
1456
-    }
1457
-
1458
-
1459
-    /**
1460
-     *    enqueue_styles_and_scripts
1461
-     *
1462
-     * @return        void
1463
-     * @throws EE_Error
1464
-     */
1465
-    public function enqueue_styles_and_scripts()
1466
-    {
1467
-        // load css
1468
-        wp_register_style(
1469
-            'single_page_checkout',
1470
-            SPCO_CSS_URL . 'single_page_checkout.css',
1471
-            array('espresso_default'),
1472
-            EVENT_ESPRESSO_VERSION
1473
-        );
1474
-        wp_enqueue_style('single_page_checkout');
1475
-        // load JS
1476
-        wp_register_script(
1477
-            'jquery_plugin',
1478
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1479
-            array('jquery'),
1480
-            '1.0.1',
1481
-            true
1482
-        );
1483
-        wp_register_script(
1484
-            'jquery_countdown',
1485
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1486
-            array('jquery_plugin'),
1487
-            '2.1.0',
1488
-            true
1489
-        );
1490
-        wp_register_script(
1491
-            'single_page_checkout',
1492
-            SPCO_JS_URL . 'single_page_checkout.js',
1493
-            array('espresso_core', 'underscore', 'ee_form_section_validation'),
1494
-            EVENT_ESPRESSO_VERSION,
1495
-            true
1496
-        );
1497
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1498
-            $this->checkout->registration_form->enqueue_js();
1499
-        }
1500
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1501
-            $this->checkout->current_step->reg_form->enqueue_js();
1502
-        }
1503
-        wp_enqueue_script('single_page_checkout');
1504
-        if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) {
1505
-            wp_enqueue_script('jquery_countdown');
1506
-        }
1507
-        /**
1508
-         * global action hook for enqueueing styles and scripts with
1509
-         * spco calls.
1510
-         */
1511
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1512
-        /**
1513
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1514
-         * The hook will end up being something like:
1515
-         *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1516
-         */
1517
-        do_action(
1518
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1519
-            $this
1520
-        );
1521
-    }
1522
-
1523
-
1524
-    /**
1525
-     *    display the Registration Single Page Checkout Form
1526
-     *
1527
-     * @return    void
1528
-     * @throws EE_Error
1529
-     * @throws ReflectionException
1530
-     */
1531
-    private function _display_spco_reg_form()
1532
-    {
1533
-        // if registering via the admin, just display the reg form for the current step
1534
-        if ($this->checkout->admin_request) {
1535
-            EED_Single_Page_Checkout::getResponse()->addOutput($this->checkout->current_step->display_reg_form());
1536
-        } else {
1537
-            // add powered by EE msg
1538
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1539
-            $empty_cart = count($this->checkout->transaction
1540
-                                    ->registrations($this->checkout->reg_cache_where_params)) < 1;
1541
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1542
-            $cookies_not_set_msg = '';
1543
-            if ($empty_cart) {
1544
-                $cookies_not_set_msg = apply_filters(
1545
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1546
-                    sprintf(
1547
-                        esc_html__(
1548
-                            '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1549
-                            'event_espresso'
1550
-                        ),
1551
-                        '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1552
-                        '</div>',
1553
-                        '<h6 class="important-notice">',
1554
-                        '</h6>',
1555
-                        '<p>',
1556
-                        '</p>',
1557
-                        '<br />',
1558
-                        '<a href="https://www.whatismybrowser.com/guides/how-to-enable-cookies/" target="_blank" rel="noopener noreferrer">',
1559
-                        '</a>'
1560
-                    )
1561
-                );
1562
-            }
1563
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1564
-                array(
1565
-                    'name'            => 'single-page-checkout',
1566
-                    'html_id'         => 'ee-single-page-checkout-dv',
1567
-                    'layout_strategy' =>
1568
-                        new EE_Template_Layout(
1569
-                            array(
1570
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1571
-                                'template_args'        => array(
1572
-                                    'empty_cart'              => $empty_cart,
1573
-                                    'revisit'                 => $this->checkout->revisit,
1574
-                                    'reg_steps'               => $this->checkout->reg_steps,
1575
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1576
-                                        ? $this->checkout->next_step->slug()
1577
-                                        : '',
1578
-                                    'empty_msg'               => apply_filters(
1579
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1580
-                                        sprintf(
1581
-                                            esc_html__(
1582
-                                                'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1583
-                                                'event_espresso'
1584
-                                            ),
1585
-                                            '<a href="'
1586
-                                            . get_post_type_archive_link('espresso_events')
1587
-                                            . '" title="',
1588
-                                            '">',
1589
-                                            '</a>'
1590
-                                        )
1591
-                                    ),
1592
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1593
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1594
-                                    'session_expiration'      => gmdate(
1595
-                                        'M d, Y H:i:s',
1596
-                                        EE_Registry::instance()->SSN->expiration()
1597
-                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1598
-                                    ),
1599
-                                ),
1600
-                            )
1601
-                        ),
1602
-                )
1603
-            );
1604
-            // load template and add to output sent that gets filtered into the_content()
1605
-            EED_Single_Page_Checkout::getResponse()->addOutput($this->checkout->registration_form->get_html());
1606
-        }
1607
-    }
1608
-
1609
-
1610
-    /**
1611
-     *    add_extra_finalize_registration_inputs
1612
-     *
1613
-     * @param $next_step
1614
-     * @internal  param string $label
1615
-     * @return void
1616
-     */
1617
-    public function add_extra_finalize_registration_inputs($next_step)
1618
-    {
1619
-        if ($next_step === 'finalize_registration') {
1620
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1621
-        }
1622
-    }
1623
-
1624
-
1625
-    /**
1626
-     *    display_registration_footer
1627
-     *
1628
-     * @return    string
1629
-     */
1630
-    public static function display_registration_footer()
1631
-    {
1632
-        if (apply_filters(
1633
-            'FHEE__EE_Front__Controller__show_reg_footer',
1634
-            EE_Registry::instance()->CFG->admin->show_reg_footer
1635
-        )) {
1636
-            add_filter(
1637
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1638
-                function ($url) {
1639
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1640
-                }
1641
-            );
1642
-            echo apply_filters(
1643
-                'FHEE__EE_Front_Controller__display_registration_footer',
1644
-                EEH_Template::powered_by_event_espresso(
1645
-                    '',
1646
-                    'espresso-registration-footer-dv',
1647
-                    array('utm_content' => 'registration_checkout')
1648
-                )
1649
-            );
1650
-        }
1651
-        return '';
1652
-    }
1653
-
1654
-
1655
-    /**
1656
-     *    unlock_transaction
1657
-     *
1658
-     * @return    void
1659
-     * @throws EE_Error
1660
-     * @throws ReflectionException
1661
-     */
1662
-    public function unlock_transaction()
1663
-    {
1664
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1665
-            $this->checkout->transaction->unlock();
1666
-        }
1667
-    }
1668
-
1669
-
1670
-    /**
1671
-     *        _setup_redirect
1672
-     *
1673
-     * @return void
1674
-     */
1675
-    private function _setup_redirect()
1676
-    {
1677
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1678
-            $this->checkout->redirect = true;
1679
-            if (empty($this->checkout->redirect_url)) {
1680
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1681
-            }
1682
-            $this->checkout->redirect_url = apply_filters(
1683
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1684
-                $this->checkout->redirect_url,
1685
-                $this->checkout
1686
-            );
1687
-        }
1688
-    }
1689
-
1690
-
1691
-    /**
1692
-     *   handle ajax message responses and redirects
1693
-     *
1694
-     * @return void
1695
-     * @throws EE_Error
1696
-     * @throws ReflectionException
1697
-     */
1698
-    public function go_to_next_step()
1699
-    {
1700
-        if ($this->request->isAjax()) {
1701
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1702
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1703
-        }
1704
-        $this->unlock_transaction();
1705
-        // just return for these conditions
1706
-        if ($this->checkout->admin_request
1707
-            || $this->checkout->action === 'redirect_form'
1708
-            || $this->checkout->action === 'update_checkout'
1709
-        ) {
1710
-            return;
1711
-        }
1712
-        // AJAX response
1713
-        $this->_handle_json_response();
1714
-        // redirect to next step or the Thank You page
1715
-        $this->_handle_html_redirects();
1716
-        // hmmm... must be something wrong, so let's just display the form again !
1717
-        $this->_display_spco_reg_form();
1718
-    }
1719
-
1720
-
1721
-    /**
1722
-     *   _handle_json_response
1723
-     *
1724
-     * @return void
1725
-     * @throws EE_Error
1726
-     */
1727
-    protected function _handle_json_response()
1728
-    {
1729
-        // if this is an ajax request
1730
-        if ($this->request->isAjax()) {
1731
-            $this->checkout->json_response->set_registration_time_limit(
1732
-                $this->checkout->get_registration_time_limit()
1733
-            );
1734
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1735
-            // just send the ajax (
1736
-            $json_response = apply_filters(
1737
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1738
-                $this->checkout->json_response
1739
-            );
1740
-            echo $json_response;
1741
-            exit();
1742
-        }
1743
-    }
1744
-
1745
-
1746
-    /**
1747
-     *   _handle_redirects
1748
-     *
1749
-     * @return void
1750
-     */
1751
-    protected function _handle_html_redirects()
1752
-    {
1753
-        // going somewhere ?
1754
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1755
-            // store notices in a transient
1756
-            EE_Error::get_notices(false, true);
1757
-            wp_safe_redirect($this->checkout->redirect_url);
1758
-            exit();
1759
-        }
1760
-    }
1761
-
1762
-
1763
-    /**
1764
-     *   set_checkout_anchor
1765
-     *
1766
-     * @return void
1767
-     */
1768
-    public function set_checkout_anchor()
1769
-    {
1770
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1771
-    }
1772
-
1773
-    /**
1774
-     *    getRegistrationExpirationNotice
1775
-     *
1776
-     * @since     4.9.59.p
1777
-     * @return    string
1778
-     */
1779
-    public static function getRegistrationExpirationNotice()
1780
-    {
1781
-        return sprintf(
1782
-            esc_html__(
1783
-                '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1784
-                'event_espresso'
1785
-            ),
1786
-            '<h4 class="important-notice">',
1787
-            '</h4>',
1788
-            '<br />',
1789
-            '<p>',
1790
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1791
-            '">',
1792
-            '</a>',
1793
-            '</p>'
1794
-        );
1795
-    }
22
+	/**
23
+	 * $_initialized - has the SPCO controller already been initialized ?
24
+	 *
25
+	 * @var bool $_initialized
26
+	 */
27
+	private static $_initialized = false;
28
+
29
+
30
+	/**
31
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
32
+	 *
33
+	 * @var bool $_valid_checkout
34
+	 */
35
+	private static $_checkout_verified = true;
36
+
37
+	/**
38
+	 *    $_reg_steps_array - holds initial array of reg steps
39
+	 *
40
+	 * @var array $_reg_steps_array
41
+	 */
42
+	private static $_reg_steps_array = array();
43
+
44
+	/**
45
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
46
+	 *
47
+	 * @var EE_Checkout $checkout
48
+	 */
49
+	public $checkout;
50
+
51
+	/**
52
+	 * @var RequestInterface $request
53
+	 */
54
+	protected $request;
55
+
56
+
57
+	/**
58
+	 * @return EED_Single_Page_Checkout|EED_Module
59
+	 * @throws EE_Error
60
+	 * @throws ReflectionException
61
+	 */
62
+	public static function instance()
63
+	{
64
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
65
+		return parent::get_instance(__CLASS__);
66
+	}
67
+
68
+
69
+	/**
70
+	 * @return EE_CART
71
+	 */
72
+	public function cart()
73
+	{
74
+		return $this->checkout->cart;
75
+	}
76
+
77
+
78
+	/**
79
+	 * @return RequestInterface
80
+	 * @since   $VID:$
81
+	 */
82
+	public static function getRequest()
83
+	{
84
+		return LoaderFactory::getLoader()->getShared(RequestInterface::class);
85
+	}
86
+
87
+
88
+	/**
89
+	 * @return EE_Transaction
90
+	 */
91
+	public function transaction()
92
+	{
93
+		return $this->checkout->transaction;
94
+	}
95
+
96
+
97
+	/**
98
+	 *    set_hooks - for hooking into EE Core, other modules, etc
99
+	 *
100
+	 * @return    void
101
+	 * @throws EE_Error
102
+	 */
103
+	public static function set_hooks()
104
+	{
105
+		EED_Single_Page_Checkout::set_definitions();
106
+	}
107
+
108
+
109
+	/**
110
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
111
+	 *
112
+	 * @return    void
113
+	 * @throws EE_Error
114
+	 */
115
+	public static function set_hooks_admin()
116
+	{
117
+		EED_Single_Page_Checkout::set_definitions();
118
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
119
+			return;
120
+		}
121
+		// going to start an output buffer in case anything gets accidentally output
122
+		// that might disrupt our JSON response
123
+		ob_start();
124
+		EED_Single_Page_Checkout::load_reg_steps();
125
+		// set ajax hooks
126
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
127
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
128
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
129
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
130
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
131
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
132
+	}
133
+
134
+
135
+	/**
136
+	 *    process ajax request
137
+	 *
138
+	 * @param string $ajax_action
139
+	 * @throws EE_Error
140
+	 * @throws ReflectionException
141
+	 */
142
+	public static function process_ajax_request($ajax_action)
143
+	{
144
+		$request = EED_Single_Page_Checkout::getRequest();
145
+		$request->setRequestParam('action', $ajax_action);
146
+		EED_Single_Page_Checkout::instance()->_initialize();
147
+	}
148
+
149
+
150
+	/**
151
+	 * ajax display registration step
152
+	 *
153
+	 * @throws EE_Error
154
+	 * @throws ReflectionException
155
+	 */
156
+	public static function display_reg_step()
157
+	{
158
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
159
+	}
160
+
161
+
162
+	/**
163
+	 * ajax process registration step
164
+	 *
165
+	 * @throws EE_Error
166
+	 * @throws ReflectionException
167
+	 */
168
+	public static function process_reg_step()
169
+	{
170
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
171
+	}
172
+
173
+
174
+	/**
175
+	 * ajax process registration step
176
+	 *
177
+	 * @throws EE_Error
178
+	 * @throws ReflectionException
179
+	 */
180
+	public static function update_reg_step()
181
+	{
182
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
183
+	}
184
+
185
+
186
+	/**
187
+	 * update_checkout
188
+	 *
189
+	 * @return void
190
+	 * @throws ReflectionException
191
+	 * @throws EE_Error
192
+	 */
193
+	public static function update_checkout()
194
+	{
195
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
196
+	}
197
+
198
+
199
+	/**
200
+	 * @return void
201
+	 * @deprecated $VID:$
202
+	 */
203
+	public static function load_request_handler()
204
+	{
205
+	}
206
+
207
+
208
+	/**
209
+	 *    set_definitions
210
+	 *
211
+	 * @return    void
212
+	 * @throws EE_Error
213
+	 */
214
+	public static function set_definitions()
215
+	{
216
+		if (defined('SPCO_BASE_PATH')) {
217
+			return;
218
+		}
219
+		define(
220
+			'SPCO_BASE_PATH',
221
+			rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
222
+		);
223
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css/');
224
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img/');
225
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js/');
226
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc/');
227
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps/');
228
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates/');
229
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
230
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
231
+		);
232
+	}
233
+
234
+
235
+	/**
236
+	 * load_reg_steps
237
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
238
+	 *
239
+	 * @throws EE_Error
240
+	 */
241
+	public static function load_reg_steps()
242
+	{
243
+		static $reg_steps_loaded = false;
244
+		if ($reg_steps_loaded) {
245
+			return;
246
+		}
247
+		// filter list of reg_steps
248
+		$reg_steps_to_load = (array) apply_filters(
249
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
250
+			EED_Single_Page_Checkout::get_reg_steps()
251
+		);
252
+		// sort by key (order)
253
+		ksort($reg_steps_to_load);
254
+		// loop through folders
255
+		foreach ($reg_steps_to_load as $order => $reg_step) {
256
+			// we need a
257
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
258
+				// copy over to the reg_steps_array
259
+				EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step;
260
+				// register custom key route for each reg step
261
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
262
+				EE_Config::register_route(
263
+					$reg_step['slug'],
264
+					'EED_Single_Page_Checkout',
265
+					'run',
266
+					'step'
267
+				);
268
+				// add AJAX or other hooks
269
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
270
+					// setup autoloaders if necessary
271
+					if (! class_exists($reg_step['class_name'])) {
272
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
273
+							$reg_step['file_path'],
274
+							true
275
+						);
276
+					}
277
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
278
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
279
+					}
280
+				}
281
+			}
282
+		}
283
+		$reg_steps_loaded = true;
284
+	}
285
+
286
+
287
+	/**
288
+	 *    get_reg_steps
289
+	 *
290
+	 * @return    array
291
+	 */
292
+	public static function get_reg_steps()
293
+	{
294
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
295
+		if (empty($reg_steps)) {
296
+			$reg_steps = array(
297
+				10  => array(
298
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
299
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
300
+					'slug'       => 'attendee_information',
301
+					'has_hooks'  => false,
302
+				),
303
+				30  => array(
304
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
305
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
306
+					'slug'       => 'payment_options',
307
+					'has_hooks'  => true,
308
+				),
309
+				999 => array(
310
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
311
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
312
+					'slug'       => 'finalize_registration',
313
+					'has_hooks'  => false,
314
+				),
315
+			);
316
+		}
317
+		return $reg_steps;
318
+	}
319
+
320
+
321
+	/**
322
+	 *    registration_checkout_for_admin
323
+	 *
324
+	 * @return    string
325
+	 * @throws EE_Error
326
+	 * @throws ReflectionException
327
+	 */
328
+	public static function registration_checkout_for_admin()
329
+	{
330
+		$request = EED_Single_Page_Checkout::getRequest();
331
+		$request->setRequestParam('step', 'attendee_information');
332
+		$request->setRequestParam('action', 'display_spco_reg_step');
333
+		$request->setRequestParam('process_form_submission', false);
334
+		EED_Single_Page_Checkout::instance()->_initialize();
335
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
336
+		return EED_Single_Page_Checkout::getResponse()->getOutput();
337
+	}
338
+
339
+
340
+	/**
341
+	 * process_registration_from_admin
342
+	 *
343
+	 * @return EE_Transaction
344
+	 * @throws EE_Error
345
+	 * @throws ReflectionException
346
+	 */
347
+	public static function process_registration_from_admin()
348
+	{
349
+		$request = EED_Single_Page_Checkout::getRequest();
350
+		$request->setRequestParam('step', 'attendee_information');
351
+		$request->setRequestParam('action', 'process_reg_step');
352
+		$request->setRequestParam('process_form_submission', true);
353
+		EED_Single_Page_Checkout::instance()->_initialize();
354
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
355
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
356
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
357
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
358
+				if ($final_reg_step->process_reg_step()) {
359
+					$final_reg_step->set_completed();
360
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
361
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
362
+				}
363
+			}
364
+		}
365
+		return null;
366
+	}
367
+
368
+
369
+	/**
370
+	 *    run
371
+	 *
372
+	 * @param WP_Query $WP
373
+	 * @return    void
374
+	 */
375
+	public function run($WP)
376
+	{
377
+		if ($WP instanceof WP_Query
378
+			&& $WP->is_main_query()
379
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
380
+			&& $this->_is_reg_checkout()
381
+		) {
382
+			$this->_initialize();
383
+		}
384
+	}
385
+
386
+
387
+	/**
388
+	 * determines whether current url matches reg page url
389
+	 *
390
+	 * @return bool
391
+	 */
392
+	protected function _is_reg_checkout()
393
+	{
394
+		// get current permalink for reg page without any extra query args
395
+		$reg_page_url = get_permalink(EE_Config::instance()->core->reg_page_id);
396
+		// get request URI for current request, but without the scheme or host
397
+		$current_request_uri = EEH_URL::filter_input_server_url();
398
+		$current_request_uri = html_entity_decode($current_request_uri);
399
+		// get array of query args from the current request URI
400
+		$query_args = EEH_URL::get_query_string($current_request_uri);
401
+		// grab page id if it is set
402
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
403
+		// and remove the page id from the query args (we will re-add it later)
404
+		unset($query_args['page_id']);
405
+		// now strip all query args from current request URI
406
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
407
+		// and re-add the page id if it was set
408
+		if ($page_id) {
409
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
410
+		}
411
+		// remove slashes and ?
412
+		$current_request_uri = trim($current_request_uri, '?/');
413
+		// is current request URI part of the known full reg page URL ?
414
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
415
+	}
416
+
417
+
418
+	/**
419
+	 * @param WP_Query $wp_query
420
+	 * @return    void
421
+	 * @throws EE_Error
422
+	 * @throws ReflectionException
423
+	 */
424
+	public static function init($wp_query)
425
+	{
426
+		EED_Single_Page_Checkout::instance()->run($wp_query);
427
+	}
428
+
429
+
430
+	/**
431
+	 *    _initialize - initial module setup
432
+	 *
433
+	 * @return    void
434
+	 */
435
+	private function _initialize()
436
+	{
437
+		// ensure SPCO doesn't run twice
438
+		if (EED_Single_Page_Checkout::$_initialized) {
439
+			return;
440
+		}
441
+		try {
442
+			$this->request = EED_Single_Page_Checkout::getRequest();
443
+			EED_Single_Page_Checkout::load_reg_steps();
444
+			$this->_verify_session();
445
+			// setup the EE_Checkout object
446
+			$this->checkout = $this->_initialize_checkout();
447
+			// filter checkout
448
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
449
+			// get the $_GET
450
+			$this->_get_request_vars();
451
+			if ($this->_block_bots()) {
452
+				return;
453
+			}
454
+			// filter continue_reg
455
+			$this->checkout->continue_reg = apply_filters(
456
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
457
+				true,
458
+				$this->checkout
459
+			);
460
+			// load the reg steps array
461
+			if (! $this->_load_and_instantiate_reg_steps()) {
462
+				EED_Single_Page_Checkout::$_initialized = true;
463
+				return;
464
+			}
465
+			// set the current step
466
+			$this->checkout->set_current_step($this->checkout->step);
467
+			// and the next step
468
+			$this->checkout->set_next_step();
469
+			// verify that everything has been setup correctly
470
+			if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
471
+				EED_Single_Page_Checkout::$_initialized = true;
472
+				return;
473
+			}
474
+			// lock the transaction
475
+			$this->checkout->transaction->lock();
476
+			// make sure all of our cached objects are added to their respective model entity mappers
477
+			$this->checkout->refresh_all_entities();
478
+			// set amount owing
479
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
480
+			// initialize each reg step, which gives them the chance to potentially alter the process
481
+			$this->_initialize_reg_steps();
482
+			// DEBUG LOG
483
+			// $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
484
+			// get reg form
485
+			if (! $this->_check_form_submission()) {
486
+				EED_Single_Page_Checkout::$_initialized = true;
487
+				return;
488
+			}
489
+			// checkout the action!!!
490
+			$this->_process_form_action();
491
+			// add some style and make it dance
492
+			$this->add_styles_and_scripts($this);
493
+			// kk... SPCO has successfully run
494
+			EED_Single_Page_Checkout::$_initialized = true;
495
+			// set no cache headers and constants
496
+			EE_System::do_not_cache();
497
+			// add anchor
498
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
499
+			// remove transaction lock
500
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
501
+		} catch (Exception $e) {
502
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
503
+		}
504
+	}
505
+
506
+
507
+	/**
508
+	 *    _verify_session
509
+	 * checks that the session is valid and not expired
510
+	 *
511
+	 * @throws EE_Error
512
+	 * @throws ReflectionException
513
+	 */
514
+	private function _verify_session()
515
+	{
516
+		if (! EE_Registry::instance()->SSN instanceof EE_Session) {
517
+			throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso'));
518
+		}
519
+		$clear_session_requested = $this->request->getRequestParam('clear_session', false, 'bool');
520
+		// is session still valid ?
521
+		if (
522
+			$clear_session_requested
523
+			|| (
524
+				EE_Registry::instance()->SSN->expired()
525
+				&& $this->request->getRequestParam('e_reg_url_link') === ''
526
+			)
527
+		) {
528
+			$this->checkout = new EE_Checkout();
529
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
530
+			// EE_Registry::instance()->SSN->reset_cart();
531
+			// EE_Registry::instance()->SSN->reset_checkout();
532
+			// EE_Registry::instance()->SSN->reset_transaction();
533
+			if (! $clear_session_requested) {
534
+				EE_Error::add_attention(
535
+					EE_Registry::$i18n_js_strings['registration_expiration_notice'],
536
+					__FILE__,
537
+					__FUNCTION__,
538
+					__LINE__
539
+				);
540
+			}
541
+			// EE_Registry::instance()->SSN->reset_expired();
542
+		}
543
+	}
544
+
545
+
546
+	/**
547
+	 *    _initialize_checkout
548
+	 * loads and instantiates EE_Checkout
549
+	 *
550
+	 * @return EE_Checkout
551
+	 * @throws EE_Error
552
+	 * @throws ReflectionException
553
+	 */
554
+	private function _initialize_checkout()
555
+	{
556
+		// look in session for existing checkout
557
+		/** @type EE_Checkout $checkout */
558
+		$checkout = EE_Registry::instance()->SSN->checkout();
559
+		// verify
560
+		if (! $checkout instanceof EE_Checkout) {
561
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
562
+			$checkout = EE_Registry::instance()->load_file(
563
+				SPCO_INC_PATH,
564
+				'EE_Checkout',
565
+				'class',
566
+				array(),
567
+				false
568
+			);
569
+		} else {
570
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
571
+				$this->unlock_transaction();
572
+				wp_safe_redirect($checkout->redirect_url);
573
+				exit();
574
+			}
575
+		}
576
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
577
+		// verify again
578
+		if (! $checkout instanceof EE_Checkout) {
579
+			throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso'));
580
+		}
581
+		// reset anything that needs a clean slate for each request
582
+		$checkout->reset_for_current_request();
583
+		return $checkout;
584
+	}
585
+
586
+
587
+	/**
588
+	 *    _get_request_vars
589
+	 *
590
+	 * @return    void
591
+	 */
592
+	private function _get_request_vars()
593
+	{
594
+		// make sure this request is marked as belonging to EE
595
+		/** @var CurrentPage $current_page */
596
+		$current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class);
597
+		$current_page->setEspressoPage(true);
598
+		// which step is being requested ?
599
+		$this->checkout->step = $this->request->getRequestParam('step', $this->_get_first_step());
600
+		// which step is being edited ?
601
+		$this->checkout->edit_step = $this->request->getRequestParam('edit_step');
602
+		// and what we're doing on the current step
603
+		$this->checkout->action = $this->request->getRequestParam('action', 'display_spco_reg_step');
604
+		// timestamp
605
+		$this->checkout->uts = $this->request->getRequestParam('uts', 0, 'int');
606
+		// returning to edit ?
607
+		$this->checkout->reg_url_link = $this->request->getRequestParam('e_reg_url_link');
608
+		// add reg url link to registration query params
609
+		if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
610
+			$this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
611
+		}
612
+		// or some other kind of revisit ?
613
+		$this->checkout->revisit = $this->request->getRequestParam('revisit', false, 'bool');
614
+		// and whether or not to generate a reg form for this request
615
+		$this->checkout->generate_reg_form = $this->request->getRequestParam('generate_reg_form', true, 'bool');
616
+		// and whether or not to process a reg form submission for this request
617
+		$this->checkout->process_form_submission = $this->request->getRequestParam(
618
+			'process_form_submission',
619
+			$this->checkout->action === 'process_reg_step',
620
+			'bool'
621
+		);
622
+		$this->checkout->process_form_submission = filter_var(
623
+			$this->checkout->action !== 'display_spco_reg_step'
624
+				? $this->checkout->process_form_submission
625
+				: false,
626
+			FILTER_VALIDATE_BOOLEAN
627
+		);
628
+		// $this->_display_request_vars();
629
+	}
630
+
631
+
632
+	/**
633
+	 *  _display_request_vars
634
+	 *
635
+	 * @return    void
636
+	 */
637
+	protected function _display_request_vars()
638
+	{
639
+		if (! WP_DEBUG) {
640
+			return;
641
+		}
642
+		EEH_Debug_Tools::printr($this->request->requestParams(), 'requestParams', __FILE__, __LINE__);
643
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
644
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
645
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
646
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
647
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
648
+		EEH_Debug_Tools::printr(
649
+			$this->checkout->generate_reg_form,
650
+			'$this->checkout->generate_reg_form',
651
+			__FILE__,
652
+			__LINE__
653
+		);
654
+		EEH_Debug_Tools::printr(
655
+			$this->checkout->process_form_submission,
656
+			'$this->checkout->process_form_submission',
657
+			__FILE__,
658
+			__LINE__
659
+		);
660
+	}
661
+
662
+
663
+	/**
664
+	 * _block_bots
665
+	 * checks that the incoming request has either of the following set:
666
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
667
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
668
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
669
+	 * then where you coming from man?
670
+	 *
671
+	 * @return boolean
672
+	 */
673
+	private function _block_bots()
674
+	{
675
+		$invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
676
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
677
+			return true;
678
+		}
679
+		return false;
680
+	}
681
+
682
+
683
+	/**
684
+	 *    _get_first_step
685
+	 *  gets slug for first step in $_reg_steps_array
686
+	 *
687
+	 * @return    string
688
+	 */
689
+	private function _get_first_step()
690
+	{
691
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
692
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
693
+	}
694
+
695
+
696
+	/**
697
+	 * instantiates each reg step based on the loaded reg_steps array
698
+	 *
699
+	 * @return    bool
700
+	 * @throws EE_Error
701
+	 * @throws InvalidArgumentException
702
+	 * @throws InvalidDataTypeException
703
+	 * @throws InvalidInterfaceException
704
+	 * @throws ReflectionException
705
+	 */
706
+	private function _load_and_instantiate_reg_steps()
707
+	{
708
+		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
709
+		// have reg_steps already been instantiated ?
710
+		if (empty($this->checkout->reg_steps)
711
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
712
+		) {
713
+			// if not, then loop through raw reg steps array
714
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
715
+				if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
716
+					return false;
717
+				}
718
+			}
719
+			if (isset($this->checkout->reg_steps['registration_confirmation'])) {
720
+				// skip the registration_confirmation page ?
721
+				if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
722
+					// just remove it from the reg steps array
723
+					$this->checkout->remove_reg_step('registration_confirmation', false);
724
+				} elseif (EE_Registry::instance()->CFG->registration->reg_confirmation_last
725
+				) {
726
+					// set the order to something big like 100
727
+					$this->checkout->set_reg_step_order('registration_confirmation');
728
+				}
729
+			}
730
+			// filter the array for good luck
731
+			$this->checkout->reg_steps = apply_filters(
732
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
733
+				$this->checkout->reg_steps
734
+			);
735
+			// finally re-sort based on the reg step class order properties
736
+			$this->checkout->sort_reg_steps();
737
+		} else {
738
+			foreach ($this->checkout->reg_steps as $reg_step) {
739
+				// set all current step stati to FALSE
740
+				$reg_step->set_is_current_step(false);
741
+			}
742
+		}
743
+		if (empty($this->checkout->reg_steps)) {
744
+			EE_Error::add_error(
745
+				esc_html__('No Reg Steps were loaded..', 'event_espresso'),
746
+				__FILE__,
747
+				__FUNCTION__,
748
+				__LINE__
749
+			);
750
+			return false;
751
+		}
752
+		// make reg step details available to JS
753
+		$this->checkout->set_reg_step_JSON_info();
754
+		return true;
755
+	}
756
+
757
+
758
+	/**
759
+	 *     _load_and_instantiate_reg_step
760
+	 *
761
+	 * @param array $reg_step
762
+	 * @param int   $order
763
+	 * @return bool
764
+	 * @throws EE_Error
765
+	 * @throws ReflectionException
766
+	 */
767
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
768
+	{
769
+		// we need a file_path, class_name, and slug to add a reg step
770
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
771
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
772
+			if ($this->checkout->reg_url_link
773
+				&& $this->checkout->step !== $reg_step['slug']
774
+				&& $reg_step['slug'] !== 'finalize_registration'
775
+				// normally at this point we would NOT load the reg step, but this filter can change that
776
+				&& apply_filters(
777
+					'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
778
+					true,
779
+					$reg_step,
780
+					$this->checkout
781
+				)
782
+			) {
783
+				return true;
784
+			}
785
+			// instantiate step class using file path and class name
786
+			$reg_step_obj = EE_Registry::instance()->load_file(
787
+				$reg_step['file_path'],
788
+				$reg_step['class_name'],
789
+				'class',
790
+				$this->checkout,
791
+				false
792
+			);
793
+			// did we gets the goods ?
794
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
795
+				// set reg step order based on config
796
+				$reg_step_obj->set_order($order);
797
+				// add instantiated reg step object to the master reg steps array
798
+				$this->checkout->add_reg_step($reg_step_obj);
799
+			} else {
800
+				EE_Error::add_error(
801
+					esc_html__('The current step could not be set.', 'event_espresso'),
802
+					__FILE__,
803
+					__FUNCTION__,
804
+					__LINE__
805
+				);
806
+				return false;
807
+			}
808
+		} else {
809
+			if (WP_DEBUG) {
810
+				EE_Error::add_error(
811
+					sprintf(
812
+						esc_html__(
813
+							'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
814
+							'event_espresso'
815
+						),
816
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
817
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
818
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
819
+						'<ul>',
820
+						'<li>',
821
+						'</li>',
822
+						'</ul>'
823
+					),
824
+					__FILE__,
825
+					__FUNCTION__,
826
+					__LINE__
827
+				);
828
+			}
829
+			return false;
830
+		}
831
+		return true;
832
+	}
833
+
834
+
835
+	/**
836
+	 * _verify_transaction_and_get_registrations
837
+	 *
838
+	 * @return bool
839
+	 * @throws EE_Error
840
+	 * @throws ReflectionException
841
+	 */
842
+	private function _verify_transaction_and_get_registrations()
843
+	{
844
+		// was there already a valid transaction in the checkout from the session ?
845
+		if (! $this->checkout->transaction instanceof EE_Transaction) {
846
+			// get transaction from db or session
847
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
848
+				? $this->_get_transaction_and_cart_for_previous_visit()
849
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
850
+			if (! $this->checkout->transaction instanceof EE_Transaction) {
851
+				EE_Error::add_error(
852
+					esc_html__(
853
+						'Your Registration and Transaction information could not be retrieved from the db.',
854
+						'event_espresso'
855
+					),
856
+					__FILE__,
857
+					__FUNCTION__,
858
+					__LINE__
859
+				);
860
+				$this->checkout->transaction = EE_Transaction::new_instance();
861
+				// add some style and make it dance
862
+				$this->add_styles_and_scripts($this);
863
+				EED_Single_Page_Checkout::$_initialized = true;
864
+				return false;
865
+			}
866
+			// and the registrations for the transaction
867
+			$this->_get_registrations($this->checkout->transaction);
868
+		}
869
+		return true;
870
+	}
871
+
872
+
873
+	/**
874
+	 * _get_transaction_and_cart_for_previous_visit
875
+	 *
876
+	 * @return EE_Transaction|null
877
+	 * @throws EE_Error
878
+	 * @throws ReflectionException
879
+	 */
880
+	private function _get_transaction_and_cart_for_previous_visit()
881
+	{
882
+		/** @var $TXN_model EEM_Transaction */
883
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
884
+		// because the reg_url_link is present in the request,
885
+		// this is a return visit to SPCO, so we'll get the transaction data from the db
886
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
887
+		// verify transaction
888
+		if ($transaction instanceof EE_Transaction) {
889
+			// and get the cart that was used for that transaction
890
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
891
+			return $transaction;
892
+		}
893
+		EE_Error::add_error(
894
+			esc_html__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
895
+			__FILE__,
896
+			__FUNCTION__,
897
+			__LINE__
898
+		);
899
+		return null;
900
+	}
901
+
902
+
903
+	/**
904
+	 * _get_cart_for_transaction
905
+	 *
906
+	 * @param EE_Transaction $transaction
907
+	 * @return EE_Cart
908
+	 */
909
+	private function _get_cart_for_transaction($transaction)
910
+	{
911
+		return $this->checkout->get_cart_for_transaction($transaction);
912
+	}
913
+
914
+
915
+	/**
916
+	 * get_cart_for_transaction
917
+	 *
918
+	 * @param EE_Transaction $transaction
919
+	 * @return EE_Cart
920
+	 */
921
+	public function get_cart_for_transaction(EE_Transaction $transaction)
922
+	{
923
+		return $this->checkout->get_cart_for_transaction($transaction);
924
+	}
925
+
926
+
927
+	/**
928
+	 * _get_transaction_and_cart_for_current_session
929
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
930
+	 *
931
+	 * @return EE_Transaction
932
+	 * @throws EE_Error
933
+	 * @throws ReflectionException
934
+	 */
935
+	private function _get_cart_for_current_session_and_setup_new_transaction()
936
+	{
937
+		//  if there's no transaction, then this is the FIRST visit to SPCO
938
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
939
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
940
+		// and then create a new transaction
941
+		$transaction = $this->_initialize_transaction();
942
+		// verify transaction
943
+		if ($transaction instanceof EE_Transaction) {
944
+			// save it so that we have an ID for other objects to use
945
+			$transaction->save();
946
+			// and save TXN data to the cart
947
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
948
+		} else {
949
+			EE_Error::add_error(
950
+				esc_html__('A Valid Transaction could not be initialized.', 'event_espresso'),
951
+				__FILE__,
952
+				__FUNCTION__,
953
+				__LINE__
954
+			);
955
+		}
956
+		return $transaction;
957
+	}
958
+
959
+
960
+	/**
961
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
962
+	 *
963
+	 * @return EE_Transaction|null
964
+	 */
965
+	private function _initialize_transaction()
966
+	{
967
+		try {
968
+			// ensure cart totals have been calculated
969
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
970
+			// grab the cart grand total
971
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
972
+			// create new TXN
973
+			$transaction = EE_Transaction::new_instance(
974
+				array(
975
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
976
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
977
+					'TXN_paid'      => 0,
978
+					'STS_ID'        => EEM_Transaction::failed_status_code,
979
+				)
980
+			);
981
+			// save it so that we have an ID for other objects to use
982
+			$transaction->save();
983
+			// set cron job for following up on TXNs after their session has expired
984
+			EE_Cron_Tasks::schedule_expired_transaction_check(
985
+				EE_Registry::instance()->SSN->expiration() + 1,
986
+				$transaction->ID()
987
+			);
988
+			return $transaction;
989
+		} catch (Exception $e) {
990
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
991
+		}
992
+		return null;
993
+	}
994
+
995
+
996
+	/**
997
+	 * _get_registrations
998
+	 *
999
+	 * @param EE_Transaction $transaction
1000
+	 * @return void
1001
+	 * @throws EE_Error
1002
+	 * @throws ReflectionException
1003
+	 */
1004
+	private function _get_registrations(EE_Transaction $transaction)
1005
+	{
1006
+		// first step: grab the registrants  { : o
1007
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params);
1008
+		$this->checkout->total_ticket_count = count($registrations);
1009
+		// verify registrations have been set
1010
+		if (empty($registrations)) {
1011
+			// if no cached registrations, then check the db
1012
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params);
1013
+			// still nothing ? well as long as this isn't a revisit
1014
+			if (empty($registrations) && ! $this->checkout->revisit) {
1015
+				// generate new registrations from scratch
1016
+				$registrations = $this->_initialize_registrations($transaction);
1017
+			}
1018
+		}
1019
+		// sort by their original registration order
1020
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1021
+		// then loop thru the array
1022
+		foreach ($registrations as $registration) {
1023
+			// verify each registration
1024
+			if ($registration instanceof EE_Registration) {
1025
+				// we display all attendee info for the primary registrant
1026
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
1027
+					&& $registration->is_primary_registrant()
1028
+				) {
1029
+					$this->checkout->primary_revisit = true;
1030
+					break;
1031
+				}
1032
+				if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1033
+					// but hide info if it doesn't belong to you
1034
+					$transaction->clear_cache('Registration', $registration->ID());
1035
+					$this->checkout->total_ticket_count--;
1036
+				}
1037
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1038
+			}
1039
+		}
1040
+	}
1041
+
1042
+
1043
+	/**
1044
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1045
+	 *
1046
+	 * @param EE_Transaction $transaction
1047
+	 * @return    array
1048
+	 * @throws EE_Error
1049
+	 * @throws ReflectionException
1050
+	 */
1051
+	private function _initialize_registrations(EE_Transaction $transaction)
1052
+	{
1053
+		$att_nmbr = 0;
1054
+		$registrations = array();
1055
+		if ($transaction instanceof EE_Transaction) {
1056
+			/** @type EE_Registration_Processor $registration_processor */
1057
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1058
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1059
+			// now let's add the cart items to the $transaction
1060
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1061
+				// do the following for each ticket of this type they selected
1062
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1063
+					$att_nmbr++;
1064
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1065
+					$CreateRegistrationCommand = EE_Registry::instance()->create(
1066
+						'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1067
+						array(
1068
+							$transaction,
1069
+							$line_item,
1070
+							$att_nmbr,
1071
+							$this->checkout->total_ticket_count,
1072
+						)
1073
+					);
1074
+					// override capabilities for frontend registrations
1075
+					if (! is_admin()) {
1076
+						$CreateRegistrationCommand->setCapCheck(
1077
+							new PublicCapabilities('', 'create_new_registration')
1078
+						);
1079
+					}
1080
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1081
+					if (! $registration instanceof EE_Registration) {
1082
+						throw new InvalidEntityException($registration, 'EE_Registration');
1083
+					}
1084
+					$registrations[ $registration->ID() ] = $registration;
1085
+				}
1086
+			}
1087
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1088
+		}
1089
+		return $registrations;
1090
+	}
1091
+
1092
+
1093
+	/**
1094
+	 * sorts registrations by REG_count
1095
+	 *
1096
+	 * @param EE_Registration $reg_A
1097
+	 * @param EE_Registration $reg_B
1098
+	 * @return int
1099
+	 */
1100
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1101
+	{
1102
+		// this shouldn't ever happen within the same TXN, but oh well
1103
+		if ($reg_A->count() === $reg_B->count()) {
1104
+			return 0;
1105
+		}
1106
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1107
+	}
1108
+
1109
+
1110
+	/**
1111
+	 *    _final_verifications
1112
+	 * just makes sure that everything is set up correctly before proceeding
1113
+	 *
1114
+	 * @return    bool
1115
+	 * @throws EE_Error
1116
+	 * @throws ReflectionException
1117
+	 */
1118
+	private function _final_verifications()
1119
+	{
1120
+		// filter checkout
1121
+		$this->checkout = apply_filters(
1122
+			'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1123
+			$this->checkout
1124
+		);
1125
+		// verify that current step is still set correctly
1126
+		if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1127
+			EE_Error::add_error(
1128
+				esc_html__(
1129
+					'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.',
1130
+					'event_espresso'
1131
+				),
1132
+				__FILE__,
1133
+				__FUNCTION__,
1134
+				__LINE__
1135
+			);
1136
+			return false;
1137
+		}
1138
+		// if returning to SPCO, then verify that primary registrant is set
1139
+		if (! empty($this->checkout->reg_url_link)) {
1140
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1141
+			if (! $valid_registrant instanceof EE_Registration) {
1142
+				EE_Error::add_error(
1143
+					esc_html__(
1144
+						'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.',
1145
+						'event_espresso'
1146
+					),
1147
+					__FILE__,
1148
+					__FUNCTION__,
1149
+					__LINE__
1150
+				);
1151
+				return false;
1152
+			}
1153
+			$valid_registrant = null;
1154
+			foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1155
+				if ($registration instanceof EE_Registration
1156
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1157
+				) {
1158
+					$valid_registrant = $registration;
1159
+				}
1160
+			}
1161
+			if (! $valid_registrant instanceof EE_Registration) {
1162
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1163
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1164
+					// clear the session, mark the checkout as unverified, and try again
1165
+					EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1166
+					EED_Single_Page_Checkout::$_initialized = false;
1167
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1168
+					$this->_initialize();
1169
+					EE_Error::reset_notices();
1170
+					return false;
1171
+				}
1172
+				EE_Error::add_error(
1173
+					esc_html__(
1174
+						'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1175
+						'event_espresso'
1176
+					),
1177
+					__FILE__,
1178
+					__FUNCTION__,
1179
+					__LINE__
1180
+				);
1181
+				return false;
1182
+			}
1183
+		}
1184
+		// now that things have been kinda sufficiently verified,
1185
+		// let's add the checkout to the session so that it's available to other systems
1186
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1187
+		return true;
1188
+	}
1189
+
1190
+
1191
+	/**
1192
+	 *    _initialize_reg_steps
1193
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1194
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1195
+	 *
1196
+	 * @param bool $reinitializing
1197
+	 * @throws EE_Error
1198
+	 */
1199
+	private function _initialize_reg_steps($reinitializing = false)
1200
+	{
1201
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1202
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1203
+		foreach ($this->checkout->reg_steps as $reg_step) {
1204
+			if (! $reg_step->initialize_reg_step()) {
1205
+				// if not initialized then maybe this step is being removed...
1206
+				if (! $reinitializing && $reg_step->is_current_step()) {
1207
+					// if it was the current step, then we need to start over here
1208
+					$this->_initialize_reg_steps(true);
1209
+					return;
1210
+				}
1211
+				continue;
1212
+			}
1213
+			// add css and JS for current step
1214
+			$this->add_styles_and_scripts($reg_step);
1215
+			if ($reg_step->is_current_step()) {
1216
+				// the text that appears on the reg step form submit button
1217
+				$reg_step->set_submit_button_text();
1218
+			}
1219
+		}
1220
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1221
+		do_action(
1222
+			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1223
+			$this->checkout->current_step
1224
+		);
1225
+	}
1226
+
1227
+
1228
+	/**
1229
+	 * _check_form_submission
1230
+	 *
1231
+	 * @return boolean
1232
+	 * @throws EE_Error
1233
+	 * @throws ReflectionException
1234
+	 */
1235
+	private function _check_form_submission()
1236
+	{
1237
+		// does this request require the reg form to be generated ?
1238
+		if ($this->checkout->generate_reg_form) {
1239
+			// ever heard that song by Blue Rodeo ?
1240
+			try {
1241
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1242
+				// if not displaying a form, then check for form submission
1243
+				if ($this->checkout->process_form_submission
1244
+					&& $this->checkout->current_step->reg_form->was_submitted()
1245
+				) {
1246
+					// clear out any old data in case this step is being run again
1247
+					$this->checkout->current_step->set_valid_data(array());
1248
+					// capture submitted form data
1249
+					$request_data = $this->request->requestParams();
1250
+					$this->checkout->current_step->reg_form->receive_form_submission(
1251
+						(array) apply_filters(
1252
+							'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1253
+							$request_data,
1254
+							$this->checkout
1255
+						)
1256
+					);
1257
+					// validate submitted form data
1258
+					if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1259
+						// thou shall not pass !!!
1260
+						$this->checkout->continue_reg = false;
1261
+						// any form validation errors?
1262
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1263
+							EE_Error::add_error(
1264
+								$this->checkout->current_step->reg_form->submission_error_message(),
1265
+								__FILE__,
1266
+								__FUNCTION__,
1267
+								__LINE__
1268
+							);
1269
+						}
1270
+						// well not really... what will happen is
1271
+						// we'll just get redirected back to redo the current step
1272
+						$this->go_to_next_step();
1273
+						return false;
1274
+					}
1275
+				}
1276
+			} catch (EE_Error $e) {
1277
+				$e->get_error();
1278
+			}
1279
+		}
1280
+		return true;
1281
+	}
1282
+
1283
+
1284
+	/**
1285
+	 * _process_action
1286
+	 *
1287
+	 * @return void
1288
+	 * @throws EE_Error
1289
+	 * @throws ReflectionException
1290
+	 */
1291
+	private function _process_form_action()
1292
+	{
1293
+		// what cha wanna do?
1294
+		switch ($this->checkout->action) {
1295
+			// AJAX next step reg form
1296
+			case 'display_spco_reg_step':
1297
+				$this->checkout->redirect = false;
1298
+				if ($this->request->isAjax()) {
1299
+					$this->checkout->json_response->set_reg_step_html(
1300
+						$this->checkout->current_step->display_reg_form()
1301
+					);
1302
+				}
1303
+				break;
1304
+			default:
1305
+				// meh... do one of those other steps first
1306
+				if (! empty($this->checkout->action)
1307
+					&& is_callable(array($this->checkout->current_step, $this->checkout->action))
1308
+				) {
1309
+					// dynamically creates hook point like:
1310
+					//   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1311
+					do_action(
1312
+						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1313
+						$this->checkout->current_step
1314
+					);
1315
+					$process_reg_step = apply_filters(
1316
+						"AHEE__Single_Page_Checkout__process_reg_step__{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1317
+						true,
1318
+						$this->checkout->current_step,
1319
+						$this
1320
+					);
1321
+					// call action on current step
1322
+					if ($process_reg_step && call_user_func([$this->checkout->current_step, $this->checkout->action])) {
1323
+						// good registrant, you get to proceed
1324
+						if ($this->checkout->current_step->success_message() !== ''
1325
+							&& apply_filters(
1326
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1327
+								false
1328
+							)
1329
+						) {
1330
+							EE_Error::add_success(
1331
+								$this->checkout->current_step->success_message()
1332
+								. '<br />' . $this->checkout->next_step->_instructions()
1333
+							);
1334
+						}
1335
+						// pack it up, pack it in...
1336
+						$this->_setup_redirect();
1337
+					}
1338
+					// dynamically creates hook point like:
1339
+					//  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1340
+					do_action(
1341
+						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1342
+						$this->checkout->current_step
1343
+					);
1344
+				} else {
1345
+					EE_Error::add_error(
1346
+						sprintf(
1347
+							esc_html__(
1348
+								'The requested form action "%s" does not exist for the current "%s" registration step.',
1349
+								'event_espresso'
1350
+							),
1351
+							$this->checkout->action,
1352
+							$this->checkout->current_step->name()
1353
+						),
1354
+						__FILE__,
1355
+						__FUNCTION__,
1356
+						__LINE__
1357
+					);
1358
+				}
1359
+			// end default
1360
+		}
1361
+		// store our progress so far
1362
+		$this->checkout->stash_transaction_and_checkout();
1363
+		// advance to the next step! If you pass GO, collect $200
1364
+		$this->go_to_next_step();
1365
+	}
1366
+
1367
+
1368
+	/**
1369
+	 * @param EED_Single_Page_Checkout|EE_SPCO_Reg_Step $target an object with the method `translate_js_strings` and
1370
+	 *                                                          `enqueue_styles_and_scripts`.
1371
+	 * @return        void
1372
+	 */
1373
+	public function add_styles_and_scripts($target)
1374
+	{
1375
+		// i18n
1376
+		$target->translate_js_strings();
1377
+		if ($this->checkout->admin_request) {
1378
+			add_action('admin_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1379
+		} else {
1380
+			add_action('wp_enqueue_scripts', array($target, 'enqueue_styles_and_scripts'), 10);
1381
+		}
1382
+	}
1383
+
1384
+	/**
1385
+	 *        translate_js_strings
1386
+	 *
1387
+	 * @return        void
1388
+	 */
1389
+	public function translate_js_strings()
1390
+	{
1391
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1392
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1393
+		EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
1394
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1395
+			'event_espresso'
1396
+		);
1397
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = esc_html__(
1398
+			'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1399
+			'event_espresso'
1400
+		);
1401
+		EE_Registry::$i18n_js_strings['validation_error'] = esc_html__(
1402
+			'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1403
+			'event_espresso'
1404
+		);
1405
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
1406
+			'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1407
+			'event_espresso'
1408
+		);
1409
+		EE_Registry::$i18n_js_strings['reg_step_error'] = esc_html__(
1410
+			'This registration step could not be completed. Please refresh the page and try again.',
1411
+			'event_espresso'
1412
+		);
1413
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = esc_html__(
1414
+			'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1415
+			'event_espresso'
1416
+		);
1417
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1418
+			esc_html__(
1419
+				'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1420
+				'event_espresso'
1421
+			),
1422
+			'<br/>',
1423
+			'<br/>'
1424
+		);
1425
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1426
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1427
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1428
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1429
+		EE_Registry::$i18n_js_strings['timer_years'] = esc_html__('years', 'event_espresso');
1430
+		EE_Registry::$i18n_js_strings['timer_months'] = esc_html__('months', 'event_espresso');
1431
+		EE_Registry::$i18n_js_strings['timer_weeks'] = esc_html__('weeks', 'event_espresso');
1432
+		EE_Registry::$i18n_js_strings['timer_days'] = esc_html__('days', 'event_espresso');
1433
+		EE_Registry::$i18n_js_strings['timer_hours'] = esc_html__('hours', 'event_espresso');
1434
+		EE_Registry::$i18n_js_strings['timer_minutes'] = esc_html__('minutes', 'event_espresso');
1435
+		EE_Registry::$i18n_js_strings['timer_seconds'] = esc_html__('seconds', 'event_espresso');
1436
+		EE_Registry::$i18n_js_strings['timer_year'] = esc_html__('year', 'event_espresso');
1437
+		EE_Registry::$i18n_js_strings['timer_month'] = esc_html__('month', 'event_espresso');
1438
+		EE_Registry::$i18n_js_strings['timer_week'] = esc_html__('week', 'event_espresso');
1439
+		EE_Registry::$i18n_js_strings['timer_day'] = esc_html__('day', 'event_espresso');
1440
+		EE_Registry::$i18n_js_strings['timer_hour'] = esc_html__('hour', 'event_espresso');
1441
+		EE_Registry::$i18n_js_strings['timer_minute'] = esc_html__('minute', 'event_espresso');
1442
+		EE_Registry::$i18n_js_strings['timer_second'] = esc_html__('second', 'event_espresso');
1443
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
1444
+		);
1445
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1446
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1447
+			true
1448
+		);
1449
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1450
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1451
+		);
1452
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1453
+			'M d, Y H:i:s',
1454
+			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1455
+		);
1456
+	}
1457
+
1458
+
1459
+	/**
1460
+	 *    enqueue_styles_and_scripts
1461
+	 *
1462
+	 * @return        void
1463
+	 * @throws EE_Error
1464
+	 */
1465
+	public function enqueue_styles_and_scripts()
1466
+	{
1467
+		// load css
1468
+		wp_register_style(
1469
+			'single_page_checkout',
1470
+			SPCO_CSS_URL . 'single_page_checkout.css',
1471
+			array('espresso_default'),
1472
+			EVENT_ESPRESSO_VERSION
1473
+		);
1474
+		wp_enqueue_style('single_page_checkout');
1475
+		// load JS
1476
+		wp_register_script(
1477
+			'jquery_plugin',
1478
+			EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1479
+			array('jquery'),
1480
+			'1.0.1',
1481
+			true
1482
+		);
1483
+		wp_register_script(
1484
+			'jquery_countdown',
1485
+			EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1486
+			array('jquery_plugin'),
1487
+			'2.1.0',
1488
+			true
1489
+		);
1490
+		wp_register_script(
1491
+			'single_page_checkout',
1492
+			SPCO_JS_URL . 'single_page_checkout.js',
1493
+			array('espresso_core', 'underscore', 'ee_form_section_validation'),
1494
+			EVENT_ESPRESSO_VERSION,
1495
+			true
1496
+		);
1497
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1498
+			$this->checkout->registration_form->enqueue_js();
1499
+		}
1500
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1501
+			$this->checkout->current_step->reg_form->enqueue_js();
1502
+		}
1503
+		wp_enqueue_script('single_page_checkout');
1504
+		if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) {
1505
+			wp_enqueue_script('jquery_countdown');
1506
+		}
1507
+		/**
1508
+		 * global action hook for enqueueing styles and scripts with
1509
+		 * spco calls.
1510
+		 */
1511
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1512
+		/**
1513
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1514
+		 * The hook will end up being something like:
1515
+		 *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1516
+		 */
1517
+		do_action(
1518
+			'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1519
+			$this
1520
+		);
1521
+	}
1522
+
1523
+
1524
+	/**
1525
+	 *    display the Registration Single Page Checkout Form
1526
+	 *
1527
+	 * @return    void
1528
+	 * @throws EE_Error
1529
+	 * @throws ReflectionException
1530
+	 */
1531
+	private function _display_spco_reg_form()
1532
+	{
1533
+		// if registering via the admin, just display the reg form for the current step
1534
+		if ($this->checkout->admin_request) {
1535
+			EED_Single_Page_Checkout::getResponse()->addOutput($this->checkout->current_step->display_reg_form());
1536
+		} else {
1537
+			// add powered by EE msg
1538
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1539
+			$empty_cart = count($this->checkout->transaction
1540
+									->registrations($this->checkout->reg_cache_where_params)) < 1;
1541
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1542
+			$cookies_not_set_msg = '';
1543
+			if ($empty_cart) {
1544
+				$cookies_not_set_msg = apply_filters(
1545
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1546
+					sprintf(
1547
+						esc_html__(
1548
+							'%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1549
+							'event_espresso'
1550
+						),
1551
+						'<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1552
+						'</div>',
1553
+						'<h6 class="important-notice">',
1554
+						'</h6>',
1555
+						'<p>',
1556
+						'</p>',
1557
+						'<br />',
1558
+						'<a href="https://www.whatismybrowser.com/guides/how-to-enable-cookies/" target="_blank" rel="noopener noreferrer">',
1559
+						'</a>'
1560
+					)
1561
+				);
1562
+			}
1563
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1564
+				array(
1565
+					'name'            => 'single-page-checkout',
1566
+					'html_id'         => 'ee-single-page-checkout-dv',
1567
+					'layout_strategy' =>
1568
+						new EE_Template_Layout(
1569
+							array(
1570
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1571
+								'template_args'        => array(
1572
+									'empty_cart'              => $empty_cart,
1573
+									'revisit'                 => $this->checkout->revisit,
1574
+									'reg_steps'               => $this->checkout->reg_steps,
1575
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1576
+										? $this->checkout->next_step->slug()
1577
+										: '',
1578
+									'empty_msg'               => apply_filters(
1579
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1580
+										sprintf(
1581
+											esc_html__(
1582
+												'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1583
+												'event_espresso'
1584
+											),
1585
+											'<a href="'
1586
+											. get_post_type_archive_link('espresso_events')
1587
+											. '" title="',
1588
+											'">',
1589
+											'</a>'
1590
+										)
1591
+									),
1592
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1593
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1594
+									'session_expiration'      => gmdate(
1595
+										'M d, Y H:i:s',
1596
+										EE_Registry::instance()->SSN->expiration()
1597
+										+ (get_option('gmt_offset') * HOUR_IN_SECONDS)
1598
+									),
1599
+								),
1600
+							)
1601
+						),
1602
+				)
1603
+			);
1604
+			// load template and add to output sent that gets filtered into the_content()
1605
+			EED_Single_Page_Checkout::getResponse()->addOutput($this->checkout->registration_form->get_html());
1606
+		}
1607
+	}
1608
+
1609
+
1610
+	/**
1611
+	 *    add_extra_finalize_registration_inputs
1612
+	 *
1613
+	 * @param $next_step
1614
+	 * @internal  param string $label
1615
+	 * @return void
1616
+	 */
1617
+	public function add_extra_finalize_registration_inputs($next_step)
1618
+	{
1619
+		if ($next_step === 'finalize_registration') {
1620
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1621
+		}
1622
+	}
1623
+
1624
+
1625
+	/**
1626
+	 *    display_registration_footer
1627
+	 *
1628
+	 * @return    string
1629
+	 */
1630
+	public static function display_registration_footer()
1631
+	{
1632
+		if (apply_filters(
1633
+			'FHEE__EE_Front__Controller__show_reg_footer',
1634
+			EE_Registry::instance()->CFG->admin->show_reg_footer
1635
+		)) {
1636
+			add_filter(
1637
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1638
+				function ($url) {
1639
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1640
+				}
1641
+			);
1642
+			echo apply_filters(
1643
+				'FHEE__EE_Front_Controller__display_registration_footer',
1644
+				EEH_Template::powered_by_event_espresso(
1645
+					'',
1646
+					'espresso-registration-footer-dv',
1647
+					array('utm_content' => 'registration_checkout')
1648
+				)
1649
+			);
1650
+		}
1651
+		return '';
1652
+	}
1653
+
1654
+
1655
+	/**
1656
+	 *    unlock_transaction
1657
+	 *
1658
+	 * @return    void
1659
+	 * @throws EE_Error
1660
+	 * @throws ReflectionException
1661
+	 */
1662
+	public function unlock_transaction()
1663
+	{
1664
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1665
+			$this->checkout->transaction->unlock();
1666
+		}
1667
+	}
1668
+
1669
+
1670
+	/**
1671
+	 *        _setup_redirect
1672
+	 *
1673
+	 * @return void
1674
+	 */
1675
+	private function _setup_redirect()
1676
+	{
1677
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1678
+			$this->checkout->redirect = true;
1679
+			if (empty($this->checkout->redirect_url)) {
1680
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1681
+			}
1682
+			$this->checkout->redirect_url = apply_filters(
1683
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1684
+				$this->checkout->redirect_url,
1685
+				$this->checkout
1686
+			);
1687
+		}
1688
+	}
1689
+
1690
+
1691
+	/**
1692
+	 *   handle ajax message responses and redirects
1693
+	 *
1694
+	 * @return void
1695
+	 * @throws EE_Error
1696
+	 * @throws ReflectionException
1697
+	 */
1698
+	public function go_to_next_step()
1699
+	{
1700
+		if ($this->request->isAjax()) {
1701
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1702
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1703
+		}
1704
+		$this->unlock_transaction();
1705
+		// just return for these conditions
1706
+		if ($this->checkout->admin_request
1707
+			|| $this->checkout->action === 'redirect_form'
1708
+			|| $this->checkout->action === 'update_checkout'
1709
+		) {
1710
+			return;
1711
+		}
1712
+		// AJAX response
1713
+		$this->_handle_json_response();
1714
+		// redirect to next step or the Thank You page
1715
+		$this->_handle_html_redirects();
1716
+		// hmmm... must be something wrong, so let's just display the form again !
1717
+		$this->_display_spco_reg_form();
1718
+	}
1719
+
1720
+
1721
+	/**
1722
+	 *   _handle_json_response
1723
+	 *
1724
+	 * @return void
1725
+	 * @throws EE_Error
1726
+	 */
1727
+	protected function _handle_json_response()
1728
+	{
1729
+		// if this is an ajax request
1730
+		if ($this->request->isAjax()) {
1731
+			$this->checkout->json_response->set_registration_time_limit(
1732
+				$this->checkout->get_registration_time_limit()
1733
+			);
1734
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1735
+			// just send the ajax (
1736
+			$json_response = apply_filters(
1737
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1738
+				$this->checkout->json_response
1739
+			);
1740
+			echo $json_response;
1741
+			exit();
1742
+		}
1743
+	}
1744
+
1745
+
1746
+	/**
1747
+	 *   _handle_redirects
1748
+	 *
1749
+	 * @return void
1750
+	 */
1751
+	protected function _handle_html_redirects()
1752
+	{
1753
+		// going somewhere ?
1754
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1755
+			// store notices in a transient
1756
+			EE_Error::get_notices(false, true);
1757
+			wp_safe_redirect($this->checkout->redirect_url);
1758
+			exit();
1759
+		}
1760
+	}
1761
+
1762
+
1763
+	/**
1764
+	 *   set_checkout_anchor
1765
+	 *
1766
+	 * @return void
1767
+	 */
1768
+	public function set_checkout_anchor()
1769
+	{
1770
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1771
+	}
1772
+
1773
+	/**
1774
+	 *    getRegistrationExpirationNotice
1775
+	 *
1776
+	 * @since     4.9.59.p
1777
+	 * @return    string
1778
+	 */
1779
+	public static function getRegistrationExpirationNotice()
1780
+	{
1781
+		return sprintf(
1782
+			esc_html__(
1783
+				'%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1784
+				'event_espresso'
1785
+			),
1786
+			'<h4 class="important-notice">',
1787
+			'</h4>',
1788
+			'<br />',
1789
+			'<p>',
1790
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1791
+			'">',
1792
+			'</a>',
1793
+			'</p>'
1794
+		);
1795
+	}
1796 1796
 }
Please login to merge, or discard this patch.
modules/ticket_selector/ProcessTicketSelector.php 2 patches
Indentation   +491 added lines, -491 removed lines patch added patch discarded remove patch
@@ -33,520 +33,520 @@
 block discarded – undo
33 33
 class ProcessTicketSelector
34 34
 {
35 35
 
36
-    /**
37
-     * @var EE_Cart $cart
38
-     */
39
-    private $cart;
36
+	/**
37
+	 * @var EE_Cart $cart
38
+	 */
39
+	private $cart;
40 40
 
41
-    /**
42
-     * @var EE_Core_Config $core_config
43
-     */
44
-    private $core_config;
41
+	/**
42
+	 * @var EE_Core_Config $core_config
43
+	 */
44
+	private $core_config;
45 45
 
46
-    /**
47
-     * @var RequestInterface $request
48
-     */
49
-    private $request;
46
+	/**
47
+	 * @var RequestInterface $request
48
+	 */
49
+	private $request;
50 50
 
51
-    /**
52
-     * @var EE_Session $session
53
-     */
54
-    private $session;
51
+	/**
52
+	 * @var EE_Session $session
53
+	 */
54
+	private $session;
55 55
 
56
-    /**
57
-     * @var EEM_Ticket $ticket_model
58
-     */
59
-    private $ticket_model;
56
+	/**
57
+	 * @var EEM_Ticket $ticket_model
58
+	 */
59
+	private $ticket_model;
60 60
 
61
-    /**
62
-     * @var TicketDatetimeAvailabilityTracker $tracker
63
-     */
64
-    private $tracker;
61
+	/**
62
+	 * @var TicketDatetimeAvailabilityTracker $tracker
63
+	 */
64
+	private $tracker;
65 65
 
66 66
 
67
-    /**
68
-     * ProcessTicketSelector constructor.
69
-     * NOTE: PLZ use the Loader to instantiate this class if need be
70
-     * so that all dependencies get injected correctly (which will happen automatically)
71
-     * Null values for parameters are only for backwards compatibility but will be removed later on.
72
-     *
73
-     * @param EE_Core_Config                    $core_config
74
-     * @param RequestInterface                           $request
75
-     * @param EE_Session                        $session
76
-     * @param EEM_Ticket                        $ticket_model
77
-     * @param TicketDatetimeAvailabilityTracker $tracker
78
-     * @throws InvalidArgumentException
79
-     * @throws InvalidDataTypeException
80
-     * @throws InvalidInterfaceException
81
-     */
82
-    public function __construct(
83
-        EE_Core_Config $core_config = null,
84
-        RequestInterface $request = null,
85
-        EE_Session $session = null,
86
-        EEM_Ticket $ticket_model = null,
87
-        TicketDatetimeAvailabilityTracker $tracker = null
88
-    ) {
89
-        $loader = LoaderFactory::getLoader();
90
-        $this->core_config = $core_config instanceof EE_Core_Config
91
-            ? $core_config
92
-            : $loader->getShared('EE_Core_Config');
93
-        $this->request = $request instanceof RequestInterface
94
-            ? $request
95
-            : $loader->getShared('EventEspresso\core\services\request\Request');
96
-        $this->session = $session instanceof EE_Session
97
-            ? $session
98
-            : $loader->getShared('EE_Session');
99
-        $this->ticket_model = $ticket_model instanceof EEM_Ticket
100
-            ? $ticket_model
101
-            : $loader->getShared('EEM_Ticket');
102
-        $this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker
103
-            ? $tracker
104
-            : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker');
105
-    }
67
+	/**
68
+	 * ProcessTicketSelector constructor.
69
+	 * NOTE: PLZ use the Loader to instantiate this class if need be
70
+	 * so that all dependencies get injected correctly (which will happen automatically)
71
+	 * Null values for parameters are only for backwards compatibility but will be removed later on.
72
+	 *
73
+	 * @param EE_Core_Config                    $core_config
74
+	 * @param RequestInterface                           $request
75
+	 * @param EE_Session                        $session
76
+	 * @param EEM_Ticket                        $ticket_model
77
+	 * @param TicketDatetimeAvailabilityTracker $tracker
78
+	 * @throws InvalidArgumentException
79
+	 * @throws InvalidDataTypeException
80
+	 * @throws InvalidInterfaceException
81
+	 */
82
+	public function __construct(
83
+		EE_Core_Config $core_config = null,
84
+		RequestInterface $request = null,
85
+		EE_Session $session = null,
86
+		EEM_Ticket $ticket_model = null,
87
+		TicketDatetimeAvailabilityTracker $tracker = null
88
+	) {
89
+		$loader = LoaderFactory::getLoader();
90
+		$this->core_config = $core_config instanceof EE_Core_Config
91
+			? $core_config
92
+			: $loader->getShared('EE_Core_Config');
93
+		$this->request = $request instanceof RequestInterface
94
+			? $request
95
+			: $loader->getShared('EventEspresso\core\services\request\Request');
96
+		$this->session = $session instanceof EE_Session
97
+			? $session
98
+			: $loader->getShared('EE_Session');
99
+		$this->ticket_model = $ticket_model instanceof EEM_Ticket
100
+			? $ticket_model
101
+			: $loader->getShared('EEM_Ticket');
102
+		$this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker
103
+			? $tracker
104
+			: $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker');
105
+	}
106 106
 
107 107
 
108
-    /**
109
-     * cancelTicketSelections
110
-     *
111
-     * @return bool
112
-     * @throws EE_Error
113
-     * @throws InvalidArgumentException
114
-     * @throws InvalidInterfaceException
115
-     * @throws InvalidDataTypeException
116
-     * @throws ReflectionException
117
-     */
118
-    public function cancelTicketSelections()
119
-    {
120
-        // check nonce
121
-        if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
122
-            return false;
123
-        }
124
-        $this->session->clear_session(__CLASS__, __FUNCTION__);
125
-        if ($this->request->requestParamIsSet('event_id')) {
126
-            EEH_URL::safeRedirectAndExit(
127
-                EEH_Event_View::event_link_url(
128
-                    $this->request->getRequestParam('event_id', 0, 'int')
129
-                )
130
-            );
131
-        }
132
-        EEH_URL::safeRedirectAndExit(
133
-            site_url('/' . $this->core_config->event_cpt_slug . '/')
134
-        );
135
-        return true;
136
-    }
108
+	/**
109
+	 * cancelTicketSelections
110
+	 *
111
+	 * @return bool
112
+	 * @throws EE_Error
113
+	 * @throws InvalidArgumentException
114
+	 * @throws InvalidInterfaceException
115
+	 * @throws InvalidDataTypeException
116
+	 * @throws ReflectionException
117
+	 */
118
+	public function cancelTicketSelections()
119
+	{
120
+		// check nonce
121
+		if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
122
+			return false;
123
+		}
124
+		$this->session->clear_session(__CLASS__, __FUNCTION__);
125
+		if ($this->request->requestParamIsSet('event_id')) {
126
+			EEH_URL::safeRedirectAndExit(
127
+				EEH_Event_View::event_link_url(
128
+					$this->request->getRequestParam('event_id', 0, 'int')
129
+				)
130
+			);
131
+		}
132
+		EEH_URL::safeRedirectAndExit(
133
+			site_url('/' . $this->core_config->event_cpt_slug . '/')
134
+		);
135
+		return true;
136
+	}
137 137
 
138 138
 
139
-    /**
140
-     * processTicketSelectorNonce
141
-     *
142
-     * @param  string $nonce_name
143
-     * @param string  $id
144
-     * @return bool
145
-     */
146
-    private function processTicketSelectorNonce($nonce_name, $id = '')
147
-    {
148
-        $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
149
-        if (! $this->request->isAdmin()
150
-            && (
151
-                ! $this->request->requestParamIsSet($nonce_name_with_id)
152
-                || ! wp_verify_nonce(
153
-                    $this->request->getRequestParam($nonce_name_with_id),
154
-                    $nonce_name
155
-                )
156
-            )
157
-        ) {
158
-            EE_Error::add_error(
159
-                sprintf(
160
-                    esc_html__(
161
-                        'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
162
-                        'event_espresso'
163
-                    ),
164
-                    '<br/>'
165
-                ),
166
-                __FILE__,
167
-                __FUNCTION__,
168
-                __LINE__
169
-            );
170
-            return false;
171
-        }
172
-        return true;
173
-    }
139
+	/**
140
+	 * processTicketSelectorNonce
141
+	 *
142
+	 * @param  string $nonce_name
143
+	 * @param string  $id
144
+	 * @return bool
145
+	 */
146
+	private function processTicketSelectorNonce($nonce_name, $id = '')
147
+	{
148
+		$nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
149
+		if (! $this->request->isAdmin()
150
+			&& (
151
+				! $this->request->requestParamIsSet($nonce_name_with_id)
152
+				|| ! wp_verify_nonce(
153
+					$this->request->getRequestParam($nonce_name_with_id),
154
+					$nonce_name
155
+				)
156
+			)
157
+		) {
158
+			EE_Error::add_error(
159
+				sprintf(
160
+					esc_html__(
161
+						'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
162
+						'event_espresso'
163
+					),
164
+					'<br/>'
165
+				),
166
+				__FILE__,
167
+				__FUNCTION__,
168
+				__LINE__
169
+			);
170
+			return false;
171
+		}
172
+		return true;
173
+	}
174 174
 
175 175
 
176
-    /**
177
-     * process_ticket_selections
178
-     *
179
-     * @return bool
180
-     * @throws EE_Error
181
-     * @throws InvalidArgumentException
182
-     * @throws InvalidDataTypeException
183
-     * @throws InvalidInterfaceException
184
-     * @throws ReflectionException
185
-     */
186
-    public function processTicketSelections()
187
-    {
188
-        do_action('EED_Ticket_Selector__process_ticket_selections__before');
189
-        if ($this->request->isBot()) {
190
-            EEH_URL::safeRedirectAndExit(
191
-                apply_filters(
192
-                    'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url',
193
-                    site_url()
194
-                )
195
-            );
196
-        }
197
-        // do we have an event id?
198
-        $id = $this->getEventId();
199
-        // we should really only have 1 registration in the works now
200
-        // (ie, no MER) so unless otherwise requested, clear the session
201
-        if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
202
-            $this->session->clear_session(__CLASS__, __FUNCTION__);
203
-        }
204
-        // validate/sanitize/filter data
205
-        $valid = apply_filters(
206
-            'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data',
207
-            $this->validatePostData($id)
208
-        );
209
-        // check total tickets ordered vs max number of attendees that can register
210
-        if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) {
211
-            $this->maxAttendeesViolation($valid);
212
-        } else {
213
-            // all data appears to be valid
214
-            if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) {
215
-                return true;
216
-            }
217
-        }
218
-        // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
219
-        // at this point, just return if registration is being made from admin
220
-        if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
221
-            return false;
222
-        }
223
-        if ($valid['return_url']) {
224
-            EEH_URL::safeRedirectAndExit($valid['return_url']);
225
-        }
226
-        if ($id) {
227
-            EEH_URL::safeRedirectAndExit(get_permalink($id));
228
-        }
229
-        echo EE_Error::get_notices();
230
-        return false;
231
-    }
176
+	/**
177
+	 * process_ticket_selections
178
+	 *
179
+	 * @return bool
180
+	 * @throws EE_Error
181
+	 * @throws InvalidArgumentException
182
+	 * @throws InvalidDataTypeException
183
+	 * @throws InvalidInterfaceException
184
+	 * @throws ReflectionException
185
+	 */
186
+	public function processTicketSelections()
187
+	{
188
+		do_action('EED_Ticket_Selector__process_ticket_selections__before');
189
+		if ($this->request->isBot()) {
190
+			EEH_URL::safeRedirectAndExit(
191
+				apply_filters(
192
+					'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url',
193
+					site_url()
194
+				)
195
+			);
196
+		}
197
+		// do we have an event id?
198
+		$id = $this->getEventId();
199
+		// we should really only have 1 registration in the works now
200
+		// (ie, no MER) so unless otherwise requested, clear the session
201
+		if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
202
+			$this->session->clear_session(__CLASS__, __FUNCTION__);
203
+		}
204
+		// validate/sanitize/filter data
205
+		$valid = apply_filters(
206
+			'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data',
207
+			$this->validatePostData($id)
208
+		);
209
+		// check total tickets ordered vs max number of attendees that can register
210
+		if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) {
211
+			$this->maxAttendeesViolation($valid);
212
+		} else {
213
+			// all data appears to be valid
214
+			if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) {
215
+				return true;
216
+			}
217
+		}
218
+		// die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
219
+		// at this point, just return if registration is being made from admin
220
+		if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
221
+			return false;
222
+		}
223
+		if ($valid['return_url']) {
224
+			EEH_URL::safeRedirectAndExit($valid['return_url']);
225
+		}
226
+		if ($id) {
227
+			EEH_URL::safeRedirectAndExit(get_permalink($id));
228
+		}
229
+		echo EE_Error::get_notices();
230
+		return false;
231
+	}
232 232
 
233 233
 
234
-    /**
235
-     * @return int
236
-     */
237
-    private function getEventId()
238
-    {
239
-        // do we have an event id?
240
-        if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
241
-            // $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
242
-            EE_Error::add_error(
243
-                sprintf(
244
-                    esc_html__(
245
-                        'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
246
-                        'event_espresso'
247
-                    ),
248
-                    '<br/>'
249
-                ),
250
-                __FILE__,
251
-                __FUNCTION__,
252
-                __LINE__
253
-            );
254
-        }
255
-        // if event id is valid
256
-        return $this->request->getRequestParam('tkt-slctr-event-id', 0, 'int');
257
-    }
234
+	/**
235
+	 * @return int
236
+	 */
237
+	private function getEventId()
238
+	{
239
+		// do we have an event id?
240
+		if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
241
+			// $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
242
+			EE_Error::add_error(
243
+				sprintf(
244
+					esc_html__(
245
+						'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
246
+						'event_espresso'
247
+					),
248
+					'<br/>'
249
+				),
250
+				__FILE__,
251
+				__FUNCTION__,
252
+				__LINE__
253
+			);
254
+		}
255
+		// if event id is valid
256
+		return $this->request->getRequestParam('tkt-slctr-event-id', 0, 'int');
257
+	}
258 258
 
259 259
 
260
-    /**
261
-     * validate_post_data
262
-     *
263
-     * @param int $id
264
-     * @return array
265
-     */
266
-    private function validatePostData($id = 0)
267
-    {
268
-        if (! $id) {
269
-            EE_Error::add_error(
270
-                esc_html__('The event id provided was not valid.', 'event_espresso'),
271
-                __FILE__,
272
-                __FUNCTION__,
273
-                __LINE__
274
-            );
275
-            return array();
276
-        }
277
-        // start with an empty array()
278
-        $valid_data = array();
279
-        // grab valid id
280
-        $valid_data['id'] = $id;
281
-        // array of other form names
282
-        $inputs_to_clean = array(
283
-            'max_atndz'  => 'tkt-slctr-max-atndz-',
284
-            'rows'       => 'tkt-slctr-rows-',
285
-            'qty'        => 'tkt-slctr-qty-',
286
-            'ticket_id'  => 'tkt-slctr-ticket-id-',
287
-            'return_url' => 'tkt-slctr-return-url-',
288
-        );
289
-        // let's track the total number of tickets ordered.'
290
-        $valid_data['total_tickets'] = 0;
291
-        // cycle through $inputs_to_clean array
292
-        foreach ($inputs_to_clean as $what => $input_to_clean) {
293
-            // check for POST data
294
-            if ($this->request->requestParamIsSet($input_to_clean . $id)) {
295
-                switch ($what) {
296
-                    // integers
297
-                    case 'event_id':
298
-                    case 'rows':
299
-                    case 'max_atndz':
300
-                        $valid_data[ $what ] = $this->request->getRequestParam($input_to_clean . $id, 0, 'int');
301
-                        break;
302
-                    // arrays of integers
303
-                    case 'qty':
304
-                        /** @var array $row_qty */
305
-                        $row_qty = $this->request->getRequestParam($input_to_clean . $id, [], 'arrayOf|int');
306
-                        // if qty is coming from a radio button input, then we need to assemble an array of rows
307
-                        if (! is_array($row_qty)) {
308
-                            /** @var string $row_qty */
309
-                            // get number of rows
310
-                            $rows = $this->request->getRequestParam('tkt-slctr-rows-' . $id, 1, 'int');
311
-                            // explode integers by the dash
312
-                            $row_qty = explode('-', $row_qty);
313
-                            $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
314
-                            $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
315
-                            $row_qty = array($row => $qty);
316
-                            for ($x = 1; $x <= $rows; $x++) {
317
-                                if (! isset($row_qty[ $x ])) {
318
-                                    $row_qty[ $x ] = 0;
319
-                                }
320
-                            }
321
-                        }
322
-                        ksort($row_qty);
323
-                        // cycle thru values
324
-                        foreach ($row_qty as $qty) {
325
-                            $qty = absint($qty);
326
-                            // sanitize as integers
327
-                            $valid_data[ $what ][] = $qty;
328
-                            $valid_data['total_tickets'] += $qty;
329
-                        }
330
-                        break;
331
-                    // array of integers
332
-                    case 'ticket_id':
333
-                        $ticket_ids = (array) $this->request->getRequestParam($input_to_clean . $id, [], 'arrayOf|int');
334
-                        // cycle thru values
335
-                        foreach ($ticket_ids as $key => $value) {
336
-                            // allow only integers
337
-                            $valid_data[ $what ][ $key ] = absint($value);
338
-                        }
339
-                        break;
340
-                    case 'return_url':
341
-                        // grab and sanitize return-url
342
-                        $input_value = $this->request->getRequestParam($input_to_clean . $id, '', 'url');
343
-                        // was the request coming from an iframe ? if so, then:
344
-                        if (strpos($input_value, 'event_list=iframe')) {
345
-                            // get anchor fragment
346
-                            $input_value = explode('#', $input_value);
347
-                            $input_value = end($input_value);
348
-                            // use event list url instead, but append anchor
349
-                            $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
350
-                        }
351
-                        $valid_data[ $what ] = $input_value;
352
-                        break;
353
-                }    // end switch $what
354
-            }
355
-        }    // end foreach $inputs_to_clean
356
-        return $valid_data;
357
-    }
260
+	/**
261
+	 * validate_post_data
262
+	 *
263
+	 * @param int $id
264
+	 * @return array
265
+	 */
266
+	private function validatePostData($id = 0)
267
+	{
268
+		if (! $id) {
269
+			EE_Error::add_error(
270
+				esc_html__('The event id provided was not valid.', 'event_espresso'),
271
+				__FILE__,
272
+				__FUNCTION__,
273
+				__LINE__
274
+			);
275
+			return array();
276
+		}
277
+		// start with an empty array()
278
+		$valid_data = array();
279
+		// grab valid id
280
+		$valid_data['id'] = $id;
281
+		// array of other form names
282
+		$inputs_to_clean = array(
283
+			'max_atndz'  => 'tkt-slctr-max-atndz-',
284
+			'rows'       => 'tkt-slctr-rows-',
285
+			'qty'        => 'tkt-slctr-qty-',
286
+			'ticket_id'  => 'tkt-slctr-ticket-id-',
287
+			'return_url' => 'tkt-slctr-return-url-',
288
+		);
289
+		// let's track the total number of tickets ordered.'
290
+		$valid_data['total_tickets'] = 0;
291
+		// cycle through $inputs_to_clean array
292
+		foreach ($inputs_to_clean as $what => $input_to_clean) {
293
+			// check for POST data
294
+			if ($this->request->requestParamIsSet($input_to_clean . $id)) {
295
+				switch ($what) {
296
+					// integers
297
+					case 'event_id':
298
+					case 'rows':
299
+					case 'max_atndz':
300
+						$valid_data[ $what ] = $this->request->getRequestParam($input_to_clean . $id, 0, 'int');
301
+						break;
302
+					// arrays of integers
303
+					case 'qty':
304
+						/** @var array $row_qty */
305
+						$row_qty = $this->request->getRequestParam($input_to_clean . $id, [], 'arrayOf|int');
306
+						// if qty is coming from a radio button input, then we need to assemble an array of rows
307
+						if (! is_array($row_qty)) {
308
+							/** @var string $row_qty */
309
+							// get number of rows
310
+							$rows = $this->request->getRequestParam('tkt-slctr-rows-' . $id, 1, 'int');
311
+							// explode integers by the dash
312
+							$row_qty = explode('-', $row_qty);
313
+							$row = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
314
+							$qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
315
+							$row_qty = array($row => $qty);
316
+							for ($x = 1; $x <= $rows; $x++) {
317
+								if (! isset($row_qty[ $x ])) {
318
+									$row_qty[ $x ] = 0;
319
+								}
320
+							}
321
+						}
322
+						ksort($row_qty);
323
+						// cycle thru values
324
+						foreach ($row_qty as $qty) {
325
+							$qty = absint($qty);
326
+							// sanitize as integers
327
+							$valid_data[ $what ][] = $qty;
328
+							$valid_data['total_tickets'] += $qty;
329
+						}
330
+						break;
331
+					// array of integers
332
+					case 'ticket_id':
333
+						$ticket_ids = (array) $this->request->getRequestParam($input_to_clean . $id, [], 'arrayOf|int');
334
+						// cycle thru values
335
+						foreach ($ticket_ids as $key => $value) {
336
+							// allow only integers
337
+							$valid_data[ $what ][ $key ] = absint($value);
338
+						}
339
+						break;
340
+					case 'return_url':
341
+						// grab and sanitize return-url
342
+						$input_value = $this->request->getRequestParam($input_to_clean . $id, '', 'url');
343
+						// was the request coming from an iframe ? if so, then:
344
+						if (strpos($input_value, 'event_list=iframe')) {
345
+							// get anchor fragment
346
+							$input_value = explode('#', $input_value);
347
+							$input_value = end($input_value);
348
+							// use event list url instead, but append anchor
349
+							$input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
350
+						}
351
+						$valid_data[ $what ] = $input_value;
352
+						break;
353
+				}    // end switch $what
354
+			}
355
+		}    // end foreach $inputs_to_clean
356
+		return $valid_data;
357
+	}
358 358
 
359 359
 
360
-    /**
361
-     * @param array $valid
362
-     */
363
-    private function maxAttendeesViolation(array $valid)
364
-    {
365
-        // ordering too many tickets !!!
366
-        $total_tickets_string = esc_html(
367
-            _n(
368
-                'You have attempted to purchase %s ticket.',
369
-                'You have attempted to purchase %s tickets.',
370
-                $valid['total_tickets'],
371
-                'event_espresso'
372
-            )
373
-        );
374
-        $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']);
375
-        // dev only message
376
-        $max_attendees_string = esc_html(
377
-            _n(
378
-                'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
379
-                'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
380
-                $valid['max_atndz'],
381
-                'event_espresso'
382
-            )
383
-        );
384
-        $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
385
-        EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
386
-    }
360
+	/**
361
+	 * @param array $valid
362
+	 */
363
+	private function maxAttendeesViolation(array $valid)
364
+	{
365
+		// ordering too many tickets !!!
366
+		$total_tickets_string = esc_html(
367
+			_n(
368
+				'You have attempted to purchase %s ticket.',
369
+				'You have attempted to purchase %s tickets.',
370
+				$valid['total_tickets'],
371
+				'event_espresso'
372
+			)
373
+		);
374
+		$limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']);
375
+		// dev only message
376
+		$max_attendees_string = esc_html(
377
+			_n(
378
+				'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
379
+				'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
380
+				$valid['max_atndz'],
381
+				'event_espresso'
382
+			)
383
+		);
384
+		$limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
385
+		EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
386
+	}
387 387
 
388 388
 
389
-    /**
390
-     * @param array $valid
391
-     * @return int
392
-     * @throws EE_Error
393
-     * @throws InvalidArgumentException
394
-     * @throws InvalidDataTypeException
395
-     * @throws InvalidInterfaceException
396
-     */
397
-    private function addTicketsToCart(array $valid)
398
-    {
399
-        $tickets_added = 0;
400
-        $tickets_selected = false;
401
-        if (! empty($valid) && $valid['total_tickets'] > 0) {
402
-            // load cart using factory because we don't want to do so until actually needed
403
-            $this->cart = CartFactory::getCart();
404
-            // if the user is an admin that can edit registrations,
405
-            // then we'll also allow them to add any tickets, even if they are expired
406
-            $current_user_is_admin = current_user_can('ee_edit_registrations');
407
-            \EEH_Debug_Tools::printr($current_user_is_admin, '$current_user_is_admin', __FILE__, __LINE__);
408
-            // cycle thru the number of data rows sent from the event listing
409
-            for ($x = 0; $x < $valid['rows']; $x++) {
410
-                // does this row actually contain a ticket quantity?
411
-                if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) {
412
-                    // YES we have a ticket quantity
413
-                    $tickets_selected = true;
414
-                    $valid_ticket = false;
415
-                    if (isset($valid['ticket_id'][ $x ])) {
416
-                        // get ticket via the ticket id we put in the form
417
-                        $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]);
418
-                        \EEH_Debug_Tools::printr($ticket->is_on_sale(), '$ticket->is_on_sale()', __FILE__, __LINE__);
419
-                        if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) {
420
-                            $valid_ticket = true;
421
-                            $tickets_added += $this->addTicketToCart(
422
-                                $ticket,
423
-                                $valid['qty'][ $x ]
424
-                            );
425
-                        }
426
-                    }
427
-                    if ($valid_ticket !== true) {
428
-                        // nothing added to cart retrieved
429
-                        EE_Error::add_error(
430
-                            sprintf(
431
-                                esc_html__(
432
-                                    'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
433
-                                    'event_espresso'
434
-                                ),
435
-                                '<br/>'
436
-                            ),
437
-                            __FILE__,
438
-                            __FUNCTION__,
439
-                            __LINE__
440
-                        );
441
-                    }
442
-                    if (EE_Error::has_error()) {
443
-                        break;
444
-                    }
445
-                }
446
-            }
447
-        }
448
-        do_action(
449
-            'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
450
-            $this->cart,
451
-            $this
452
-        );
453
-        if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
454
-            // no ticket quantities were selected
455
-            EE_Error::add_error(
456
-                esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
457
-                __FILE__,
458
-                __FUNCTION__,
459
-                __LINE__
460
-            );
461
-        }
462
-        return $tickets_added;
463
-    }
389
+	/**
390
+	 * @param array $valid
391
+	 * @return int
392
+	 * @throws EE_Error
393
+	 * @throws InvalidArgumentException
394
+	 * @throws InvalidDataTypeException
395
+	 * @throws InvalidInterfaceException
396
+	 */
397
+	private function addTicketsToCart(array $valid)
398
+	{
399
+		$tickets_added = 0;
400
+		$tickets_selected = false;
401
+		if (! empty($valid) && $valid['total_tickets'] > 0) {
402
+			// load cart using factory because we don't want to do so until actually needed
403
+			$this->cart = CartFactory::getCart();
404
+			// if the user is an admin that can edit registrations,
405
+			// then we'll also allow them to add any tickets, even if they are expired
406
+			$current_user_is_admin = current_user_can('ee_edit_registrations');
407
+			\EEH_Debug_Tools::printr($current_user_is_admin, '$current_user_is_admin', __FILE__, __LINE__);
408
+			// cycle thru the number of data rows sent from the event listing
409
+			for ($x = 0; $x < $valid['rows']; $x++) {
410
+				// does this row actually contain a ticket quantity?
411
+				if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) {
412
+					// YES we have a ticket quantity
413
+					$tickets_selected = true;
414
+					$valid_ticket = false;
415
+					if (isset($valid['ticket_id'][ $x ])) {
416
+						// get ticket via the ticket id we put in the form
417
+						$ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]);
418
+						\EEH_Debug_Tools::printr($ticket->is_on_sale(), '$ticket->is_on_sale()', __FILE__, __LINE__);
419
+						if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) {
420
+							$valid_ticket = true;
421
+							$tickets_added += $this->addTicketToCart(
422
+								$ticket,
423
+								$valid['qty'][ $x ]
424
+							);
425
+						}
426
+					}
427
+					if ($valid_ticket !== true) {
428
+						// nothing added to cart retrieved
429
+						EE_Error::add_error(
430
+							sprintf(
431
+								esc_html__(
432
+									'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
433
+									'event_espresso'
434
+								),
435
+								'<br/>'
436
+							),
437
+							__FILE__,
438
+							__FUNCTION__,
439
+							__LINE__
440
+						);
441
+					}
442
+					if (EE_Error::has_error()) {
443
+						break;
444
+					}
445
+				}
446
+			}
447
+		}
448
+		do_action(
449
+			'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
450
+			$this->cart,
451
+			$this
452
+		);
453
+		if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
454
+			// no ticket quantities were selected
455
+			EE_Error::add_error(
456
+				esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
457
+				__FILE__,
458
+				__FUNCTION__,
459
+				__LINE__
460
+			);
461
+		}
462
+		return $tickets_added;
463
+	}
464 464
 
465 465
 
466
-    /**
467
-     * adds a ticket to the cart
468
-     *
469
-     * @param EE_Ticket $ticket
470
-     * @param int       $qty
471
-     * @return bool TRUE on success, FALSE on fail
472
-     * @throws InvalidArgumentException
473
-     * @throws InvalidInterfaceException
474
-     * @throws InvalidDataTypeException
475
-     * @throws EE_Error
476
-     */
477
-    private function addTicketToCart(EE_Ticket $ticket, $qty = 1)
478
-    {
479
-        // get the number of spaces left for this datetime ticket
480
-        $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket);
481
-        // compare available spaces against the number of tickets being purchased
482
-        if ($available_spaces >= $qty) {
483
-            // allow addons to prevent a ticket from being added to cart
484
-            if (! apply_filters(
485
-                'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
486
-                true,
487
-                $ticket,
488
-                $qty,
489
-                $available_spaces
490
-            )) {
491
-                return false;
492
-            }
493
-            $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
494
-            // add event to cart
495
-            if ($this->cart->add_ticket_to_cart($ticket, $qty)) {
496
-                $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty);
497
-                return true;
498
-            }
499
-            return false;
500
-        }
501
-        $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count());
502
-        return false;
503
-    }
466
+	/**
467
+	 * adds a ticket to the cart
468
+	 *
469
+	 * @param EE_Ticket $ticket
470
+	 * @param int       $qty
471
+	 * @return bool TRUE on success, FALSE on fail
472
+	 * @throws InvalidArgumentException
473
+	 * @throws InvalidInterfaceException
474
+	 * @throws InvalidDataTypeException
475
+	 * @throws EE_Error
476
+	 */
477
+	private function addTicketToCart(EE_Ticket $ticket, $qty = 1)
478
+	{
479
+		// get the number of spaces left for this datetime ticket
480
+		$available_spaces = $this->tracker->ticketDatetimeAvailability($ticket);
481
+		// compare available spaces against the number of tickets being purchased
482
+		if ($available_spaces >= $qty) {
483
+			// allow addons to prevent a ticket from being added to cart
484
+			if (! apply_filters(
485
+				'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
486
+				true,
487
+				$ticket,
488
+				$qty,
489
+				$available_spaces
490
+			)) {
491
+				return false;
492
+			}
493
+			$qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
494
+			// add event to cart
495
+			if ($this->cart->add_ticket_to_cart($ticket, $qty)) {
496
+				$this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty);
497
+				return true;
498
+			}
499
+			return false;
500
+		}
501
+		$this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count());
502
+		return false;
503
+	}
504 504
 
505 505
 
506
-    /**
507
-     * @param $tickets_added
508
-     * @return bool
509
-     * @throws InvalidInterfaceException
510
-     * @throws InvalidDataTypeException
511
-     * @throws EE_Error
512
-     * @throws InvalidArgumentException
513
-     */
514
-    private function processSuccessfulCart($tickets_added)
515
-    {
516
-        // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
517
-        if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
518
-            // make sure cart is loaded
519
-            if (! $this->cart instanceof EE_Cart) {
520
-                $this->cart = CartFactory::getCart();
521
-            }
522
-            do_action(
523
-                'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
524
-                $this->cart,
525
-                $this
526
-            );
527
-            $this->cart->recalculate_all_cart_totals();
528
-            $this->cart->save_cart(false);
529
-            // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE
530
-            // just return TRUE for registrations being made from admin
531
-            if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
532
-                return true;
533
-            }
534
-            EEH_URL::safeRedirectAndExit(
535
-                apply_filters(
536
-                    'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
537
-                    $this->core_config->reg_page_url()
538
-                )
539
-            );
540
-        }
541
-        if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
542
-            // nothing added to cart
543
-            EE_Error::add_attention(
544
-                esc_html__('No tickets were added for the event', 'event_espresso'),
545
-                __FILE__,
546
-                __FUNCTION__,
547
-                __LINE__
548
-            );
549
-        }
550
-        return false;
551
-    }
506
+	/**
507
+	 * @param $tickets_added
508
+	 * @return bool
509
+	 * @throws InvalidInterfaceException
510
+	 * @throws InvalidDataTypeException
511
+	 * @throws EE_Error
512
+	 * @throws InvalidArgumentException
513
+	 */
514
+	private function processSuccessfulCart($tickets_added)
515
+	{
516
+		// exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
517
+		if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
518
+			// make sure cart is loaded
519
+			if (! $this->cart instanceof EE_Cart) {
520
+				$this->cart = CartFactory::getCart();
521
+			}
522
+			do_action(
523
+				'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
524
+				$this->cart,
525
+				$this
526
+			);
527
+			$this->cart->recalculate_all_cart_totals();
528
+			$this->cart->save_cart(false);
529
+			// exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE
530
+			// just return TRUE for registrations being made from admin
531
+			if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
532
+				return true;
533
+			}
534
+			EEH_URL::safeRedirectAndExit(
535
+				apply_filters(
536
+					'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
537
+					$this->core_config->reg_page_url()
538
+				)
539
+			);
540
+		}
541
+		if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
542
+			// nothing added to cart
543
+			EE_Error::add_attention(
544
+				esc_html__('No tickets were added for the event', 'event_espresso'),
545
+				__FILE__,
546
+				__FUNCTION__,
547
+				__LINE__
548
+			);
549
+		}
550
+		return false;
551
+	}
552 552
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
     public function cancelTicketSelections()
119 119
     {
120 120
         // check nonce
121
-        if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
121
+        if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
122 122
             return false;
123 123
         }
124 124
         $this->session->clear_session(__CLASS__, __FUNCTION__);
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
             );
131 131
         }
132 132
         EEH_URL::safeRedirectAndExit(
133
-            site_url('/' . $this->core_config->event_cpt_slug . '/')
133
+            site_url('/'.$this->core_config->event_cpt_slug.'/')
134 134
         );
135 135
         return true;
136 136
     }
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
     private function processTicketSelectorNonce($nonce_name, $id = '')
147 147
     {
148 148
         $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
149
-        if (! $this->request->isAdmin()
149
+        if ( ! $this->request->isAdmin()
150 150
             && (
151 151
                 ! $this->request->requestParamIsSet($nonce_name_with_id)
152 152
                 || ! wp_verify_nonce(
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
             $this->validatePostData($id)
208 208
         );
209 209
         // check total tickets ordered vs max number of attendees that can register
210
-        if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) {
210
+        if ( ! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) {
211 211
             $this->maxAttendeesViolation($valid);
212 212
         } else {
213 213
             // all data appears to be valid
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
     private function getEventId()
238 238
     {
239 239
         // do we have an event id?
240
-        if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
240
+        if ( ! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
241 241
             // $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
242 242
             EE_Error::add_error(
243 243
                 sprintf(
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
      */
266 266
     private function validatePostData($id = 0)
267 267
     {
268
-        if (! $id) {
268
+        if ( ! $id) {
269 269
             EE_Error::add_error(
270 270
                 esc_html__('The event id provided was not valid.', 'event_espresso'),
271 271
                 __FILE__,
@@ -291,31 +291,31 @@  discard block
 block discarded – undo
291 291
         // cycle through $inputs_to_clean array
292 292
         foreach ($inputs_to_clean as $what => $input_to_clean) {
293 293
             // check for POST data
294
-            if ($this->request->requestParamIsSet($input_to_clean . $id)) {
294
+            if ($this->request->requestParamIsSet($input_to_clean.$id)) {
295 295
                 switch ($what) {
296 296
                     // integers
297 297
                     case 'event_id':
298 298
                     case 'rows':
299 299
                     case 'max_atndz':
300
-                        $valid_data[ $what ] = $this->request->getRequestParam($input_to_clean . $id, 0, 'int');
300
+                        $valid_data[$what] = $this->request->getRequestParam($input_to_clean.$id, 0, 'int');
301 301
                         break;
302 302
                     // arrays of integers
303 303
                     case 'qty':
304 304
                         /** @var array $row_qty */
305
-                        $row_qty = $this->request->getRequestParam($input_to_clean . $id, [], 'arrayOf|int');
305
+                        $row_qty = $this->request->getRequestParam($input_to_clean.$id, [], 'arrayOf|int');
306 306
                         // if qty is coming from a radio button input, then we need to assemble an array of rows
307
-                        if (! is_array($row_qty)) {
307
+                        if ( ! is_array($row_qty)) {
308 308
                             /** @var string $row_qty */
309 309
                             // get number of rows
310
-                            $rows = $this->request->getRequestParam('tkt-slctr-rows-' . $id, 1, 'int');
310
+                            $rows = $this->request->getRequestParam('tkt-slctr-rows-'.$id, 1, 'int');
311 311
                             // explode integers by the dash
312 312
                             $row_qty = explode('-', $row_qty);
313 313
                             $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
314 314
                             $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
315 315
                             $row_qty = array($row => $qty);
316 316
                             for ($x = 1; $x <= $rows; $x++) {
317
-                                if (! isset($row_qty[ $x ])) {
318
-                                    $row_qty[ $x ] = 0;
317
+                                if ( ! isset($row_qty[$x])) {
318
+                                    $row_qty[$x] = 0;
319 319
                                 }
320 320
                             }
321 321
                         }
@@ -324,31 +324,31 @@  discard block
 block discarded – undo
324 324
                         foreach ($row_qty as $qty) {
325 325
                             $qty = absint($qty);
326 326
                             // sanitize as integers
327
-                            $valid_data[ $what ][] = $qty;
327
+                            $valid_data[$what][] = $qty;
328 328
                             $valid_data['total_tickets'] += $qty;
329 329
                         }
330 330
                         break;
331 331
                     // array of integers
332 332
                     case 'ticket_id':
333
-                        $ticket_ids = (array) $this->request->getRequestParam($input_to_clean . $id, [], 'arrayOf|int');
333
+                        $ticket_ids = (array) $this->request->getRequestParam($input_to_clean.$id, [], 'arrayOf|int');
334 334
                         // cycle thru values
335 335
                         foreach ($ticket_ids as $key => $value) {
336 336
                             // allow only integers
337
-                            $valid_data[ $what ][ $key ] = absint($value);
337
+                            $valid_data[$what][$key] = absint($value);
338 338
                         }
339 339
                         break;
340 340
                     case 'return_url':
341 341
                         // grab and sanitize return-url
342
-                        $input_value = $this->request->getRequestParam($input_to_clean . $id, '', 'url');
342
+                        $input_value = $this->request->getRequestParam($input_to_clean.$id, '', 'url');
343 343
                         // was the request coming from an iframe ? if so, then:
344 344
                         if (strpos($input_value, 'event_list=iframe')) {
345 345
                             // get anchor fragment
346 346
                             $input_value = explode('#', $input_value);
347 347
                             $input_value = end($input_value);
348 348
                             // use event list url instead, but append anchor
349
-                            $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
349
+                            $input_value = EEH_Event_View::event_archive_url().'#'.$input_value;
350 350
                         }
351
-                        $valid_data[ $what ] = $input_value;
351
+                        $valid_data[$what] = $input_value;
352 352
                         break;
353 353
                 }    // end switch $what
354 354
             }
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
             )
383 383
         );
384 384
         $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
385
-        EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
385
+        EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__);
386 386
     }
387 387
 
388 388
 
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
     {
399 399
         $tickets_added = 0;
400 400
         $tickets_selected = false;
401
-        if (! empty($valid) && $valid['total_tickets'] > 0) {
401
+        if ( ! empty($valid) && $valid['total_tickets'] > 0) {
402 402
             // load cart using factory because we don't want to do so until actually needed
403 403
             $this->cart = CartFactory::getCart();
404 404
             // if the user is an admin that can edit registrations,
@@ -408,19 +408,19 @@  discard block
 block discarded – undo
408 408
             // cycle thru the number of data rows sent from the event listing
409 409
             for ($x = 0; $x < $valid['rows']; $x++) {
410 410
                 // does this row actually contain a ticket quantity?
411
-                if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) {
411
+                if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) {
412 412
                     // YES we have a ticket quantity
413 413
                     $tickets_selected = true;
414 414
                     $valid_ticket = false;
415
-                    if (isset($valid['ticket_id'][ $x ])) {
415
+                    if (isset($valid['ticket_id'][$x])) {
416 416
                         // get ticket via the ticket id we put in the form
417
-                        $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]);
417
+                        $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][$x]);
418 418
                         \EEH_Debug_Tools::printr($ticket->is_on_sale(), '$ticket->is_on_sale()', __FILE__, __LINE__);
419 419
                         if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) {
420 420
                             $valid_ticket = true;
421 421
                             $tickets_added += $this->addTicketToCart(
422 422
                                 $ticket,
423
-                                $valid['qty'][ $x ]
423
+                                $valid['qty'][$x]
424 424
                             );
425 425
                         }
426 426
                     }
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
             $this->cart,
451 451
             $this
452 452
         );
453
-        if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
453
+        if ( ! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
454 454
             // no ticket quantities were selected
455 455
             EE_Error::add_error(
456 456
                 esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
         // compare available spaces against the number of tickets being purchased
482 482
         if ($available_spaces >= $qty) {
483 483
             // allow addons to prevent a ticket from being added to cart
484
-            if (! apply_filters(
484
+            if ( ! apply_filters(
485 485
                 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
486 486
                 true,
487 487
                 $ticket,
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
         // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
517 517
         if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
518 518
             // make sure cart is loaded
519
-            if (! $this->cart instanceof EE_Cart) {
519
+            if ( ! $this->cart instanceof EE_Cart) {
520 520
                 $this->cart = CartFactory::getCart();
521 521
             }
522 522
             do_action(
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
                 )
539 539
             );
540 540
         }
541
-        if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
541
+        if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
542 542
             // nothing added to cart
543 543
             EE_Error::add_attention(
544 544
                 esc_html__('No tickets were added for the event', 'event_espresso'),
Please login to merge, or discard this patch.
core/services/container/RegistryContainer.php 2 patches
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -17,165 +17,165 @@
 block discarded – undo
17 17
 class RegistryContainer implements ArrayAccess, CountableTraversableAggregate
18 18
 {
19 19
 
20
-    /**
21
-     * @var array $container
22
-     */
23
-    private $container = [];
24
-
25
-    /**
26
-     * RegistryContainer constructor.
27
-     * Container data can be seeded by passing parameters to constructor.
28
-     * Each parameter will become its own element in the container
29
-     */
30
-    public function __construct()
31
-    {
32
-    }
33
-
34
-
35
-    /**
36
-     * @param mixed $offset
37
-     * @param mixed $value
38
-     */
39
-    public function offsetSet($offset, $value)
40
-    {
41
-        $this->container[ $offset ] = $value;
42
-    }
43
-
44
-
45
-    /**
46
-     * @param mixed $offset
47
-     * @return bool
48
-     */
49
-    public function offsetExists($offset)
50
-    {
51
-        return isset($this->container[ $offset ]);
52
-    }
53
-
54
-
55
-    /**
56
-     * @param mixed $offset
57
-     */
58
-    public function offsetUnset($offset)
59
-    {
60
-        unset($this->container[ $offset ]);
61
-    }
62
-
63
-
64
-    /**
65
-     * @param mixed $offset
66
-     * @return mixed|null
67
-     */
68
-    public function offsetGet($offset)
69
-    {
70
-        return $this->offsetExists($offset) ? $this->container[ $offset ] : null;
71
-    }
72
-
73
-
74
-    /**
75
-     * @return int
76
-     */
77
-    public function count()
78
-    {
79
-        return count($this->container);
80
-    }
81
-
82
-
83
-    /**
84
-     * @return ArrayIterator
85
-     */
86
-    public function getIterator()
87
-    {
88
-        return new ArrayIterator($this->container);
89
-    }
90
-
91
-
92
-    /**
93
-     * @param $offset
94
-     * @param $value
95
-     */
96
-    public function __set($offset, $value)
97
-    {
98
-        $this->offsetSet($offset, $value);
99
-    }
100
-
101
-
102
-    /**
103
-     * @param $offset
104
-     * @return mixed
105
-     * @throws OutOfBoundsException
106
-     */
107
-    public function __get($offset)
108
-    {
109
-        if (! array_key_exists($offset, $this->container)) {
110
-            $trace = debug_backtrace();
111
-            throw new OutOfBoundsException(
112
-                sprintf(
113
-                    esc_html__('Invalid offset: %1$s %2$sCalled from %3$s on line %4$d', 'event_espresso'),
114
-                    $offset,
115
-                    '<br  />',
116
-                    $trace[0]['file'],
117
-                    $trace[0]['line']
118
-                )
119
-            );
120
-        }
121
-        return $this->offsetGet($offset);
122
-    }
123
-
124
-
125
-    /**
126
-     * @param $offset
127
-     * @return bool
128
-     */
129
-    public function __isset($offset)
130
-    {
131
-        return $this->offsetExists($offset);
132
-    }
133
-
134
-
135
-    /**
136
-     * @param $offset
137
-     */
138
-    public function __unset($offset)
139
-    {
140
-        $this->offsetUnset($offset);
141
-    }
142
-
143
-
144
-    /**
145
-     * @param $offset
146
-     * @param $value
147
-     */
148
-    public function add($offset, $value)
149
-    {
150
-        $this->offsetSet($offset, $value);
151
-    }
152
-
153
-
154
-    /**
155
-     * @param $offset
156
-     */
157
-    public function remove($offset)
158
-    {
159
-        $this->offsetUnset($offset);
160
-    }
161
-
162
-
163
-    /**
164
-     * @param $offset
165
-     * @return bool
166
-     */
167
-    public function has($offset)
168
-    {
169
-        return $this->offsetExists($offset);
170
-    }
171
-
172
-
173
-    /**
174
-     * @param $offset
175
-     * @return mixed|null
176
-     */
177
-    public function get($offset)
178
-    {
179
-        return $this->offsetGet($offset);
180
-    }
20
+	/**
21
+	 * @var array $container
22
+	 */
23
+	private $container = [];
24
+
25
+	/**
26
+	 * RegistryContainer constructor.
27
+	 * Container data can be seeded by passing parameters to constructor.
28
+	 * Each parameter will become its own element in the container
29
+	 */
30
+	public function __construct()
31
+	{
32
+	}
33
+
34
+
35
+	/**
36
+	 * @param mixed $offset
37
+	 * @param mixed $value
38
+	 */
39
+	public function offsetSet($offset, $value)
40
+	{
41
+		$this->container[ $offset ] = $value;
42
+	}
43
+
44
+
45
+	/**
46
+	 * @param mixed $offset
47
+	 * @return bool
48
+	 */
49
+	public function offsetExists($offset)
50
+	{
51
+		return isset($this->container[ $offset ]);
52
+	}
53
+
54
+
55
+	/**
56
+	 * @param mixed $offset
57
+	 */
58
+	public function offsetUnset($offset)
59
+	{
60
+		unset($this->container[ $offset ]);
61
+	}
62
+
63
+
64
+	/**
65
+	 * @param mixed $offset
66
+	 * @return mixed|null
67
+	 */
68
+	public function offsetGet($offset)
69
+	{
70
+		return $this->offsetExists($offset) ? $this->container[ $offset ] : null;
71
+	}
72
+
73
+
74
+	/**
75
+	 * @return int
76
+	 */
77
+	public function count()
78
+	{
79
+		return count($this->container);
80
+	}
81
+
82
+
83
+	/**
84
+	 * @return ArrayIterator
85
+	 */
86
+	public function getIterator()
87
+	{
88
+		return new ArrayIterator($this->container);
89
+	}
90
+
91
+
92
+	/**
93
+	 * @param $offset
94
+	 * @param $value
95
+	 */
96
+	public function __set($offset, $value)
97
+	{
98
+		$this->offsetSet($offset, $value);
99
+	}
100
+
101
+
102
+	/**
103
+	 * @param $offset
104
+	 * @return mixed
105
+	 * @throws OutOfBoundsException
106
+	 */
107
+	public function __get($offset)
108
+	{
109
+		if (! array_key_exists($offset, $this->container)) {
110
+			$trace = debug_backtrace();
111
+			throw new OutOfBoundsException(
112
+				sprintf(
113
+					esc_html__('Invalid offset: %1$s %2$sCalled from %3$s on line %4$d', 'event_espresso'),
114
+					$offset,
115
+					'<br  />',
116
+					$trace[0]['file'],
117
+					$trace[0]['line']
118
+				)
119
+			);
120
+		}
121
+		return $this->offsetGet($offset);
122
+	}
123
+
124
+
125
+	/**
126
+	 * @param $offset
127
+	 * @return bool
128
+	 */
129
+	public function __isset($offset)
130
+	{
131
+		return $this->offsetExists($offset);
132
+	}
133
+
134
+
135
+	/**
136
+	 * @param $offset
137
+	 */
138
+	public function __unset($offset)
139
+	{
140
+		$this->offsetUnset($offset);
141
+	}
142
+
143
+
144
+	/**
145
+	 * @param $offset
146
+	 * @param $value
147
+	 */
148
+	public function add($offset, $value)
149
+	{
150
+		$this->offsetSet($offset, $value);
151
+	}
152
+
153
+
154
+	/**
155
+	 * @param $offset
156
+	 */
157
+	public function remove($offset)
158
+	{
159
+		$this->offsetUnset($offset);
160
+	}
161
+
162
+
163
+	/**
164
+	 * @param $offset
165
+	 * @return bool
166
+	 */
167
+	public function has($offset)
168
+	{
169
+		return $this->offsetExists($offset);
170
+	}
171
+
172
+
173
+	/**
174
+	 * @param $offset
175
+	 * @return mixed|null
176
+	 */
177
+	public function get($offset)
178
+	{
179
+		return $this->offsetGet($offset);
180
+	}
181 181
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function offsetSet($offset, $value)
40 40
     {
41
-        $this->container[ $offset ] = $value;
41
+        $this->container[$offset] = $value;
42 42
     }
43 43
 
44 44
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      */
49 49
     public function offsetExists($offset)
50 50
     {
51
-        return isset($this->container[ $offset ]);
51
+        return isset($this->container[$offset]);
52 52
     }
53 53
 
54 54
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public function offsetUnset($offset)
59 59
     {
60
-        unset($this->container[ $offset ]);
60
+        unset($this->container[$offset]);
61 61
     }
62 62
 
63 63
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      */
68 68
     public function offsetGet($offset)
69 69
     {
70
-        return $this->offsetExists($offset) ? $this->container[ $offset ] : null;
70
+        return $this->offsetExists($offset) ? $this->container[$offset] : null;
71 71
     }
72 72
 
73 73
 
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      */
107 107
     public function __get($offset)
108 108
     {
109
-        if (! array_key_exists($offset, $this->container)) {
109
+        if ( ! array_key_exists($offset, $this->container)) {
110 110
             $trace = debug_backtrace();
111 111
             throw new OutOfBoundsException(
112 112
                 sprintf(
Please login to merge, or discard this patch.
core/services/loaders/CoreLoader.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -29,111 +29,111 @@
 block discarded – undo
29 29
 class CoreLoader implements LoaderDecoratorInterface
30 30
 {
31 31
 
32
-    /**
33
-     * @var EE_Registry|CoffeeShop $generator
34
-     */
35
-    private $generator;
32
+	/**
33
+	 * @var EE_Registry|CoffeeShop $generator
34
+	 */
35
+	private $generator;
36 36
 
37 37
 
38
-    /**
39
-     * CoreLoader constructor.
40
-     *
41
-     * @param EE_Registry|CoffeeShop $generator
42
-     * @throws InvalidArgumentException
43
-     */
44
-    public function __construct($generator)
45
-    {
46
-        if (! ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
47
-            throw new InvalidArgumentException(
48
-                esc_html__(
49
-                    'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
50
-                    'event_espresso'
51
-                )
52
-            );
53
-        }
54
-        $this->generator = $generator;
55
-    }
38
+	/**
39
+	 * CoreLoader constructor.
40
+	 *
41
+	 * @param EE_Registry|CoffeeShop $generator
42
+	 * @throws InvalidArgumentException
43
+	 */
44
+	public function __construct($generator)
45
+	{
46
+		if (! ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
47
+			throw new InvalidArgumentException(
48
+				esc_html__(
49
+					'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
50
+					'event_espresso'
51
+				)
52
+			);
53
+		}
54
+		$this->generator = $generator;
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * Calls the appropriate loading method from the installed generator;
60
-     * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method
61
-     * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(),
62
-     * but NOT to the class being instantiated.
63
-     * This is done by adding the parameters to the $arguments array as follows:
64
-     *  array(
65
-     *      'EE_Registry::create(from_db)'   => true, // boolean value, default = false
66
-     *      'EE_Registry::create(load_only)' => true, // boolean value, default = false
67
-     *      'EE_Registry::create(addon)'     => true, // boolean value, default = false
68
-     *  )
69
-     *
70
-     * @param string $fqcn
71
-     * @param array  $arguments
72
-     * @param bool   $shared
73
-     * @return mixed
74
-     * @throws OutOfBoundsException
75
-     * @throws ServiceExistsException
76
-     * @throws InstantiationException
77
-     * @throws InvalidIdentifierException
78
-     * @throws InvalidDataTypeException
79
-     * @throws InvalidClassException
80
-     * @throws EE_Error
81
-     * @throws ServiceNotFoundException
82
-     * @throws ReflectionException
83
-     * @throws InvalidInterfaceException
84
-     * @throws InvalidArgumentException
85
-     */
86
-    public function load($fqcn, $arguments = array(), $shared = true)
87
-    {
88
-        $shared = filter_var($shared, FILTER_VALIDATE_BOOLEAN);
89
-        if ($this->generator instanceof EE_Registry) {
90
-            // check if additional EE_Registry::create() arguments have been passed
91
-            // from_db
92
-            $from_db = isset($arguments['EE_Registry::create(from_db)'])
93
-                ? filter_var($arguments['EE_Registry::create(from_db)'], FILTER_VALIDATE_BOOLEAN)
94
-                : false;
95
-            // load_only
96
-            $load_only = isset($arguments['EE_Registry::create(load_only)'])
97
-                ? filter_var($arguments['EE_Registry::create(load_only)'], FILTER_VALIDATE_BOOLEAN)
98
-                : false;
99
-            // addon
100
-            $addon = isset($arguments['EE_Registry::create(addon)'])
101
-                ? filter_var($arguments['EE_Registry::create(addon)'], FILTER_VALIDATE_BOOLEAN)
102
-                : false;
103
-            unset(
104
-                $arguments['EE_Registry::create(from_db)'],
105
-                $arguments['EE_Registry::create(load_only)'],
106
-                $arguments['EE_Registry::create(addon)']
107
-            );
108
-            // addons need to be cached on EE_Registry
109
-            $shared = $addon ? true : $shared;
110
-            return $this->generator->create(
111
-                $fqcn,
112
-                $arguments,
113
-                $shared,
114
-                $from_db,
115
-                $load_only,
116
-                $addon
117
-            );
118
-        }
119
-        return $this->generator->brew(
120
-            $fqcn,
121
-            $arguments,
122
-            $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW
123
-        );
124
-    }
58
+	/**
59
+	 * Calls the appropriate loading method from the installed generator;
60
+	 * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method
61
+	 * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(),
62
+	 * but NOT to the class being instantiated.
63
+	 * This is done by adding the parameters to the $arguments array as follows:
64
+	 *  array(
65
+	 *      'EE_Registry::create(from_db)'   => true, // boolean value, default = false
66
+	 *      'EE_Registry::create(load_only)' => true, // boolean value, default = false
67
+	 *      'EE_Registry::create(addon)'     => true, // boolean value, default = false
68
+	 *  )
69
+	 *
70
+	 * @param string $fqcn
71
+	 * @param array  $arguments
72
+	 * @param bool   $shared
73
+	 * @return mixed
74
+	 * @throws OutOfBoundsException
75
+	 * @throws ServiceExistsException
76
+	 * @throws InstantiationException
77
+	 * @throws InvalidIdentifierException
78
+	 * @throws InvalidDataTypeException
79
+	 * @throws InvalidClassException
80
+	 * @throws EE_Error
81
+	 * @throws ServiceNotFoundException
82
+	 * @throws ReflectionException
83
+	 * @throws InvalidInterfaceException
84
+	 * @throws InvalidArgumentException
85
+	 */
86
+	public function load($fqcn, $arguments = array(), $shared = true)
87
+	{
88
+		$shared = filter_var($shared, FILTER_VALIDATE_BOOLEAN);
89
+		if ($this->generator instanceof EE_Registry) {
90
+			// check if additional EE_Registry::create() arguments have been passed
91
+			// from_db
92
+			$from_db = isset($arguments['EE_Registry::create(from_db)'])
93
+				? filter_var($arguments['EE_Registry::create(from_db)'], FILTER_VALIDATE_BOOLEAN)
94
+				: false;
95
+			// load_only
96
+			$load_only = isset($arguments['EE_Registry::create(load_only)'])
97
+				? filter_var($arguments['EE_Registry::create(load_only)'], FILTER_VALIDATE_BOOLEAN)
98
+				: false;
99
+			// addon
100
+			$addon = isset($arguments['EE_Registry::create(addon)'])
101
+				? filter_var($arguments['EE_Registry::create(addon)'], FILTER_VALIDATE_BOOLEAN)
102
+				: false;
103
+			unset(
104
+				$arguments['EE_Registry::create(from_db)'],
105
+				$arguments['EE_Registry::create(load_only)'],
106
+				$arguments['EE_Registry::create(addon)']
107
+			);
108
+			// addons need to be cached on EE_Registry
109
+			$shared = $addon ? true : $shared;
110
+			return $this->generator->create(
111
+				$fqcn,
112
+				$arguments,
113
+				$shared,
114
+				$from_db,
115
+				$load_only,
116
+				$addon
117
+			);
118
+		}
119
+		return $this->generator->brew(
120
+			$fqcn,
121
+			$arguments,
122
+			$shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW
123
+		);
124
+	}
125 125
 
126 126
 
127
-    /**
128
-     * calls reset() on generator if method exists
129
-     *
130
-     * @throws EE_Error
131
-     * @throws ReflectionException
132
-     */
133
-    public function reset()
134
-    {
135
-        if ($this->generator instanceof ResettableInterface) {
136
-            $this->generator->reset();
137
-        }
138
-    }
127
+	/**
128
+	 * calls reset() on generator if method exists
129
+	 *
130
+	 * @throws EE_Error
131
+	 * @throws ReflectionException
132
+	 */
133
+	public function reset()
134
+	{
135
+		if ($this->generator instanceof ResettableInterface) {
136
+			$this->generator->reset();
137
+		}
138
+	}
139 139
 }
Please login to merge, or discard this patch.
core/services/loaders/Loader.php 1 patch
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -15,127 +15,127 @@
 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
-     * @param FullyQualifiedName|string $fqcn
124
-     * @return bool
125
-     * @throws InvalidArgumentException
126
-     */
127
-    public function remove($fqcn, array $arguments = [])
128
-    {
129
-        $fqcn = $this->class_cache->getFqn($fqcn);
130
-        return $this->getSharedLoader()->remove($fqcn, $arguments);
131
-    }
132
-
133
-
134
-    /**
135
-     * calls reset() on loaders if that method exists
136
-     */
137
-    public function reset()
138
-    {
139
-        $this->shared_loader->reset();
140
-    }
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
+	 * @param FullyQualifiedName|string $fqcn
124
+	 * @return bool
125
+	 * @throws InvalidArgumentException
126
+	 */
127
+	public function remove($fqcn, array $arguments = [])
128
+	{
129
+		$fqcn = $this->class_cache->getFqn($fqcn);
130
+		return $this->getSharedLoader()->remove($fqcn, $arguments);
131
+	}
132
+
133
+
134
+	/**
135
+	 * calls reset() on loaders if that method exists
136
+	 */
137
+	public function reset()
138
+	{
139
+		$this->shared_loader->reset();
140
+	}
141 141
 }
Please login to merge, or discard this patch.
core/services/loaders/CachingLoaderDecoratorInterface.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,20 +11,20 @@
 block discarded – undo
11 11
 interface CachingLoaderDecoratorInterface extends LoaderDecoratorInterface
12 12
 {
13 13
 
14
-    /**
15
-     * @param string $fqcn
16
-     * @param mixed  $object
17
-     * @return bool
18
-     * @throws InvalidArgumentException
19
-     */
20
-    public function share($fqcn, $object);
14
+	/**
15
+	 * @param string $fqcn
16
+	 * @param mixed  $object
17
+	 * @return bool
18
+	 * @throws InvalidArgumentException
19
+	 */
20
+	public function share($fqcn, $object);
21 21
 
22 22
 
23
-    /**
24
-     * @param string $fqcn
25
-     * @param array  $arguments
26
-     * @return bool
27
-     * @throws InvalidArgumentException
28
-     */
29
-    public function remove($fqcn, array $arguments = []);
23
+	/**
24
+	 * @param string $fqcn
25
+	 * @param array  $arguments
26
+	 * @return bool
27
+	 * @throws InvalidArgumentException
28
+	 */
29
+	public function remove($fqcn, array $arguments = []);
30 30
 }
Please login to merge, or discard this patch.
core/services/loaders/ObjectIdentifier.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -16,117 +16,117 @@
 block discarded – undo
16 16
 class ObjectIdentifier
17 17
 {
18 18
 
19
-    /**
20
-     * used to separate the FQCN from the class's arguments identifier
21
-     */
22
-    const DELIMITER = '____';
19
+	/**
20
+	 * used to separate the FQCN from the class's arguments identifier
21
+	 */
22
+	const DELIMITER = '____';
23 23
 
24
-    /**
25
-     * @var ClassInterfaceCache $class_cache
26
-     */
27
-    private $class_cache;
24
+	/**
25
+	 * @var ClassInterfaceCache $class_cache
26
+	 */
27
+	private $class_cache;
28 28
 
29 29
 
30
-    /**
31
-     * ObjectIdentifier constructor.
32
-     *
33
-     * @param ClassInterfaceCache $class_cache
34
-     */
35
-    public function __construct(ClassInterfaceCache $class_cache)
36
-    {
37
-        $this->class_cache = $class_cache;
38
-    }
30
+	/**
31
+	 * ObjectIdentifier constructor.
32
+	 *
33
+	 * @param ClassInterfaceCache $class_cache
34
+	 */
35
+	public function __construct(ClassInterfaceCache $class_cache)
36
+	{
37
+		$this->class_cache = $class_cache;
38
+	}
39 39
 
40 40
 
41
-    /**
42
-     * Returns true if the supplied $object_identifier contains
43
-     * the delimiter used to separate an fqcn from the arguments hash
44
-     *
45
-     * @param string $object_identifier
46
-     * @return bool
47
-     */
48
-    public function hasArguments($object_identifier)
49
-    {
50
-        // type casting to bool instead of using strpos() !== false
51
-        // because an object identifier should never begin with the delimiter
52
-        // therefore the delimiter should NOT be found at position 0
53
-        return (bool) strpos($object_identifier, ObjectIdentifier::DELIMITER);
54
-    }
41
+	/**
42
+	 * Returns true if the supplied $object_identifier contains
43
+	 * the delimiter used to separate an fqcn from the arguments hash
44
+	 *
45
+	 * @param string $object_identifier
46
+	 * @return bool
47
+	 */
48
+	public function hasArguments($object_identifier)
49
+	{
50
+		// type casting to bool instead of using strpos() !== false
51
+		// because an object identifier should never begin with the delimiter
52
+		// therefore the delimiter should NOT be found at position 0
53
+		return (bool) strpos($object_identifier, ObjectIdentifier::DELIMITER);
54
+	}
55 55
 
56 56
 
57
-    /**
58
-     * Returns true if the supplied FQCN equals the supplied $object_identifier
59
-     * OR the supplied FQCN matches the FQCN portion of the supplied $object_identifier
60
-     * AND that $object_identifier is for an object with arguments.
61
-     * This allows a request for an object using a FQCN to match
62
-     * a previously instantiated object with arguments
63
-     * without having to know those arguments.
64
-     *
65
-     * @param string $fqcn
66
-     * @param string $object_identifier
67
-     * @return bool
68
-     */
69
-    public function fqcnMatchesObjectIdentifier($fqcn, $object_identifier)
70
-    {
71
-        return $fqcn === $object_identifier
72
-               || strpos($object_identifier, $fqcn . ObjectIdentifier::DELIMITER) === 0;
73
-    }
57
+	/**
58
+	 * Returns true if the supplied FQCN equals the supplied $object_identifier
59
+	 * OR the supplied FQCN matches the FQCN portion of the supplied $object_identifier
60
+	 * AND that $object_identifier is for an object with arguments.
61
+	 * This allows a request for an object using a FQCN to match
62
+	 * a previously instantiated object with arguments
63
+	 * without having to know those arguments.
64
+	 *
65
+	 * @param string $fqcn
66
+	 * @param string $object_identifier
67
+	 * @return bool
68
+	 */
69
+	public function fqcnMatchesObjectIdentifier($fqcn, $object_identifier)
70
+	{
71
+		return $fqcn === $object_identifier
72
+			   || strpos($object_identifier, $fqcn . ObjectIdentifier::DELIMITER) === 0;
73
+	}
74 74
 
75 75
 
76
-    /**
77
-     * build a string representation of an object's FQCN and arguments
78
-     *
79
-     * @param string $fqcn
80
-     * @param array  $arguments
81
-     * @return string
82
-     */
83
-    public function getIdentifier($fqcn, array $arguments = array())
84
-    {
85
-        // only build identifier from arguments if class is not ReservedInstanceInterface
86
-        $identifier = ! $this->class_cache->hasInterface(
87
-            $fqcn,
88
-            'EventEspresso\core\interfaces\ReservedInstanceInterface'
89
-        )
90
-            ? $this->getIdentifierForArguments($arguments)
91
-            : '';
92
-        if (! empty($identifier)) {
93
-            $fqcn .= ObjectIdentifier::DELIMITER . md5($identifier);
94
-        }
95
-        return $fqcn;
96
-    }
76
+	/**
77
+	 * build a string representation of an object's FQCN and arguments
78
+	 *
79
+	 * @param string $fqcn
80
+	 * @param array  $arguments
81
+	 * @return string
82
+	 */
83
+	public function getIdentifier($fqcn, array $arguments = array())
84
+	{
85
+		// only build identifier from arguments if class is not ReservedInstanceInterface
86
+		$identifier = ! $this->class_cache->hasInterface(
87
+			$fqcn,
88
+			'EventEspresso\core\interfaces\ReservedInstanceInterface'
89
+		)
90
+			? $this->getIdentifierForArguments($arguments)
91
+			: '';
92
+		if (! empty($identifier)) {
93
+			$fqcn .= ObjectIdentifier::DELIMITER . md5($identifier);
94
+		}
95
+		return $fqcn;
96
+	}
97 97
 
98 98
 
99
-    /**
100
-     * build a string representation of a object's arguments
101
-     * (mostly because Closures can't be serialized)
102
-     *
103
-     * @param array $arguments
104
-     * @return string
105
-     */
106
-    protected function getIdentifierForArguments(array $arguments)
107
-    {
108
-        if (empty($arguments)) {
109
-            return '';
110
-        }
111
-        $identifier = '';
112
-        foreach ($arguments as $key => $argument) {
113
-            // don't include arguments used to assist with loading legacy classes
114
-            if (is_string($key) && strpos($key, 'EE_Registry::create') === 0) {
115
-                continue;
116
-            }
117
-            switch (true) {
118
-                case is_object($argument):
119
-                case $argument instanceof Closure:
120
-                    $identifier .= spl_object_hash($argument);
121
-                    break;
122
-                case is_array($argument):
123
-                    $identifier .= $this->getIdentifierForArguments($argument);
124
-                    break;
125
-                default:
126
-                    $identifier .= $argument;
127
-                    break;
128
-            }
129
-        }
130
-        return $identifier;
131
-    }
99
+	/**
100
+	 * build a string representation of a object's arguments
101
+	 * (mostly because Closures can't be serialized)
102
+	 *
103
+	 * @param array $arguments
104
+	 * @return string
105
+	 */
106
+	protected function getIdentifierForArguments(array $arguments)
107
+	{
108
+		if (empty($arguments)) {
109
+			return '';
110
+		}
111
+		$identifier = '';
112
+		foreach ($arguments as $key => $argument) {
113
+			// don't include arguments used to assist with loading legacy classes
114
+			if (is_string($key) && strpos($key, 'EE_Registry::create') === 0) {
115
+				continue;
116
+			}
117
+			switch (true) {
118
+				case is_object($argument):
119
+				case $argument instanceof Closure:
120
+					$identifier .= spl_object_hash($argument);
121
+					break;
122
+				case is_array($argument):
123
+					$identifier .= $this->getIdentifierForArguments($argument);
124
+					break;
125
+				default:
126
+					$identifier .= $argument;
127
+					break;
128
+			}
129
+		}
130
+		return $identifier;
131
+	}
132 132
 }
Please login to merge, or discard this patch.
core/services/loaders/ClassInterfaceCache.php 1 patch
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -17,180 +17,180 @@
 block discarded – undo
17 17
 class ClassInterfaceCache
18 18
 {
19 19
 
20
-    /**
21
-     * array of interfaces indexed by FQCNs where values are arrays of interface FQNs
22
-     *
23
-     * @var string[][] $interfaces
24
-     */
25
-    private $interfaces = array();
26
-
27
-    /**
28
-     * @type string[][] $aliases
29
-     */
30
-    protected $aliases = array();
31
-
32
-
33
-    /**
34
-     * @param string $fqn
35
-     * @return string
36
-     */
37
-    public function getFqn($fqn)
38
-    {
39
-        $fqn = $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn;
40
-        return ltrim($fqn, '\\');
41
-    }
42
-
43
-
44
-    /**
45
-     * @param string $fqn
46
-     * @return array
47
-     */
48
-    public function getInterfaces($fqn)
49
-    {
50
-        $fqn = $this->getFqn($fqn);
51
-        // have we already seen this FQCN ?
52
-        if (! array_key_exists($fqn, $this->interfaces)) {
53
-            $this->interfaces[ $fqn ] = array();
54
-            if (class_exists($fqn)) {
55
-                $this->interfaces[ $fqn ] = class_implements($fqn, false);
56
-                $this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
57
-                    ? $this->interfaces[ $fqn ]
58
-                    : array();
59
-            }
60
-        }
61
-        return $this->interfaces[ $fqn ];
62
-    }
63
-
64
-
65
-    /**
66
-     * @param string $fqn
67
-     * @param string $interface
68
-     * @return bool
69
-     */
70
-    public function hasInterface($fqn, $interface)
71
-    {
72
-        $fqn        = $this->getFqn($fqn);
73
-        $interfaces = $this->getInterfaces($fqn);
74
-        return in_array($interface, $interfaces, true);
75
-    }
76
-
77
-
78
-    /**
79
-     * adds an alias for a classname
80
-     *
81
-     * @param string $fqn       the class name that should be used (concrete class to replace interface)
82
-     * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
83
-     * @param string $for_class the class that has the dependency (is type hinting for the interface)
84
-     * @throws InvalidAliasException
85
-     */
86
-    public function addAlias($fqn, $alias, $for_class = '')
87
-    {
88
-        $fqn   = $this->getFqn($fqn);
89
-        $alias = $this->getFqn($alias);
90
-        if (strpos($alias, '\\') !== false && ! is_subclass_of($fqn, $alias)) {
91
-            throw new InvalidAliasException($fqn, $alias);
92
-        }
93
-        // are we adding an alias for a specific class?
94
-        if ($for_class !== '') {
95
-            // make sure it's set up as an array
96
-            if (! isset($this->aliases[ $for_class ])) {
97
-                $this->aliases[ $for_class ] = array();
98
-            }
99
-            $this->aliases[ $for_class ][ $alias ] = $fqn;
100
-            return;
101
-        }
102
-        $this->aliases[ $alias ] = $fqn;
103
-    }
104
-
105
-
106
-    /**
107
-     * returns TRUE if the provided FQN is an alias
108
-     *
109
-     * @param string $fqn
110
-     * @param string $for_class
111
-     * @return bool
112
-     */
113
-    public function isAlias($fqn = '', $for_class = '')
114
-    {
115
-        $fqn = $this->getFqn($fqn);
116
-        if ($this->isAliasForClass($fqn, $for_class)) {
117
-            return true;
118
-        }
119
-        if ($this->isDirectAlias($fqn)) {
120
-            return true;
121
-        }
122
-        return false;
123
-    }
124
-
125
-
126
-    /**
127
-     * returns TRUE if the provided FQN is an alias
128
-     *
129
-     * @param string $fqn
130
-     * @return bool
131
-     */
132
-    protected function isDirectAlias($fqn = '')
133
-    {
134
-        return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]);
135
-    }
136
-
137
-
138
-    /**
139
-     * returns TRUE if the provided FQN is an alias for the specified class
140
-     *
141
-     * @param string $fqn
142
-     * @param string $for_class
143
-     * @return bool
144
-     */
145
-    protected function isAliasForClass($fqn = '', $for_class = '')
146
-    {
147
-        return (
148
-            $for_class !== ''
149
-            && isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
150
-        );
151
-    }
152
-
153
-
154
-    /**
155
-     * returns FQN for provided alias if one exists, otherwise returns the original FQN
156
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
157
-     *  for example:
158
-     *      if the following two entries were added to the aliases array:
159
-     *          array(
160
-     *              'interface_alias'           => 'some\namespace\interface'
161
-     *              'some\namespace\interface'  => 'some\namespace\classname'
162
-     *          )
163
-     *      then one could use Loader::getNew( 'interface_alias' )
164
-     *      to load an instance of 'some\namespace\classname'
165
-     *
166
-     * @param string $alias
167
-     * @param string $for_class
168
-     * @return string
169
-     */
170
-    public function getFqnForAlias($alias = '', $for_class = '')
171
-    {
172
-        $alias = $this->getFqn($alias);
173
-        if ($this->isAliasForClass($alias, $for_class)) {
174
-            return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
175
-        }
176
-        if ($this->isDirectAlias($alias)) {
177
-            // note: changed '' to $for_class
178
-            return $this->getFqnForAlias($this->aliases[ (string) $alias ], $for_class);
179
-        }
180
-        return $alias;
181
-    }
182
-
183
-
184
-    // public function debug($for_class = '')
185
-    // {
186
-    //     if ($for_class !== '') {
187
-    //         if ( ! isset($this->aliases[ $for_class ])) {
188
-    //             \EEH_Debug_Tools::printr('NOT FOUND', "aliases[ $for_class ]", __FILE__, __LINE__);
189
-    //             return;
190
-    //         }
191
-    //         \EEH_Debug_Tools::printr($this->aliases[ $for_class ], "aliases[ $for_class ]", __FILE__, __LINE__);
192
-    //         return;
193
-    //     }
194
-    //     \EEH_Debug_Tools::printr($this->aliases, '$this->aliases', __FILE__, __LINE__);
195
-    // }
20
+	/**
21
+	 * array of interfaces indexed by FQCNs where values are arrays of interface FQNs
22
+	 *
23
+	 * @var string[][] $interfaces
24
+	 */
25
+	private $interfaces = array();
26
+
27
+	/**
28
+	 * @type string[][] $aliases
29
+	 */
30
+	protected $aliases = array();
31
+
32
+
33
+	/**
34
+	 * @param string $fqn
35
+	 * @return string
36
+	 */
37
+	public function getFqn($fqn)
38
+	{
39
+		$fqn = $fqn instanceof FullyQualifiedName ? $fqn->string() : $fqn;
40
+		return ltrim($fqn, '\\');
41
+	}
42
+
43
+
44
+	/**
45
+	 * @param string $fqn
46
+	 * @return array
47
+	 */
48
+	public function getInterfaces($fqn)
49
+	{
50
+		$fqn = $this->getFqn($fqn);
51
+		// have we already seen this FQCN ?
52
+		if (! array_key_exists($fqn, $this->interfaces)) {
53
+			$this->interfaces[ $fqn ] = array();
54
+			if (class_exists($fqn)) {
55
+				$this->interfaces[ $fqn ] = class_implements($fqn, false);
56
+				$this->interfaces[ $fqn ] = $this->interfaces[ $fqn ] !== false
57
+					? $this->interfaces[ $fqn ]
58
+					: array();
59
+			}
60
+		}
61
+		return $this->interfaces[ $fqn ];
62
+	}
63
+
64
+
65
+	/**
66
+	 * @param string $fqn
67
+	 * @param string $interface
68
+	 * @return bool
69
+	 */
70
+	public function hasInterface($fqn, $interface)
71
+	{
72
+		$fqn        = $this->getFqn($fqn);
73
+		$interfaces = $this->getInterfaces($fqn);
74
+		return in_array($interface, $interfaces, true);
75
+	}
76
+
77
+
78
+	/**
79
+	 * adds an alias for a classname
80
+	 *
81
+	 * @param string $fqn       the class name that should be used (concrete class to replace interface)
82
+	 * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
83
+	 * @param string $for_class the class that has the dependency (is type hinting for the interface)
84
+	 * @throws InvalidAliasException
85
+	 */
86
+	public function addAlias($fqn, $alias, $for_class = '')
87
+	{
88
+		$fqn   = $this->getFqn($fqn);
89
+		$alias = $this->getFqn($alias);
90
+		if (strpos($alias, '\\') !== false && ! is_subclass_of($fqn, $alias)) {
91
+			throw new InvalidAliasException($fqn, $alias);
92
+		}
93
+		// are we adding an alias for a specific class?
94
+		if ($for_class !== '') {
95
+			// make sure it's set up as an array
96
+			if (! isset($this->aliases[ $for_class ])) {
97
+				$this->aliases[ $for_class ] = array();
98
+			}
99
+			$this->aliases[ $for_class ][ $alias ] = $fqn;
100
+			return;
101
+		}
102
+		$this->aliases[ $alias ] = $fqn;
103
+	}
104
+
105
+
106
+	/**
107
+	 * returns TRUE if the provided FQN is an alias
108
+	 *
109
+	 * @param string $fqn
110
+	 * @param string $for_class
111
+	 * @return bool
112
+	 */
113
+	public function isAlias($fqn = '', $for_class = '')
114
+	{
115
+		$fqn = $this->getFqn($fqn);
116
+		if ($this->isAliasForClass($fqn, $for_class)) {
117
+			return true;
118
+		}
119
+		if ($this->isDirectAlias($fqn)) {
120
+			return true;
121
+		}
122
+		return false;
123
+	}
124
+
125
+
126
+	/**
127
+	 * returns TRUE if the provided FQN is an alias
128
+	 *
129
+	 * @param string $fqn
130
+	 * @return bool
131
+	 */
132
+	protected function isDirectAlias($fqn = '')
133
+	{
134
+		return isset($this->aliases[ (string) $fqn ]) && ! is_array($this->aliases[ (string) $fqn ]);
135
+	}
136
+
137
+
138
+	/**
139
+	 * returns TRUE if the provided FQN is an alias for the specified class
140
+	 *
141
+	 * @param string $fqn
142
+	 * @param string $for_class
143
+	 * @return bool
144
+	 */
145
+	protected function isAliasForClass($fqn = '', $for_class = '')
146
+	{
147
+		return (
148
+			$for_class !== ''
149
+			&& isset($this->aliases[ (string) $for_class ][ (string) $fqn ])
150
+		);
151
+	}
152
+
153
+
154
+	/**
155
+	 * returns FQN for provided alias if one exists, otherwise returns the original FQN
156
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
157
+	 *  for example:
158
+	 *      if the following two entries were added to the aliases array:
159
+	 *          array(
160
+	 *              'interface_alias'           => 'some\namespace\interface'
161
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
162
+	 *          )
163
+	 *      then one could use Loader::getNew( 'interface_alias' )
164
+	 *      to load an instance of 'some\namespace\classname'
165
+	 *
166
+	 * @param string $alias
167
+	 * @param string $for_class
168
+	 * @return string
169
+	 */
170
+	public function getFqnForAlias($alias = '', $for_class = '')
171
+	{
172
+		$alias = $this->getFqn($alias);
173
+		if ($this->isAliasForClass($alias, $for_class)) {
174
+			return $this->getFqnForAlias($this->aliases[ (string) $for_class ][ (string) $alias ], $for_class);
175
+		}
176
+		if ($this->isDirectAlias($alias)) {
177
+			// note: changed '' to $for_class
178
+			return $this->getFqnForAlias($this->aliases[ (string) $alias ], $for_class);
179
+		}
180
+		return $alias;
181
+	}
182
+
183
+
184
+	// public function debug($for_class = '')
185
+	// {
186
+	//     if ($for_class !== '') {
187
+	//         if ( ! isset($this->aliases[ $for_class ])) {
188
+	//             \EEH_Debug_Tools::printr('NOT FOUND', "aliases[ $for_class ]", __FILE__, __LINE__);
189
+	//             return;
190
+	//         }
191
+	//         \EEH_Debug_Tools::printr($this->aliases[ $for_class ], "aliases[ $for_class ]", __FILE__, __LINE__);
192
+	//         return;
193
+	//     }
194
+	//     \EEH_Debug_Tools::printr($this->aliases, '$this->aliases', __FILE__, __LINE__);
195
+	// }
196 196
 }
Please login to merge, or discard this patch.
core/services/loaders/LoaderInterface.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -8,57 +8,57 @@
 block discarded – undo
8 8
 interface LoaderInterface
9 9
 {
10 10
 
11
-    /**
12
-     * Can be for instantiating a new instance of a class,
13
-     * or for getting a shared instance of a class (default)
14
-     *
15
-     * @param FullyQualifiedName|string $fqcn
16
-     * @param array                     $arguments
17
-     * @param bool                      $shared
18
-     * @return mixed
19
-     */
20
-    public function load($fqcn, array $arguments = array(), $shared = true);
11
+	/**
12
+	 * Can be for instantiating a new instance of a class,
13
+	 * or for getting a shared instance of a class (default)
14
+	 *
15
+	 * @param FullyQualifiedName|string $fqcn
16
+	 * @param array                     $arguments
17
+	 * @param bool                      $shared
18
+	 * @return mixed
19
+	 */
20
+	public function load($fqcn, array $arguments = array(), $shared = true);
21 21
 
22 22
 
23
-    /**
24
-     * Used for instantiating a new instance of a class
25
-     *
26
-     * @param FullyQualifiedName|string $fqcn
27
-     * @param array                     $arguments
28
-     * @return mixed
29
-     */
30
-    public function getNew($fqcn, array $arguments = array());
23
+	/**
24
+	 * Used for instantiating a new instance of a class
25
+	 *
26
+	 * @param FullyQualifiedName|string $fqcn
27
+	 * @param array                     $arguments
28
+	 * @return mixed
29
+	 */
30
+	public function getNew($fqcn, array $arguments = array());
31 31
 
32 32
 
33
-    /**
34
-     * Used for getting a shared instance of a class
35
-     *
36
-     * @param FullyQualifiedName|string $fqcn
37
-     * @param array                     $arguments
38
-     * @return mixed
39
-     */
40
-    public function getShared($fqcn, array $arguments = array());
33
+	/**
34
+	 * Used for getting a shared instance of a class
35
+	 *
36
+	 * @param FullyQualifiedName|string $fqcn
37
+	 * @param array                     $arguments
38
+	 * @return mixed
39
+	 */
40
+	public function getShared($fqcn, array $arguments = array());
41 41
 
42 42
 
43
-    /**
44
-     * @param FullyQualifiedName|string $fqcn
45
-     * @param mixed                     $object
46
-     * @return bool
47
-     * @throws InvalidArgumentException
48
-     */
49
-    public function share($fqcn, $object);
43
+	/**
44
+	 * @param FullyQualifiedName|string $fqcn
45
+	 * @param mixed                     $object
46
+	 * @return bool
47
+	 * @throws InvalidArgumentException
48
+	 */
49
+	public function share($fqcn, $object);
50 50
 
51 51
 
52
-    /**
53
-     * @param FullyQualifiedName|string $fqcn
54
-     * @return bool
55
-     * @throws InvalidArgumentException
56
-     */
57
-    public function remove($fqcn);
52
+	/**
53
+	 * @param FullyQualifiedName|string $fqcn
54
+	 * @return bool
55
+	 * @throws InvalidArgumentException
56
+	 */
57
+	public function remove($fqcn);
58 58
 
59 59
 
60
-    /**
61
-     * calls reset() on loader if method exists
62
-     */
63
-    public function reset();
60
+	/**
61
+	 * calls reset() on loader if method exists
62
+	 */
63
+	public function reset();
64 64
 }
Please login to merge, or discard this patch.