Completed
Branch TASK-10784-decaf-about-page (d55fb3)
by
unknown
130:57 queued 118:59
created
modules/ticket_selector/ProcessTicketSelector.php 1 patch
Indentation   +565 added lines, -565 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 namespace EventEspresso\modules\ticket_selector;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -19,570 +19,570 @@  discard block
 block discarded – undo
19 19
 class ProcessTicketSelector
20 20
 {
21 21
 
22
-    /**
23
-     * array of datetimes and the spaces available for them
24
-     *
25
-     * @access private
26
-     * @var array
27
-     */
28
-    private static $_available_spaces = array();
29
-
30
-
31
-
32
-    /**
33
-     * cancelTicketSelections
34
-     *
35
-     * @return        string
36
-     */
37
-    public function cancelTicketSelections()
38
-    {
39
-        // check nonce
40
-        if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
41
-            return false;
42
-        }
43
-        \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
44
-        if (\EE_Registry::instance()->REQ->is_set('event_id')) {
45
-            wp_safe_redirect(
46
-                \EEH_Event_View::event_link_url(
47
-                    \EE_Registry::instance()->REQ->get('event_id')
48
-                )
49
-            );
50
-        } else {
51
-            wp_safe_redirect(
52
-                site_url('/' . \EE_Registry::instance()->CFG->core->event_cpt_slug . '/')
53
-            );
54
-        }
55
-        exit();
56
-    }
57
-
58
-
59
-
60
-    /**
61
-     * processTicketSelectorNonce
62
-     *
63
-     * @param  string $nonce_name
64
-     * @param string  $id
65
-     * @return bool
66
-     */
67
-    private function processTicketSelectorNonce($nonce_name, $id = '')
68
-    {
69
-        $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
70
-        if (
71
-            ! is_admin()
72
-            && (
73
-                ! \EE_Registry::instance()->REQ->is_set($nonce_name_with_id)
74
-                || ! wp_verify_nonce(
75
-                    \EE_Registry::instance()->REQ->get($nonce_name_with_id),
76
-                    $nonce_name
77
-                )
78
-            )
79
-        ) {
80
-            \EE_Error::add_error(
81
-                sprintf(
82
-                    __(
83
-                        'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
84
-                        'event_espresso'
85
-                    ),
86
-                    '<br/>'
87
-                ),
88
-                __FILE__,
89
-                __FUNCTION__,
90
-                __LINE__
91
-            );
92
-            return false;
93
-        }
94
-        return true;
95
-    }
96
-
97
-
98
-
99
-    /**
100
-     * process_ticket_selections
101
-     *
102
-     * @return array|bool
103
-     * @throws \EE_Error
104
-     */
105
-    public function processTicketSelections()
106
-    {
107
-        do_action('EED_Ticket_Selector__process_ticket_selections__before');
108
-        // do we have an event id?
109
-        if ( ! \EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) {
110
-            // $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
111
-            \EE_Error::add_error(
112
-                sprintf(
113
-                    __(
114
-                        'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
115
-                        'event_espresso'
116
-                    ),
117
-                    '<br/>'
118
-                ),
119
-                __FILE__,
120
-                __FUNCTION__,
121
-                __LINE__
122
-            );
123
-        }
124
-        //if event id is valid
125
-        $id = absint(\EE_Registry::instance()->REQ->get('tkt-slctr-event-id'));
126
-        //		d( \EE_Registry::instance()->REQ );
127
-        self::$_available_spaces = array(
128
-            'tickets'   => array(),
129
-            'datetimes' => array(),
130
-        );
131
-        //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart.
132
-        // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc.
133
-        \EE_Registry::instance()->load_core('Session');
134
-        // unless otherwise requested, clear the session
135
-        if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
136
-            \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
137
-        }
138
-        //d( \EE_Registry::instance()->SSN );
139
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
140
-        // validate/sanitize data
141
-        $valid = $this->validatePostData($id);
142
-        //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
143
-        //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ );
144
-        //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ );
145
-        //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ );
146
-        //check total tickets ordered vs max number of attendees that can register
147
-        if ($valid['total_tickets'] > $valid['max_atndz']) {
148
-            // ordering too many tickets !!!
149
-            $total_tickets_string = _n(
150
-                'You have attempted to purchase %s ticket.',
151
-                'You have attempted to purchase %s tickets.',
152
-                $valid['total_tickets'],
153
-                'event_espresso'
154
-            );
155
-            $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']);
156
-            // dev only message
157
-            $max_atndz_string = _n(
158
-                '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.',
159
-                '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.',
160
-                $valid['max_atndz'],
161
-                'event_espresso'
162
-            );
163
-            $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']);
164
-            \EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
165
-        } else {
166
-            // all data appears to be valid
167
-            $tckts_slctd = false;
168
-            $tickets_added = 0;
169
-            $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', $valid);
170
-            if ($valid['total_tickets'] > 0) {
171
-                // load cart
172
-                \EE_Registry::instance()->load_core('Cart');
173
-                // cycle thru the number of data rows sent from the event listing
174
-                for ($x = 0; $x < $valid['rows']; $x++) {
175
-                    // does this row actually contain a ticket quantity?
176
-                    if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) {
177
-                        // YES we have a ticket quantity
178
-                        $tckts_slctd = true;
179
-                        //						d( $valid['ticket_obj'][$x] );
180
-                        if ($valid['ticket_obj'][$x] instanceof \EE_Ticket) {
181
-                            // then add ticket to cart
182
-                            $tickets_added += $this->addTicketToCart(
183
-                                $valid['ticket_obj'][$x],
184
-                                $valid['qty'][$x]
185
-                            );
186
-                            if (\EE_Error::has_error()) {
187
-                                break;
188
-                            }
189
-                        } else {
190
-                            // nothing added to cart retrieved
191
-                            \EE_Error::add_error(
192
-                                sprintf(
193
-                                    __(
194
-                                        'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
195
-                                        'event_espresso'
196
-                                    ),
197
-                                    '<br/>'
198
-                                ),
199
-                                __FILE__, __FUNCTION__, __LINE__
200
-                            );
201
-                        }
202
-                    }
203
-                }
204
-            }
205
-            do_action(
206
-                'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
207
-                \EE_Registry::instance()->CART,
208
-                $this
209
-            );
210
-            //d( \EE_Registry::instance()->CART );
211
-            //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
212
-            if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) {
213
-                if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
214
-                    do_action(
215
-                        'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
216
-                        \EE_Registry::instance()->CART,
217
-                        $this
218
-                    );
219
-                    \EE_Registry::instance()->CART->recalculate_all_cart_totals();
220
-                    \EE_Registry::instance()->CART->save_cart(false);
221
-                    // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE
222
-                    // just return TRUE for registrations being made from admin
223
-                    if (is_admin()) {
224
-                        return true;
225
-                    }
226
-                    \EE_Error::get_notices(false, true);
227
-                    wp_safe_redirect(
228
-                        apply_filters(
229
-                            'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
230
-                            \EE_Registry::instance()->CFG->core->reg_page_url()
231
-                        )
232
-                    );
233
-                    exit();
234
-                } else {
235
-                    if ( ! \EE_Error::has_error() && ! \EE_Error::has_error(true, 'attention')) {
236
-                        // nothing added to cart
237
-                        \EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'),
238
-                            __FILE__, __FUNCTION__, __LINE__);
239
-                    }
240
-                }
241
-            } else {
242
-                // no ticket quantities were selected
243
-                \EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.',
244
-                    'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
245
-            }
246
-        }
247
-        //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
248
-        // at this point, just return if registration is being made from admin
249
-        if (is_admin()) {
250
-            return false;
251
-        }
252
-        if ($valid['return_url']) {
253
-            \EE_Error::get_notices(false, true);
254
-            wp_safe_redirect($valid['return_url']);
255
-            exit();
256
-        } elseif (isset($event_to_add['id'])) {
257
-            \EE_Error::get_notices(false, true);
258
-            wp_safe_redirect(get_permalink($event_to_add['id']));
259
-            exit();
260
-        } else {
261
-            echo \EE_Error::get_notices();
262
-        }
263
-        return false;
264
-    }
265
-
266
-
267
-
268
-    /**
269
-     * validate_post_data
270
-     *
271
-     * @param int $id
272
-     * @return array|FALSE
273
-     */
274
-    private function validatePostData($id = 0)
275
-    {
276
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
277
-        if ( ! $id) {
278
-            \EE_Error::add_error(
279
-                __('The event id provided was not valid.', 'event_espresso'),
280
-                __FILE__,
281
-                __FUNCTION__,
282
-                __LINE__
283
-            );
284
-            return false;
285
-        }
286
-        // start with an empty array()
287
-        $valid_data = array();
288
-        // grab valid id
289
-        $valid_data['id'] = $id;
290
-        // array of other form names
291
-        $inputs_to_clean = array(
292
-            'event_id'   => 'tkt-slctr-event-id',
293
-            'max_atndz'  => 'tkt-slctr-max-atndz-',
294
-            'rows'       => 'tkt-slctr-rows-',
295
-            'qty'        => 'tkt-slctr-qty-',
296
-            'ticket_id'  => 'tkt-slctr-ticket-id-',
297
-            'return_url' => 'tkt-slctr-return-url-',
298
-        );
299
-        // let's track the total number of tickets ordered.'
300
-        $valid_data['total_tickets'] = 0;
301
-        // cycle through $inputs_to_clean array
302
-        foreach ($inputs_to_clean as $what => $input_to_clean) {
303
-            // check for POST data
304
-            if (\EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) {
305
-                // grab value
306
-                $input_value = \EE_Registry::instance()->REQ->get($input_to_clean . $id);
307
-                switch ($what) {
308
-                    // integers
309
-                    case 'event_id':
310
-                        $valid_data[$what] = absint($input_value);
311
-                        // get event via the event id we put in the form
312
-                        $valid_data['event'] = \EE_Registry::instance()
313
-                                                           ->load_model('Event')
314
-                                                           ->get_one_by_ID($valid_data['event_id']);
315
-                        break;
316
-                    case 'rows':
317
-                    case 'max_atndz':
318
-                        $valid_data[$what] = absint($input_value);
319
-                        break;
320
-                    // arrays of integers
321
-                    case 'qty':
322
-                        /** @var array $row_qty */
323
-                        $row_qty = $input_value;
324
-                        // if qty is coming from a radio button input, then we need to assemble an array of rows
325
-                        if ( ! is_array($row_qty)) {
326
-                            // get number of rows
327
-                            $rows = \EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id)
328
-                                ? absint(\EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id))
329
-                                : 1;
330
-                            // explode ints by the dash
331
-                            $row_qty = explode('-', $row_qty);
332
-                            $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
333
-                            $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
334
-                            $row_qty = array($row => $qty);
335
-                            for ($x = 1; $x <= $rows; $x++) {
336
-                                if ( ! isset($row_qty[$x])) {
337
-                                    $row_qty[$x] = 0;
338
-                                }
339
-                            }
340
-                        }
341
-                        ksort($row_qty);
342
-                        // cycle thru values
343
-                        foreach ($row_qty as $qty) {
344
-                            $qty = absint($qty);
345
-                            // sanitize as integers
346
-                            $valid_data[$what][] = $qty;
347
-                            $valid_data['total_tickets'] += $qty;
348
-                        }
349
-                        break;
350
-                    // array of integers
351
-                    case 'ticket_id':
352
-                        $value_array = array();
353
-                        // cycle thru values
354
-                        foreach ((array)$input_value as $key => $value) {
355
-                            // allow only numbers, letters,  spaces, commas and dashes
356
-                            $value_array[$key] = wp_strip_all_tags($value);
357
-                            // get ticket via the ticket id we put in the form
358
-                            $ticket_obj = \EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($value);
359
-                            $valid_data['ticket_obj'][$key] = $ticket_obj;
360
-                        }
361
-                        $valid_data[$what] = $value_array;
362
-                        break;
363
-                    case 'return_url' :
364
-                        // grab and sanitize return-url
365
-                        $input_value = esc_url_raw($input_value);
366
-                        // was the request coming from an iframe ? if so, then:
367
-                        if (strpos($input_value, 'event_list=iframe')) {
368
-                            // get anchor fragment
369
-                            $input_value = explode('#', $input_value);
370
-                            $input_value = end($input_value);
371
-                            // use event list url instead, but append anchor
372
-                            $input_value = \EEH_Event_View::event_archive_url() . '#' . $input_value;
373
-                        }
374
-                        $valid_data[$what] = $input_value;
375
-                        break;
376
-                }    // end switch $what
377
-            }
378
-        }    // end foreach $inputs_to_clean
379
-        return $valid_data;
380
-    }
381
-
382
-
383
-
384
-    /**
385
-     * adds a ticket to the cart
386
-     *
387
-     * @param \EE_Ticket $ticket
388
-     * @param int        $qty
389
-     * @return TRUE on success, FALSE on fail
390
-     * @throws \EE_Error
391
-     */
392
-    private function addTicketToCart(\EE_Ticket $ticket = null, $qty = 1)
393
-    {
394
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
395
-        // get the number of spaces left for this datetime ticket
396
-        $available_spaces = $this->ticketDatetimeAvailability($ticket);
397
-        // compare available spaces against the number of tickets being purchased
398
-        if ($available_spaces >= $qty) {
399
-            // allow addons to prevent a ticket from being added to cart
400
-            if (
401
-            ! apply_filters(
402
-                'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
403
-                true,
404
-                $ticket,
405
-                $qty,
406
-                $available_spaces
407
-            )
408
-            ) {
409
-                return false;
410
-            }
411
-            $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
412
-            // add event to cart
413
-            if (\EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) {
414
-                $this->recalculateTicketDatetimeAvailability($ticket, $qty);
415
-                return true;
416
-            }
417
-            return false;
418
-        }
419
-        // tickets can not be purchased but let's find the exact number left
420
-        // for the last ticket selected PRIOR to subtracting tickets
421
-        $available_spaces = $this->ticketDatetimeAvailability($ticket, true);
422
-        // greedy greedy greedy eh?
423
-        if ($available_spaces > 0) {
424
-            if (
425
-            apply_filters(
426
-                'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error',
427
-                true,
428
-                $ticket,
429
-                $qty,
430
-                $available_spaces
431
-            )
432
-            ) {
433
-                $this->displayAvailabilityError($available_spaces);
434
-            }
435
-        } else {
436
-            \EE_Error::add_error(
437
-                __(
438
-                    'We\'re sorry, but there are no available spaces left for this event at this particular date and time.',
439
-                    'event_espresso'
440
-                ),
441
-                __FILE__, __FUNCTION__, __LINE__
442
-            );
443
-        }
444
-        return false;
445
-    }
446
-
447
-
448
-
449
-    /**
450
-     * @param int $available_spaces
451
-     * @throws \EE_Error
452
-     */
453
-    private function displayAvailabilityError($available_spaces = 1)
454
-    {
455
-        // add error messaging - we're using the _n function that will generate
456
-        // the appropriate singular or plural message based on the number of $available_spaces
457
-        if (\EE_Registry::instance()->CART->all_ticket_quantity_count()) {
458
-            $msg = sprintf(
459
-                _n(
460
-                    'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.',
461
-                    'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.',
462
-                    $available_spaces,
463
-                    'event_espresso'
464
-                ),
465
-                $available_spaces,
466
-                '<br />'
467
-            );
468
-        } else {
469
-            $msg = sprintf(
470
-                _n(
471
-                    'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.',
472
-                    'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.',
473
-                    $available_spaces,
474
-                    'event_espresso'
475
-                ),
476
-                $available_spaces,
477
-                '<br />'
478
-            );
479
-        }
480
-        \EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
481
-    }
482
-
483
-
484
-
485
-    /**
486
-     * ticketDatetimeAvailability
487
-     * creates an array of tickets plus all of the datetimes available to each ticket
488
-     * and tracks the spaces remaining for each of those datetimes
489
-     *
490
-     * @param \EE_Ticket $ticket - selected ticket
491
-     * @param bool       $get_original_ticket_spaces
492
-     * @return int
493
-     * @throws \EE_Error
494
-     */
495
-    private function ticketDatetimeAvailability(\EE_Ticket $ticket, $get_original_ticket_spaces = false)
496
-    {
497
-        // if the $_available_spaces array has not been set up yet...
498
-        if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
499
-            $this->setInitialTicketDatetimeAvailability($ticket);
500
-        }
501
-        $available_spaces = $ticket->qty() - $ticket->sold();
502
-        if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
503
-            // loop thru tickets, which will ALSO include individual ticket records AND a total
504
-            foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) {
505
-                // if we want the original datetime availability BEFORE we started subtracting tickets ?
506
-                if ($get_original_ticket_spaces) {
507
-                    // then grab the available spaces from the "tickets" array
508
-                    // and compare with the above to get the lowest number
509
-                    $available_spaces = min(
510
-                        $available_spaces,
511
-                        self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID]
512
-                    );
513
-                } else {
514
-                    // we want the updated ticket availability as stored in the "datetimes" array
515
-                    $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]);
516
-                }
517
-            }
518
-        }
519
-        return $available_spaces;
520
-    }
521
-
522
-
523
-
524
-    /**
525
-     * @param \EE_Ticket $ticket
526
-     * @return void
527
-     * @throws \EE_Error
528
-     */
529
-    private function setInitialTicketDatetimeAvailability(\EE_Ticket $ticket)
530
-    {
531
-        // first, get all of the datetimes that are available to this ticket
532
-        $datetimes = $ticket->get_many_related(
533
-            'Datetime',
534
-            array(
535
-                array(
536
-                    'DTT_EVT_end' => array(
537
-                        '>=',
538
-                        \EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
539
-                    ),
540
-                ),
541
-                'order_by' => array('DTT_EVT_start' => 'ASC'),
542
-            )
543
-        );
544
-        if ( ! empty($datetimes)) {
545
-            // now loop thru all of the datetimes
546
-            foreach ($datetimes as $datetime) {
547
-                if ($datetime instanceof \EE_Datetime) {
548
-                    // the number of spaces available for the datetime without considering individual ticket quantities
549
-                    $spaces_remaining = $datetime->spaces_remaining();
550
-                    // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold
551
-                    // or the datetime spaces remaining) to this ticket using the datetime ID as the key
552
-                    self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min(
553
-                        $ticket->qty() - $ticket->sold(),
554
-                        $spaces_remaining
555
-                    );
556
-                    // if the remaining spaces for this datetime is already set,
557
-                    // then compare that against the datetime spaces remaining, and take the lowest number,
558
-                    // else just take the datetime spaces remaining, and assign to the datetimes array
559
-                    self::$_available_spaces['datetimes'][$datetime->ID()] = isset(
560
-                        self::$_available_spaces['datetimes'][$datetime->ID()]
561
-                    )
562
-                        ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining)
563
-                        : $spaces_remaining;
564
-                }
565
-            }
566
-        }
567
-    }
568
-
569
-
570
-
571
-    /**
572
-     * @param    \EE_Ticket $ticket
573
-     * @param    int        $qty
574
-     * @return    void
575
-     */
576
-    private function recalculateTicketDatetimeAvailability(\EE_Ticket $ticket, $qty = 0)
577
-    {
578
-        if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
579
-            // loop thru tickets, which will ALSO include individual ticket records AND a total
580
-            foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) {
581
-                // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to,
582
-                self::$_available_spaces['datetimes'][$DTD_ID] -= $qty;
583
-            }
584
-        }
585
-    }
22
+	/**
23
+	 * array of datetimes and the spaces available for them
24
+	 *
25
+	 * @access private
26
+	 * @var array
27
+	 */
28
+	private static $_available_spaces = array();
29
+
30
+
31
+
32
+	/**
33
+	 * cancelTicketSelections
34
+	 *
35
+	 * @return        string
36
+	 */
37
+	public function cancelTicketSelections()
38
+	{
39
+		// check nonce
40
+		if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
41
+			return false;
42
+		}
43
+		\EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
44
+		if (\EE_Registry::instance()->REQ->is_set('event_id')) {
45
+			wp_safe_redirect(
46
+				\EEH_Event_View::event_link_url(
47
+					\EE_Registry::instance()->REQ->get('event_id')
48
+				)
49
+			);
50
+		} else {
51
+			wp_safe_redirect(
52
+				site_url('/' . \EE_Registry::instance()->CFG->core->event_cpt_slug . '/')
53
+			);
54
+		}
55
+		exit();
56
+	}
57
+
58
+
59
+
60
+	/**
61
+	 * processTicketSelectorNonce
62
+	 *
63
+	 * @param  string $nonce_name
64
+	 * @param string  $id
65
+	 * @return bool
66
+	 */
67
+	private function processTicketSelectorNonce($nonce_name, $id = '')
68
+	{
69
+		$nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
70
+		if (
71
+			! is_admin()
72
+			&& (
73
+				! \EE_Registry::instance()->REQ->is_set($nonce_name_with_id)
74
+				|| ! wp_verify_nonce(
75
+					\EE_Registry::instance()->REQ->get($nonce_name_with_id),
76
+					$nonce_name
77
+				)
78
+			)
79
+		) {
80
+			\EE_Error::add_error(
81
+				sprintf(
82
+					__(
83
+						'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
84
+						'event_espresso'
85
+					),
86
+					'<br/>'
87
+				),
88
+				__FILE__,
89
+				__FUNCTION__,
90
+				__LINE__
91
+			);
92
+			return false;
93
+		}
94
+		return true;
95
+	}
96
+
97
+
98
+
99
+	/**
100
+	 * process_ticket_selections
101
+	 *
102
+	 * @return array|bool
103
+	 * @throws \EE_Error
104
+	 */
105
+	public function processTicketSelections()
106
+	{
107
+		do_action('EED_Ticket_Selector__process_ticket_selections__before');
108
+		// do we have an event id?
109
+		if ( ! \EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) {
110
+			// $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
111
+			\EE_Error::add_error(
112
+				sprintf(
113
+					__(
114
+						'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
115
+						'event_espresso'
116
+					),
117
+					'<br/>'
118
+				),
119
+				__FILE__,
120
+				__FUNCTION__,
121
+				__LINE__
122
+			);
123
+		}
124
+		//if event id is valid
125
+		$id = absint(\EE_Registry::instance()->REQ->get('tkt-slctr-event-id'));
126
+		//		d( \EE_Registry::instance()->REQ );
127
+		self::$_available_spaces = array(
128
+			'tickets'   => array(),
129
+			'datetimes' => array(),
130
+		);
131
+		//we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart.
132
+		// When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc.
133
+		\EE_Registry::instance()->load_core('Session');
134
+		// unless otherwise requested, clear the session
135
+		if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
136
+			\EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
137
+		}
138
+		//d( \EE_Registry::instance()->SSN );
139
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
140
+		// validate/sanitize data
141
+		$valid = $this->validatePostData($id);
142
+		//EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
143
+		//EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ );
144
+		//EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ );
145
+		//EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ );
146
+		//check total tickets ordered vs max number of attendees that can register
147
+		if ($valid['total_tickets'] > $valid['max_atndz']) {
148
+			// ordering too many tickets !!!
149
+			$total_tickets_string = _n(
150
+				'You have attempted to purchase %s ticket.',
151
+				'You have attempted to purchase %s tickets.',
152
+				$valid['total_tickets'],
153
+				'event_espresso'
154
+			);
155
+			$limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']);
156
+			// dev only message
157
+			$max_atndz_string = _n(
158
+				'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.',
159
+				'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.',
160
+				$valid['max_atndz'],
161
+				'event_espresso'
162
+			);
163
+			$limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']);
164
+			\EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
165
+		} else {
166
+			// all data appears to be valid
167
+			$tckts_slctd = false;
168
+			$tickets_added = 0;
169
+			$valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', $valid);
170
+			if ($valid['total_tickets'] > 0) {
171
+				// load cart
172
+				\EE_Registry::instance()->load_core('Cart');
173
+				// cycle thru the number of data rows sent from the event listing
174
+				for ($x = 0; $x < $valid['rows']; $x++) {
175
+					// does this row actually contain a ticket quantity?
176
+					if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) {
177
+						// YES we have a ticket quantity
178
+						$tckts_slctd = true;
179
+						//						d( $valid['ticket_obj'][$x] );
180
+						if ($valid['ticket_obj'][$x] instanceof \EE_Ticket) {
181
+							// then add ticket to cart
182
+							$tickets_added += $this->addTicketToCart(
183
+								$valid['ticket_obj'][$x],
184
+								$valid['qty'][$x]
185
+							);
186
+							if (\EE_Error::has_error()) {
187
+								break;
188
+							}
189
+						} else {
190
+							// nothing added to cart retrieved
191
+							\EE_Error::add_error(
192
+								sprintf(
193
+									__(
194
+										'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
195
+										'event_espresso'
196
+									),
197
+									'<br/>'
198
+								),
199
+								__FILE__, __FUNCTION__, __LINE__
200
+							);
201
+						}
202
+					}
203
+				}
204
+			}
205
+			do_action(
206
+				'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
207
+				\EE_Registry::instance()->CART,
208
+				$this
209
+			);
210
+			//d( \EE_Registry::instance()->CART );
211
+			//die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
212
+			if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) {
213
+				if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
214
+					do_action(
215
+						'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
216
+						\EE_Registry::instance()->CART,
217
+						$this
218
+					);
219
+					\EE_Registry::instance()->CART->recalculate_all_cart_totals();
220
+					\EE_Registry::instance()->CART->save_cart(false);
221
+					// exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE
222
+					// just return TRUE for registrations being made from admin
223
+					if (is_admin()) {
224
+						return true;
225
+					}
226
+					\EE_Error::get_notices(false, true);
227
+					wp_safe_redirect(
228
+						apply_filters(
229
+							'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
230
+							\EE_Registry::instance()->CFG->core->reg_page_url()
231
+						)
232
+					);
233
+					exit();
234
+				} else {
235
+					if ( ! \EE_Error::has_error() && ! \EE_Error::has_error(true, 'attention')) {
236
+						// nothing added to cart
237
+						\EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'),
238
+							__FILE__, __FUNCTION__, __LINE__);
239
+					}
240
+				}
241
+			} else {
242
+				// no ticket quantities were selected
243
+				\EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.',
244
+					'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
245
+			}
246
+		}
247
+		//die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
248
+		// at this point, just return if registration is being made from admin
249
+		if (is_admin()) {
250
+			return false;
251
+		}
252
+		if ($valid['return_url']) {
253
+			\EE_Error::get_notices(false, true);
254
+			wp_safe_redirect($valid['return_url']);
255
+			exit();
256
+		} elseif (isset($event_to_add['id'])) {
257
+			\EE_Error::get_notices(false, true);
258
+			wp_safe_redirect(get_permalink($event_to_add['id']));
259
+			exit();
260
+		} else {
261
+			echo \EE_Error::get_notices();
262
+		}
263
+		return false;
264
+	}
265
+
266
+
267
+
268
+	/**
269
+	 * validate_post_data
270
+	 *
271
+	 * @param int $id
272
+	 * @return array|FALSE
273
+	 */
274
+	private function validatePostData($id = 0)
275
+	{
276
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
277
+		if ( ! $id) {
278
+			\EE_Error::add_error(
279
+				__('The event id provided was not valid.', 'event_espresso'),
280
+				__FILE__,
281
+				__FUNCTION__,
282
+				__LINE__
283
+			);
284
+			return false;
285
+		}
286
+		// start with an empty array()
287
+		$valid_data = array();
288
+		// grab valid id
289
+		$valid_data['id'] = $id;
290
+		// array of other form names
291
+		$inputs_to_clean = array(
292
+			'event_id'   => 'tkt-slctr-event-id',
293
+			'max_atndz'  => 'tkt-slctr-max-atndz-',
294
+			'rows'       => 'tkt-slctr-rows-',
295
+			'qty'        => 'tkt-slctr-qty-',
296
+			'ticket_id'  => 'tkt-slctr-ticket-id-',
297
+			'return_url' => 'tkt-slctr-return-url-',
298
+		);
299
+		// let's track the total number of tickets ordered.'
300
+		$valid_data['total_tickets'] = 0;
301
+		// cycle through $inputs_to_clean array
302
+		foreach ($inputs_to_clean as $what => $input_to_clean) {
303
+			// check for POST data
304
+			if (\EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) {
305
+				// grab value
306
+				$input_value = \EE_Registry::instance()->REQ->get($input_to_clean . $id);
307
+				switch ($what) {
308
+					// integers
309
+					case 'event_id':
310
+						$valid_data[$what] = absint($input_value);
311
+						// get event via the event id we put in the form
312
+						$valid_data['event'] = \EE_Registry::instance()
313
+														   ->load_model('Event')
314
+														   ->get_one_by_ID($valid_data['event_id']);
315
+						break;
316
+					case 'rows':
317
+					case 'max_atndz':
318
+						$valid_data[$what] = absint($input_value);
319
+						break;
320
+					// arrays of integers
321
+					case 'qty':
322
+						/** @var array $row_qty */
323
+						$row_qty = $input_value;
324
+						// if qty is coming from a radio button input, then we need to assemble an array of rows
325
+						if ( ! is_array($row_qty)) {
326
+							// get number of rows
327
+							$rows = \EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id)
328
+								? absint(\EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id))
329
+								: 1;
330
+							// explode ints by the dash
331
+							$row_qty = explode('-', $row_qty);
332
+							$row = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
333
+							$qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
334
+							$row_qty = array($row => $qty);
335
+							for ($x = 1; $x <= $rows; $x++) {
336
+								if ( ! isset($row_qty[$x])) {
337
+									$row_qty[$x] = 0;
338
+								}
339
+							}
340
+						}
341
+						ksort($row_qty);
342
+						// cycle thru values
343
+						foreach ($row_qty as $qty) {
344
+							$qty = absint($qty);
345
+							// sanitize as integers
346
+							$valid_data[$what][] = $qty;
347
+							$valid_data['total_tickets'] += $qty;
348
+						}
349
+						break;
350
+					// array of integers
351
+					case 'ticket_id':
352
+						$value_array = array();
353
+						// cycle thru values
354
+						foreach ((array)$input_value as $key => $value) {
355
+							// allow only numbers, letters,  spaces, commas and dashes
356
+							$value_array[$key] = wp_strip_all_tags($value);
357
+							// get ticket via the ticket id we put in the form
358
+							$ticket_obj = \EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($value);
359
+							$valid_data['ticket_obj'][$key] = $ticket_obj;
360
+						}
361
+						$valid_data[$what] = $value_array;
362
+						break;
363
+					case 'return_url' :
364
+						// grab and sanitize return-url
365
+						$input_value = esc_url_raw($input_value);
366
+						// was the request coming from an iframe ? if so, then:
367
+						if (strpos($input_value, 'event_list=iframe')) {
368
+							// get anchor fragment
369
+							$input_value = explode('#', $input_value);
370
+							$input_value = end($input_value);
371
+							// use event list url instead, but append anchor
372
+							$input_value = \EEH_Event_View::event_archive_url() . '#' . $input_value;
373
+						}
374
+						$valid_data[$what] = $input_value;
375
+						break;
376
+				}    // end switch $what
377
+			}
378
+		}    // end foreach $inputs_to_clean
379
+		return $valid_data;
380
+	}
381
+
382
+
383
+
384
+	/**
385
+	 * adds a ticket to the cart
386
+	 *
387
+	 * @param \EE_Ticket $ticket
388
+	 * @param int        $qty
389
+	 * @return TRUE on success, FALSE on fail
390
+	 * @throws \EE_Error
391
+	 */
392
+	private function addTicketToCart(\EE_Ticket $ticket = null, $qty = 1)
393
+	{
394
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
395
+		// get the number of spaces left for this datetime ticket
396
+		$available_spaces = $this->ticketDatetimeAvailability($ticket);
397
+		// compare available spaces against the number of tickets being purchased
398
+		if ($available_spaces >= $qty) {
399
+			// allow addons to prevent a ticket from being added to cart
400
+			if (
401
+			! apply_filters(
402
+				'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
403
+				true,
404
+				$ticket,
405
+				$qty,
406
+				$available_spaces
407
+			)
408
+			) {
409
+				return false;
410
+			}
411
+			$qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
412
+			// add event to cart
413
+			if (\EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) {
414
+				$this->recalculateTicketDatetimeAvailability($ticket, $qty);
415
+				return true;
416
+			}
417
+			return false;
418
+		}
419
+		// tickets can not be purchased but let's find the exact number left
420
+		// for the last ticket selected PRIOR to subtracting tickets
421
+		$available_spaces = $this->ticketDatetimeAvailability($ticket, true);
422
+		// greedy greedy greedy eh?
423
+		if ($available_spaces > 0) {
424
+			if (
425
+			apply_filters(
426
+				'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error',
427
+				true,
428
+				$ticket,
429
+				$qty,
430
+				$available_spaces
431
+			)
432
+			) {
433
+				$this->displayAvailabilityError($available_spaces);
434
+			}
435
+		} else {
436
+			\EE_Error::add_error(
437
+				__(
438
+					'We\'re sorry, but there are no available spaces left for this event at this particular date and time.',
439
+					'event_espresso'
440
+				),
441
+				__FILE__, __FUNCTION__, __LINE__
442
+			);
443
+		}
444
+		return false;
445
+	}
446
+
447
+
448
+
449
+	/**
450
+	 * @param int $available_spaces
451
+	 * @throws \EE_Error
452
+	 */
453
+	private function displayAvailabilityError($available_spaces = 1)
454
+	{
455
+		// add error messaging - we're using the _n function that will generate
456
+		// the appropriate singular or plural message based on the number of $available_spaces
457
+		if (\EE_Registry::instance()->CART->all_ticket_quantity_count()) {
458
+			$msg = sprintf(
459
+				_n(
460
+					'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.',
461
+					'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.',
462
+					$available_spaces,
463
+					'event_espresso'
464
+				),
465
+				$available_spaces,
466
+				'<br />'
467
+			);
468
+		} else {
469
+			$msg = sprintf(
470
+				_n(
471
+					'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.',
472
+					'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.',
473
+					$available_spaces,
474
+					'event_espresso'
475
+				),
476
+				$available_spaces,
477
+				'<br />'
478
+			);
479
+		}
480
+		\EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
481
+	}
482
+
483
+
484
+
485
+	/**
486
+	 * ticketDatetimeAvailability
487
+	 * creates an array of tickets plus all of the datetimes available to each ticket
488
+	 * and tracks the spaces remaining for each of those datetimes
489
+	 *
490
+	 * @param \EE_Ticket $ticket - selected ticket
491
+	 * @param bool       $get_original_ticket_spaces
492
+	 * @return int
493
+	 * @throws \EE_Error
494
+	 */
495
+	private function ticketDatetimeAvailability(\EE_Ticket $ticket, $get_original_ticket_spaces = false)
496
+	{
497
+		// if the $_available_spaces array has not been set up yet...
498
+		if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
499
+			$this->setInitialTicketDatetimeAvailability($ticket);
500
+		}
501
+		$available_spaces = $ticket->qty() - $ticket->sold();
502
+		if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
503
+			// loop thru tickets, which will ALSO include individual ticket records AND a total
504
+			foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) {
505
+				// if we want the original datetime availability BEFORE we started subtracting tickets ?
506
+				if ($get_original_ticket_spaces) {
507
+					// then grab the available spaces from the "tickets" array
508
+					// and compare with the above to get the lowest number
509
+					$available_spaces = min(
510
+						$available_spaces,
511
+						self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID]
512
+					);
513
+				} else {
514
+					// we want the updated ticket availability as stored in the "datetimes" array
515
+					$available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]);
516
+				}
517
+			}
518
+		}
519
+		return $available_spaces;
520
+	}
521
+
522
+
523
+
524
+	/**
525
+	 * @param \EE_Ticket $ticket
526
+	 * @return void
527
+	 * @throws \EE_Error
528
+	 */
529
+	private function setInitialTicketDatetimeAvailability(\EE_Ticket $ticket)
530
+	{
531
+		// first, get all of the datetimes that are available to this ticket
532
+		$datetimes = $ticket->get_many_related(
533
+			'Datetime',
534
+			array(
535
+				array(
536
+					'DTT_EVT_end' => array(
537
+						'>=',
538
+						\EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
539
+					),
540
+				),
541
+				'order_by' => array('DTT_EVT_start' => 'ASC'),
542
+			)
543
+		);
544
+		if ( ! empty($datetimes)) {
545
+			// now loop thru all of the datetimes
546
+			foreach ($datetimes as $datetime) {
547
+				if ($datetime instanceof \EE_Datetime) {
548
+					// the number of spaces available for the datetime without considering individual ticket quantities
549
+					$spaces_remaining = $datetime->spaces_remaining();
550
+					// save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold
551
+					// or the datetime spaces remaining) to this ticket using the datetime ID as the key
552
+					self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min(
553
+						$ticket->qty() - $ticket->sold(),
554
+						$spaces_remaining
555
+					);
556
+					// if the remaining spaces for this datetime is already set,
557
+					// then compare that against the datetime spaces remaining, and take the lowest number,
558
+					// else just take the datetime spaces remaining, and assign to the datetimes array
559
+					self::$_available_spaces['datetimes'][$datetime->ID()] = isset(
560
+						self::$_available_spaces['datetimes'][$datetime->ID()]
561
+					)
562
+						? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining)
563
+						: $spaces_remaining;
564
+				}
565
+			}
566
+		}
567
+	}
568
+
569
+
570
+
571
+	/**
572
+	 * @param    \EE_Ticket $ticket
573
+	 * @param    int        $qty
574
+	 * @return    void
575
+	 */
576
+	private function recalculateTicketDatetimeAvailability(\EE_Ticket $ticket, $qty = 0)
577
+	{
578
+		if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
579
+			// loop thru tickets, which will ALSO include individual ticket records AND a total
580
+			foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) {
581
+				// subtract the qty of selected tickets from each datetime's available spaces this ticket has access to,
582
+				self::$_available_spaces['datetimes'][$DTD_ID] -= $qty;
583
+			}
584
+		}
585
+	}
586 586
 
587 587
 
588 588
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                ); ?>
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+				); ?>
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.41.rc.008');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.41.rc.008');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
283 283
\ No newline at end of file
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\exceptions\InvalidInterfaceException;
4 4
 use EventEspresso\core\services\loaders\LoaderInterface;
5 5
 
6
-if (! defined('EVENT_ESPRESSO_VERSION')) {
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7 7
     exit('No direct script access allowed');
8 8
 }
9 9
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
     public static function instance(EE_Request $request = null, EE_Response $response = null)
130 130
     {
131 131
         // check if class object is instantiated, and instantiated properly
132
-        if (! self::$_instance instanceof EE_Dependency_Map) {
132
+        if ( ! self::$_instance instanceof EE_Dependency_Map) {
133 133
             self::$_instance = new EE_Dependency_Map($request, $response);
134 134
         }
135 135
         return self::$_instance;
@@ -183,16 +183,16 @@  discard block
 block discarded – undo
183 183
         $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
184 184
     ) {
185 185
         $registered = false;
186
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
187
-            self::$_instance->_dependency_map[ $class ] = array();
186
+        if (empty(self::$_instance->_dependency_map[$class])) {
187
+            self::$_instance->_dependency_map[$class] = array();
188 188
         }
189 189
         // we need to make sure that any aliases used when registering a dependency
190 190
         // get resolved to the correct class name
191
-        foreach ((array)$dependencies as $dependency => $load_source) {
191
+        foreach ((array) $dependencies as $dependency => $load_source) {
192 192
             $alias = self::$_instance->get_alias($dependency);
193 193
             if (
194 194
                 $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
195
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
195
+                || ! isset(self::$_instance->_dependency_map[$class][$alias])
196 196
             ) {
197 197
                 unset($dependencies[$dependency]);
198 198
                 $dependencies[$alias] = $load_source;
@@ -205,13 +205,13 @@  discard block
 block discarded – undo
205 205
         // ie: with A = B + C, entries in B take precedence over duplicate entries in C
206 206
         // Union is way faster than array_merge() but should be used with caution...
207 207
         // especially with numerically indexed arrays
208
-        $dependencies += self::$_instance->_dependency_map[ $class ];
208
+        $dependencies += self::$_instance->_dependency_map[$class];
209 209
         // now we need to ensure that the resulting dependencies
210 210
         // array only has the entries that are required for the class
211 211
         // so first count how many dependencies were originally registered for the class
212
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
212
+        $dependency_count = count(self::$_instance->_dependency_map[$class]);
213 213
         // if that count is non-zero (meaning dependencies were already registered)
214
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
214
+        self::$_instance->_dependency_map[$class] = $dependency_count
215 215
             // then truncate the  final array to match that count
216 216
             ? array_slice($dependencies, 0, $dependency_count)
217 217
             // otherwise just take the incoming array because nothing previously existed
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
             );
254 254
         }
255 255
         $class_name = self::$_instance->get_alias($class_name);
256
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
256
+        if ( ! isset(self::$_instance->_class_loaders[$class_name])) {
257 257
             self::$_instance->_class_loaders[$class_name] = $loader;
258 258
             return true;
259 259
         }
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
     public function class_loader($class_name)
327 327
     {
328 328
         // don't use loaders for FQCNs
329
-        if(strpos($class_name, '\\') !== false){
329
+        if (strpos($class_name, '\\') !== false) {
330 330
             return '';
331 331
         }
332 332
         $class_name = $this->get_alias($class_name);
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
     public function add_alias($class_name, $alias, $for_class = '')
356 356
     {
357 357
         if ($for_class !== '') {
358
-            if (! isset($this->_aliases[$for_class])) {
358
+            if ( ! isset($this->_aliases[$for_class])) {
359 359
                 $this->_aliases[$for_class] = array();
360 360
             }
361 361
             $this->_aliases[$for_class][$class_name] = $alias;
@@ -401,10 +401,10 @@  discard block
 block discarded – undo
401 401
      */
402 402
     public function get_alias($class_name = '', $for_class = '')
403 403
     {
404
-        if (! $this->has_alias($class_name, $for_class)) {
404
+        if ( ! $this->has_alias($class_name, $for_class)) {
405 405
             return $class_name;
406 406
         }
407
-        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
407
+        if ($for_class !== '' && isset($this->_aliases[$for_class][$class_name])) {
408 408
             return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
409 409
         }
410 410
         return $this->get_alias($this->_aliases[$class_name]);
@@ -641,10 +641,10 @@  discard block
 block discarded – undo
641 641
             'EE_Front_Controller'                  => 'load_core',
642 642
             'EE_Module_Request_Router'             => 'load_core',
643 643
             'EE_Registry'                          => 'load_core',
644
-            'EE_Request'                           => function () use (&$request) {
644
+            'EE_Request'                           => function() use (&$request) {
645 645
                 return $request;
646 646
             },
647
-            'EE_Response'                          => function () use (&$response) {
647
+            'EE_Response'                          => function() use (&$response) {
648 648
                 return $response;
649 649
             },
650 650
             'EE_Request_Handler'                   => 'load_core',
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
             'EE_Messages_Queue'                    => 'load_lib',
664 664
             'EE_Messages_Data_Handler_Collection'  => 'load_lib',
665 665
             'EE_Message_Template_Group_Collection' => 'load_lib',
666
-            'EE_Messages_Generator'                => function () {
666
+            'EE_Messages_Generator'                => function() {
667 667
                 return EE_Registry::instance()->load_lib(
668 668
                     'Messages_Generator',
669 669
                     array(),
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
                     false
672 672
                 );
673 673
             },
674
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
674
+            'EE_Messages_Template_Defaults'        => function($arguments = array()) {
675 675
                 return EE_Registry::instance()->load_lib(
676 676
                     'Messages_Template_Defaults',
677 677
                     $arguments,
@@ -683,19 +683,19 @@  discard block
 block discarded – undo
683 683
             'EEM_Message_Template_Group'           => 'load_model',
684 684
             'EEM_Message_Template'                 => 'load_model',
685 685
             //load_helper
686
-            'EEH_Parse_Shortcodes'                 => function () {
686
+            'EEH_Parse_Shortcodes'                 => function() {
687 687
                 if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
688 688
                     return new EEH_Parse_Shortcodes();
689 689
                 }
690 690
                 return null;
691 691
             },
692
-            'EE_Template_Config'                   => function () {
692
+            'EE_Template_Config'                   => function() {
693 693
                 return EE_Config::instance()->template_settings;
694 694
             },
695
-            'EE_Currency_Config'                   => function () {
695
+            'EE_Currency_Config'                   => function() {
696 696
                 return EE_Config::instance()->currency;
697 697
             },
698
-            'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) {
698
+            'EventEspresso\core\services\loaders\Loader' => function() use (&$loader) {
699 699
                 return $loader;
700 700
             },
701 701
         );
Please login to merge, or discard this patch.
Indentation   +727 added lines, -727 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\loaders\LoaderInterface;
5 5
 
6 6
 if (! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -21,732 +21,732 @@  discard block
 block discarded – undo
21 21
 class EE_Dependency_Map
22 22
 {
23 23
 
24
-    /**
25
-     * This means that the requested class dependency is not present in the dependency map
26
-     */
27
-    const not_registered = 0;
28
-
29
-    /**
30
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
31
-     */
32
-    const load_new_object = 1;
33
-
34
-    /**
35
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
36
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
37
-     */
38
-    const load_from_cache = 2;
39
-
40
-    /**
41
-     * When registering a dependency,
42
-     * this indicates to keep any existing dependencies that already exist,
43
-     * and simply discard any new dependencies declared in the incoming data
44
-     */
45
-    const KEEP_EXISTING_DEPENDENCIES = 0;
46
-
47
-    /**
48
-     * When registering a dependency,
49
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
50
-     */
51
-    const OVERWRITE_DEPENDENCIES = 1;
52
-
53
-
54
-
55
-    /**
56
-     * @type EE_Dependency_Map $_instance
57
-     */
58
-    protected static $_instance;
59
-
60
-    /**
61
-     * @type EE_Request $request
62
-     */
63
-    protected $_request;
64
-
65
-    /**
66
-     * @type EE_Response $response
67
-     */
68
-    protected $_response;
69
-
70
-    /**
71
-     * @type LoaderInterface $loader
72
-     */
73
-    protected $loader;
74
-
75
-    /**
76
-     * @type array $_dependency_map
77
-     */
78
-    protected $_dependency_map = array();
79
-
80
-    /**
81
-     * @type array $_class_loaders
82
-     */
83
-    protected $_class_loaders = array();
84
-
85
-    /**
86
-     * @type array $_aliases
87
-     */
88
-    protected $_aliases = array();
89
-
90
-
91
-
92
-    /**
93
-     * EE_Dependency_Map constructor.
94
-     *
95
-     * @param EE_Request  $request
96
-     * @param EE_Response $response
97
-     */
98
-    protected function __construct(EE_Request $request, EE_Response $response)
99
-    {
100
-        $this->_request = $request;
101
-        $this->_response = $response;
102
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
103
-        do_action('EE_Dependency_Map____construct');
104
-    }
105
-
106
-
107
-
108
-    /**
109
-     * @throws InvalidDataTypeException
110
-     * @throws InvalidInterfaceException
111
-     * @throws InvalidArgumentException
112
-     */
113
-    public function initialize()
114
-    {
115
-        $this->_register_core_dependencies();
116
-        $this->_register_core_class_loaders();
117
-        $this->_register_core_aliases();
118
-    }
119
-
120
-
121
-
122
-    /**
123
-     * @singleton method used to instantiate class object
124
-     * @access    public
125
-     * @param EE_Request  $request
126
-     * @param EE_Response $response
127
-     * @return EE_Dependency_Map
128
-     */
129
-    public static function instance(EE_Request $request = null, EE_Response $response = null)
130
-    {
131
-        // check if class object is instantiated, and instantiated properly
132
-        if (! self::$_instance instanceof EE_Dependency_Map) {
133
-            self::$_instance = new EE_Dependency_Map($request, $response);
134
-        }
135
-        return self::$_instance;
136
-    }
137
-
138
-
139
-
140
-    /**
141
-     * @param LoaderInterface $loader
142
-     */
143
-    public function setLoader(LoaderInterface $loader)
144
-    {
145
-        $this->loader = $loader;
146
-    }
147
-
148
-
149
-
150
-    /**
151
-     * @param string $class
152
-     * @param array  $dependencies
153
-     * @param int    $overwrite
154
-     * @return bool
155
-     */
156
-    public static function register_dependencies(
157
-        $class,
158
-        array $dependencies,
159
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
160
-    ) {
161
-        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
162
-    }
163
-
164
-
165
-
166
-    /**
167
-     * Assigns an array of class names and corresponding load sources (new or cached)
168
-     * to the class specified by the first parameter.
169
-     * IMPORTANT !!!
170
-     * The order of elements in the incoming $dependencies array MUST match
171
-     * the order of the constructor parameters for the class in question.
172
-     * This is especially important when overriding any existing dependencies that are registered.
173
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
174
-     *
175
-     * @param string $class
176
-     * @param array  $dependencies
177
-     * @param int    $overwrite
178
-     * @return bool
179
-     */
180
-    public function registerDependencies(
181
-        $class,
182
-        array $dependencies,
183
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
184
-    ) {
185
-        $registered = false;
186
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
187
-            self::$_instance->_dependency_map[ $class ] = array();
188
-        }
189
-        // we need to make sure that any aliases used when registering a dependency
190
-        // get resolved to the correct class name
191
-        foreach ((array)$dependencies as $dependency => $load_source) {
192
-            $alias = self::$_instance->get_alias($dependency);
193
-            if (
194
-                $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
195
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
196
-            ) {
197
-                unset($dependencies[$dependency]);
198
-                $dependencies[$alias] = $load_source;
199
-                $registered = true;
200
-            }
201
-        }
202
-        // now add our two lists of dependencies together.
203
-        // using Union (+=) favours the arrays in precedence from left to right,
204
-        // so $dependencies is NOT overwritten because it is listed first
205
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
206
-        // Union is way faster than array_merge() but should be used with caution...
207
-        // especially with numerically indexed arrays
208
-        $dependencies += self::$_instance->_dependency_map[ $class ];
209
-        // now we need to ensure that the resulting dependencies
210
-        // array only has the entries that are required for the class
211
-        // so first count how many dependencies were originally registered for the class
212
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
213
-        // if that count is non-zero (meaning dependencies were already registered)
214
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
215
-            // then truncate the  final array to match that count
216
-            ? array_slice($dependencies, 0, $dependency_count)
217
-            // otherwise just take the incoming array because nothing previously existed
218
-            : $dependencies;
219
-        return $registered;
220
-    }
221
-
222
-
223
-
224
-    /**
225
-     * @param string $class_name
226
-     * @param string $loader
227
-     * @return bool
228
-     * @throws DomainException
229
-     */
230
-    public static function register_class_loader($class_name, $loader = 'load_core')
231
-    {
232
-        if (strpos($class_name, '\\') !== false) {
233
-            throw new DomainException(
234
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
235
-            );
236
-        }
237
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
238
-        if (
239
-            ! is_callable($loader)
240
-            && (
241
-                strpos($loader, 'load_') !== 0
242
-                || ! method_exists('EE_Registry', $loader)
243
-            )
244
-        ) {
245
-            throw new DomainException(
246
-                sprintf(
247
-                    esc_html__(
248
-                        '"%1$s" is not a valid loader method on EE_Registry.',
249
-                        'event_espresso'
250
-                    ),
251
-                    $loader
252
-                )
253
-            );
254
-        }
255
-        $class_name = self::$_instance->get_alias($class_name);
256
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
257
-            self::$_instance->_class_loaders[$class_name] = $loader;
258
-            return true;
259
-        }
260
-        return false;
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     * @return array
267
-     */
268
-    public function dependency_map()
269
-    {
270
-        return $this->_dependency_map;
271
-    }
272
-
273
-
274
-
275
-    /**
276
-     * returns TRUE if dependency map contains a listing for the provided class name
277
-     *
278
-     * @param string $class_name
279
-     * @return boolean
280
-     */
281
-    public function has($class_name = '')
282
-    {
283
-        return isset($this->_dependency_map[$class_name]) ? true : false;
284
-    }
285
-
286
-
287
-
288
-    /**
289
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
290
-     *
291
-     * @param string $class_name
292
-     * @param string $dependency
293
-     * @return bool
294
-     */
295
-    public function has_dependency_for_class($class_name = '', $dependency = '')
296
-    {
297
-        $dependency = $this->get_alias($dependency);
298
-        return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency])
299
-            ? true
300
-            : false;
301
-    }
302
-
303
-
304
-
305
-    /**
306
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
307
-     *
308
-     * @param string $class_name
309
-     * @param string $dependency
310
-     * @return int
311
-     */
312
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
313
-    {
314
-        $dependency = $this->get_alias($dependency);
315
-        return $this->has_dependency_for_class($class_name, $dependency)
316
-            ? $this->_dependency_map[$class_name][$dependency]
317
-            : EE_Dependency_Map::not_registered;
318
-    }
319
-
320
-
321
-
322
-    /**
323
-     * @param string $class_name
324
-     * @return string | Closure
325
-     */
326
-    public function class_loader($class_name)
327
-    {
328
-        // don't use loaders for FQCNs
329
-        if(strpos($class_name, '\\') !== false){
330
-            return '';
331
-        }
332
-        $class_name = $this->get_alias($class_name);
333
-        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
334
-    }
335
-
336
-
337
-
338
-    /**
339
-     * @return array
340
-     */
341
-    public function class_loaders()
342
-    {
343
-        return $this->_class_loaders;
344
-    }
345
-
346
-
347
-
348
-    /**
349
-     * adds an alias for a classname
350
-     *
351
-     * @param string $class_name the class name that should be used (concrete class to replace interface)
352
-     * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
353
-     * @param string $for_class  the class that has the dependency (is type hinting for the interface)
354
-     */
355
-    public function add_alias($class_name, $alias, $for_class = '')
356
-    {
357
-        if ($for_class !== '') {
358
-            if (! isset($this->_aliases[$for_class])) {
359
-                $this->_aliases[$for_class] = array();
360
-            }
361
-            $this->_aliases[$for_class][$class_name] = $alias;
362
-        }
363
-        $this->_aliases[$class_name] = $alias;
364
-    }
365
-
366
-
367
-
368
-    /**
369
-     * returns TRUE if the provided class name has an alias
370
-     *
371
-     * @param string $class_name
372
-     * @param string $for_class
373
-     * @return bool
374
-     */
375
-    public function has_alias($class_name = '', $for_class = '')
376
-    {
377
-        return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])
378
-               || (
379
-                   isset($this->_aliases[$class_name])
380
-                   && ! is_array($this->_aliases[$class_name])
381
-               );
382
-    }
383
-
384
-
385
-
386
-    /**
387
-     * returns alias for class name if one exists, otherwise returns the original classname
388
-     * functions recursively, so that multiple aliases can be used to drill down to a classname
389
-     *  for example:
390
-     *      if the following two entries were added to the _aliases array:
391
-     *          array(
392
-     *              'interface_alias'           => 'some\namespace\interface'
393
-     *              'some\namespace\interface'  => 'some\namespace\classname'
394
-     *          )
395
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
396
-     *      to load an instance of 'some\namespace\classname'
397
-     *
398
-     * @param string $class_name
399
-     * @param string $for_class
400
-     * @return string
401
-     */
402
-    public function get_alias($class_name = '', $for_class = '')
403
-    {
404
-        if (! $this->has_alias($class_name, $for_class)) {
405
-            return $class_name;
406
-        }
407
-        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
408
-            return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
409
-        }
410
-        return $this->get_alias($this->_aliases[$class_name]);
411
-    }
412
-
413
-
414
-
415
-    /**
416
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
417
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
418
-     * This is done by using the following class constants:
419
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
420
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
421
-     */
422
-    protected function _register_core_dependencies()
423
-    {
424
-        $this->_dependency_map = array(
425
-            'EE_Request_Handler'                                                                                          => array(
426
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
427
-            ),
428
-            'EE_System'                                                                                                   => array(
429
-                'EE_Registry' => EE_Dependency_Map::load_from_cache,
430
-            ),
431
-            'EE_Session'                                                                                                  => array(
432
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
433
-                'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
434
-            ),
435
-            'EE_Cart'                                                                                                     => array(
436
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
437
-            ),
438
-            'EE_Front_Controller'                                                                                         => array(
439
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
440
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
441
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
442
-            ),
443
-            'EE_Messenger_Collection_Loader'                                                                              => array(
444
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
445
-            ),
446
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
447
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
448
-            ),
449
-            'EE_Message_Resource_Manager'                                                                                 => array(
450
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
451
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
452
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
453
-            ),
454
-            'EE_Message_Factory'                                                                                          => array(
455
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
456
-            ),
457
-            'EE_messages'                                                                                                 => array(
458
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
459
-            ),
460
-            'EE_Messages_Generator'                                                                                       => array(
461
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
462
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
463
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
464
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
465
-            ),
466
-            'EE_Messages_Processor'                                                                                       => array(
467
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
468
-            ),
469
-            'EE_Messages_Queue'                                                                                           => array(
470
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
471
-            ),
472
-            'EE_Messages_Template_Defaults'                                                                               => array(
473
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
474
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
475
-            ),
476
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
477
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
478
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
479
-            ),
480
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
481
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
482
-            ),
483
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
484
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
485
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
486
-            ),
487
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
488
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
489
-            ),
490
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
491
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
492
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
493
-            ),
494
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
495
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
496
-            ),
497
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
498
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
499
-            ),
500
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
501
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
502
-            ),
503
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
504
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
505
-            ),
506
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
507
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
508
-            ),
509
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
510
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
511
-            ),
512
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
513
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
514
-            ),
515
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
516
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
517
-            ),
518
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
519
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
520
-            ),
521
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
522
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
523
-            ),
524
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
525
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
526
-            ),
527
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
528
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
529
-            ),
530
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
531
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
532
-            ),
533
-            'EE_Data_Migration_Class_Base'                                                                                => array(
534
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
535
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
536
-            ),
537
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
538
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
539
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
540
-            ),
541
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
542
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
543
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
544
-            ),
545
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
546
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
547
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
548
-            ),
549
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
550
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
551
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
552
-            ),
553
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
554
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
555
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
556
-            ),
557
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
558
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
559
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
560
-            ),
561
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
562
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
563
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
564
-            ),
565
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
566
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
567
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
568
-            ),
569
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
570
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
571
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
572
-            ),
573
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
574
-                'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
575
-                'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
576
-            ),
577
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
578
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
579
-            ),
580
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
581
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
582
-            ),
583
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
584
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
585
-            ),
586
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
587
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
588
-            ),
589
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
590
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
591
-            ),
592
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
593
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
594
-            ),
595
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
596
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
597
-            ),
598
-            'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
599
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
600
-            ),
601
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
602
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
603
-                'EE_Session'                                              => EE_Dependency_Map::load_from_cache,
604
-            ),
605
-        );
606
-    }
607
-
608
-
609
-
610
-    /**
611
-     * Registers how core classes are loaded.
612
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
613
-     *        'EE_Request_Handler' => 'load_core'
614
-     *        'EE_Messages_Queue'  => 'load_lib'
615
-     *        'EEH_Debug_Tools'    => 'load_helper'
616
-     * or, if greater control is required, by providing a custom closure. For example:
617
-     *        'Some_Class' => function () {
618
-     *            return new Some_Class();
619
-     *        },
620
-     * This is required for instantiating dependencies
621
-     * where an interface has been type hinted in a class constructor. For example:
622
-     *        'Required_Interface' => function () {
623
-     *            return new A_Class_That_Implements_Required_Interface();
624
-     *        },
625
-     */
626
-    protected function _register_core_class_loaders()
627
-    {
628
-        //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
629
-        //be used in a closure.
630
-        $request = &$this->_request;
631
-        $response = &$this->_response;
632
-        $loader = &$this->loader;
633
-        $this->_class_loaders = array(
634
-            //load_core
635
-            'EE_Capabilities'                      => 'load_core',
636
-            'EE_Encryption'                        => 'load_core',
637
-            'EE_Front_Controller'                  => 'load_core',
638
-            'EE_Module_Request_Router'             => 'load_core',
639
-            'EE_Registry'                          => 'load_core',
640
-            'EE_Request'                           => function () use (&$request) {
641
-                return $request;
642
-            },
643
-            'EE_Response'                          => function () use (&$response) {
644
-                return $response;
645
-            },
646
-            'EE_Request_Handler'                   => 'load_core',
647
-            'EE_Session'                           => 'load_core',
648
-            'EE_System'                            => 'load_core',
649
-            //load_lib
650
-            'EE_Message_Resource_Manager'          => 'load_lib',
651
-            'EE_Message_Type_Collection'           => 'load_lib',
652
-            'EE_Message_Type_Collection_Loader'    => 'load_lib',
653
-            'EE_Messenger_Collection'              => 'load_lib',
654
-            'EE_Messenger_Collection_Loader'       => 'load_lib',
655
-            'EE_Messages_Processor'                => 'load_lib',
656
-            'EE_Message_Repository'                => 'load_lib',
657
-            'EE_Messages_Queue'                    => 'load_lib',
658
-            'EE_Messages_Data_Handler_Collection'  => 'load_lib',
659
-            'EE_Message_Template_Group_Collection' => 'load_lib',
660
-            'EE_Messages_Generator'                => function () {
661
-                return EE_Registry::instance()->load_lib(
662
-                    'Messages_Generator',
663
-                    array(),
664
-                    false,
665
-                    false
666
-                );
667
-            },
668
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
669
-                return EE_Registry::instance()->load_lib(
670
-                    'Messages_Template_Defaults',
671
-                    $arguments,
672
-                    false,
673
-                    false
674
-                );
675
-            },
676
-            //load_model
677
-            'EEM_Message_Template_Group'           => 'load_model',
678
-            'EEM_Message_Template'                 => 'load_model',
679
-            //load_helper
680
-            'EEH_Parse_Shortcodes'                 => function () {
681
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
682
-                    return new EEH_Parse_Shortcodes();
683
-                }
684
-                return null;
685
-            },
686
-            'EE_Template_Config'                   => function () {
687
-                return EE_Config::instance()->template_settings;
688
-            },
689
-            'EE_Currency_Config'                   => function () {
690
-                return EE_Config::instance()->currency;
691
-            },
692
-            'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) {
693
-                return $loader;
694
-            },
695
-        );
696
-    }
697
-
698
-
699
-
700
-    /**
701
-     * can be used for supplying alternate names for classes,
702
-     * or for connecting interface names to instantiable classes
703
-     */
704
-    protected function _register_core_aliases()
705
-    {
706
-        $this->_aliases = array(
707
-            'CommandBusInterface'                                                 => 'EventEspresso\core\services\commands\CommandBusInterface',
708
-            'EventEspresso\core\services\commands\CommandBusInterface'            => 'EventEspresso\core\services\commands\CommandBus',
709
-            'CommandHandlerManagerInterface'                                      => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
710
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager',
711
-            'CapChecker'                                                          => 'EventEspresso\core\services\commands\middleware\CapChecker',
712
-            'AddActionHook'                                                       => 'EventEspresso\core\services\commands\middleware\AddActionHook',
713
-            'CapabilitiesChecker'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
714
-            'CapabilitiesCheckerInterface'                                        => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
715
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
716
-            'CreateRegistrationService'                                           => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
717
-            'CreateRegCodeCommandHandler'                                         => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
718
-            'CreateRegUrlLinkCommandHandler'                                      => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
719
-            'CreateRegistrationCommandHandler'                                    => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
720
-            'CopyRegistrationDetailsCommandHandler'                               => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
721
-            'CopyRegistrationPaymentsCommandHandler'                              => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
722
-            'CancelRegistrationAndTicketLineItemCommandHandler'                   => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
723
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'           => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
724
-            'CreateTicketLineItemCommandHandler'                                  => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
725
-            'TableManager'                                                        => 'EventEspresso\core\services\database\TableManager',
726
-            'TableAnalysis'                                                       => 'EventEspresso\core\services\database\TableAnalysis',
727
-            'EspressoShortcode'                                                   => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
728
-            'ShortcodeInterface'                                                  => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
729
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'           => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
730
-            'EventEspresso\core\services\cache\CacheStorageInterface'             => 'EventEspresso\core\services\cache\TransientCacheStorage',
731
-            'LoaderInterface'                                                     => 'EventEspresso\core\services\loaders\LoaderInterface',
732
-            'EventEspresso\core\services\loaders\LoaderInterface'                 => 'EventEspresso\core\services\loaders\Loader',
733
-            'CommandFactoryInterface'                                             => 'EventEspresso\core\services\commands\CommandFactoryInterface',
734
-            'EventEspresso\core\services\commands\CommandFactoryInterface'        => 'EventEspresso\core\services\commands\CommandFactory',
735
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session',
736
-        );
737
-    }
738
-
739
-
740
-
741
-    /**
742
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
743
-     * request Primarily used by unit tests.
744
-     */
745
-    public function reset()
746
-    {
747
-        $this->_register_core_class_loaders();
748
-        $this->_register_core_dependencies();
749
-    }
24
+	/**
25
+	 * This means that the requested class dependency is not present in the dependency map
26
+	 */
27
+	const not_registered = 0;
28
+
29
+	/**
30
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
31
+	 */
32
+	const load_new_object = 1;
33
+
34
+	/**
35
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
36
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
37
+	 */
38
+	const load_from_cache = 2;
39
+
40
+	/**
41
+	 * When registering a dependency,
42
+	 * this indicates to keep any existing dependencies that already exist,
43
+	 * and simply discard any new dependencies declared in the incoming data
44
+	 */
45
+	const KEEP_EXISTING_DEPENDENCIES = 0;
46
+
47
+	/**
48
+	 * When registering a dependency,
49
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
50
+	 */
51
+	const OVERWRITE_DEPENDENCIES = 1;
52
+
53
+
54
+
55
+	/**
56
+	 * @type EE_Dependency_Map $_instance
57
+	 */
58
+	protected static $_instance;
59
+
60
+	/**
61
+	 * @type EE_Request $request
62
+	 */
63
+	protected $_request;
64
+
65
+	/**
66
+	 * @type EE_Response $response
67
+	 */
68
+	protected $_response;
69
+
70
+	/**
71
+	 * @type LoaderInterface $loader
72
+	 */
73
+	protected $loader;
74
+
75
+	/**
76
+	 * @type array $_dependency_map
77
+	 */
78
+	protected $_dependency_map = array();
79
+
80
+	/**
81
+	 * @type array $_class_loaders
82
+	 */
83
+	protected $_class_loaders = array();
84
+
85
+	/**
86
+	 * @type array $_aliases
87
+	 */
88
+	protected $_aliases = array();
89
+
90
+
91
+
92
+	/**
93
+	 * EE_Dependency_Map constructor.
94
+	 *
95
+	 * @param EE_Request  $request
96
+	 * @param EE_Response $response
97
+	 */
98
+	protected function __construct(EE_Request $request, EE_Response $response)
99
+	{
100
+		$this->_request = $request;
101
+		$this->_response = $response;
102
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
103
+		do_action('EE_Dependency_Map____construct');
104
+	}
105
+
106
+
107
+
108
+	/**
109
+	 * @throws InvalidDataTypeException
110
+	 * @throws InvalidInterfaceException
111
+	 * @throws InvalidArgumentException
112
+	 */
113
+	public function initialize()
114
+	{
115
+		$this->_register_core_dependencies();
116
+		$this->_register_core_class_loaders();
117
+		$this->_register_core_aliases();
118
+	}
119
+
120
+
121
+
122
+	/**
123
+	 * @singleton method used to instantiate class object
124
+	 * @access    public
125
+	 * @param EE_Request  $request
126
+	 * @param EE_Response $response
127
+	 * @return EE_Dependency_Map
128
+	 */
129
+	public static function instance(EE_Request $request = null, EE_Response $response = null)
130
+	{
131
+		// check if class object is instantiated, and instantiated properly
132
+		if (! self::$_instance instanceof EE_Dependency_Map) {
133
+			self::$_instance = new EE_Dependency_Map($request, $response);
134
+		}
135
+		return self::$_instance;
136
+	}
137
+
138
+
139
+
140
+	/**
141
+	 * @param LoaderInterface $loader
142
+	 */
143
+	public function setLoader(LoaderInterface $loader)
144
+	{
145
+		$this->loader = $loader;
146
+	}
147
+
148
+
149
+
150
+	/**
151
+	 * @param string $class
152
+	 * @param array  $dependencies
153
+	 * @param int    $overwrite
154
+	 * @return bool
155
+	 */
156
+	public static function register_dependencies(
157
+		$class,
158
+		array $dependencies,
159
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
160
+	) {
161
+		return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
162
+	}
163
+
164
+
165
+
166
+	/**
167
+	 * Assigns an array of class names and corresponding load sources (new or cached)
168
+	 * to the class specified by the first parameter.
169
+	 * IMPORTANT !!!
170
+	 * The order of elements in the incoming $dependencies array MUST match
171
+	 * the order of the constructor parameters for the class in question.
172
+	 * This is especially important when overriding any existing dependencies that are registered.
173
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
174
+	 *
175
+	 * @param string $class
176
+	 * @param array  $dependencies
177
+	 * @param int    $overwrite
178
+	 * @return bool
179
+	 */
180
+	public function registerDependencies(
181
+		$class,
182
+		array $dependencies,
183
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
184
+	) {
185
+		$registered = false;
186
+		if (empty(self::$_instance->_dependency_map[ $class ])) {
187
+			self::$_instance->_dependency_map[ $class ] = array();
188
+		}
189
+		// we need to make sure that any aliases used when registering a dependency
190
+		// get resolved to the correct class name
191
+		foreach ((array)$dependencies as $dependency => $load_source) {
192
+			$alias = self::$_instance->get_alias($dependency);
193
+			if (
194
+				$overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
195
+				|| ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
196
+			) {
197
+				unset($dependencies[$dependency]);
198
+				$dependencies[$alias] = $load_source;
199
+				$registered = true;
200
+			}
201
+		}
202
+		// now add our two lists of dependencies together.
203
+		// using Union (+=) favours the arrays in precedence from left to right,
204
+		// so $dependencies is NOT overwritten because it is listed first
205
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
206
+		// Union is way faster than array_merge() but should be used with caution...
207
+		// especially with numerically indexed arrays
208
+		$dependencies += self::$_instance->_dependency_map[ $class ];
209
+		// now we need to ensure that the resulting dependencies
210
+		// array only has the entries that are required for the class
211
+		// so first count how many dependencies were originally registered for the class
212
+		$dependency_count = count(self::$_instance->_dependency_map[ $class ]);
213
+		// if that count is non-zero (meaning dependencies were already registered)
214
+		self::$_instance->_dependency_map[ $class ] = $dependency_count
215
+			// then truncate the  final array to match that count
216
+			? array_slice($dependencies, 0, $dependency_count)
217
+			// otherwise just take the incoming array because nothing previously existed
218
+			: $dependencies;
219
+		return $registered;
220
+	}
221
+
222
+
223
+
224
+	/**
225
+	 * @param string $class_name
226
+	 * @param string $loader
227
+	 * @return bool
228
+	 * @throws DomainException
229
+	 */
230
+	public static function register_class_loader($class_name, $loader = 'load_core')
231
+	{
232
+		if (strpos($class_name, '\\') !== false) {
233
+			throw new DomainException(
234
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
235
+			);
236
+		}
237
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
238
+		if (
239
+			! is_callable($loader)
240
+			&& (
241
+				strpos($loader, 'load_') !== 0
242
+				|| ! method_exists('EE_Registry', $loader)
243
+			)
244
+		) {
245
+			throw new DomainException(
246
+				sprintf(
247
+					esc_html__(
248
+						'"%1$s" is not a valid loader method on EE_Registry.',
249
+						'event_espresso'
250
+					),
251
+					$loader
252
+				)
253
+			);
254
+		}
255
+		$class_name = self::$_instance->get_alias($class_name);
256
+		if (! isset(self::$_instance->_class_loaders[$class_name])) {
257
+			self::$_instance->_class_loaders[$class_name] = $loader;
258
+			return true;
259
+		}
260
+		return false;
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 * @return array
267
+	 */
268
+	public function dependency_map()
269
+	{
270
+		return $this->_dependency_map;
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * returns TRUE if dependency map contains a listing for the provided class name
277
+	 *
278
+	 * @param string $class_name
279
+	 * @return boolean
280
+	 */
281
+	public function has($class_name = '')
282
+	{
283
+		return isset($this->_dependency_map[$class_name]) ? true : false;
284
+	}
285
+
286
+
287
+
288
+	/**
289
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
290
+	 *
291
+	 * @param string $class_name
292
+	 * @param string $dependency
293
+	 * @return bool
294
+	 */
295
+	public function has_dependency_for_class($class_name = '', $dependency = '')
296
+	{
297
+		$dependency = $this->get_alias($dependency);
298
+		return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency])
299
+			? true
300
+			: false;
301
+	}
302
+
303
+
304
+
305
+	/**
306
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
307
+	 *
308
+	 * @param string $class_name
309
+	 * @param string $dependency
310
+	 * @return int
311
+	 */
312
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
313
+	{
314
+		$dependency = $this->get_alias($dependency);
315
+		return $this->has_dependency_for_class($class_name, $dependency)
316
+			? $this->_dependency_map[$class_name][$dependency]
317
+			: EE_Dependency_Map::not_registered;
318
+	}
319
+
320
+
321
+
322
+	/**
323
+	 * @param string $class_name
324
+	 * @return string | Closure
325
+	 */
326
+	public function class_loader($class_name)
327
+	{
328
+		// don't use loaders for FQCNs
329
+		if(strpos($class_name, '\\') !== false){
330
+			return '';
331
+		}
332
+		$class_name = $this->get_alias($class_name);
333
+		return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
334
+	}
335
+
336
+
337
+
338
+	/**
339
+	 * @return array
340
+	 */
341
+	public function class_loaders()
342
+	{
343
+		return $this->_class_loaders;
344
+	}
345
+
346
+
347
+
348
+	/**
349
+	 * adds an alias for a classname
350
+	 *
351
+	 * @param string $class_name the class name that should be used (concrete class to replace interface)
352
+	 * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
353
+	 * @param string $for_class  the class that has the dependency (is type hinting for the interface)
354
+	 */
355
+	public function add_alias($class_name, $alias, $for_class = '')
356
+	{
357
+		if ($for_class !== '') {
358
+			if (! isset($this->_aliases[$for_class])) {
359
+				$this->_aliases[$for_class] = array();
360
+			}
361
+			$this->_aliases[$for_class][$class_name] = $alias;
362
+		}
363
+		$this->_aliases[$class_name] = $alias;
364
+	}
365
+
366
+
367
+
368
+	/**
369
+	 * returns TRUE if the provided class name has an alias
370
+	 *
371
+	 * @param string $class_name
372
+	 * @param string $for_class
373
+	 * @return bool
374
+	 */
375
+	public function has_alias($class_name = '', $for_class = '')
376
+	{
377
+		return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name])
378
+			   || (
379
+				   isset($this->_aliases[$class_name])
380
+				   && ! is_array($this->_aliases[$class_name])
381
+			   );
382
+	}
383
+
384
+
385
+
386
+	/**
387
+	 * returns alias for class name if one exists, otherwise returns the original classname
388
+	 * functions recursively, so that multiple aliases can be used to drill down to a classname
389
+	 *  for example:
390
+	 *      if the following two entries were added to the _aliases array:
391
+	 *          array(
392
+	 *              'interface_alias'           => 'some\namespace\interface'
393
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
394
+	 *          )
395
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
396
+	 *      to load an instance of 'some\namespace\classname'
397
+	 *
398
+	 * @param string $class_name
399
+	 * @param string $for_class
400
+	 * @return string
401
+	 */
402
+	public function get_alias($class_name = '', $for_class = '')
403
+	{
404
+		if (! $this->has_alias($class_name, $for_class)) {
405
+			return $class_name;
406
+		}
407
+		if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
408
+			return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
409
+		}
410
+		return $this->get_alias($this->_aliases[$class_name]);
411
+	}
412
+
413
+
414
+
415
+	/**
416
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
417
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
418
+	 * This is done by using the following class constants:
419
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
420
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
421
+	 */
422
+	protected function _register_core_dependencies()
423
+	{
424
+		$this->_dependency_map = array(
425
+			'EE_Request_Handler'                                                                                          => array(
426
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
427
+			),
428
+			'EE_System'                                                                                                   => array(
429
+				'EE_Registry' => EE_Dependency_Map::load_from_cache,
430
+			),
431
+			'EE_Session'                                                                                                  => array(
432
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
433
+				'EE_Encryption'                                           => EE_Dependency_Map::load_from_cache,
434
+			),
435
+			'EE_Cart'                                                                                                     => array(
436
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
437
+			),
438
+			'EE_Front_Controller'                                                                                         => array(
439
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
440
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
441
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
442
+			),
443
+			'EE_Messenger_Collection_Loader'                                                                              => array(
444
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
445
+			),
446
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
447
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
448
+			),
449
+			'EE_Message_Resource_Manager'                                                                                 => array(
450
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
451
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
452
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
453
+			),
454
+			'EE_Message_Factory'                                                                                          => array(
455
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
456
+			),
457
+			'EE_messages'                                                                                                 => array(
458
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
459
+			),
460
+			'EE_Messages_Generator'                                                                                       => array(
461
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
462
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
463
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
464
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
465
+			),
466
+			'EE_Messages_Processor'                                                                                       => array(
467
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
468
+			),
469
+			'EE_Messages_Queue'                                                                                           => array(
470
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
471
+			),
472
+			'EE_Messages_Template_Defaults'                                                                               => array(
473
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
474
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
475
+			),
476
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
477
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
478
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
479
+			),
480
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
481
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
482
+			),
483
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
484
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
485
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
486
+			),
487
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
488
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
489
+			),
490
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
491
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
492
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
493
+			),
494
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
495
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
496
+			),
497
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
498
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
499
+			),
500
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
501
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
502
+			),
503
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
504
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
505
+			),
506
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
507
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
508
+			),
509
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
510
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
511
+			),
512
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
513
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
514
+			),
515
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
516
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
517
+			),
518
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
519
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
520
+			),
521
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
522
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
523
+			),
524
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
525
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
526
+			),
527
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
528
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
529
+			),
530
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
531
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
532
+			),
533
+			'EE_Data_Migration_Class_Base'                                                                                => array(
534
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
535
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
536
+			),
537
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
538
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
539
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
540
+			),
541
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
542
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
543
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
544
+			),
545
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
546
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
547
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
548
+			),
549
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
550
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
551
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
552
+			),
553
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
554
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
555
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
556
+			),
557
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
558
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
559
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
560
+			),
561
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
562
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
563
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
564
+			),
565
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
566
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
567
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
568
+			),
569
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
570
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
571
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
572
+			),
573
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
574
+				'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
575
+				'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
576
+			),
577
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
578
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
579
+			),
580
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
581
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
582
+			),
583
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
584
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
585
+			),
586
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
587
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
588
+			),
589
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
590
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
591
+			),
592
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
593
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
594
+			),
595
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
596
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
597
+			),
598
+			'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
599
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
600
+			),
601
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
602
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
603
+				'EE_Session'                                              => EE_Dependency_Map::load_from_cache,
604
+			),
605
+		);
606
+	}
607
+
608
+
609
+
610
+	/**
611
+	 * Registers how core classes are loaded.
612
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
613
+	 *        'EE_Request_Handler' => 'load_core'
614
+	 *        'EE_Messages_Queue'  => 'load_lib'
615
+	 *        'EEH_Debug_Tools'    => 'load_helper'
616
+	 * or, if greater control is required, by providing a custom closure. For example:
617
+	 *        'Some_Class' => function () {
618
+	 *            return new Some_Class();
619
+	 *        },
620
+	 * This is required for instantiating dependencies
621
+	 * where an interface has been type hinted in a class constructor. For example:
622
+	 *        'Required_Interface' => function () {
623
+	 *            return new A_Class_That_Implements_Required_Interface();
624
+	 *        },
625
+	 */
626
+	protected function _register_core_class_loaders()
627
+	{
628
+		//for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
629
+		//be used in a closure.
630
+		$request = &$this->_request;
631
+		$response = &$this->_response;
632
+		$loader = &$this->loader;
633
+		$this->_class_loaders = array(
634
+			//load_core
635
+			'EE_Capabilities'                      => 'load_core',
636
+			'EE_Encryption'                        => 'load_core',
637
+			'EE_Front_Controller'                  => 'load_core',
638
+			'EE_Module_Request_Router'             => 'load_core',
639
+			'EE_Registry'                          => 'load_core',
640
+			'EE_Request'                           => function () use (&$request) {
641
+				return $request;
642
+			},
643
+			'EE_Response'                          => function () use (&$response) {
644
+				return $response;
645
+			},
646
+			'EE_Request_Handler'                   => 'load_core',
647
+			'EE_Session'                           => 'load_core',
648
+			'EE_System'                            => 'load_core',
649
+			//load_lib
650
+			'EE_Message_Resource_Manager'          => 'load_lib',
651
+			'EE_Message_Type_Collection'           => 'load_lib',
652
+			'EE_Message_Type_Collection_Loader'    => 'load_lib',
653
+			'EE_Messenger_Collection'              => 'load_lib',
654
+			'EE_Messenger_Collection_Loader'       => 'load_lib',
655
+			'EE_Messages_Processor'                => 'load_lib',
656
+			'EE_Message_Repository'                => 'load_lib',
657
+			'EE_Messages_Queue'                    => 'load_lib',
658
+			'EE_Messages_Data_Handler_Collection'  => 'load_lib',
659
+			'EE_Message_Template_Group_Collection' => 'load_lib',
660
+			'EE_Messages_Generator'                => function () {
661
+				return EE_Registry::instance()->load_lib(
662
+					'Messages_Generator',
663
+					array(),
664
+					false,
665
+					false
666
+				);
667
+			},
668
+			'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
669
+				return EE_Registry::instance()->load_lib(
670
+					'Messages_Template_Defaults',
671
+					$arguments,
672
+					false,
673
+					false
674
+				);
675
+			},
676
+			//load_model
677
+			'EEM_Message_Template_Group'           => 'load_model',
678
+			'EEM_Message_Template'                 => 'load_model',
679
+			//load_helper
680
+			'EEH_Parse_Shortcodes'                 => function () {
681
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
682
+					return new EEH_Parse_Shortcodes();
683
+				}
684
+				return null;
685
+			},
686
+			'EE_Template_Config'                   => function () {
687
+				return EE_Config::instance()->template_settings;
688
+			},
689
+			'EE_Currency_Config'                   => function () {
690
+				return EE_Config::instance()->currency;
691
+			},
692
+			'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) {
693
+				return $loader;
694
+			},
695
+		);
696
+	}
697
+
698
+
699
+
700
+	/**
701
+	 * can be used for supplying alternate names for classes,
702
+	 * or for connecting interface names to instantiable classes
703
+	 */
704
+	protected function _register_core_aliases()
705
+	{
706
+		$this->_aliases = array(
707
+			'CommandBusInterface'                                                 => 'EventEspresso\core\services\commands\CommandBusInterface',
708
+			'EventEspresso\core\services\commands\CommandBusInterface'            => 'EventEspresso\core\services\commands\CommandBus',
709
+			'CommandHandlerManagerInterface'                                      => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
710
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager',
711
+			'CapChecker'                                                          => 'EventEspresso\core\services\commands\middleware\CapChecker',
712
+			'AddActionHook'                                                       => 'EventEspresso\core\services\commands\middleware\AddActionHook',
713
+			'CapabilitiesChecker'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
714
+			'CapabilitiesCheckerInterface'                                        => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
715
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
716
+			'CreateRegistrationService'                                           => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
717
+			'CreateRegCodeCommandHandler'                                         => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
718
+			'CreateRegUrlLinkCommandHandler'                                      => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
719
+			'CreateRegistrationCommandHandler'                                    => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
720
+			'CopyRegistrationDetailsCommandHandler'                               => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
721
+			'CopyRegistrationPaymentsCommandHandler'                              => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
722
+			'CancelRegistrationAndTicketLineItemCommandHandler'                   => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
723
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'           => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
724
+			'CreateTicketLineItemCommandHandler'                                  => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
725
+			'TableManager'                                                        => 'EventEspresso\core\services\database\TableManager',
726
+			'TableAnalysis'                                                       => 'EventEspresso\core\services\database\TableAnalysis',
727
+			'EspressoShortcode'                                                   => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
728
+			'ShortcodeInterface'                                                  => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
729
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'           => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
730
+			'EventEspresso\core\services\cache\CacheStorageInterface'             => 'EventEspresso\core\services\cache\TransientCacheStorage',
731
+			'LoaderInterface'                                                     => 'EventEspresso\core\services\loaders\LoaderInterface',
732
+			'EventEspresso\core\services\loaders\LoaderInterface'                 => 'EventEspresso\core\services\loaders\Loader',
733
+			'CommandFactoryInterface'                                             => 'EventEspresso\core\services\commands\CommandFactoryInterface',
734
+			'EventEspresso\core\services\commands\CommandFactoryInterface'        => 'EventEspresso\core\services\commands\CommandFactory',
735
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session',
736
+		);
737
+	}
738
+
739
+
740
+
741
+	/**
742
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
743
+	 * request Primarily used by unit tests.
744
+	 */
745
+	public function reset()
746
+	{
747
+		$this->_register_core_class_loaders();
748
+		$this->_register_core_dependencies();
749
+	}
750 750
 
751 751
 
752 752
 }
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoEvents.php 1 patch
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -34,139 +34,139 @@
 block discarded – undo
34 34
 
35 35
 
36 36
 
37
-    /**
38
-     * the actual shortcode tag that gets registered with WordPress
39
-     *
40
-     * @return string
41
-     */
42
-    public function getTag()
43
-    {
44
-        return 'ESPRESSO_EVENTS';
45
-    }
46
-
47
-
48
-
49
-    /**
50
-     * the time in seconds to cache the results of the processShortcode() method
51
-     * 0 means the processShortcode() results will NOT be cached at all
52
-     *
53
-     * @return int
54
-     */
55
-    public function cacheExpiration()
56
-    {
57
-        return 0;
58
-    }
59
-
60
-
61
-
62
-    /**
63
-     * a place for adding any initialization code that needs to run prior to wp_header().
64
-     * this may be required for shortcodes that utilize a corresponding module,
65
-     * and need to enqueue assets for that module
66
-     *
67
-     * @return void
68
-     */
69
-    public function initializeShortcode()
70
-    {
71
-        EED_Events_Archive::instance()->event_list();
72
-        $this->shortcodeHasBeenInitialized();
73
-    }
74
-
75
-
76
-
77
-    /**
78
-     * callback that runs when the shortcode is encountered in post content.
79
-     * IMPORTANT !!!
80
-     * remember that shortcode content should be RETURNED and NOT echoed out
81
-     *
82
-     * @param array $attributes
83
-     * @return string
84
-     */
85
-    public function processShortcode($attributes = array())
86
-    {
87
-        // grab attributes and merge with defaults
88
-        $attributes = $this->getAttributes($attributes);
89
-        // make sure we use the_excerpt()
90
-        add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true');
91
-        // apply query filters
92
-        add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true');
93
-        // run the query
94
-        global $wp_query;
95
-        // yes we have to overwrite the main wp query, but it's ok...
96
-        // we're going to reset it again below, so everything will be Hunky Dory (amazing album)
97
-        $wp_query = new EventListQuery($attributes);
98
-        // check what template is loaded and load filters accordingly
99
-        EED_Events_Archive::instance()->template_include('loop-espresso_events.php');
100
-        // load our template
101
-        $event_list = EEH_Template::locate_template(
102
-            'loop-espresso_events.php',
103
-            array(),
104
-            true,
105
-            true
106
-        );
107
-        // now reset the query and post data
108
-        wp_reset_query();
109
-        wp_reset_postdata();
110
-        EED_Events_Archive::remove_all_events_archive_filters();
111
-        // remove query filters
112
-        remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true');
113
-        // pull our content from the output buffer and return it
114
-        return $event_list;
115
-    }
116
-
117
-
118
-
119
-    /**
120
-     * merge incoming attributes with filtered defaults
121
-     *
122
-     * @param array $attributes
123
-     * @return array
124
-     */
125
-    private function getAttributes(array $attributes)
126
-    {
127
-        return array_merge(
128
-            (array)apply_filters(
129
-                'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts',
130
-                array(
131
-                    'title'         => '',
132
-                    'limit'         => 10,
133
-                    'css_class'     => '',
134
-                    'show_expired'  => false,
135
-                    'month'         => '',
136
-                    'category_slug' => '',
137
-                    'order_by'      => 'start_date',
138
-                    'sort'          => 'ASC',
139
-                    'show_title'    => true,
140
-                )
141
-            ),
142
-            $attributes
143
-        );
144
-    }
145
-
146
-
147
-
148
-    /**
149
-     * array for defining custom attribute sanitization callbacks,
150
-     * where keys match keys in your attributes array,
151
-     * and values represent the sanitization function you wish to be applied to that attribute.
152
-     * So for example, if you had an integer attribute named "event_id"
153
-     * that you wanted to be sanitized using absint(),
154
-     * then you would pass the following for your $custom_sanitization array:
155
-     *      array('event_id' => 'absint')
156
-     *
157
-     * @return array
158
-     */
159
-    protected function customAttributeSanitizationMap()
160
-    {
161
-        // the following get sanitized/whitelisted in EEH_Event_Query
162
-        return array(
163
-            'category_slug' => 'skip_sanitization',
164
-            'show_expired'  => 'skip_sanitization',
165
-            'order_by'      => 'skip_sanitization',
166
-            'month'         => 'skip_sanitization',
167
-            'sort'          => 'skip_sanitization',
168
-        );
169
-    }
37
+	/**
38
+	 * the actual shortcode tag that gets registered with WordPress
39
+	 *
40
+	 * @return string
41
+	 */
42
+	public function getTag()
43
+	{
44
+		return 'ESPRESSO_EVENTS';
45
+	}
46
+
47
+
48
+
49
+	/**
50
+	 * the time in seconds to cache the results of the processShortcode() method
51
+	 * 0 means the processShortcode() results will NOT be cached at all
52
+	 *
53
+	 * @return int
54
+	 */
55
+	public function cacheExpiration()
56
+	{
57
+		return 0;
58
+	}
59
+
60
+
61
+
62
+	/**
63
+	 * a place for adding any initialization code that needs to run prior to wp_header().
64
+	 * this may be required for shortcodes that utilize a corresponding module,
65
+	 * and need to enqueue assets for that module
66
+	 *
67
+	 * @return void
68
+	 */
69
+	public function initializeShortcode()
70
+	{
71
+		EED_Events_Archive::instance()->event_list();
72
+		$this->shortcodeHasBeenInitialized();
73
+	}
74
+
75
+
76
+
77
+	/**
78
+	 * callback that runs when the shortcode is encountered in post content.
79
+	 * IMPORTANT !!!
80
+	 * remember that shortcode content should be RETURNED and NOT echoed out
81
+	 *
82
+	 * @param array $attributes
83
+	 * @return string
84
+	 */
85
+	public function processShortcode($attributes = array())
86
+	{
87
+		// grab attributes and merge with defaults
88
+		$attributes = $this->getAttributes($attributes);
89
+		// make sure we use the_excerpt()
90
+		add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true');
91
+		// apply query filters
92
+		add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true');
93
+		// run the query
94
+		global $wp_query;
95
+		// yes we have to overwrite the main wp query, but it's ok...
96
+		// we're going to reset it again below, so everything will be Hunky Dory (amazing album)
97
+		$wp_query = new EventListQuery($attributes);
98
+		// check what template is loaded and load filters accordingly
99
+		EED_Events_Archive::instance()->template_include('loop-espresso_events.php');
100
+		// load our template
101
+		$event_list = EEH_Template::locate_template(
102
+			'loop-espresso_events.php',
103
+			array(),
104
+			true,
105
+			true
106
+		);
107
+		// now reset the query and post data
108
+		wp_reset_query();
109
+		wp_reset_postdata();
110
+		EED_Events_Archive::remove_all_events_archive_filters();
111
+		// remove query filters
112
+		remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true');
113
+		// pull our content from the output buffer and return it
114
+		return $event_list;
115
+	}
116
+
117
+
118
+
119
+	/**
120
+	 * merge incoming attributes with filtered defaults
121
+	 *
122
+	 * @param array $attributes
123
+	 * @return array
124
+	 */
125
+	private function getAttributes(array $attributes)
126
+	{
127
+		return array_merge(
128
+			(array)apply_filters(
129
+				'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts',
130
+				array(
131
+					'title'         => '',
132
+					'limit'         => 10,
133
+					'css_class'     => '',
134
+					'show_expired'  => false,
135
+					'month'         => '',
136
+					'category_slug' => '',
137
+					'order_by'      => 'start_date',
138
+					'sort'          => 'ASC',
139
+					'show_title'    => true,
140
+				)
141
+			),
142
+			$attributes
143
+		);
144
+	}
145
+
146
+
147
+
148
+	/**
149
+	 * array for defining custom attribute sanitization callbacks,
150
+	 * where keys match keys in your attributes array,
151
+	 * and values represent the sanitization function you wish to be applied to that attribute.
152
+	 * So for example, if you had an integer attribute named "event_id"
153
+	 * that you wanted to be sanitized using absint(),
154
+	 * then you would pass the following for your $custom_sanitization array:
155
+	 *      array('event_id' => 'absint')
156
+	 *
157
+	 * @return array
158
+	 */
159
+	protected function customAttributeSanitizationMap()
160
+	{
161
+		// the following get sanitized/whitelisted in EEH_Event_Query
162
+		return array(
163
+			'category_slug' => 'skip_sanitization',
164
+			'show_expired'  => 'skip_sanitization',
165
+			'order_by'      => 'skip_sanitization',
166
+			'month'         => 'skip_sanitization',
167
+			'sort'          => 'skip_sanitization',
168
+		);
169
+	}
170 170
 
171 171
 
172 172
 
Please login to merge, or discard this patch.
admin_pages/about/templates/decafvpro.template.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1
-<h2 style="text-align: left;"><?php esc_html_e( 'Who uses Event Espresso?', 'event_espresso'); ?></h2>
2
-<p><?php echo sprintf( esc_html__('Event Espresso is used by over 40,000 event organizers across the world. They host %sconferences%s, %sart classes%s, training courses, concerts, fundraisers, workshops, %sfilm festivals%s, and more.', 'event_espresso'), '<a href="https://eventespresso.com/use-cases/conference-registration/?utm_source=wordpress_org&amp;utm_medium=link&amp;utm_campaign=decaf_about_page&amp;utm_content=Decaf+vs+Regular">', '</a>', '<a href="https://eventespresso.com/use-cases/paint-wine-party-ticketing-software/?utm_source=wordpress_org&amp;utm_medium=link&amp;utm_campaign=decaf_about_page&amp;utm_content=Decaf+vs+Regular">', '</a>','<a href="https://eventespresso.com/use-cases/film-festival-ticketing-software/?utm_source=wordpress_org&amp;utm_medium=link&amp;utm_campaign=decaf_about_page&amp;utm_content=Decaf+vs+Regular">','</a>');?></p>
3
-<p><?php echo sprintf( esc_html__('We offer a free version of Event Espresso 4 called Decaf which is a good fit for basic events. Need more features like custom registration forms and advanced email notifications? %sCheck out Event Espresso 4%s.', 'event_espresso'),'<a href="https://eventespresso.com/pricing/?ee_ver=ee4&utm_source=wordpress_org&amp;utm_medium=link&amp;utm_campaign=decaf_about_page&amp;utm_content=Decaf+vs+Regular">','</a>');?><br>
1
+<h2 style="text-align: left;"><?php esc_html_e('Who uses Event Espresso?', 'event_espresso'); ?></h2>
2
+<p><?php echo sprintf(esc_html__('Event Espresso is used by over 40,000 event organizers across the world. They host %sconferences%s, %sart classes%s, training courses, concerts, fundraisers, workshops, %sfilm festivals%s, and more.', 'event_espresso'), '<a href="https://eventespresso.com/use-cases/conference-registration/?utm_source=wordpress_org&amp;utm_medium=link&amp;utm_campaign=decaf_about_page&amp;utm_content=Decaf+vs+Regular">', '</a>', '<a href="https://eventespresso.com/use-cases/paint-wine-party-ticketing-software/?utm_source=wordpress_org&amp;utm_medium=link&amp;utm_campaign=decaf_about_page&amp;utm_content=Decaf+vs+Regular">', '</a>', '<a href="https://eventespresso.com/use-cases/film-festival-ticketing-software/?utm_source=wordpress_org&amp;utm_medium=link&amp;utm_campaign=decaf_about_page&amp;utm_content=Decaf+vs+Regular">', '</a>'); ?></p>
3
+<p><?php echo sprintf(esc_html__('We offer a free version of Event Espresso 4 called Decaf which is a good fit for basic events. Need more features like custom registration forms and advanced email notifications? %sCheck out Event Espresso 4%s.', 'event_espresso'), '<a href="https://eventespresso.com/pricing/?ee_ver=ee4&utm_source=wordpress_org&amp;utm_medium=link&amp;utm_campaign=decaf_about_page&amp;utm_content=Decaf+vs+Regular">', '</a>'); ?><br>
4 4
 <?php
5 5
 
6 6
 /**
@@ -9,37 +9,37 @@  discard block
 block discarded – undo
9 9
 
10 10
 $features = array(
11 11
 	'pricing-options' => array(
12
-		'label'   	=> esc_html__( 'Handle multiple dates and pricing options', 'event_espresso' ),
12
+		'label'   	=> esc_html__('Handle multiple dates and pricing options', 'event_espresso'),
13 13
 		'decaf'     	=> '<span class="dashicons dashicons-no-alt"></span>',
14 14
 		'regular'	=> '<span class="dashicons dashicons-yes"></span></i>'
15 15
 	),
16 16
 	'custom-registration' => array(
17
-		'label'  	=> esc_html__( 'Create custom registration forms', 'event_espresso' ),
17
+		'label'  	=> esc_html__('Create custom registration forms', 'event_espresso'),
18 18
 		'decaf'     	=> '<span class="dashicons dashicons-no-alt"></span>',
19 19
 		'regular' 	=> '<span class="dashicons dashicons-yes"></span></i>'
20 20
 	),
21 21
 	'advanced-notifications' => array(
22
-		'label'       => esc_html__( 'Customize advanced email notifications', 'event_espresso' ),
22
+		'label'       => esc_html__('Customize advanced email notifications', 'event_espresso'),
23 23
 		'decaf'     => '<span class="dashicons dashicons-no-alt"></span>',
24 24
 		'regular' => '<span class="dashicons dashicons-yes"></span></i>'
25 25
 	),
26 26
 	'manage-taxes'    => array(
27
-		'label'       => esc_html__( 'Manage taxes', 'event_espresso' ),
27
+		'label'       => esc_html__('Manage taxes', 'event_espresso'),
28 28
 		'decaf'     => '<span class="dashicons dashicons-no-alt"></span>',
29 29
 		'regular' => '<span class="dashicons dashicons-yes"></span></i>'
30 30
 	),
31 31
 	'typography'       => array(
32
-		'label'       => esc_html__( 'Additional payment methods available', 'event_espresso' ),
32
+		'label'       => esc_html__('Additional payment methods available', 'event_espresso'),
33 33
 		'decaf'     => '<span class="dashicons dashicons-no-alt"></span>',
34 34
 		'regular' => '<span class="dashicons dashicons-yes"></span></i>'
35 35
 	),
36 36
 	'add-on-compatibility' => array(
37
-		'label'       => esc_html__( 'Compatibility with add-ons', 'event_espresso' ),
37
+		'label'       => esc_html__('Compatibility with add-ons', 'event_espresso'),
38 38
 		'decaf'     => '<span class="dashicons dashicons-no-alt"></span>',
39 39
 		'regular' => '<span class="dashicons dashicons-yes"></span></i>'
40 40
 	),
41 41
 	'best-support' => array(
42
-		'label'       => esc_html__( 'Best in class support', 'event_espresso' ),
42
+		'label'       => esc_html__('Best in class support', 'event_espresso'),
43 43
 		'decaf'     => '<span class="dashicons dashicons-no-alt"></span>',
44 44
 		'regular' => '<span class="dashicons dashicons-yes"></span></i>'
45 45
 	),
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
         <thead>
51 51
         <tr>
52 52
             <th></th>
53
-            <th><?php esc_html_e( 'Decaf', 'event_espresso' ) ?></th>
54
-            <th><?php esc_html_e( 'Regular', 'event_espresso' ) ?></th>
53
+            <th><?php esc_html_e('Decaf', 'event_espresso') ?></th>
54
+            <th><?php esc_html_e('Regular', 'event_espresso') ?></th>
55 55
         </tr>
56 56
         </thead>
57 57
         <tbody>
58
-		<?php foreach ( $features as $feature ): ?>
58
+		<?php foreach ($features as $feature): ?>
59 59
             <tr>
60 60
                 <td class="feature">
61 61
                     <h3>
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 		<?php endforeach; ?>
73 73
         <tr>
74 74
             <td></td>
75
-            <td colspan="2" class="text-right"><a href="https://eventespresso.com/pricing/?utm_source=wordpress_org&amp;utm_medium=link&amp;utm_campaign=decaf_about_page&amp;utm_content=Decaf+vs+Regular" target="_blank" class="button button-primary button-hero"><span class="dashicons dashicons-cart"></span><?php esc_html_e( 'Upgrade Now!', 'event_espresso' ) ?></a></td>
75
+            <td colspan="2" class="text-right"><a href="https://eventespresso.com/pricing/?utm_source=wordpress_org&amp;utm_medium=link&amp;utm_campaign=decaf_about_page&amp;utm_content=Decaf+vs+Regular" target="_blank" class="button button-primary button-hero"><span class="dashicons dashicons-cart"></span><?php esc_html_e('Upgrade Now!', 'event_espresso') ?></a></td>
76 76
         </tr>
77 77
         </tbody>
78 78
     </table>
Please login to merge, or discard this patch.