Completed
Branch FET/9575/invisible-recaptcha (4e0b6f)
by
unknown
44:51 queued 31:17
created
modules/core_rest_api/EED_Core_Rest_Api.module.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 use EventEspresso\core\domain\Domain;
4
-use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice;
5 4
 use EventEspresso\core\domain\services\factories\EmailAddressFactory;
6 5
 use EventEspresso\core\domain\services\validation\email\EmailValidationException;
7 6
 use EventEspresso\core\exceptions\InvalidDataTypeException;
Please login to merge, or discard this patch.
Indentation   +1249 added lines, -1249 removed lines patch added patch discarded remove patch
@@ -26,1256 +26,1256 @@
 block discarded – undo
26 26
 class EED_Core_Rest_Api extends \EED_Module
27 27
 {
28 28
 
29
-    const ee_api_namespace           = Domain::API_NAMESPACE;
29
+	const ee_api_namespace           = Domain::API_NAMESPACE;
30 30
 
31
-    const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/';
32
-
33
-    const saved_routes_option_names  = 'ee_core_routes';
34
-
35
-    /**
36
-     * string used in _links response bodies to make them globally unique.
37
-     *
38
-     * @see http://v2.wp-api.org/extending/linking/
39
-     */
40
-    const ee_api_link_namespace = 'https://api.eventespresso.com/';
41
-
42
-    /**
43
-     * @var CalculatedModelFields
44
-     */
45
-    protected static $_field_calculator;
46
-
47
-
48
-
49
-    /**
50
-     * @return EED_Core_Rest_Api|EED_Module
51
-     */
52
-    public static function instance()
53
-    {
54
-        self::$_field_calculator = new CalculatedModelFields();
55
-        return parent::get_instance(__CLASS__);
56
-    }
57
-
58
-
59
-
60
-    /**
61
-     *    set_hooks - for hooking into EE Core, other modules, etc
62
-     *
63
-     * @access    public
64
-     * @return    void
65
-     */
66
-    public static function set_hooks()
67
-    {
68
-        self::set_hooks_both();
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
75
-     *
76
-     * @access    public
77
-     * @return    void
78
-     */
79
-    public static function set_hooks_admin()
80
-    {
81
-        self::set_hooks_both();
82
-    }
83
-
84
-
85
-
86
-    public static function set_hooks_both()
87
-    {
88
-        add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10);
89
-        add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5);
90
-        add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2);
91
-        add_filter('rest_index',
92
-            array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex'));
93
-        EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change();
94
-    }
95
-
96
-
97
-
98
-    /**
99
-     * sets up hooks which only need to be included as part of REST API requests;
100
-     * other requests like to the frontend or admin etc don't need them
101
-     *
102
-     * @throws \EE_Error
103
-     */
104
-    public static function set_hooks_rest_api()
105
-    {
106
-        //set hooks which account for changes made to the API
107
-        EED_Core_Rest_Api::_set_hooks_for_changes();
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * public wrapper of _set_hooks_for_changes.
114
-     * Loads all the hooks which make requests to old versions of the API
115
-     * appear the same as they always did
116
-     *
117
-     * @throws EE_Error
118
-     */
119
-    public static function set_hooks_for_changes()
120
-    {
121
-        self::_set_hooks_for_changes();
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * Loads all the hooks which make requests to old versions of the API
128
-     * appear the same as they always did
129
-     *
130
-     * @throws EE_Error
131
-     */
132
-    protected static function _set_hooks_for_changes()
133
-    {
134
-        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
135
-        foreach ($folder_contents as $classname_in_namespace => $filepath) {
136
-            //ignore the base parent class
137
-            //and legacy named classes
138
-            if ($classname_in_namespace === 'ChangesInBase'
139
-                || strpos($classname_in_namespace, 'Changes_In_') === 0
140
-            ) {
141
-                continue;
142
-            }
143
-            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
144
-            if (class_exists($full_classname)) {
145
-                $instance_of_class = new $full_classname;
146
-                if ($instance_of_class instanceof ChangesInBase) {
147
-                    $instance_of_class->setHooks();
148
-                }
149
-            }
150
-        }
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * Filters the WP routes to add our EE-related ones. This takes a bit of time
157
-     * so we actually prefer to only do it when an EE plugin is activated or upgraded
158
-     *
159
-     * @throws \EE_Error
160
-     */
161
-    public static function register_routes()
162
-    {
163
-        foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) {
164
-            foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) {
165
-                /**
166
-                 * @var array $data_for_multiple_endpoints numerically indexed array
167
-                 *                                         but can also contain route options like {
168
-                 * @type array    $schema                      {
169
-                 * @type callable $schema_callback
170
-                 * @type array    $callback_args               arguments that will be passed to the callback, after the
171
-                 * WP_REST_Request of course
172
-                 * }
173
-                 * }
174
-                 */
175
-                //when registering routes, register all the endpoints' data at the same time
176
-                $multiple_endpoint_args = array();
177
-                foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) {
178
-                    /**
179
-                     * @var array     $data_for_single_endpoint {
180
-                     * @type callable $callback
181
-                     * @type string methods
182
-                     * @type array args
183
-                     * @type array _links
184
-                     * @type array    $callback_args            arguments that will be passed to the callback, after the
185
-                     * WP_REST_Request of course
186
-                     * }
187
-                     */
188
-                    //skip route options
189
-                    if (! is_numeric($endpoint_key)) {
190
-                        continue;
191
-                    }
192
-                    if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
193
-                        throw new EE_Error(
194
-                            esc_html__(
195
-                                // @codingStandardsIgnoreStart
196
-                                'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).',
197
-                                // @codingStandardsIgnoreEnd
198
-                                'event_espresso')
199
-                        );
200
-                    }
201
-                    $callback = $data_for_single_endpoint['callback'];
202
-                    $single_endpoint_args = array(
203
-                        'methods' => $data_for_single_endpoint['methods'],
204
-                        'args'    => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args']
205
-                            : array(),
206
-                    );
207
-                    if (isset($data_for_single_endpoint['_links'])) {
208
-                        $single_endpoint_args['_links'] = $data_for_single_endpoint['_links'];
209
-                    }
210
-                    if (isset($data_for_single_endpoint['callback_args'])) {
211
-                        $callback_args = $data_for_single_endpoint['callback_args'];
212
-                        $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use (
213
-                            $callback,
214
-                            $callback_args
215
-                        ) {
216
-                            array_unshift($callback_args, $request);
217
-                            return call_user_func_array(
218
-                                $callback,
219
-                                $callback_args
220
-                            );
221
-                        };
222
-                    } else {
223
-                        $single_endpoint_args['callback'] = $data_for_single_endpoint['callback'];
224
-                    }
225
-                    $multiple_endpoint_args[] = $single_endpoint_args;
226
-                }
227
-                if (isset($data_for_multiple_endpoints['schema'])) {
228
-                    $schema_route_data = $data_for_multiple_endpoints['schema'];
229
-                    $schema_callback = $schema_route_data['schema_callback'];
230
-                    $callback_args = $schema_route_data['callback_args'];
231
-                    $multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) {
232
-                        return call_user_func_array(
233
-                            $schema_callback,
234
-                            $callback_args
235
-                        );
236
-                    };
237
-                }
238
-                register_rest_route(
239
-                    $namespace,
240
-                    $relative_route,
241
-                    $multiple_endpoint_args
242
-                );
243
-            }
244
-        }
245
-    }
246
-
247
-
248
-
249
-    /**
250
-     * Checks if there was a version change or something that merits invalidating the cached
251
-     * route data. If so, invalidates the cached route data so that it gets refreshed
252
-     * next time the WP API is used
253
-     */
254
-    public static function invalidate_cached_route_data_on_version_change()
255
-    {
256
-        if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) {
257
-            EED_Core_Rest_Api::invalidate_cached_route_data();
258
-        }
259
-        foreach (EE_Registry::instance()->addons as $addon) {
260
-            if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) {
261
-                EED_Core_Rest_Api::invalidate_cached_route_data();
262
-            }
263
-        }
264
-    }
265
-
266
-
267
-
268
-    /**
269
-     * Removes the cached route data so it will get refreshed next time the WP API is used
270
-     */
271
-    public static function invalidate_cached_route_data()
272
-    {
273
-        //delete the saved EE REST API routes
274
-        foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
275
-            delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
276
-        }
277
-    }
278
-
279
-
280
-
281
-    /**
282
-     * Gets the EE route data
283
-     *
284
-     * @return array top-level key is the namespace, next-level key is the route and its value is array{
285
-     * @throws \EE_Error
286
-     * @type string|array $callback
287
-     * @type string       $methods
288
-     * @type boolean      $hidden_endpoint
289
-     * }
290
-     */
291
-    public static function get_ee_route_data()
292
-    {
293
-        $ee_routes = array();
294
-        foreach (self::versions_served() as $version => $hidden_endpoints) {
295
-            $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version(
296
-                $version,
297
-                $hidden_endpoints
298
-            );
299
-        }
300
-        return $ee_routes;
301
-    }
302
-
303
-
304
-
305
-    /**
306
-     * Gets the EE route data from the wp options if it exists already,
307
-     * otherwise re-generates it and saves it to the option
308
-     *
309
-     * @param string  $version
310
-     * @param boolean $hidden_endpoints
311
-     * @return array
312
-     * @throws \EE_Error
313
-     */
314
-    protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
315
-    {
316
-        $ee_routes = get_option(self::saved_routes_option_names . $version, null);
317
-        if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
318
-            $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
319
-        }
320
-        return $ee_routes;
321
-    }
322
-
323
-
324
-
325
-    /**
326
-     * Saves the EE REST API route data to a wp option and returns it
327
-     *
328
-     * @param string  $version
329
-     * @param boolean $hidden_endpoints
330
-     * @return mixed|null
331
-     * @throws \EE_Error
332
-     */
333
-    protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false)
334
-    {
335
-        $instance = self::instance();
336
-        $routes = apply_filters(
337
-            'EED_Core_Rest_Api__save_ee_route_data_for_version__routes',
338
-            array_replace_recursive(
339
-                $instance->_get_config_route_data_for_version($version, $hidden_endpoints),
340
-                $instance->_get_meta_route_data_for_version($version, $hidden_endpoints),
341
-                $instance->_get_model_route_data_for_version($version, $hidden_endpoints),
342
-                $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
343
-            )
344
-        );
345
-        $option_name = self::saved_routes_option_names . $version;
346
-        if (get_option($option_name)) {
347
-            update_option($option_name, $routes, true);
348
-        } else {
349
-            add_option($option_name, $routes, null, 'no');
350
-        }
351
-        return $routes;
352
-    }
353
-
354
-
355
-
356
-    /**
357
-     * Calculates all the EE routes and saves it to a WordPress option so we don't
358
-     * need to calculate it on every request
359
-     *
360
-     * @deprecated since version 4.9.1
361
-     * @return void
362
-     */
363
-    public static function save_ee_routes()
364
-    {
365
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
366
-            $instance = self::instance();
367
-            $routes = apply_filters(
368
-                'EED_Core_Rest_Api__save_ee_routes__routes',
369
-                array_replace_recursive(
370
-                    $instance->_register_config_routes(),
371
-                    $instance->_register_meta_routes(),
372
-                    $instance->_register_model_routes(),
373
-                    $instance->_register_rpc_routes()
374
-                )
375
-            );
376
-            update_option(self::saved_routes_option_names, $routes, true);
377
-        }
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * Gets all the route information relating to EE models
384
-     *
385
-     * @return array @see get_ee_route_data
386
-     * @deprecated since version 4.9.1
387
-     */
388
-    protected function _register_model_routes()
389
-    {
390
-        $model_routes = array();
391
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
392
-            $model_routes[EED_Core_Rest_Api::ee_api_namespace
393
-                          . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
394
-        }
395
-        return $model_routes;
396
-    }
397
-
398
-
399
-
400
-    /**
401
-     * Decides whether or not to add write endpoints for this model.
402
-     *
403
-     * Currently, this defaults to exclude all global tables and models
404
-     * which would allow inserting WP core data (we don't want to duplicate
405
-     * what WP API does, as it's unnecessary, extra work, and potentially extra bugs)
406
-     * @param EEM_Base $model
407
-     * @return bool
408
-     */
409
-    public static function should_have_write_endpoints(EEM_Base $model)
410
-    {
411
-        if ($model->is_wp_core_model()){
412
-            return false;
413
-        }
414
-        foreach($model->get_tables() as $table){
415
-            if( $table->is_global()){
416
-                return false;
417
-            }
418
-        }
419
-        return true;
420
-    }
421
-
422
-
423
-
424
-    /**
425
-     * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`)
426
-     * in this versioned namespace of EE4
427
-     * @param $version
428
-     * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event')
429
-     */
430
-    public static function model_names_with_plural_routes($version){
431
-        $model_version_info = new ModelVersionInfo($version);
432
-        $models_to_register = $model_version_info->modelsForRequestedVersion();
433
-        //let's not bother having endpoints for extra metas
434
-        unset(
435
-            $models_to_register['Extra_Meta'],
436
-            $models_to_register['Extra_Join'],
437
-            $models_to_register['Post_Meta']
438
-        );
439
-        return apply_filters(
440
-            'FHEE__EED_Core_REST_API___register_model_routes',
441
-            $models_to_register
442
-        );
443
-    }
444
-
445
-
446
-
447
-    /**
448
-     * Gets the route data for EE models in the specified version
449
-     *
450
-     * @param string  $version
451
-     * @param boolean $hidden_endpoint
452
-     * @return array
453
-     * @throws EE_Error
454
-     */
455
-    protected function _get_model_route_data_for_version($version, $hidden_endpoint = false)
456
-    {
457
-        $model_routes = array();
458
-        $model_version_info = new ModelVersionInfo($version);
459
-        foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) {
460
-            $model = \EE_Registry::instance()->load_model($model_name);
461
-            //if this isn't a valid model then let's skip iterate to the next item in the loop.
462
-            if (! $model instanceof EEM_Base) {
463
-                continue;
464
-            }
465
-            //yes we could just register one route for ALL models, but then they wouldn't show up in the index
466
-            $plural_model_route = EED_Core_Rest_Api::get_collection_route($model);
467
-            $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)');
468
-            $model_routes[$plural_model_route] = array(
469
-                array(
470
-                    'callback'        => array(
471
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
472
-                        'handleRequestGetAll',
473
-                    ),
474
-                    'callback_args'   => array($version, $model_name),
475
-                    'methods'         => WP_REST_Server::READABLE,
476
-                    'hidden_endpoint' => $hidden_endpoint,
477
-                    'args'            => $this->_get_read_query_params($model, $version),
478
-                    '_links'          => array(
479
-                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
480
-                    ),
481
-                ),
482
-                'schema' => array(
483
-                    'schema_callback' => array(
484
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
485
-                        'handleSchemaRequest',
486
-                    ),
487
-                    'callback_args'   => array($version, $model_name),
488
-                ),
489
-            );
490
-            $model_routes[$singular_model_route] = array(
491
-                array(
492
-                    'callback'        => array(
493
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
494
-                        'handleRequestGetOne',
495
-                    ),
496
-                    'callback_args'   => array($version, $model_name),
497
-                    'methods'         => WP_REST_Server::READABLE,
498
-                    'hidden_endpoint' => $hidden_endpoint,
499
-                    'args'            => $this->_get_response_selection_query_params($model, $version),
500
-                ),
501
-            );
502
-            if( apply_filters(
503
-                'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints',
504
-                EED_Core_Rest_Api::should_have_write_endpoints($model),
505
-                $model
506
-            )){
507
-                $model_routes[$plural_model_route][] = array(
508
-                    'callback'        => array(
509
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Write',
510
-                        'handleRequestInsert',
511
-                    ),
512
-                    'callback_args'   => array($version, $model_name),
513
-                    'methods'         => WP_REST_Server::CREATABLE,
514
-                    'hidden_endpoint' => $hidden_endpoint,
515
-                    'args'            => $this->_get_write_params($model_name, $model_version_info, true),
516
-                );
517
-                $model_routes[$singular_model_route] = array_merge(
518
-                    $model_routes[$singular_model_route],
519
-                    array(
520
-                        array(
521
-                            'callback'        => array(
522
-                                'EventEspresso\core\libraries\rest_api\controllers\model\Write',
523
-                                'handleRequestUpdate',
524
-                            ),
525
-                            'callback_args'   => array($version, $model_name),
526
-                            'methods'         => WP_REST_Server::EDITABLE,
527
-                            'hidden_endpoint' => $hidden_endpoint,
528
-                            'args'            => $this->_get_write_params($model_name, $model_version_info),
529
-                        ),
530
-                        array(
531
-                            'callback'        => array(
532
-                                'EventEspresso\core\libraries\rest_api\controllers\model\Write',
533
-                                'handleRequestDelete',
534
-                            ),
535
-                            'callback_args'   => array($version, $model_name),
536
-                            'methods'         => WP_REST_Server::DELETABLE,
537
-                            'hidden_endpoint' => $hidden_endpoint,
538
-                            'args'            => $this->_get_delete_query_params($model, $version),
539
-                        )
540
-                    )
541
-                );
542
-            }
543
-            foreach ($model->relation_settings() as $relation_name => $relation_obj) {
544
-
545
-                $related_route = EED_Core_Rest_Api::get_relation_route_via(
546
-                    $model,
547
-                    '(?P<id>[^\/]+)',
548
-                    $relation_obj
549
-                );
550
-                $endpoints = array(
551
-                    array(
552
-                        'callback'        => array(
553
-                            'EventEspresso\core\libraries\rest_api\controllers\model\Read',
554
-                            'handleRequestGetRelated',
555
-                        ),
556
-                        'callback_args'   => array($version, $model_name, $relation_name),
557
-                        'methods'         => WP_REST_Server::READABLE,
558
-                        'hidden_endpoint' => $hidden_endpoint,
559
-                        'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
560
-                    ),
561
-                );
562
-                $model_routes[$related_route] = $endpoints;
563
-            }
564
-        }
565
-        return $model_routes;
566
-    }
567
-
568
-
569
-
570
-    /**
571
-     * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace,
572
-     * excluding the preceding slash.
573
-     * Eg you pass get_plural_route_to('Event') = 'events'
574
-     *
575
-     * @param EEM_Base $model
576
-     * @return string
577
-     */
578
-    public static function get_collection_route(EEM_Base $model)
579
-    {
580
-        return EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
581
-    }
582
-
583
-
584
-
585
-    /**
586
-     * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
587
-     * excluding the preceding slash.
588
-     * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
589
-     *
590
-     * @param EEM_Base $model eg Event or Venue
591
-     * @param string $id
592
-     * @return string
593
-     */
594
-    public static function get_entity_route($model, $id)
595
-    {
596
-        return EED_Core_Rest_Api::get_collection_route($model). '/' . $id;
597
-    }
598
-
599
-
600
-    /**
601
-     * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
602
-     * excluding the preceding slash.
603
-     * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
604
-     *
605
-     * @param EEM_Base                 $model eg Event or Venue
606
-     * @param string                 $id
607
-     * @param EE_Model_Relation_Base $relation_obj
608
-     * @return string
609
-     */
610
-    public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj)
611
-    {
612
-        $related_model_name_endpoint_part = ModelRead::getRelatedEntityName(
613
-            $relation_obj->get_other_model()->get_this_model_name(),
614
-            $relation_obj
615
-        );
616
-        return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part;
617
-    }
618
-
619
-
620
-
621
-    /**
622
-     * Adds onto the $relative_route the EE4 REST API versioned namespace.
623
-     * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events'
624
-     * @param string $relative_route
625
-     * @param string $version
626
-     * @return string
627
-     */
628
-    public static function get_versioned_route_to($relative_route, $version = '4.8.36'){
629
-        return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route;
630
-    }
631
-
632
-
633
-
634
-    /**
635
-     * Adds all the RPC-style routes (remote procedure call-like routes, ie
636
-     * routes that don't conform to the traditional REST CRUD-style).
637
-     *
638
-     * @deprecated since 4.9.1
639
-     */
640
-    protected function _register_rpc_routes()
641
-    {
642
-        $routes = array();
643
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
644
-            $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version(
645
-                $version,
646
-                $hidden_endpoint
647
-            );
648
-        }
649
-        return $routes;
650
-    }
651
-
652
-
653
-
654
-    /**
655
-     * @param string  $version
656
-     * @param boolean $hidden_endpoint
657
-     * @return array
658
-     */
659
-    protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false)
660
-    {
661
-        $this_versions_routes = array();
662
-        //checkin endpoint
663
-        $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array(
664
-            array(
665
-                'callback'        => array(
666
-                    'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin',
667
-                    'handleRequestToggleCheckin',
668
-                ),
669
-                'methods'         => WP_REST_Server::CREATABLE,
670
-                'hidden_endpoint' => $hidden_endpoint,
671
-                'args'            => array(
672
-                    'force' => array(
673
-                        'required'    => false,
674
-                        'default'     => false,
675
-                        'description' => __(
676
-                            // @codingStandardsIgnoreStart
677
-                            'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses',
678
-                            // @codingStandardsIgnoreEnd
679
-                            'event_espresso'
680
-                        ),
681
-                    ),
682
-                ),
683
-                'callback_args'   => array($version),
684
-            ),
685
-        );
686
-        return apply_filters(
687
-            'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
688
-            $this_versions_routes,
689
-            $version,
690
-            $hidden_endpoint
691
-        );
692
-    }
693
-
694
-
695
-
696
-    /**
697
-     * Gets the query params that can be used when request one or many
698
-     *
699
-     * @param EEM_Base $model
700
-     * @param string   $version
701
-     * @return array
702
-     */
703
-    protected function _get_response_selection_query_params(\EEM_Base $model, $version)
704
-    {
705
-        return apply_filters(
706
-            'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
707
-            array(
708
-                'include'   => array(
709
-                    'required' => false,
710
-                    'default'  => '*',
711
-                    'type'     => 'string',
712
-                ),
713
-                'calculate' => array(
714
-                    'required'          => false,
715
-                    'default'           => '',
716
-                    'enum'              => self::$_field_calculator->retrieveCalculatedFieldsForModel($model),
717
-                    'type'              => 'string',
718
-                    //because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization
719
-                    //freaks out. We'll just validate this argument while handling the request
720
-                    'validate_callback' => null,
721
-                    'sanitize_callback' => null,
722
-                ),
723
-            ),
724
-            $model,
725
-            $version
726
-        );
727
-    }
728
-
729
-
730
-
731
-    /**
732
-     * Gets the parameters acceptable for delete requests
733
-     *
734
-     * @param \EEM_Base $model
735
-     * @param string    $version
736
-     * @return array
737
-     */
738
-    protected function _get_delete_query_params(\EEM_Base $model, $version)
739
-    {
740
-        $params_for_delete = array(
741
-            'allow_blocking' => array(
742
-                'required' => false,
743
-                'default'  => true,
744
-                'type'     => 'boolean',
745
-            ),
746
-        );
747
-        $params_for_delete['force'] = array(
748
-            'required' => false,
749
-            'default'  => false,
750
-            'type'     => 'boolean',
751
-        );
752
-        return apply_filters(
753
-            'FHEE__EED_Core_Rest_Api___get_delete_query_params',
754
-            $params_for_delete,
755
-            $model,
756
-            $version
757
-        );
758
-    }
759
-
760
-
761
-
762
-    /**
763
-     * Gets info about reading query params that are acceptable
764
-     *
765
-     * @param \EEM_Base $model eg 'Event' or 'Venue'
766
-     * @param  string   $version
767
-     * @return array    describing the args acceptable when querying this model
768
-     * @throws EE_Error
769
-     */
770
-    protected function _get_read_query_params(\EEM_Base $model, $version)
771
-    {
772
-        $default_orderby = array();
773
-        foreach ($model->get_combined_primary_key_fields() as $key_field) {
774
-            $default_orderby[$key_field->get_name()] = 'ASC';
775
-        }
776
-        return array_merge(
777
-            $this->_get_response_selection_query_params($model, $version),
778
-            array(
779
-                'where'    => array(
780
-                    'required' => false,
781
-                    'default'  => array(),
782
-                    'type'     => 'object',
783
-                    //because we accept an almost infinite list of possible where conditions, WP
784
-                    // core validation and sanitization freaks out. We'll just validate this argument
785
-                    // while handling the request
786
-                    'validate_callback' => null,
787
-                    'sanitize_callback' => null,
788
-                ),
789
-                'limit'    => array(
790
-                    'required' => false,
791
-                    'default'  => EED_Core_Rest_Api::get_default_query_limit(),
792
-                    'type'     => array(
793
-                        'array',
794
-                        'string',
795
-                        'integer',
796
-                    ),
797
-                    //because we accept a variety of types, WP core validation and sanitization
798
-                    //freaks out. We'll just validate this argument while handling the request
799
-                    'validate_callback' => null,
800
-                    'sanitize_callback' => null,
801
-                ),
802
-                'order_by' => array(
803
-                    'required' => false,
804
-                    'default'  => $default_orderby,
805
-                    'type'     => array(
806
-                        'object',
807
-                        'string',
808
-                    ),//because we accept a variety of types, WP core validation and sanitization
809
-                    //freaks out. We'll just validate this argument while handling the request
810
-                    'validate_callback' => null,
811
-                    'sanitize_callback' => null,
812
-                ),
813
-                'group_by' => array(
814
-                    'required' => false,
815
-                    'default'  => null,
816
-                    'type'     => array(
817
-                        'object',
818
-                        'string',
819
-                    ),
820
-                    //because we accept  an almost infinite list of possible groupings,
821
-                    // WP core validation and sanitization
822
-                    //freaks out. We'll just validate this argument while handling the request
823
-                    'validate_callback' => null,
824
-                    'sanitize_callback' => null,
825
-                ),
826
-                'having'   => array(
827
-                    'required' => false,
828
-                    'default'  => null,
829
-                    'type'     => 'object',
830
-                    //because we accept an almost infinite list of possible where conditions, WP
831
-                    // core validation and sanitization freaks out. We'll just validate this argument
832
-                    // while handling the request
833
-                    'validate_callback' => null,
834
-                    'sanitize_callback' => null,
835
-                ),
836
-                'caps'     => array(
837
-                    'required' => false,
838
-                    'default'  => EEM_Base::caps_read,
839
-                    'type'     => 'string',
840
-                    'enum'     => array(
841
-                        EEM_Base::caps_read,
842
-                        EEM_Base::caps_read_admin,
843
-                        EEM_Base::caps_edit,
844
-                        EEM_Base::caps_delete
845
-                    )
846
-                ),
847
-            )
848
-        );
849
-    }
850
-
851
-
852
-
853
-    /**
854
-     * Gets parameter information for a model regarding writing data
855
-     *
856
-     * @param string           $model_name
857
-     * @param ModelVersionInfo $model_version_info
858
-     * @param boolean          $create                                       whether this is for request to create (in which case we need
859
-     *                                                                       all required params) or just to update (in which case we don't need those on every request)
860
-     * @return array
861
-     */
862
-    protected function _get_write_params(
863
-        $model_name,
864
-        ModelVersionInfo $model_version_info,
865
-        $create = false
866
-    ) {
867
-        $model = EE_Registry::instance()->load_model($model_name);
868
-        $fields = $model_version_info->fieldsOnModelInThisVersion($model);
869
-        $args_info = array();
870
-        foreach ($fields as $field_name => $field_obj) {
871
-            if ($field_obj->is_auto_increment()) {
872
-                //totally ignore auto increment IDs
873
-                continue;
874
-            }
875
-            $arg_info = $field_obj->getSchema();
876
-            $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null;
877
-            $arg_info['required'] = $required;
878
-            //remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right?
879
-            unset($arg_info['readonly']);
880
-            $schema_properties = $field_obj->getSchemaProperties();
881
-            if (
882
-                isset($schema_properties['raw'])
883
-                && $field_obj->getSchemaType() === 'object'
884
-            ) {
885
-                //if there's a "raw" form of this argument, use those properties instead
886
-                $arg_info = array_replace(
887
-                    $arg_info,
888
-                    $schema_properties['raw']
889
-                );
890
-            }
891
-            $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson(
892
-                $field_obj,
893
-                $field_obj->get_default_value(),
894
-                $model_version_info->requestedVersion()
895
-            );
896
-            //we do our own validation and sanitization within the controller
897
-            $arg_info['sanitize_callback'] =
898
-                array(
899
-                    'EED_Core_Rest_Api',
900
-                    'default_sanitize_callback',
901
-                );
902
-            $args_info[$field_name] = $arg_info;
903
-            if ($field_obj instanceof EE_Datetime_Field) {
904
-                $gmt_arg_info = $arg_info;
905
-                $gmt_arg_info['description'] = sprintf(
906
-                    esc_html__(
907
-                        '%1$s - the value for this field in UTC. Ignored if %2$s is provided.',
908
-                        'event_espresso'
909
-                    ),
910
-                    $field_obj->get_nicename(),
911
-                    $field_name
912
-                );
913
-                $args_info[$field_name . '_gmt'] = $gmt_arg_info;
914
-            }
915
-        }
916
-        return $args_info;
917
-    }
918
-
919
-
920
-
921
-    /**
922
-     * Replacement for WP API's 'rest_parse_request_arg'.
923
-     * If the value is blank but not required, don't bother validating it.
924
-     * Also, it uses our email validation instead of WP API's default.
925
-     *
926
-     * @param                 $value
927
-     * @param WP_REST_Request $request
928
-     * @param                 $param
929
-     * @return bool|true|WP_Error
930
-     * @throws InvalidArgumentException
931
-     * @throws InvalidInterfaceException
932
-     * @throws InvalidDataTypeException
933
-     */
934
-    public static function default_sanitize_callback( $value, WP_REST_Request $request, $param)
935
-    {
936
-        $attributes = $request->get_attributes();
937
-        if (! isset($attributes['args'][$param])
938
-            || ! is_array($attributes['args'][$param])) {
939
-            $validation_result = true;
940
-        } else {
941
-            $args = $attributes['args'][$param];
942
-            if ((
943
-                    $value === ''
944
-                    || $value === null
945
-                )
946
-                && (! isset($args['required'])
947
-                    || $args['required'] === false
948
-                )
949
-            ) {
950
-                //not required and not provided? that's cool
951
-                $validation_result = true;
952
-            } elseif (isset($args['format'])
953
-                && $args['format'] === 'email'
954
-            ) {
955
-                $validation_result = true;
956
-                if (! self::_validate_email($value)) {
957
-                    $validation_result = new WP_Error(
958
-                        'rest_invalid_param',
959
-                        esc_html__(
960
-                            'The email address is not valid or does not exist.',
961
-                            'event_espresso'
962
-                        )
963
-                    );
964
-                }
965
-            } else {
966
-                $validation_result = rest_validate_value_from_schema($value, $args, $param);
967
-            }
968
-        }
969
-        if (is_wp_error($validation_result)) {
970
-            return $validation_result;
971
-        }
972
-        return rest_sanitize_request_arg($value, $request, $param);
973
-    }
974
-
975
-
976
-
977
-    /**
978
-     * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email()
979
-     *
980
-     * @param $email
981
-     * @return bool
982
-     * @throws InvalidArgumentException
983
-     * @throws InvalidInterfaceException
984
-     * @throws InvalidDataTypeException
985
-     */
986
-    protected static function _validate_email($email){
987
-        try {
988
-            EmailAddressFactory::create($email);
989
-            return true;
990
-        } catch (EmailValidationException $e) {
991
-            return false;
992
-        }
993
-    }
994
-
995
-
996
-
997
-    /**
998
-     * Gets routes for the config
999
-     *
1000
-     * @return array @see _register_model_routes
1001
-     * @deprecated since version 4.9.1
1002
-     */
1003
-    protected function _register_config_routes()
1004
-    {
1005
-        $config_routes = array();
1006
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
1007
-            $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version(
1008
-                $version,
1009
-                $hidden_endpoint
1010
-            );
1011
-        }
1012
-        return $config_routes;
1013
-    }
1014
-
1015
-
1016
-
1017
-    /**
1018
-     * Gets routes for the config for the specified version
1019
-     *
1020
-     * @param string  $version
1021
-     * @param boolean $hidden_endpoint
1022
-     * @return array
1023
-     */
1024
-    protected function _get_config_route_data_for_version($version, $hidden_endpoint)
1025
-    {
1026
-        return array(
1027
-            'config'    => array(
1028
-                array(
1029
-                    'callback'        => array(
1030
-                        'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1031
-                        'handleRequest',
1032
-                    ),
1033
-                    'methods'         => WP_REST_Server::READABLE,
1034
-                    'hidden_endpoint' => $hidden_endpoint,
1035
-                    'callback_args'   => array($version),
1036
-                ),
1037
-            ),
1038
-            'site_info' => array(
1039
-                array(
1040
-                    'callback'        => array(
1041
-                        'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1042
-                        'handleRequestSiteInfo',
1043
-                    ),
1044
-                    'methods'         => WP_REST_Server::READABLE,
1045
-                    'hidden_endpoint' => $hidden_endpoint,
1046
-                    'callback_args'   => array($version),
1047
-                ),
1048
-            ),
1049
-        );
1050
-    }
1051
-
1052
-
1053
-
1054
-    /**
1055
-     * Gets the meta info routes
1056
-     *
1057
-     * @return array @see _register_model_routes
1058
-     * @deprecated since version 4.9.1
1059
-     */
1060
-    protected function _register_meta_routes()
1061
-    {
1062
-        $meta_routes = array();
1063
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
1064
-            $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version(
1065
-                $version,
1066
-                $hidden_endpoint
1067
-            );
1068
-        }
1069
-        return $meta_routes;
1070
-    }
1071
-
1072
-
1073
-
1074
-    /**
1075
-     * @param string  $version
1076
-     * @param boolean $hidden_endpoint
1077
-     * @return array
1078
-     */
1079
-    protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false)
1080
-    {
1081
-        return array(
1082
-            'resources' => array(
1083
-                array(
1084
-                    'callback'        => array(
1085
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Meta',
1086
-                        'handleRequestModelsMeta',
1087
-                    ),
1088
-                    'methods'         => WP_REST_Server::READABLE,
1089
-                    'hidden_endpoint' => $hidden_endpoint,
1090
-                    'callback_args'   => array($version),
1091
-                ),
1092
-            ),
1093
-        );
1094
-    }
1095
-
1096
-
1097
-
1098
-    /**
1099
-     * Tries to hide old 4.6 endpoints from the
1100
-     *
1101
-     * @param array $route_data
1102
-     * @return array
1103
-     * @throws \EE_Error
1104
-     */
1105
-    public static function hide_old_endpoints($route_data)
1106
-    {
1107
-        //allow API clients to override which endpoints get hidden, in case
1108
-        //they want to discover particular endpoints
1109
-        //also, we don't have access to the request so we have to just grab it from the superglobal
1110
-        $force_show_ee_namespace = ltrim(
1111
-            EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''),
1112
-            '/'
1113
-        );
1114
-        foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
1115
-            foreach ($relative_urls as $resource_name => $endpoints) {
1116
-                foreach ($endpoints as $key => $endpoint) {
1117
-                    //skip schema and other route options
1118
-                    if (! is_numeric($key)) {
1119
-                        continue;
1120
-                    }
1121
-                    //by default, hide "hidden_endpoint"s, unless the request indicates
1122
-                    //to $force_show_ee_namespace, in which case only show that one
1123
-                    //namespace's endpoints (and hide all others)
1124
-                    if (
1125
-                        ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
1126
-                        || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '')
1127
-                    ) {
1128
-                        $full_route = '/' . ltrim($namespace, '/');
1129
-                        $full_route .= '/' . ltrim($resource_name, '/');
1130
-                        unset($route_data[$full_route]);
1131
-                    }
1132
-                }
1133
-            }
1134
-        }
1135
-        return $route_data;
1136
-    }
1137
-
1138
-
1139
-
1140
-    /**
1141
-     * Returns an array describing which versions of core support serving requests for.
1142
-     * Keys are core versions' major and minor version, and values are the
1143
-     * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like
1144
-     * data by just removing a few models and fields from the responses. However, 4.15 might remove
1145
-     * the answers table entirely, in which case it would be very difficult for
1146
-     * it to serve 4.6-style responses.
1147
-     * Versions of core that are missing from this array are unknowns.
1148
-     * previous ver
1149
-     *
1150
-     * @return array
1151
-     */
1152
-    public static function version_compatibilities()
1153
-    {
1154
-        return apply_filters(
1155
-            'FHEE__EED_Core_REST_API__version_compatibilities',
1156
-            array(
1157
-                '4.8.29' => '4.8.29',
1158
-                '4.8.33' => '4.8.29',
1159
-                '4.8.34' => '4.8.29',
1160
-                '4.8.36' => '4.8.29',
1161
-            )
1162
-        );
1163
-    }
1164
-
1165
-
1166
-
1167
-    /**
1168
-     * Gets the latest API version served. Eg if there
1169
-     * are two versions served of the API, 4.8.29 and 4.8.32, and
1170
-     * we are on core version 4.8.34, it will return the string "4.8.32"
1171
-     *
1172
-     * @return string
1173
-     */
1174
-    public static function latest_rest_api_version()
1175
-    {
1176
-        $versions_served = \EED_Core_Rest_Api::versions_served();
1177
-        $versions_served_keys = array_keys($versions_served);
1178
-        return end($versions_served_keys);
1179
-    }
1180
-
1181
-
1182
-
1183
-    /**
1184
-     * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of
1185
-     * EE the API can serve requests for. Eg, if we are on 4.15 of core, and
1186
-     * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ).
1187
-     * We also indicate whether or not this version should be put in the index or not
1188
-     *
1189
-     * @return array keys are API version numbers (just major and minor numbers), and values
1190
-     * are whether or not they should be hidden
1191
-     */
1192
-    public static function versions_served()
1193
-    {
1194
-        $versions_served = array();
1195
-        $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities();
1196
-        $lowest_compatible_version = end($possibly_served_versions);
1197
-        reset($possibly_served_versions);
1198
-        $versions_served_historically = array_keys($possibly_served_versions);
1199
-        $latest_version = end($versions_served_historically);
1200
-        reset($versions_served_historically);
1201
-        //for each version of core we have ever served:
1202
-        foreach ($versions_served_historically as $key_versioned_endpoint) {
1203
-            //if it's not above the current core version, and it's compatible with the current version of core
1204
-            if ($key_versioned_endpoint === $latest_version) {
1205
-                //don't hide the latest version in the index
1206
-                $versions_served[$key_versioned_endpoint] = false;
1207
-            } elseif (
1208
-                $key_versioned_endpoint >= $lowest_compatible_version
1209
-                && $key_versioned_endpoint < EED_Core_Rest_Api::core_version()
1210
-            ) {
1211
-                //include, but hide, previous versions which are still supported
1212
-                $versions_served[$key_versioned_endpoint] = true;
1213
-            } elseif (apply_filters(
1214
-                'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
1215
-                false,
1216
-                $possibly_served_versions
1217
-            )) {
1218
-                //if a version is no longer supported, don't include it in index or list of versions served
1219
-                $versions_served[$key_versioned_endpoint] = true;
1220
-            }
1221
-        }
1222
-        return $versions_served;
1223
-    }
1224
-
1225
-
1226
-
1227
-    /**
1228
-     * Gets the major and minor version of EE core's version string
1229
-     *
1230
-     * @return string
1231
-     */
1232
-    public static function core_version()
1233
-    {
1234
-        return apply_filters(
1235
-            'FHEE__EED_Core_REST_API__core_version',
1236
-            implode(
1237
-                '.',
1238
-                array_slice(
1239
-                    explode(
1240
-                        '.',
1241
-                        espresso_version()
1242
-                    ),
1243
-                0,
1244
-                3
1245
-                )
1246
-            )
1247
-        );
1248
-    }
1249
-
1250
-
1251
-
1252
-    /**
1253
-     * Gets the default limit that should be used when querying for resources
1254
-     *
1255
-     * @return int
1256
-     */
1257
-    public static function get_default_query_limit()
1258
-    {
1259
-        //we actually don't use a const because we want folks to always use
1260
-        //this method, not the const directly
1261
-        return apply_filters(
1262
-            'FHEE__EED_Core_Rest_Api__get_default_query_limit',
1263
-            50
1264
-        );
1265
-    }
1266
-
1267
-
1268
-
1269
-    /**
1270
-     *    run - initial module setup
1271
-     *
1272
-     * @access    public
1273
-     * @param  WP $WP
1274
-     * @return    void
1275
-     */
1276
-    public function run($WP)
1277
-    {
1278
-    }
31
+	const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/';
32
+
33
+	const saved_routes_option_names  = 'ee_core_routes';
34
+
35
+	/**
36
+	 * string used in _links response bodies to make them globally unique.
37
+	 *
38
+	 * @see http://v2.wp-api.org/extending/linking/
39
+	 */
40
+	const ee_api_link_namespace = 'https://api.eventespresso.com/';
41
+
42
+	/**
43
+	 * @var CalculatedModelFields
44
+	 */
45
+	protected static $_field_calculator;
46
+
47
+
48
+
49
+	/**
50
+	 * @return EED_Core_Rest_Api|EED_Module
51
+	 */
52
+	public static function instance()
53
+	{
54
+		self::$_field_calculator = new CalculatedModelFields();
55
+		return parent::get_instance(__CLASS__);
56
+	}
57
+
58
+
59
+
60
+	/**
61
+	 *    set_hooks - for hooking into EE Core, other modules, etc
62
+	 *
63
+	 * @access    public
64
+	 * @return    void
65
+	 */
66
+	public static function set_hooks()
67
+	{
68
+		self::set_hooks_both();
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
75
+	 *
76
+	 * @access    public
77
+	 * @return    void
78
+	 */
79
+	public static function set_hooks_admin()
80
+	{
81
+		self::set_hooks_both();
82
+	}
83
+
84
+
85
+
86
+	public static function set_hooks_both()
87
+	{
88
+		add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10);
89
+		add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5);
90
+		add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2);
91
+		add_filter('rest_index',
92
+			array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex'));
93
+		EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change();
94
+	}
95
+
96
+
97
+
98
+	/**
99
+	 * sets up hooks which only need to be included as part of REST API requests;
100
+	 * other requests like to the frontend or admin etc don't need them
101
+	 *
102
+	 * @throws \EE_Error
103
+	 */
104
+	public static function set_hooks_rest_api()
105
+	{
106
+		//set hooks which account for changes made to the API
107
+		EED_Core_Rest_Api::_set_hooks_for_changes();
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * public wrapper of _set_hooks_for_changes.
114
+	 * Loads all the hooks which make requests to old versions of the API
115
+	 * appear the same as they always did
116
+	 *
117
+	 * @throws EE_Error
118
+	 */
119
+	public static function set_hooks_for_changes()
120
+	{
121
+		self::_set_hooks_for_changes();
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * Loads all the hooks which make requests to old versions of the API
128
+	 * appear the same as they always did
129
+	 *
130
+	 * @throws EE_Error
131
+	 */
132
+	protected static function _set_hooks_for_changes()
133
+	{
134
+		$folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
135
+		foreach ($folder_contents as $classname_in_namespace => $filepath) {
136
+			//ignore the base parent class
137
+			//and legacy named classes
138
+			if ($classname_in_namespace === 'ChangesInBase'
139
+				|| strpos($classname_in_namespace, 'Changes_In_') === 0
140
+			) {
141
+				continue;
142
+			}
143
+			$full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
144
+			if (class_exists($full_classname)) {
145
+				$instance_of_class = new $full_classname;
146
+				if ($instance_of_class instanceof ChangesInBase) {
147
+					$instance_of_class->setHooks();
148
+				}
149
+			}
150
+		}
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * Filters the WP routes to add our EE-related ones. This takes a bit of time
157
+	 * so we actually prefer to only do it when an EE plugin is activated or upgraded
158
+	 *
159
+	 * @throws \EE_Error
160
+	 */
161
+	public static function register_routes()
162
+	{
163
+		foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) {
164
+			foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) {
165
+				/**
166
+				 * @var array $data_for_multiple_endpoints numerically indexed array
167
+				 *                                         but can also contain route options like {
168
+				 * @type array    $schema                      {
169
+				 * @type callable $schema_callback
170
+				 * @type array    $callback_args               arguments that will be passed to the callback, after the
171
+				 * WP_REST_Request of course
172
+				 * }
173
+				 * }
174
+				 */
175
+				//when registering routes, register all the endpoints' data at the same time
176
+				$multiple_endpoint_args = array();
177
+				foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) {
178
+					/**
179
+					 * @var array     $data_for_single_endpoint {
180
+					 * @type callable $callback
181
+					 * @type string methods
182
+					 * @type array args
183
+					 * @type array _links
184
+					 * @type array    $callback_args            arguments that will be passed to the callback, after the
185
+					 * WP_REST_Request of course
186
+					 * }
187
+					 */
188
+					//skip route options
189
+					if (! is_numeric($endpoint_key)) {
190
+						continue;
191
+					}
192
+					if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) {
193
+						throw new EE_Error(
194
+							esc_html__(
195
+								// @codingStandardsIgnoreStart
196
+								'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).',
197
+								// @codingStandardsIgnoreEnd
198
+								'event_espresso')
199
+						);
200
+					}
201
+					$callback = $data_for_single_endpoint['callback'];
202
+					$single_endpoint_args = array(
203
+						'methods' => $data_for_single_endpoint['methods'],
204
+						'args'    => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args']
205
+							: array(),
206
+					);
207
+					if (isset($data_for_single_endpoint['_links'])) {
208
+						$single_endpoint_args['_links'] = $data_for_single_endpoint['_links'];
209
+					}
210
+					if (isset($data_for_single_endpoint['callback_args'])) {
211
+						$callback_args = $data_for_single_endpoint['callback_args'];
212
+						$single_endpoint_args['callback'] = function (\WP_REST_Request $request) use (
213
+							$callback,
214
+							$callback_args
215
+						) {
216
+							array_unshift($callback_args, $request);
217
+							return call_user_func_array(
218
+								$callback,
219
+								$callback_args
220
+							);
221
+						};
222
+					} else {
223
+						$single_endpoint_args['callback'] = $data_for_single_endpoint['callback'];
224
+					}
225
+					$multiple_endpoint_args[] = $single_endpoint_args;
226
+				}
227
+				if (isset($data_for_multiple_endpoints['schema'])) {
228
+					$schema_route_data = $data_for_multiple_endpoints['schema'];
229
+					$schema_callback = $schema_route_data['schema_callback'];
230
+					$callback_args = $schema_route_data['callback_args'];
231
+					$multiple_endpoint_args['schema'] = function () use ($schema_callback, $callback_args) {
232
+						return call_user_func_array(
233
+							$schema_callback,
234
+							$callback_args
235
+						);
236
+					};
237
+				}
238
+				register_rest_route(
239
+					$namespace,
240
+					$relative_route,
241
+					$multiple_endpoint_args
242
+				);
243
+			}
244
+		}
245
+	}
246
+
247
+
248
+
249
+	/**
250
+	 * Checks if there was a version change or something that merits invalidating the cached
251
+	 * route data. If so, invalidates the cached route data so that it gets refreshed
252
+	 * next time the WP API is used
253
+	 */
254
+	public static function invalidate_cached_route_data_on_version_change()
255
+	{
256
+		if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) {
257
+			EED_Core_Rest_Api::invalidate_cached_route_data();
258
+		}
259
+		foreach (EE_Registry::instance()->addons as $addon) {
260
+			if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) {
261
+				EED_Core_Rest_Api::invalidate_cached_route_data();
262
+			}
263
+		}
264
+	}
265
+
266
+
267
+
268
+	/**
269
+	 * Removes the cached route data so it will get refreshed next time the WP API is used
270
+	 */
271
+	public static function invalidate_cached_route_data()
272
+	{
273
+		//delete the saved EE REST API routes
274
+		foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
275
+			delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
276
+		}
277
+	}
278
+
279
+
280
+
281
+	/**
282
+	 * Gets the EE route data
283
+	 *
284
+	 * @return array top-level key is the namespace, next-level key is the route and its value is array{
285
+	 * @throws \EE_Error
286
+	 * @type string|array $callback
287
+	 * @type string       $methods
288
+	 * @type boolean      $hidden_endpoint
289
+	 * }
290
+	 */
291
+	public static function get_ee_route_data()
292
+	{
293
+		$ee_routes = array();
294
+		foreach (self::versions_served() as $version => $hidden_endpoints) {
295
+			$ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version(
296
+				$version,
297
+				$hidden_endpoints
298
+			);
299
+		}
300
+		return $ee_routes;
301
+	}
302
+
303
+
304
+
305
+	/**
306
+	 * Gets the EE route data from the wp options if it exists already,
307
+	 * otherwise re-generates it and saves it to the option
308
+	 *
309
+	 * @param string  $version
310
+	 * @param boolean $hidden_endpoints
311
+	 * @return array
312
+	 * @throws \EE_Error
313
+	 */
314
+	protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
315
+	{
316
+		$ee_routes = get_option(self::saved_routes_option_names . $version, null);
317
+		if (! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
318
+			$ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
319
+		}
320
+		return $ee_routes;
321
+	}
322
+
323
+
324
+
325
+	/**
326
+	 * Saves the EE REST API route data to a wp option and returns it
327
+	 *
328
+	 * @param string  $version
329
+	 * @param boolean $hidden_endpoints
330
+	 * @return mixed|null
331
+	 * @throws \EE_Error
332
+	 */
333
+	protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false)
334
+	{
335
+		$instance = self::instance();
336
+		$routes = apply_filters(
337
+			'EED_Core_Rest_Api__save_ee_route_data_for_version__routes',
338
+			array_replace_recursive(
339
+				$instance->_get_config_route_data_for_version($version, $hidden_endpoints),
340
+				$instance->_get_meta_route_data_for_version($version, $hidden_endpoints),
341
+				$instance->_get_model_route_data_for_version($version, $hidden_endpoints),
342
+				$instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
343
+			)
344
+		);
345
+		$option_name = self::saved_routes_option_names . $version;
346
+		if (get_option($option_name)) {
347
+			update_option($option_name, $routes, true);
348
+		} else {
349
+			add_option($option_name, $routes, null, 'no');
350
+		}
351
+		return $routes;
352
+	}
353
+
354
+
355
+
356
+	/**
357
+	 * Calculates all the EE routes and saves it to a WordPress option so we don't
358
+	 * need to calculate it on every request
359
+	 *
360
+	 * @deprecated since version 4.9.1
361
+	 * @return void
362
+	 */
363
+	public static function save_ee_routes()
364
+	{
365
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
366
+			$instance = self::instance();
367
+			$routes = apply_filters(
368
+				'EED_Core_Rest_Api__save_ee_routes__routes',
369
+				array_replace_recursive(
370
+					$instance->_register_config_routes(),
371
+					$instance->_register_meta_routes(),
372
+					$instance->_register_model_routes(),
373
+					$instance->_register_rpc_routes()
374
+				)
375
+			);
376
+			update_option(self::saved_routes_option_names, $routes, true);
377
+		}
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * Gets all the route information relating to EE models
384
+	 *
385
+	 * @return array @see get_ee_route_data
386
+	 * @deprecated since version 4.9.1
387
+	 */
388
+	protected function _register_model_routes()
389
+	{
390
+		$model_routes = array();
391
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
392
+			$model_routes[EED_Core_Rest_Api::ee_api_namespace
393
+						  . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
394
+		}
395
+		return $model_routes;
396
+	}
397
+
398
+
399
+
400
+	/**
401
+	 * Decides whether or not to add write endpoints for this model.
402
+	 *
403
+	 * Currently, this defaults to exclude all global tables and models
404
+	 * which would allow inserting WP core data (we don't want to duplicate
405
+	 * what WP API does, as it's unnecessary, extra work, and potentially extra bugs)
406
+	 * @param EEM_Base $model
407
+	 * @return bool
408
+	 */
409
+	public static function should_have_write_endpoints(EEM_Base $model)
410
+	{
411
+		if ($model->is_wp_core_model()){
412
+			return false;
413
+		}
414
+		foreach($model->get_tables() as $table){
415
+			if( $table->is_global()){
416
+				return false;
417
+			}
418
+		}
419
+		return true;
420
+	}
421
+
422
+
423
+
424
+	/**
425
+	 * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`)
426
+	 * in this versioned namespace of EE4
427
+	 * @param $version
428
+	 * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event')
429
+	 */
430
+	public static function model_names_with_plural_routes($version){
431
+		$model_version_info = new ModelVersionInfo($version);
432
+		$models_to_register = $model_version_info->modelsForRequestedVersion();
433
+		//let's not bother having endpoints for extra metas
434
+		unset(
435
+			$models_to_register['Extra_Meta'],
436
+			$models_to_register['Extra_Join'],
437
+			$models_to_register['Post_Meta']
438
+		);
439
+		return apply_filters(
440
+			'FHEE__EED_Core_REST_API___register_model_routes',
441
+			$models_to_register
442
+		);
443
+	}
444
+
445
+
446
+
447
+	/**
448
+	 * Gets the route data for EE models in the specified version
449
+	 *
450
+	 * @param string  $version
451
+	 * @param boolean $hidden_endpoint
452
+	 * @return array
453
+	 * @throws EE_Error
454
+	 */
455
+	protected function _get_model_route_data_for_version($version, $hidden_endpoint = false)
456
+	{
457
+		$model_routes = array();
458
+		$model_version_info = new ModelVersionInfo($version);
459
+		foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) {
460
+			$model = \EE_Registry::instance()->load_model($model_name);
461
+			//if this isn't a valid model then let's skip iterate to the next item in the loop.
462
+			if (! $model instanceof EEM_Base) {
463
+				continue;
464
+			}
465
+			//yes we could just register one route for ALL models, but then they wouldn't show up in the index
466
+			$plural_model_route = EED_Core_Rest_Api::get_collection_route($model);
467
+			$singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)');
468
+			$model_routes[$plural_model_route] = array(
469
+				array(
470
+					'callback'        => array(
471
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
472
+						'handleRequestGetAll',
473
+					),
474
+					'callback_args'   => array($version, $model_name),
475
+					'methods'         => WP_REST_Server::READABLE,
476
+					'hidden_endpoint' => $hidden_endpoint,
477
+					'args'            => $this->_get_read_query_params($model, $version),
478
+					'_links'          => array(
479
+						'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
480
+					),
481
+				),
482
+				'schema' => array(
483
+					'schema_callback' => array(
484
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
485
+						'handleSchemaRequest',
486
+					),
487
+					'callback_args'   => array($version, $model_name),
488
+				),
489
+			);
490
+			$model_routes[$singular_model_route] = array(
491
+				array(
492
+					'callback'        => array(
493
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
494
+						'handleRequestGetOne',
495
+					),
496
+					'callback_args'   => array($version, $model_name),
497
+					'methods'         => WP_REST_Server::READABLE,
498
+					'hidden_endpoint' => $hidden_endpoint,
499
+					'args'            => $this->_get_response_selection_query_params($model, $version),
500
+				),
501
+			);
502
+			if( apply_filters(
503
+				'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints',
504
+				EED_Core_Rest_Api::should_have_write_endpoints($model),
505
+				$model
506
+			)){
507
+				$model_routes[$plural_model_route][] = array(
508
+					'callback'        => array(
509
+						'EventEspresso\core\libraries\rest_api\controllers\model\Write',
510
+						'handleRequestInsert',
511
+					),
512
+					'callback_args'   => array($version, $model_name),
513
+					'methods'         => WP_REST_Server::CREATABLE,
514
+					'hidden_endpoint' => $hidden_endpoint,
515
+					'args'            => $this->_get_write_params($model_name, $model_version_info, true),
516
+				);
517
+				$model_routes[$singular_model_route] = array_merge(
518
+					$model_routes[$singular_model_route],
519
+					array(
520
+						array(
521
+							'callback'        => array(
522
+								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
523
+								'handleRequestUpdate',
524
+							),
525
+							'callback_args'   => array($version, $model_name),
526
+							'methods'         => WP_REST_Server::EDITABLE,
527
+							'hidden_endpoint' => $hidden_endpoint,
528
+							'args'            => $this->_get_write_params($model_name, $model_version_info),
529
+						),
530
+						array(
531
+							'callback'        => array(
532
+								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
533
+								'handleRequestDelete',
534
+							),
535
+							'callback_args'   => array($version, $model_name),
536
+							'methods'         => WP_REST_Server::DELETABLE,
537
+							'hidden_endpoint' => $hidden_endpoint,
538
+							'args'            => $this->_get_delete_query_params($model, $version),
539
+						)
540
+					)
541
+				);
542
+			}
543
+			foreach ($model->relation_settings() as $relation_name => $relation_obj) {
544
+
545
+				$related_route = EED_Core_Rest_Api::get_relation_route_via(
546
+					$model,
547
+					'(?P<id>[^\/]+)',
548
+					$relation_obj
549
+				);
550
+				$endpoints = array(
551
+					array(
552
+						'callback'        => array(
553
+							'EventEspresso\core\libraries\rest_api\controllers\model\Read',
554
+							'handleRequestGetRelated',
555
+						),
556
+						'callback_args'   => array($version, $model_name, $relation_name),
557
+						'methods'         => WP_REST_Server::READABLE,
558
+						'hidden_endpoint' => $hidden_endpoint,
559
+						'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
560
+					),
561
+				);
562
+				$model_routes[$related_route] = $endpoints;
563
+			}
564
+		}
565
+		return $model_routes;
566
+	}
567
+
568
+
569
+
570
+	/**
571
+	 * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace,
572
+	 * excluding the preceding slash.
573
+	 * Eg you pass get_plural_route_to('Event') = 'events'
574
+	 *
575
+	 * @param EEM_Base $model
576
+	 * @return string
577
+	 */
578
+	public static function get_collection_route(EEM_Base $model)
579
+	{
580
+		return EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
581
+	}
582
+
583
+
584
+
585
+	/**
586
+	 * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
587
+	 * excluding the preceding slash.
588
+	 * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
589
+	 *
590
+	 * @param EEM_Base $model eg Event or Venue
591
+	 * @param string $id
592
+	 * @return string
593
+	 */
594
+	public static function get_entity_route($model, $id)
595
+	{
596
+		return EED_Core_Rest_Api::get_collection_route($model). '/' . $id;
597
+	}
598
+
599
+
600
+	/**
601
+	 * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace,
602
+	 * excluding the preceding slash.
603
+	 * Eg you pass get_plural_route_to('Event', 12) = 'events/12'
604
+	 *
605
+	 * @param EEM_Base                 $model eg Event or Venue
606
+	 * @param string                 $id
607
+	 * @param EE_Model_Relation_Base $relation_obj
608
+	 * @return string
609
+	 */
610
+	public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj)
611
+	{
612
+		$related_model_name_endpoint_part = ModelRead::getRelatedEntityName(
613
+			$relation_obj->get_other_model()->get_this_model_name(),
614
+			$relation_obj
615
+		);
616
+		return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part;
617
+	}
618
+
619
+
620
+
621
+	/**
622
+	 * Adds onto the $relative_route the EE4 REST API versioned namespace.
623
+	 * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events'
624
+	 * @param string $relative_route
625
+	 * @param string $version
626
+	 * @return string
627
+	 */
628
+	public static function get_versioned_route_to($relative_route, $version = '4.8.36'){
629
+		return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route;
630
+	}
631
+
632
+
633
+
634
+	/**
635
+	 * Adds all the RPC-style routes (remote procedure call-like routes, ie
636
+	 * routes that don't conform to the traditional REST CRUD-style).
637
+	 *
638
+	 * @deprecated since 4.9.1
639
+	 */
640
+	protected function _register_rpc_routes()
641
+	{
642
+		$routes = array();
643
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
644
+			$routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version(
645
+				$version,
646
+				$hidden_endpoint
647
+			);
648
+		}
649
+		return $routes;
650
+	}
651
+
652
+
653
+
654
+	/**
655
+	 * @param string  $version
656
+	 * @param boolean $hidden_endpoint
657
+	 * @return array
658
+	 */
659
+	protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false)
660
+	{
661
+		$this_versions_routes = array();
662
+		//checkin endpoint
663
+		$this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array(
664
+			array(
665
+				'callback'        => array(
666
+					'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin',
667
+					'handleRequestToggleCheckin',
668
+				),
669
+				'methods'         => WP_REST_Server::CREATABLE,
670
+				'hidden_endpoint' => $hidden_endpoint,
671
+				'args'            => array(
672
+					'force' => array(
673
+						'required'    => false,
674
+						'default'     => false,
675
+						'description' => __(
676
+							// @codingStandardsIgnoreStart
677
+							'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses',
678
+							// @codingStandardsIgnoreEnd
679
+							'event_espresso'
680
+						),
681
+					),
682
+				),
683
+				'callback_args'   => array($version),
684
+			),
685
+		);
686
+		return apply_filters(
687
+			'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
688
+			$this_versions_routes,
689
+			$version,
690
+			$hidden_endpoint
691
+		);
692
+	}
693
+
694
+
695
+
696
+	/**
697
+	 * Gets the query params that can be used when request one or many
698
+	 *
699
+	 * @param EEM_Base $model
700
+	 * @param string   $version
701
+	 * @return array
702
+	 */
703
+	protected function _get_response_selection_query_params(\EEM_Base $model, $version)
704
+	{
705
+		return apply_filters(
706
+			'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
707
+			array(
708
+				'include'   => array(
709
+					'required' => false,
710
+					'default'  => '*',
711
+					'type'     => 'string',
712
+				),
713
+				'calculate' => array(
714
+					'required'          => false,
715
+					'default'           => '',
716
+					'enum'              => self::$_field_calculator->retrieveCalculatedFieldsForModel($model),
717
+					'type'              => 'string',
718
+					//because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization
719
+					//freaks out. We'll just validate this argument while handling the request
720
+					'validate_callback' => null,
721
+					'sanitize_callback' => null,
722
+				),
723
+			),
724
+			$model,
725
+			$version
726
+		);
727
+	}
728
+
729
+
730
+
731
+	/**
732
+	 * Gets the parameters acceptable for delete requests
733
+	 *
734
+	 * @param \EEM_Base $model
735
+	 * @param string    $version
736
+	 * @return array
737
+	 */
738
+	protected function _get_delete_query_params(\EEM_Base $model, $version)
739
+	{
740
+		$params_for_delete = array(
741
+			'allow_blocking' => array(
742
+				'required' => false,
743
+				'default'  => true,
744
+				'type'     => 'boolean',
745
+			),
746
+		);
747
+		$params_for_delete['force'] = array(
748
+			'required' => false,
749
+			'default'  => false,
750
+			'type'     => 'boolean',
751
+		);
752
+		return apply_filters(
753
+			'FHEE__EED_Core_Rest_Api___get_delete_query_params',
754
+			$params_for_delete,
755
+			$model,
756
+			$version
757
+		);
758
+	}
759
+
760
+
761
+
762
+	/**
763
+	 * Gets info about reading query params that are acceptable
764
+	 *
765
+	 * @param \EEM_Base $model eg 'Event' or 'Venue'
766
+	 * @param  string   $version
767
+	 * @return array    describing the args acceptable when querying this model
768
+	 * @throws EE_Error
769
+	 */
770
+	protected function _get_read_query_params(\EEM_Base $model, $version)
771
+	{
772
+		$default_orderby = array();
773
+		foreach ($model->get_combined_primary_key_fields() as $key_field) {
774
+			$default_orderby[$key_field->get_name()] = 'ASC';
775
+		}
776
+		return array_merge(
777
+			$this->_get_response_selection_query_params($model, $version),
778
+			array(
779
+				'where'    => array(
780
+					'required' => false,
781
+					'default'  => array(),
782
+					'type'     => 'object',
783
+					//because we accept an almost infinite list of possible where conditions, WP
784
+					// core validation and sanitization freaks out. We'll just validate this argument
785
+					// while handling the request
786
+					'validate_callback' => null,
787
+					'sanitize_callback' => null,
788
+				),
789
+				'limit'    => array(
790
+					'required' => false,
791
+					'default'  => EED_Core_Rest_Api::get_default_query_limit(),
792
+					'type'     => array(
793
+						'array',
794
+						'string',
795
+						'integer',
796
+					),
797
+					//because we accept a variety of types, WP core validation and sanitization
798
+					//freaks out. We'll just validate this argument while handling the request
799
+					'validate_callback' => null,
800
+					'sanitize_callback' => null,
801
+				),
802
+				'order_by' => array(
803
+					'required' => false,
804
+					'default'  => $default_orderby,
805
+					'type'     => array(
806
+						'object',
807
+						'string',
808
+					),//because we accept a variety of types, WP core validation and sanitization
809
+					//freaks out. We'll just validate this argument while handling the request
810
+					'validate_callback' => null,
811
+					'sanitize_callback' => null,
812
+				),
813
+				'group_by' => array(
814
+					'required' => false,
815
+					'default'  => null,
816
+					'type'     => array(
817
+						'object',
818
+						'string',
819
+					),
820
+					//because we accept  an almost infinite list of possible groupings,
821
+					// WP core validation and sanitization
822
+					//freaks out. We'll just validate this argument while handling the request
823
+					'validate_callback' => null,
824
+					'sanitize_callback' => null,
825
+				),
826
+				'having'   => array(
827
+					'required' => false,
828
+					'default'  => null,
829
+					'type'     => 'object',
830
+					//because we accept an almost infinite list of possible where conditions, WP
831
+					// core validation and sanitization freaks out. We'll just validate this argument
832
+					// while handling the request
833
+					'validate_callback' => null,
834
+					'sanitize_callback' => null,
835
+				),
836
+				'caps'     => array(
837
+					'required' => false,
838
+					'default'  => EEM_Base::caps_read,
839
+					'type'     => 'string',
840
+					'enum'     => array(
841
+						EEM_Base::caps_read,
842
+						EEM_Base::caps_read_admin,
843
+						EEM_Base::caps_edit,
844
+						EEM_Base::caps_delete
845
+					)
846
+				),
847
+			)
848
+		);
849
+	}
850
+
851
+
852
+
853
+	/**
854
+	 * Gets parameter information for a model regarding writing data
855
+	 *
856
+	 * @param string           $model_name
857
+	 * @param ModelVersionInfo $model_version_info
858
+	 * @param boolean          $create                                       whether this is for request to create (in which case we need
859
+	 *                                                                       all required params) or just to update (in which case we don't need those on every request)
860
+	 * @return array
861
+	 */
862
+	protected function _get_write_params(
863
+		$model_name,
864
+		ModelVersionInfo $model_version_info,
865
+		$create = false
866
+	) {
867
+		$model = EE_Registry::instance()->load_model($model_name);
868
+		$fields = $model_version_info->fieldsOnModelInThisVersion($model);
869
+		$args_info = array();
870
+		foreach ($fields as $field_name => $field_obj) {
871
+			if ($field_obj->is_auto_increment()) {
872
+				//totally ignore auto increment IDs
873
+				continue;
874
+			}
875
+			$arg_info = $field_obj->getSchema();
876
+			$required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null;
877
+			$arg_info['required'] = $required;
878
+			//remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right?
879
+			unset($arg_info['readonly']);
880
+			$schema_properties = $field_obj->getSchemaProperties();
881
+			if (
882
+				isset($schema_properties['raw'])
883
+				&& $field_obj->getSchemaType() === 'object'
884
+			) {
885
+				//if there's a "raw" form of this argument, use those properties instead
886
+				$arg_info = array_replace(
887
+					$arg_info,
888
+					$schema_properties['raw']
889
+				);
890
+			}
891
+			$arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson(
892
+				$field_obj,
893
+				$field_obj->get_default_value(),
894
+				$model_version_info->requestedVersion()
895
+			);
896
+			//we do our own validation and sanitization within the controller
897
+			$arg_info['sanitize_callback'] =
898
+				array(
899
+					'EED_Core_Rest_Api',
900
+					'default_sanitize_callback',
901
+				);
902
+			$args_info[$field_name] = $arg_info;
903
+			if ($field_obj instanceof EE_Datetime_Field) {
904
+				$gmt_arg_info = $arg_info;
905
+				$gmt_arg_info['description'] = sprintf(
906
+					esc_html__(
907
+						'%1$s - the value for this field in UTC. Ignored if %2$s is provided.',
908
+						'event_espresso'
909
+					),
910
+					$field_obj->get_nicename(),
911
+					$field_name
912
+				);
913
+				$args_info[$field_name . '_gmt'] = $gmt_arg_info;
914
+			}
915
+		}
916
+		return $args_info;
917
+	}
918
+
919
+
920
+
921
+	/**
922
+	 * Replacement for WP API's 'rest_parse_request_arg'.
923
+	 * If the value is blank but not required, don't bother validating it.
924
+	 * Also, it uses our email validation instead of WP API's default.
925
+	 *
926
+	 * @param                 $value
927
+	 * @param WP_REST_Request $request
928
+	 * @param                 $param
929
+	 * @return bool|true|WP_Error
930
+	 * @throws InvalidArgumentException
931
+	 * @throws InvalidInterfaceException
932
+	 * @throws InvalidDataTypeException
933
+	 */
934
+	public static function default_sanitize_callback( $value, WP_REST_Request $request, $param)
935
+	{
936
+		$attributes = $request->get_attributes();
937
+		if (! isset($attributes['args'][$param])
938
+			|| ! is_array($attributes['args'][$param])) {
939
+			$validation_result = true;
940
+		} else {
941
+			$args = $attributes['args'][$param];
942
+			if ((
943
+					$value === ''
944
+					|| $value === null
945
+				)
946
+				&& (! isset($args['required'])
947
+					|| $args['required'] === false
948
+				)
949
+			) {
950
+				//not required and not provided? that's cool
951
+				$validation_result = true;
952
+			} elseif (isset($args['format'])
953
+				&& $args['format'] === 'email'
954
+			) {
955
+				$validation_result = true;
956
+				if (! self::_validate_email($value)) {
957
+					$validation_result = new WP_Error(
958
+						'rest_invalid_param',
959
+						esc_html__(
960
+							'The email address is not valid or does not exist.',
961
+							'event_espresso'
962
+						)
963
+					);
964
+				}
965
+			} else {
966
+				$validation_result = rest_validate_value_from_schema($value, $args, $param);
967
+			}
968
+		}
969
+		if (is_wp_error($validation_result)) {
970
+			return $validation_result;
971
+		}
972
+		return rest_sanitize_request_arg($value, $request, $param);
973
+	}
974
+
975
+
976
+
977
+	/**
978
+	 * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email()
979
+	 *
980
+	 * @param $email
981
+	 * @return bool
982
+	 * @throws InvalidArgumentException
983
+	 * @throws InvalidInterfaceException
984
+	 * @throws InvalidDataTypeException
985
+	 */
986
+	protected static function _validate_email($email){
987
+		try {
988
+			EmailAddressFactory::create($email);
989
+			return true;
990
+		} catch (EmailValidationException $e) {
991
+			return false;
992
+		}
993
+	}
994
+
995
+
996
+
997
+	/**
998
+	 * Gets routes for the config
999
+	 *
1000
+	 * @return array @see _register_model_routes
1001
+	 * @deprecated since version 4.9.1
1002
+	 */
1003
+	protected function _register_config_routes()
1004
+	{
1005
+		$config_routes = array();
1006
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
1007
+			$config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version(
1008
+				$version,
1009
+				$hidden_endpoint
1010
+			);
1011
+		}
1012
+		return $config_routes;
1013
+	}
1014
+
1015
+
1016
+
1017
+	/**
1018
+	 * Gets routes for the config for the specified version
1019
+	 *
1020
+	 * @param string  $version
1021
+	 * @param boolean $hidden_endpoint
1022
+	 * @return array
1023
+	 */
1024
+	protected function _get_config_route_data_for_version($version, $hidden_endpoint)
1025
+	{
1026
+		return array(
1027
+			'config'    => array(
1028
+				array(
1029
+					'callback'        => array(
1030
+						'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1031
+						'handleRequest',
1032
+					),
1033
+					'methods'         => WP_REST_Server::READABLE,
1034
+					'hidden_endpoint' => $hidden_endpoint,
1035
+					'callback_args'   => array($version),
1036
+				),
1037
+			),
1038
+			'site_info' => array(
1039
+				array(
1040
+					'callback'        => array(
1041
+						'EventEspresso\core\libraries\rest_api\controllers\config\Read',
1042
+						'handleRequestSiteInfo',
1043
+					),
1044
+					'methods'         => WP_REST_Server::READABLE,
1045
+					'hidden_endpoint' => $hidden_endpoint,
1046
+					'callback_args'   => array($version),
1047
+				),
1048
+			),
1049
+		);
1050
+	}
1051
+
1052
+
1053
+
1054
+	/**
1055
+	 * Gets the meta info routes
1056
+	 *
1057
+	 * @return array @see _register_model_routes
1058
+	 * @deprecated since version 4.9.1
1059
+	 */
1060
+	protected function _register_meta_routes()
1061
+	{
1062
+		$meta_routes = array();
1063
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
1064
+			$meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version(
1065
+				$version,
1066
+				$hidden_endpoint
1067
+			);
1068
+		}
1069
+		return $meta_routes;
1070
+	}
1071
+
1072
+
1073
+
1074
+	/**
1075
+	 * @param string  $version
1076
+	 * @param boolean $hidden_endpoint
1077
+	 * @return array
1078
+	 */
1079
+	protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false)
1080
+	{
1081
+		return array(
1082
+			'resources' => array(
1083
+				array(
1084
+					'callback'        => array(
1085
+						'EventEspresso\core\libraries\rest_api\controllers\model\Meta',
1086
+						'handleRequestModelsMeta',
1087
+					),
1088
+					'methods'         => WP_REST_Server::READABLE,
1089
+					'hidden_endpoint' => $hidden_endpoint,
1090
+					'callback_args'   => array($version),
1091
+				),
1092
+			),
1093
+		);
1094
+	}
1095
+
1096
+
1097
+
1098
+	/**
1099
+	 * Tries to hide old 4.6 endpoints from the
1100
+	 *
1101
+	 * @param array $route_data
1102
+	 * @return array
1103
+	 * @throws \EE_Error
1104
+	 */
1105
+	public static function hide_old_endpoints($route_data)
1106
+	{
1107
+		//allow API clients to override which endpoints get hidden, in case
1108
+		//they want to discover particular endpoints
1109
+		//also, we don't have access to the request so we have to just grab it from the superglobal
1110
+		$force_show_ee_namespace = ltrim(
1111
+			EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''),
1112
+			'/'
1113
+		);
1114
+		foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
1115
+			foreach ($relative_urls as $resource_name => $endpoints) {
1116
+				foreach ($endpoints as $key => $endpoint) {
1117
+					//skip schema and other route options
1118
+					if (! is_numeric($key)) {
1119
+						continue;
1120
+					}
1121
+					//by default, hide "hidden_endpoint"s, unless the request indicates
1122
+					//to $force_show_ee_namespace, in which case only show that one
1123
+					//namespace's endpoints (and hide all others)
1124
+					if (
1125
+						($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
1126
+						|| ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '')
1127
+					) {
1128
+						$full_route = '/' . ltrim($namespace, '/');
1129
+						$full_route .= '/' . ltrim($resource_name, '/');
1130
+						unset($route_data[$full_route]);
1131
+					}
1132
+				}
1133
+			}
1134
+		}
1135
+		return $route_data;
1136
+	}
1137
+
1138
+
1139
+
1140
+	/**
1141
+	 * Returns an array describing which versions of core support serving requests for.
1142
+	 * Keys are core versions' major and minor version, and values are the
1143
+	 * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like
1144
+	 * data by just removing a few models and fields from the responses. However, 4.15 might remove
1145
+	 * the answers table entirely, in which case it would be very difficult for
1146
+	 * it to serve 4.6-style responses.
1147
+	 * Versions of core that are missing from this array are unknowns.
1148
+	 * previous ver
1149
+	 *
1150
+	 * @return array
1151
+	 */
1152
+	public static function version_compatibilities()
1153
+	{
1154
+		return apply_filters(
1155
+			'FHEE__EED_Core_REST_API__version_compatibilities',
1156
+			array(
1157
+				'4.8.29' => '4.8.29',
1158
+				'4.8.33' => '4.8.29',
1159
+				'4.8.34' => '4.8.29',
1160
+				'4.8.36' => '4.8.29',
1161
+			)
1162
+		);
1163
+	}
1164
+
1165
+
1166
+
1167
+	/**
1168
+	 * Gets the latest API version served. Eg if there
1169
+	 * are two versions served of the API, 4.8.29 and 4.8.32, and
1170
+	 * we are on core version 4.8.34, it will return the string "4.8.32"
1171
+	 *
1172
+	 * @return string
1173
+	 */
1174
+	public static function latest_rest_api_version()
1175
+	{
1176
+		$versions_served = \EED_Core_Rest_Api::versions_served();
1177
+		$versions_served_keys = array_keys($versions_served);
1178
+		return end($versions_served_keys);
1179
+	}
1180
+
1181
+
1182
+
1183
+	/**
1184
+	 * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of
1185
+	 * EE the API can serve requests for. Eg, if we are on 4.15 of core, and
1186
+	 * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ).
1187
+	 * We also indicate whether or not this version should be put in the index or not
1188
+	 *
1189
+	 * @return array keys are API version numbers (just major and minor numbers), and values
1190
+	 * are whether or not they should be hidden
1191
+	 */
1192
+	public static function versions_served()
1193
+	{
1194
+		$versions_served = array();
1195
+		$possibly_served_versions = EED_Core_Rest_Api::version_compatibilities();
1196
+		$lowest_compatible_version = end($possibly_served_versions);
1197
+		reset($possibly_served_versions);
1198
+		$versions_served_historically = array_keys($possibly_served_versions);
1199
+		$latest_version = end($versions_served_historically);
1200
+		reset($versions_served_historically);
1201
+		//for each version of core we have ever served:
1202
+		foreach ($versions_served_historically as $key_versioned_endpoint) {
1203
+			//if it's not above the current core version, and it's compatible with the current version of core
1204
+			if ($key_versioned_endpoint === $latest_version) {
1205
+				//don't hide the latest version in the index
1206
+				$versions_served[$key_versioned_endpoint] = false;
1207
+			} elseif (
1208
+				$key_versioned_endpoint >= $lowest_compatible_version
1209
+				&& $key_versioned_endpoint < EED_Core_Rest_Api::core_version()
1210
+			) {
1211
+				//include, but hide, previous versions which are still supported
1212
+				$versions_served[$key_versioned_endpoint] = true;
1213
+			} elseif (apply_filters(
1214
+				'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
1215
+				false,
1216
+				$possibly_served_versions
1217
+			)) {
1218
+				//if a version is no longer supported, don't include it in index or list of versions served
1219
+				$versions_served[$key_versioned_endpoint] = true;
1220
+			}
1221
+		}
1222
+		return $versions_served;
1223
+	}
1224
+
1225
+
1226
+
1227
+	/**
1228
+	 * Gets the major and minor version of EE core's version string
1229
+	 *
1230
+	 * @return string
1231
+	 */
1232
+	public static function core_version()
1233
+	{
1234
+		return apply_filters(
1235
+			'FHEE__EED_Core_REST_API__core_version',
1236
+			implode(
1237
+				'.',
1238
+				array_slice(
1239
+					explode(
1240
+						'.',
1241
+						espresso_version()
1242
+					),
1243
+				0,
1244
+				3
1245
+				)
1246
+			)
1247
+		);
1248
+	}
1249
+
1250
+
1251
+
1252
+	/**
1253
+	 * Gets the default limit that should be used when querying for resources
1254
+	 *
1255
+	 * @return int
1256
+	 */
1257
+	public static function get_default_query_limit()
1258
+	{
1259
+		//we actually don't use a const because we want folks to always use
1260
+		//this method, not the const directly
1261
+		return apply_filters(
1262
+			'FHEE__EED_Core_Rest_Api__get_default_query_limit',
1263
+			50
1264
+		);
1265
+	}
1266
+
1267
+
1268
+
1269
+	/**
1270
+	 *    run - initial module setup
1271
+	 *
1272
+	 * @access    public
1273
+	 * @param  WP $WP
1274
+	 * @return    void
1275
+	 */
1276
+	public function run($WP)
1277
+	{
1278
+	}
1279 1279
 }
1280 1280
 
1281 1281
 // End of file EED_Core_Rest_Api.module.php
Please login to merge, or discard this patch.
core/services/request/RequestStackBuilder.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -22,49 +22,49 @@
 block discarded – undo
22 22
 class RequestStackBuilder extends SplDoublyLinkedList
23 23
 {
24 24
 
25
-    /**
26
-     * @type LoaderInterface $loader
27
-     */
28
-    private $loader;
25
+	/**
26
+	 * @type LoaderInterface $loader
27
+	 */
28
+	private $loader;
29 29
 
30 30
 
31
-    /**
32
-     * RequestStackBuilder constructor.
33
-     *
34
-     * @param LoaderInterface $loader
35
-     */
36
-    public function __construct(LoaderInterface $loader)
37
-    {
38
-        $this->loader = $loader;
39
-        $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP);
40
-    }
31
+	/**
32
+	 * RequestStackBuilder constructor.
33
+	 *
34
+	 * @param LoaderInterface $loader
35
+	 */
36
+	public function __construct(LoaderInterface $loader)
37
+	{
38
+		$this->loader = $loader;
39
+		$this->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP);
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * builds decorated middleware stack
45
-     * by continuously injecting previous middleware app into the next
46
-     *
47
-     * @param RequestStackCoreAppInterface $application
48
-     * @return RequestStack
49
-     */
50
-    public function resolve(RequestStackCoreAppInterface $application)
51
-    {
52
-        $core_app = $application;
53
-        // NOW... because the RequestStack is following the decorator pattern,
54
-        // the first stack app we add will end up at the center of the stack,
55
-        // and will end up being the last item to actually run, but we don't want that!
56
-        // Basically we're dealing with TWO stacks, and transferring items from one to the other,
57
-        // BUT... we want the final stack to be in the same order as the first.
58
-        // So we need to reverse the iterator mode when transferring items,
59
-        // because if we don't, the second stack will end  up in the incorrect order.
60
-        $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP);
61
-        for ($this->rewind(); $this->valid(); $this->next()) {
62
-            $middleware_app       = $this->current();
63
-            $middleware_app_class = array_shift($middleware_app);
64
-            $middleware_app_args  = is_array($middleware_app) ? $middleware_app : array();
65
-            $middleware_app_args  = array($application, $this->loader) + $middleware_app_args;
66
-            $application = $this->loader->getShared($middleware_app_class, $middleware_app_args);
67
-        }
68
-        return new RequestStack($application, $core_app);
69
-    }
43
+	/**
44
+	 * builds decorated middleware stack
45
+	 * by continuously injecting previous middleware app into the next
46
+	 *
47
+	 * @param RequestStackCoreAppInterface $application
48
+	 * @return RequestStack
49
+	 */
50
+	public function resolve(RequestStackCoreAppInterface $application)
51
+	{
52
+		$core_app = $application;
53
+		// NOW... because the RequestStack is following the decorator pattern,
54
+		// the first stack app we add will end up at the center of the stack,
55
+		// and will end up being the last item to actually run, but we don't want that!
56
+		// Basically we're dealing with TWO stacks, and transferring items from one to the other,
57
+		// BUT... we want the final stack to be in the same order as the first.
58
+		// So we need to reverse the iterator mode when transferring items,
59
+		// because if we don't, the second stack will end  up in the incorrect order.
60
+		$this->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP);
61
+		for ($this->rewind(); $this->valid(); $this->next()) {
62
+			$middleware_app       = $this->current();
63
+			$middleware_app_class = array_shift($middleware_app);
64
+			$middleware_app_args  = is_array($middleware_app) ? $middleware_app : array();
65
+			$middleware_app_args  = array($application, $this->loader) + $middleware_app_args;
66
+			$application = $this->loader->getShared($middleware_app_class, $middleware_app_args);
67
+		}
68
+		return new RequestStack($application, $core_app);
69
+	}
70 70
 }
Please login to merge, or discard this patch.
core/services/bootstrap/BootstrapCore.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         // load interfaces
170 170
         espresso_load_required(
171 171
             'EEH_Autoloader',
172
-            EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php'
172
+            EE_CORE.'helpers'.DS.'EEH_Autoloader.helper.php'
173 173
         );
174 174
         EEH_Autoloader::instance();
175 175
     }
@@ -184,13 +184,13 @@  discard block
 block discarded – undo
184 184
     protected function setAutoloadersForRequiredFiles()
185 185
     {
186 186
         // load interfaces
187
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true);
187
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces', true);
188 188
         // load helpers
189 189
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
190 190
         // load request stack
191
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS);
191
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'request_stack'.DS);
192 192
         // load middleware
193
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS);
193
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'middleware'.DS);
194 194
     }
195 195
 
196 196
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
          * so items at the beginning of the final middleware stack will run last.
209 209
          * First parameter is the middleware classname, second is an array of arguments
210 210
          */
211
-        $stack_apps            = apply_filters(
211
+        $stack_apps = apply_filters(
212 212
             'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps',
213 213
             array(
214 214
                 // first in last out
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
             )
221 221
         );
222 222
         // legacy filter for backwards compatibility
223
-        $stack_apps            = apply_filters(
223
+        $stack_apps = apply_filters(
224 224
             'FHEE__EE_Bootstrap__build_request_stack__stack_apps',
225 225
             $stack_apps
226 226
         );
Please login to merge, or discard this patch.
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -44,204 +44,204 @@
 block discarded – undo
44 44
 class BootstrapCore
45 45
 {
46 46
 
47
-    /**
48
-     * @type LoaderInterface $loader
49
-     */
50
-    private $loader;
51
-
52
-    /**
53
-     * @var RequestInterface $request
54
-     */
55
-    protected $request;
56
-
57
-    /**
58
-     * @var ResponseInterface $response
59
-     */
60
-    protected $response;
61
-
62
-    /**
63
-     * @var RequestStackBuilder $request_stack_builder
64
-     */
65
-    protected $request_stack_builder;
66
-
67
-    /**
68
-     * @var RequestStack $request_stack
69
-     */
70
-    protected $request_stack;
71
-
72
-
73
-
74
-    public function __construct()
75
-    {
76
-        // construct request stack and run middleware apps as soon as all WP plugins are loaded
77
-        add_action('plugins_loaded', array($this, 'initialize'), 0);
78
-    }
79
-
80
-
81
-    /**
82
-     * @throws EE_Error
83
-     * @throws InvalidArgumentException
84
-     * @throws InvalidDataTypeException
85
-     * @throws InvalidInterfaceException
86
-     * @throws ReflectionException
87
-     */
88
-    public function initialize()
89
-    {
90
-        $this->bootstrapDependencyInjectionContainer();
91
-        $bootstrap_request = $this->bootstrapRequestResponseObjects();
92
-        add_action(
93
-            'EE_Load_Espresso_Core__handle_request__initialize_core_loading',
94
-            array($bootstrap_request, 'setupLegacyRequest')
95
-        );
96
-        $this->runRequestStack();
97
-    }
98
-
99
-
100
-    /**
101
-     * @throws ReflectionException
102
-     * @throws EE_Error
103
-     * @throws InvalidArgumentException
104
-     * @throws InvalidDataTypeException
105
-     * @throws InvalidInterfaceException
106
-     */
107
-    private function bootstrapDependencyInjectionContainer()
108
-    {
109
-        $bootstrap_di = new BootstrapDependencyInjectionContainer();
110
-        $bootstrap_di->buildLegacyDependencyInjectionContainer();
111
-        $bootstrap_di->buildLoader();
112
-        $registry = $bootstrap_di->getRegistry();
113
-        $dependency_map = $bootstrap_di->getDependencyMap();
114
-        $dependency_map->initialize();
115
-        $registry->initialize();
116
-        $this->loader = $bootstrap_di->getLoader();
117
-    }
118
-
119
-
120
-    /**
121
-     * sets up the request and response objects
122
-     *
123
-     * @return BootstrapRequestResponseObjects
124
-     * @throws InvalidArgumentException
125
-     */
126
-    private function bootstrapRequestResponseObjects()
127
-    {
128
-        /** @var BootstrapRequestResponseObjects $bootstrap_request */
129
-        $bootstrap_request = $this->loader->getShared(
130
-            'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects',
131
-            array($this->loader)
132
-        );
133
-        $bootstrap_request->buildRequestResponse();
134
-        $bootstrap_request->shareRequestResponse();
135
-        $this->request  = $this->loader->getShared('EventEspresso\core\services\request\Request');
136
-        $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response');
137
-        return $bootstrap_request;
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * run_request_stack
144
-     * construct request stack and run middleware apps
145
-     *
146
-     * @throws InvalidInterfaceException
147
-     * @throws InvalidDataTypeException
148
-     * @throws EE_Error
149
-     * @throws InvalidArgumentException
150
-     * @throws ReflectionException
151
-     */
152
-    public function runRequestStack()
153
-    {
154
-        $this->loadAutoloader();
155
-        $this->setAutoloadersForRequiredFiles();
156
-        $this->request_stack_builder = $this->buildRequestStack();
157
-        $this->request_stack         = $this->request_stack_builder->resolve(
158
-            new RequestStackCoreApp()
159
-        );
160
-        $this->request_stack->handleRequest($this->request, $this->response);
161
-        $this->request_stack->handleResponse();
162
-    }
163
-
164
-
165
-    /**
166
-     * load_autoloader
167
-     *
168
-     * @throws EE_Error
169
-     */
170
-    protected function loadAutoloader()
171
-    {
172
-        // load interfaces
173
-        espresso_load_required(
174
-            'EEH_Autoloader',
175
-            EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php'
176
-        );
177
-        EEH_Autoloader::instance();
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     * load_required_files
184
-     *
185
-     * @throws EE_Error
186
-     */
187
-    protected function setAutoloadersForRequiredFiles()
188
-    {
189
-        // load interfaces
190
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true);
191
-        // load helpers
192
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
193
-        // load request stack
194
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS);
195
-        // load middleware
196
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS);
197
-    }
198
-
199
-
200
-
201
-    /**
202
-     * build_request_stack
203
-     *
204
-     * @return RequestStackBuilder
205
-     */
206
-    public function buildRequestStack()
207
-    {
208
-        $request_stack_builder = new RequestStackBuilder($this->loader);
209
-        /**
210
-         * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT
211
-         * so items at the beginning of the final middleware stack will run last.
212
-         * First parameter is the middleware classname, second is an array of arguments
213
-         */
214
-        $stack_apps            = apply_filters(
215
-            'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps',
216
-            array(
217
-                // first in last out
218
-                'EventEspresso\core\services\request\middleware\BotDetector' => array(),
219
-                'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(),
220
-                'EventEspresso\core\services\request\middleware\RecommendedVersions' => array(),
221
-                // last in first out
222
-                'EventEspresso\core\services\request\middleware\DetectLogin' => array(),
223
-            )
224
-        );
225
-        // legacy filter for backwards compatibility
226
-        $stack_apps            = apply_filters(
227
-            'FHEE__EE_Bootstrap__build_request_stack__stack_apps',
228
-            $stack_apps
229
-        );
230
-        // load middleware onto stack : FIFO (First In First Out)
231
-        // items at the beginning of the $stack_apps array will run last
232
-        foreach ((array) $stack_apps as $stack_app => $stack_app_args) {
233
-            $request_stack_builder->push(array($stack_app, $stack_app_args));
234
-        }
235
-        // finally, we'll add this on its own because we need it to always be part of the stack
236
-        // and we also need it to always run first because the rest of the system relies on it
237
-        $request_stack_builder->push(
238
-            array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array())
239
-        );
240
-        return apply_filters(
241
-            'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder',
242
-            $request_stack_builder
243
-        );
244
-    }
47
+	/**
48
+	 * @type LoaderInterface $loader
49
+	 */
50
+	private $loader;
51
+
52
+	/**
53
+	 * @var RequestInterface $request
54
+	 */
55
+	protected $request;
56
+
57
+	/**
58
+	 * @var ResponseInterface $response
59
+	 */
60
+	protected $response;
61
+
62
+	/**
63
+	 * @var RequestStackBuilder $request_stack_builder
64
+	 */
65
+	protected $request_stack_builder;
66
+
67
+	/**
68
+	 * @var RequestStack $request_stack
69
+	 */
70
+	protected $request_stack;
71
+
72
+
73
+
74
+	public function __construct()
75
+	{
76
+		// construct request stack and run middleware apps as soon as all WP plugins are loaded
77
+		add_action('plugins_loaded', array($this, 'initialize'), 0);
78
+	}
79
+
80
+
81
+	/**
82
+	 * @throws EE_Error
83
+	 * @throws InvalidArgumentException
84
+	 * @throws InvalidDataTypeException
85
+	 * @throws InvalidInterfaceException
86
+	 * @throws ReflectionException
87
+	 */
88
+	public function initialize()
89
+	{
90
+		$this->bootstrapDependencyInjectionContainer();
91
+		$bootstrap_request = $this->bootstrapRequestResponseObjects();
92
+		add_action(
93
+			'EE_Load_Espresso_Core__handle_request__initialize_core_loading',
94
+			array($bootstrap_request, 'setupLegacyRequest')
95
+		);
96
+		$this->runRequestStack();
97
+	}
98
+
99
+
100
+	/**
101
+	 * @throws ReflectionException
102
+	 * @throws EE_Error
103
+	 * @throws InvalidArgumentException
104
+	 * @throws InvalidDataTypeException
105
+	 * @throws InvalidInterfaceException
106
+	 */
107
+	private function bootstrapDependencyInjectionContainer()
108
+	{
109
+		$bootstrap_di = new BootstrapDependencyInjectionContainer();
110
+		$bootstrap_di->buildLegacyDependencyInjectionContainer();
111
+		$bootstrap_di->buildLoader();
112
+		$registry = $bootstrap_di->getRegistry();
113
+		$dependency_map = $bootstrap_di->getDependencyMap();
114
+		$dependency_map->initialize();
115
+		$registry->initialize();
116
+		$this->loader = $bootstrap_di->getLoader();
117
+	}
118
+
119
+
120
+	/**
121
+	 * sets up the request and response objects
122
+	 *
123
+	 * @return BootstrapRequestResponseObjects
124
+	 * @throws InvalidArgumentException
125
+	 */
126
+	private function bootstrapRequestResponseObjects()
127
+	{
128
+		/** @var BootstrapRequestResponseObjects $bootstrap_request */
129
+		$bootstrap_request = $this->loader->getShared(
130
+			'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects',
131
+			array($this->loader)
132
+		);
133
+		$bootstrap_request->buildRequestResponse();
134
+		$bootstrap_request->shareRequestResponse();
135
+		$this->request  = $this->loader->getShared('EventEspresso\core\services\request\Request');
136
+		$this->response = $this->loader->getShared('EventEspresso\core\services\request\Response');
137
+		return $bootstrap_request;
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * run_request_stack
144
+	 * construct request stack and run middleware apps
145
+	 *
146
+	 * @throws InvalidInterfaceException
147
+	 * @throws InvalidDataTypeException
148
+	 * @throws EE_Error
149
+	 * @throws InvalidArgumentException
150
+	 * @throws ReflectionException
151
+	 */
152
+	public function runRequestStack()
153
+	{
154
+		$this->loadAutoloader();
155
+		$this->setAutoloadersForRequiredFiles();
156
+		$this->request_stack_builder = $this->buildRequestStack();
157
+		$this->request_stack         = $this->request_stack_builder->resolve(
158
+			new RequestStackCoreApp()
159
+		);
160
+		$this->request_stack->handleRequest($this->request, $this->response);
161
+		$this->request_stack->handleResponse();
162
+	}
163
+
164
+
165
+	/**
166
+	 * load_autoloader
167
+	 *
168
+	 * @throws EE_Error
169
+	 */
170
+	protected function loadAutoloader()
171
+	{
172
+		// load interfaces
173
+		espresso_load_required(
174
+			'EEH_Autoloader',
175
+			EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php'
176
+		);
177
+		EEH_Autoloader::instance();
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 * load_required_files
184
+	 *
185
+	 * @throws EE_Error
186
+	 */
187
+	protected function setAutoloadersForRequiredFiles()
188
+	{
189
+		// load interfaces
190
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true);
191
+		// load helpers
192
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
193
+		// load request stack
194
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS);
195
+		// load middleware
196
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS);
197
+	}
198
+
199
+
200
+
201
+	/**
202
+	 * build_request_stack
203
+	 *
204
+	 * @return RequestStackBuilder
205
+	 */
206
+	public function buildRequestStack()
207
+	{
208
+		$request_stack_builder = new RequestStackBuilder($this->loader);
209
+		/**
210
+		 * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT
211
+		 * so items at the beginning of the final middleware stack will run last.
212
+		 * First parameter is the middleware classname, second is an array of arguments
213
+		 */
214
+		$stack_apps            = apply_filters(
215
+			'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps',
216
+			array(
217
+				// first in last out
218
+				'EventEspresso\core\services\request\middleware\BotDetector' => array(),
219
+				'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(),
220
+				'EventEspresso\core\services\request\middleware\RecommendedVersions' => array(),
221
+				// last in first out
222
+				'EventEspresso\core\services\request\middleware\DetectLogin' => array(),
223
+			)
224
+		);
225
+		// legacy filter for backwards compatibility
226
+		$stack_apps            = apply_filters(
227
+			'FHEE__EE_Bootstrap__build_request_stack__stack_apps',
228
+			$stack_apps
229
+		);
230
+		// load middleware onto stack : FIFO (First In First Out)
231
+		// items at the beginning of the $stack_apps array will run last
232
+		foreach ((array) $stack_apps as $stack_app => $stack_app_args) {
233
+			$request_stack_builder->push(array($stack_app, $stack_app_args));
234
+		}
235
+		// finally, we'll add this on its own because we need it to always be part of the stack
236
+		// and we also need it to always run first because the rest of the system relies on it
237
+		$request_stack_builder->push(
238
+			array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array())
239
+		);
240
+		return apply_filters(
241
+			'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder',
242
+			$request_stack_builder
243
+		);
244
+	}
245 245
 
246 246
 
247 247
 }
Please login to merge, or discard this patch.
core/services/loaders/Loader.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -22,114 +22,114 @@
 block discarded – undo
22 22
 {
23 23
 
24 24
 
25
-    /**
26
-     * @var LoaderDecoratorInterface $new_loader
27
-     */
28
-    private $new_loader;
29
-
30
-
31
-    /**
32
-     * @var LoaderDecoratorInterface $shared_loader
33
-     */
34
-    private $shared_loader;
35
-
36
-
37
-
38
-    /**
39
-     * Loader constructor.
40
-     *
41
-     * @param LoaderDecoratorInterface $new_loader
42
-     * @param CachingLoaderDecoratorInterface $shared_loader
43
-     * @throws InvalidInterfaceException
44
-     * @throws InvalidArgumentException
45
-     * @throws InvalidDataTypeException
46
-     */
47
-    public function __construct(LoaderDecoratorInterface $new_loader, CachingLoaderDecoratorInterface $shared_loader)
48
-    {
49
-        $this->new_loader = $new_loader;
50
-        $this->shared_loader = $shared_loader;
51
-    }
52
-
53
-
54
-
55
-    /**
56
-     * @return LoaderDecoratorInterface
57
-     */
58
-    public function getNewLoader()
59
-    {
60
-        return $this->new_loader;
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     * @return CachingLoaderDecoratorInterface
67
-     */
68
-    public function getSharedLoader()
69
-    {
70
-        return $this->shared_loader;
71
-    }
72
-
73
-
74
-
75
-    /**
76
-     * @param string $fqcn
77
-     * @param array  $arguments
78
-     * @param bool   $shared
79
-     * @return mixed
80
-     */
81
-    public function load($fqcn, $arguments = array(), $shared = true)
82
-    {
83
-        return $shared
84
-            ? $this->getSharedLoader()->load($fqcn, $arguments, $shared)
85
-            : $this->getNewLoader()->load($fqcn, $arguments, $shared);
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * @param string $fqcn
92
-     * @param array  $arguments
93
-     * @return mixed
94
-     */
95
-    public function getNew($fqcn, $arguments = array())
96
-    {
97
-        return $this->getNewLoader()->load($fqcn, $arguments, false);
98
-    }
99
-
100
-
101
-
102
-    /**
103
-     * @param string $fqcn
104
-     * @param array  $arguments
105
-     * @return mixed
106
-     */
107
-    public function getShared($fqcn, $arguments = array())
108
-    {
109
-        return $this->getSharedLoader()->load($fqcn, $arguments);
110
-    }
111
-
112
-
113
-    /**
114
-     * @param string $fqcn
115
-     * @param mixed  $object
116
-     * @return bool
117
-     * @throws InvalidArgumentException
118
-     */
119
-    public function share($fqcn, $object)
120
-    {
121
-        return $this->getSharedLoader()->share($fqcn, $object);
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * calls reset() on loaders if that method exists
128
-     */
129
-    public function reset()
130
-    {
131
-        $this->shared_loader->reset();
132
-    }
25
+	/**
26
+	 * @var LoaderDecoratorInterface $new_loader
27
+	 */
28
+	private $new_loader;
29
+
30
+
31
+	/**
32
+	 * @var LoaderDecoratorInterface $shared_loader
33
+	 */
34
+	private $shared_loader;
35
+
36
+
37
+
38
+	/**
39
+	 * Loader constructor.
40
+	 *
41
+	 * @param LoaderDecoratorInterface $new_loader
42
+	 * @param CachingLoaderDecoratorInterface $shared_loader
43
+	 * @throws InvalidInterfaceException
44
+	 * @throws InvalidArgumentException
45
+	 * @throws InvalidDataTypeException
46
+	 */
47
+	public function __construct(LoaderDecoratorInterface $new_loader, CachingLoaderDecoratorInterface $shared_loader)
48
+	{
49
+		$this->new_loader = $new_loader;
50
+		$this->shared_loader = $shared_loader;
51
+	}
52
+
53
+
54
+
55
+	/**
56
+	 * @return LoaderDecoratorInterface
57
+	 */
58
+	public function getNewLoader()
59
+	{
60
+		return $this->new_loader;
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 * @return CachingLoaderDecoratorInterface
67
+	 */
68
+	public function getSharedLoader()
69
+	{
70
+		return $this->shared_loader;
71
+	}
72
+
73
+
74
+
75
+	/**
76
+	 * @param string $fqcn
77
+	 * @param array  $arguments
78
+	 * @param bool   $shared
79
+	 * @return mixed
80
+	 */
81
+	public function load($fqcn, $arguments = array(), $shared = true)
82
+	{
83
+		return $shared
84
+			? $this->getSharedLoader()->load($fqcn, $arguments, $shared)
85
+			: $this->getNewLoader()->load($fqcn, $arguments, $shared);
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * @param string $fqcn
92
+	 * @param array  $arguments
93
+	 * @return mixed
94
+	 */
95
+	public function getNew($fqcn, $arguments = array())
96
+	{
97
+		return $this->getNewLoader()->load($fqcn, $arguments, false);
98
+	}
99
+
100
+
101
+
102
+	/**
103
+	 * @param string $fqcn
104
+	 * @param array  $arguments
105
+	 * @return mixed
106
+	 */
107
+	public function getShared($fqcn, $arguments = array())
108
+	{
109
+		return $this->getSharedLoader()->load($fqcn, $arguments);
110
+	}
111
+
112
+
113
+	/**
114
+	 * @param string $fqcn
115
+	 * @param mixed  $object
116
+	 * @return bool
117
+	 * @throws InvalidArgumentException
118
+	 */
119
+	public function share($fqcn, $object)
120
+	{
121
+		return $this->getSharedLoader()->share($fqcn, $object);
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * calls reset() on loaders if that method exists
128
+	 */
129
+	public function reset()
130
+	{
131
+		$this->shared_loader->reset();
132
+	}
133 133
 
134 134
 }
135 135
 // End of file Loader.php
Please login to merge, or discard this patch.
core/EE_Load_Espresso_Core.core.php 2 patches
Unused Use Statements   -5 removed lines patch added patch discarded remove patch
@@ -1,12 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-use EventEspresso\core\domain\DomainFactory;
4
-use EventEspresso\core\domain\values\FilePath;
5
-use EventEspresso\core\domain\values\FullyQualifiedName;
6
-use EventEspresso\core\domain\values\Version;
7 3
 use EventEspresso\core\exceptions\InvalidDataTypeException;
8 4
 use EventEspresso\core\exceptions\InvalidInterfaceException;
9
-use EventEspresso\core\services\loaders\LoaderFactory;
10 5
 use EventEspresso\core\services\request\RequestDecoratorInterface;
11 6
 use EventEspresso\core\services\request\RequestInterface;
12 7
 use EventEspresso\core\services\request\RequestStackCoreAppInterface;
Please login to merge, or discard this patch.
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -31,123 +31,123 @@
 block discarded – undo
31 31
 class EE_Load_Espresso_Core implements RequestDecoratorInterface, RequestStackCoreAppInterface
32 32
 {
33 33
 
34
-    /**
35
-     * @var RequestInterface $request
36
-     */
37
-    protected $request;
38
-
39
-    /**
40
-     * @var ResponseInterface $response
41
-     */
42
-    protected $response;
43
-
44
-    /**
45
-     * @var EE_Dependency_Map $dependency_map
46
-     */
47
-    protected $dependency_map;
48
-
49
-    /**
50
-     * @var EE_Registry $registry
51
-     */
52
-    protected $registry;
53
-
54
-
55
-    /**
56
-     * EE_Load_Espresso_Core constructor
57
-     *
58
-     * @param EE_Registry       $registry
59
-     * @param EE_Dependency_Map $dependency_map
60
-     * @throws EE_Error
61
-     */
34
+	/**
35
+	 * @var RequestInterface $request
36
+	 */
37
+	protected $request;
38
+
39
+	/**
40
+	 * @var ResponseInterface $response
41
+	 */
42
+	protected $response;
43
+
44
+	/**
45
+	 * @var EE_Dependency_Map $dependency_map
46
+	 */
47
+	protected $dependency_map;
48
+
49
+	/**
50
+	 * @var EE_Registry $registry
51
+	 */
52
+	protected $registry;
53
+
54
+
55
+	/**
56
+	 * EE_Load_Espresso_Core constructor
57
+	 *
58
+	 * @param EE_Registry       $registry
59
+	 * @param EE_Dependency_Map $dependency_map
60
+	 * @throws EE_Error
61
+	 */
62 62
 	public function __construct(EE_Registry $registry, EE_Dependency_Map $dependency_map) {
63
-        EE_Error::doing_it_wrong(
64
-            __METHOD__,
65
-            sprintf(
66
-                esc_html__(
67
-                    'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace',
68
-                    'event_espresso'
69
-                ),
70
-                'EventEspresso\core\services\request\RequestStackCoreApp',
71
-                '\core\services\request',
72
-                'EventEspresso\core\services\request'
73
-            ),
74
-            '4.9.53'
75
-        );
76
-    }
77
-
78
-
79
-    /**
80
-     * handle
81
-     * sets hooks for running rest of system
82
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
83
-     * starting EE Addons from any other point may lead to problems
84
-     *
85
-     * @param RequestInterface $request
86
-     * @param ResponseInterface      $response
87
-     * @return ResponseInterface
88
-     * @throws EE_Error
89
-     * @throws InvalidDataTypeException
90
-     * @throws InvalidInterfaceException
91
-     * @throws InvalidArgumentException
92
-     * @throws DomainException
93
-     */
94
-    public function handleRequest(RequestInterface $request, ResponseInterface $response)
95
-    {
96
-    }
97
-
98
-
99
-
100
-    /**
101
-     * @return RequestInterface
102
-     */
103
-    public function request()
104
-    {
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * @return ResponseInterface
111
-     */
112
-    public function response()
113
-    {
114
-    }
115
-
116
-
117
-
118
-    /**
119
-     * @return EE_Dependency_Map
120
-     * @throws EE_Error
121
-     */
122
-    public function dependency_map()
123
-    {
124
-    }
125
-
126
-
127
-
128
-    /**
129
-     * @return EE_Registry
130
-     * @throws EE_Error
131
-     */
132
-    public function registry()
133
-    {
134
-    }
135
-
136
-
137
-
138
-
139
-
140
-
141
-    /**
142
-     * called after the request stack has been fully processed
143
-     * if any of the middleware apps has requested the plugin be deactivated, then we do that now
144
-     *
145
-     * @param RequestInterface $request
146
-     * @param ResponseInterface $response
147
-     */
148
-    public function handleResponse(RequestInterface $request, ResponseInterface $response)
149
-    {
150
-    }
63
+		EE_Error::doing_it_wrong(
64
+			__METHOD__,
65
+			sprintf(
66
+				esc_html__(
67
+					'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace',
68
+					'event_espresso'
69
+				),
70
+				'EventEspresso\core\services\request\RequestStackCoreApp',
71
+				'\core\services\request',
72
+				'EventEspresso\core\services\request'
73
+			),
74
+			'4.9.53'
75
+		);
76
+	}
77
+
78
+
79
+	/**
80
+	 * handle
81
+	 * sets hooks for running rest of system
82
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
83
+	 * starting EE Addons from any other point may lead to problems
84
+	 *
85
+	 * @param RequestInterface $request
86
+	 * @param ResponseInterface      $response
87
+	 * @return ResponseInterface
88
+	 * @throws EE_Error
89
+	 * @throws InvalidDataTypeException
90
+	 * @throws InvalidInterfaceException
91
+	 * @throws InvalidArgumentException
92
+	 * @throws DomainException
93
+	 */
94
+	public function handleRequest(RequestInterface $request, ResponseInterface $response)
95
+	{
96
+	}
97
+
98
+
99
+
100
+	/**
101
+	 * @return RequestInterface
102
+	 */
103
+	public function request()
104
+	{
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * @return ResponseInterface
111
+	 */
112
+	public function response()
113
+	{
114
+	}
115
+
116
+
117
+
118
+	/**
119
+	 * @return EE_Dependency_Map
120
+	 * @throws EE_Error
121
+	 */
122
+	public function dependency_map()
123
+	{
124
+	}
125
+
126
+
127
+
128
+	/**
129
+	 * @return EE_Registry
130
+	 * @throws EE_Error
131
+	 */
132
+	public function registry()
133
+	{
134
+	}
135
+
136
+
137
+
138
+
139
+
140
+
141
+	/**
142
+	 * called after the request stack has been fully processed
143
+	 * if any of the middleware apps has requested the plugin be deactivated, then we do that now
144
+	 *
145
+	 * @param RequestInterface $request
146
+	 * @param ResponseInterface $response
147
+	 */
148
+	public function handleResponse(RequestInterface $request, ResponseInterface $response)
149
+	{
150
+	}
151 151
 
152 152
 
153 153
 
Please login to merge, or discard this patch.
core/EE_Registry.core.php 1 patch
Indentation   +1583 added lines, -1583 removed lines patch added patch discarded remove patch
@@ -23,1589 +23,1589 @@
 block discarded – undo
23 23
 class EE_Registry implements ResettableInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Registry $_instance
28
-     */
29
-    private static $_instance;
30
-
31
-    /**
32
-     * @var EE_Dependency_Map $_dependency_map
33
-     */
34
-    protected $_dependency_map;
35
-
36
-    /**
37
-     * @var array $_class_abbreviations
38
-     */
39
-    protected $_class_abbreviations = array();
40
-
41
-    /**
42
-     * @var CommandBusInterface $BUS
43
-     */
44
-    public $BUS;
45
-
46
-    /**
47
-     * @var EE_Cart $CART
48
-     */
49
-    public $CART;
50
-
51
-    /**
52
-     * @var EE_Config $CFG
53
-     */
54
-    public $CFG;
55
-
56
-    /**
57
-     * @var EE_Network_Config $NET_CFG
58
-     */
59
-    public $NET_CFG;
60
-
61
-    /**
62
-     * StdClass object for storing library classes in
63
-     *
64
-     * @var StdClass $LIB
65
-     */
66
-    public $LIB;
67
-
68
-    /**
69
-     * @var EE_Request_Handler $REQ
70
-     */
71
-    public $REQ;
72
-
73
-    /**
74
-     * @var EE_Session $SSN
75
-     */
76
-    public $SSN;
77
-
78
-    /**
79
-     * @since 4.5.0
80
-     * @var EE_Capabilities $CAP
81
-     */
82
-    public $CAP;
83
-
84
-    /**
85
-     * @since 4.9.0
86
-     * @var EE_Message_Resource_Manager $MRM
87
-     */
88
-    public $MRM;
89
-
90
-
91
-    /**
92
-     * @var Registry $AssetsRegistry
93
-     */
94
-    public $AssetsRegistry;
95
-
96
-    /**
97
-     * StdClass object for holding addons which have registered themselves to work with EE core
98
-     *
99
-     * @var EE_Addon[] $addons
100
-     */
101
-    public $addons;
102
-
103
-    /**
104
-     * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
105
-     *
106
-     * @var EEM_Base[] $models
107
-     */
108
-    public $models = array();
109
-
110
-    /**
111
-     * @var EED_Module[] $modules
112
-     */
113
-    public $modules;
114
-
115
-    /**
116
-     * @var EES_Shortcode[] $shortcodes
117
-     */
118
-    public $shortcodes;
119
-
120
-    /**
121
-     * @var WP_Widget[] $widgets
122
-     */
123
-    public $widgets;
124
-
125
-    /**
126
-     * this is an array of all implemented model names (i.e. not the parent abstract models, or models
127
-     * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
128
-     * Keys are model "short names" (eg "Event") as used in model relations, and values are
129
-     * classnames (eg "EEM_Event")
130
-     *
131
-     * @var array $non_abstract_db_models
132
-     */
133
-    public $non_abstract_db_models = array();
134
-
135
-
136
-    /**
137
-     * internationalization for JS strings
138
-     *    usage:   EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' );
139
-     *    in js file:  var translatedString = eei18n.string_key;
140
-     *
141
-     * @var array $i18n_js_strings
142
-     */
143
-    public static $i18n_js_strings = array();
144
-
145
-
146
-    /**
147
-     * $main_file - path to espresso.php
148
-     *
149
-     * @var array $main_file
150
-     */
151
-    public $main_file;
152
-
153
-    /**
154
-     * array of ReflectionClass objects where the key is the class name
155
-     *
156
-     * @var ReflectionClass[] $_reflectors
157
-     */
158
-    public $_reflectors;
159
-
160
-    /**
161
-     * boolean flag to indicate whether or not to load/save dependencies from/to the cache
162
-     *
163
-     * @var boolean $_cache_on
164
-     */
165
-    protected $_cache_on = true;
166
-
167
-
168
-
169
-    /**
170
-     * @singleton method used to instantiate class object
171
-     * @param  EE_Dependency_Map $dependency_map
172
-     * @return EE_Registry instance
173
-     * @throws InvalidArgumentException
174
-     * @throws InvalidInterfaceException
175
-     * @throws InvalidDataTypeException
176
-     */
177
-    public static function instance(EE_Dependency_Map $dependency_map = null)
178
-    {
179
-        // check if class object is instantiated
180
-        if (! self::$_instance instanceof EE_Registry) {
181
-            self::$_instance = new self($dependency_map);
182
-        }
183
-        return self::$_instance;
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * protected constructor to prevent direct creation
190
-     *
191
-     * @Constructor
192
-     * @param  EE_Dependency_Map $dependency_map
193
-     * @throws InvalidDataTypeException
194
-     * @throws InvalidInterfaceException
195
-     * @throws InvalidArgumentException
196
-     */
197
-    protected function __construct(EE_Dependency_Map $dependency_map)
198
-    {
199
-        $this->_dependency_map = $dependency_map;
200
-        // $registry_container = new RegistryContainer();
201
-        $this->LIB = new RegistryContainer();
202
-        $this->addons = new RegistryContainer();
203
-        $this->modules = new RegistryContainer();
204
-        $this->shortcodes = new RegistryContainer();
205
-        $this->widgets = new RegistryContainer();
206
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
207
-    }
208
-
209
-
210
-
211
-    /**
212
-     * initialize
213
-     *
214
-     * @throws EE_Error
215
-     * @throws ReflectionException
216
-     */
217
-    public function initialize()
218
-    {
219
-        $this->_class_abbreviations = apply_filters(
220
-            'FHEE__EE_Registry____construct___class_abbreviations',
221
-            array(
222
-                'EE_Config'                                       => 'CFG',
223
-                'EE_Session'                                      => 'SSN',
224
-                'EE_Capabilities'                                 => 'CAP',
225
-                'EE_Cart'                                         => 'CART',
226
-                'EE_Network_Config'                               => 'NET_CFG',
227
-                'EE_Request_Handler'                              => 'REQ',
228
-                'EE_Message_Resource_Manager'                     => 'MRM',
229
-                'EventEspresso\core\services\commands\CommandBus' => 'BUS',
230
-                'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
231
-            )
232
-        );
233
-        $this->load_core('Base', array(), true);
234
-        // add our request and response objects to the cache
235
-        $request_loader = $this->_dependency_map->class_loader(
236
-            'EventEspresso\core\services\request\Request'
237
-        );
238
-        $this->_set_cached_class(
239
-            $request_loader(),
240
-            'EventEspresso\core\services\request\Request'
241
-        );
242
-        $response_loader = $this->_dependency_map->class_loader(
243
-            'EventEspresso\core\services\request\Response'
244
-        );
245
-        $this->_set_cached_class(
246
-            $response_loader(),
247
-            'EventEspresso\core\services\request\Response'
248
-        );
249
-        add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
250
-    }
251
-
252
-
253
-
254
-    /**
255
-     * @return void
256
-     */
257
-    public function init()
258
-    {
259
-        // Get current page protocol
260
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
261
-        // Output admin-ajax.php URL with same protocol as current page
262
-        self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
263
-        self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
264
-    }
265
-
266
-
267
-
268
-    /**
269
-     * localize_i18n_js_strings
270
-     *
271
-     * @return string
272
-     */
273
-    public static function localize_i18n_js_strings()
274
-    {
275
-        $i18n_js_strings = (array)self::$i18n_js_strings;
276
-        foreach ($i18n_js_strings as $key => $value) {
277
-            if (is_scalar($value)) {
278
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
279
-            }
280
-        }
281
-        return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * @param mixed string | EED_Module $module
288
-     * @throws EE_Error
289
-     * @throws ReflectionException
290
-     */
291
-    public function add_module($module)
292
-    {
293
-        if ($module instanceof EED_Module) {
294
-            $module_class = get_class($module);
295
-            $this->modules->{$module_class} = $module;
296
-        } else {
297
-            if ( ! class_exists('EE_Module_Request_Router', false)) {
298
-                $this->load_core('Module_Request_Router');
299
-            }
300
-            EE_Module_Request_Router::module_factory($module);
301
-        }
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * @param string $module_name
308
-     * @return mixed EED_Module | NULL
309
-     */
310
-    public function get_module($module_name = '')
311
-    {
312
-        return isset($this->modules->{$module_name})
313
-            ? $this->modules->{$module_name}
314
-            : null;
315
-    }
316
-
317
-
318
-
319
-    /**
320
-     * loads core classes - must be singletons
321
-     *
322
-     * @param string $class_name - simple class name ie: session
323
-     * @param mixed  $arguments
324
-     * @param bool   $load_only
325
-     * @return mixed
326
-     * @throws EE_Error
327
-     * @throws ReflectionException
328
-     */
329
-    public function load_core($class_name, $arguments = array(), $load_only = false)
330
-    {
331
-        $core_paths = apply_filters(
332
-            'FHEE__EE_Registry__load_core__core_paths',
333
-            array(
334
-                EE_CORE,
335
-                EE_ADMIN,
336
-                EE_CPTS,
337
-                EE_CORE . 'data_migration_scripts' . DS,
338
-                EE_CORE . 'capabilities' . DS,
339
-                EE_CORE . 'request_stack' . DS,
340
-                EE_CORE . 'middleware' . DS,
341
-            )
342
-        );
343
-        // retrieve instantiated class
344
-        return $this->_load(
345
-            $core_paths,
346
-            'EE_',
347
-            $class_name,
348
-            'core',
349
-            $arguments,
350
-            false,
351
-            true,
352
-            $load_only
353
-        );
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * loads service classes
360
-     *
361
-     * @param string $class_name - simple class name ie: session
362
-     * @param mixed  $arguments
363
-     * @param bool   $load_only
364
-     * @return mixed
365
-     * @throws EE_Error
366
-     * @throws ReflectionException
367
-     */
368
-    public function load_service($class_name, $arguments = array(), $load_only = false)
369
-    {
370
-        $service_paths = apply_filters(
371
-            'FHEE__EE_Registry__load_service__service_paths',
372
-            array(
373
-                EE_CORE . 'services' . DS,
374
-            )
375
-        );
376
-        // retrieve instantiated class
377
-        return $this->_load(
378
-            $service_paths,
379
-            'EE_',
380
-            $class_name,
381
-            'class',
382
-            $arguments,
383
-            false,
384
-            true,
385
-            $load_only
386
-        );
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     * loads data_migration_scripts
393
-     *
394
-     * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
395
-     * @param mixed  $arguments
396
-     * @return EE_Data_Migration_Script_Base|mixed
397
-     * @throws EE_Error
398
-     * @throws ReflectionException
399
-     */
400
-    public function load_dms($class_name, $arguments = array())
401
-    {
402
-        // retrieve instantiated class
403
-        return $this->_load(
404
-            EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(),
405
-            'EE_DMS_',
406
-            $class_name,
407
-            'dms',
408
-            $arguments,
409
-            false,
410
-            false
411
-        );
412
-    }
413
-
414
-
415
-
416
-    /**
417
-     * loads object creating classes - must be singletons
418
-     *
419
-     * @param string $class_name - simple class name ie: attendee
420
-     * @param mixed  $arguments  - an array of arguments to pass to the class
421
-     * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to
422
-     *                           instantiate
423
-     * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then
424
-     *                           set this to FALSE (ie. when instantiating model objects from client in a loop)
425
-     * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate
426
-     *                           (default)
427
-     * @return EE_Base_Class | bool
428
-     * @throws EE_Error
429
-     * @throws ReflectionException
430
-     */
431
-    public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
432
-    {
433
-        $paths = apply_filters(
434
-            'FHEE__EE_Registry__load_class__paths', array(
435
-            EE_CORE,
436
-            EE_CLASSES,
437
-            EE_BUSINESS,
438
-        )
439
-        );
440
-        // retrieve instantiated class
441
-        return $this->_load(
442
-            $paths,
443
-            'EE_',
444
-            $class_name,
445
-            'class',
446
-            $arguments,
447
-            $from_db,
448
-            $cache,
449
-            $load_only
450
-        );
451
-    }
452
-
453
-
454
-
455
-    /**
456
-     * loads helper classes - must be singletons
457
-     *
458
-     * @param string $class_name - simple class name ie: price
459
-     * @param mixed  $arguments
460
-     * @param bool   $load_only
461
-     * @return EEH_Base | bool
462
-     * @throws EE_Error
463
-     * @throws ReflectionException
464
-     */
465
-    public function load_helper($class_name, $arguments = array(), $load_only = true)
466
-    {
467
-        // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
468
-        $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
469
-        // retrieve instantiated class
470
-        return $this->_load(
471
-            $helper_paths,
472
-            'EEH_',
473
-            $class_name,
474
-            'helper',
475
-            $arguments,
476
-            false,
477
-            true,
478
-            $load_only
479
-        );
480
-    }
481
-
482
-
483
-
484
-    /**
485
-     * loads core classes - must be singletons
486
-     *
487
-     * @param string $class_name - simple class name ie: session
488
-     * @param mixed  $arguments
489
-     * @param bool   $load_only
490
-     * @param bool   $cache      whether to cache the object or not.
491
-     * @return mixed
492
-     * @throws EE_Error
493
-     * @throws ReflectionException
494
-     */
495
-    public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
496
-    {
497
-        $paths = array(
498
-            EE_LIBRARIES,
499
-            EE_LIBRARIES . 'messages' . DS,
500
-            EE_LIBRARIES . 'shortcodes' . DS,
501
-            EE_LIBRARIES . 'qtips' . DS,
502
-            EE_LIBRARIES . 'payment_methods' . DS,
503
-        );
504
-        // retrieve instantiated class
505
-        return $this->_load(
506
-            $paths,
507
-            'EE_',
508
-            $class_name,
509
-            'lib',
510
-            $arguments,
511
-            false,
512
-            $cache,
513
-            $load_only
514
-        );
515
-    }
516
-
517
-
518
-
519
-    /**
520
-     * loads model classes - must be singletons
521
-     *
522
-     * @param string $class_name - simple class name ie: price
523
-     * @param mixed  $arguments
524
-     * @param bool   $load_only
525
-     * @return EEM_Base | bool
526
-     * @throws EE_Error
527
-     * @throws ReflectionException
528
-     */
529
-    public function load_model($class_name, $arguments = array(), $load_only = false)
530
-    {
531
-        $paths = apply_filters(
532
-            'FHEE__EE_Registry__load_model__paths', array(
533
-            EE_MODELS,
534
-            EE_CORE,
535
-        )
536
-        );
537
-        // retrieve instantiated class
538
-        return $this->_load(
539
-            $paths,
540
-            'EEM_',
541
-            $class_name,
542
-            'model',
543
-            $arguments,
544
-            false,
545
-            true,
546
-            $load_only
547
-        );
548
-    }
549
-
550
-
551
-
552
-    /**
553
-     * loads model classes - must be singletons
554
-     *
555
-     * @param string $class_name - simple class name ie: price
556
-     * @param mixed  $arguments
557
-     * @param bool   $load_only
558
-     * @return mixed | bool
559
-     * @throws EE_Error
560
-     * @throws ReflectionException
561
-     */
562
-    public function load_model_class($class_name, $arguments = array(), $load_only = true)
563
-    {
564
-        $paths = array(
565
-            EE_MODELS . 'fields' . DS,
566
-            EE_MODELS . 'helpers' . DS,
567
-            EE_MODELS . 'relations' . DS,
568
-            EE_MODELS . 'strategies' . DS,
569
-        );
570
-        // retrieve instantiated class
571
-        return $this->_load(
572
-            $paths,
573
-            'EE_',
574
-            $class_name,
575
-            '',
576
-            $arguments,
577
-            false,
578
-            true,
579
-            $load_only
580
-        );
581
-    }
582
-
583
-
584
-
585
-    /**
586
-     * Determines if $model_name is the name of an actual EE model.
587
-     *
588
-     * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
589
-     * @return boolean
590
-     */
591
-    public function is_model_name($model_name)
592
-    {
593
-        return isset($this->models[$model_name]);
594
-    }
595
-
596
-
597
-
598
-    /**
599
-     * generic class loader
600
-     *
601
-     * @param string $path_to_file - directory path to file location, not including filename
602
-     * @param string $file_name    - file name  ie:  my_file.php, including extension
603
-     * @param string $type         - file type - core? class? helper? model?
604
-     * @param mixed  $arguments
605
-     * @param bool   $load_only
606
-     * @return mixed
607
-     * @throws EE_Error
608
-     * @throws ReflectionException
609
-     */
610
-    public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
611
-    {
612
-        // retrieve instantiated class
613
-        return $this->_load(
614
-            $path_to_file,
615
-            '',
616
-            $file_name,
617
-            $type,
618
-            $arguments,
619
-            false,
620
-            true,
621
-            $load_only
622
-        );
623
-    }
624
-
625
-
626
-
627
-    /**
628
-     * @param string $path_to_file - directory path to file location, not including filename
629
-     * @param string $class_name   - full class name  ie:  My_Class
630
-     * @param string $type         - file type - core? class? helper? model?
631
-     * @param mixed  $arguments
632
-     * @param bool   $load_only
633
-     * @return bool|EE_Addon|object
634
-     * @throws EE_Error
635
-     * @throws ReflectionException
636
-     */
637
-    public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
638
-    {
639
-        // retrieve instantiated class
640
-        return $this->_load(
641
-            $path_to_file,
642
-            'addon',
643
-            $class_name,
644
-            $type,
645
-            $arguments,
646
-            false,
647
-            true,
648
-            $load_only
649
-        );
650
-    }
651
-
652
-
653
-
654
-    /**
655
-     * instantiates, caches, and automatically resolves dependencies
656
-     * for classes that use a Fully Qualified Class Name.
657
-     * if the class is not capable of being loaded using PSR-4 autoloading,
658
-     * then you need to use one of the existing load_*() methods
659
-     * which can resolve the classname and filepath from the passed arguments
660
-     *
661
-     * @param bool|string $class_name   Fully Qualified Class Name
662
-     * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
663
-     * @param bool        $cache        whether to cache the instantiated object for reuse
664
-     * @param bool        $from_db      some classes are instantiated from the db
665
-     *                                  and thus call a different method to instantiate
666
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
667
-     * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
668
-     * @return bool|null|mixed          null = failure to load or instantiate class object.
669
-     *                                  object = class loaded and instantiated successfully.
670
-     *                                  bool = fail or success when $load_only is true
671
-     * @throws EE_Error
672
-     * @throws ReflectionException
673
-     */
674
-    public function create(
675
-        $class_name = false,
676
-        $arguments = array(),
677
-        $cache = false,
678
-        $from_db = false,
679
-        $load_only = false,
680
-        $addon = false
681
-    ) {
682
-        $class_name = ltrim($class_name, '\\');
683
-        $class_name = $this->_dependency_map->get_alias($class_name);
684
-        $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
685
-        // if a non-FQCN was passed, then verifyClassExists() might return an object
686
-        // or it could return null if the class just could not be found anywhere
687
-        if ($class_exists instanceof $class_name || $class_exists === null){
688
-            // either way, return the results
689
-            return $class_exists;
690
-        }
691
-        $class_name = $class_exists;
692
-        // if we're only loading the class and it already exists, then let's just return true immediately
693
-        if ($load_only) {
694
-            return true;
695
-        }
696
-        $addon = $addon
697
-            ? 'addon'
698
-            : '';
699
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
700
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
701
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
702
-        if ($this->_cache_on && $cache && ! $load_only) {
703
-            // return object if it's already cached
704
-            $cached_class = $this->_get_cached_class($class_name, $addon);
705
-            if ($cached_class !== null) {
706
-                return $cached_class;
707
-            }
708
-        }
709
-        // obtain the loader method from the dependency map
710
-        $loader = $this->_dependency_map->class_loader($class_name);
711
-        // instantiate the requested object
712
-        if ($loader instanceof Closure) {
713
-            $class_obj = $loader($arguments);
714
-        } else if ($loader && method_exists($this, $loader)) {
715
-            $class_obj = $this->{$loader}($class_name, $arguments);
716
-        } else {
717
-            $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
718
-        }
719
-        if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) {
720
-            // save it for later... kinda like gum  { : $
721
-            $this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
722
-        }
723
-        $this->_cache_on = true;
724
-        return $class_obj;
725
-    }
726
-
727
-
728
-
729
-    /**
730
-     * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
731
-     *
732
-     * @param string $class_name
733
-     * @param array  $arguments
734
-     * @param int    $attempt
735
-     * @return mixed
736
-     */
737
-    private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) {
738
-        if (is_object($class_name) || class_exists($class_name)) {
739
-            return $class_name;
740
-        }
741
-        switch ($attempt) {
742
-            case 1:
743
-                // if it's a FQCN then maybe the class is registered with a preceding \
744
-                $class_name = strpos($class_name, '\\') !== false
745
-                    ? '\\' . ltrim($class_name, '\\')
746
-                    : $class_name;
747
-                break;
748
-            case 2:
749
-                //
750
-                $loader = $this->_dependency_map->class_loader($class_name);
751
-                if ($loader && method_exists($this, $loader)) {
752
-                    return $this->{$loader}($class_name, $arguments);
753
-                }
754
-                break;
755
-            case 3:
756
-            default;
757
-                return null;
758
-        }
759
-        $attempt++;
760
-        return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
761
-    }
762
-
763
-
764
-
765
-    /**
766
-     * instantiates, caches, and injects dependencies for classes
767
-     *
768
-     * @param array       $file_paths   an array of paths to folders to look in
769
-     * @param string      $class_prefix EE  or EEM or... ???
770
-     * @param bool|string $class_name   $class name
771
-     * @param string      $type         file type - core? class? helper? model?
772
-     * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
773
-     * @param bool        $from_db      some classes are instantiated from the db
774
-     *                                  and thus call a different method to instantiate
775
-     * @param bool        $cache        whether to cache the instantiated object for reuse
776
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
777
-     * @return bool|null|object null = failure to load or instantiate class object.
778
-     *                                  object = class loaded and instantiated successfully.
779
-     *                                  bool = fail or success when $load_only is true
780
-     * @throws EE_Error
781
-     * @throws ReflectionException
782
-     */
783
-    protected function _load(
784
-        $file_paths = array(),
785
-        $class_prefix = 'EE_',
786
-        $class_name = false,
787
-        $type = 'class',
788
-        $arguments = array(),
789
-        $from_db = false,
790
-        $cache = true,
791
-        $load_only = false
792
-    ) {
793
-        $class_name = ltrim($class_name, '\\');
794
-        // strip php file extension
795
-        $class_name = str_replace('.php', '', trim($class_name));
796
-        // does the class have a prefix ?
797
-        if (! empty($class_prefix) && $class_prefix !== 'addon') {
798
-            // make sure $class_prefix is uppercase
799
-            $class_prefix = strtoupper(trim($class_prefix));
800
-            // add class prefix ONCE!!!
801
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
802
-        }
803
-        $class_name = $this->_dependency_map->get_alias($class_name);
804
-        $class_exists = class_exists($class_name, false);
805
-        // if we're only loading the class and it already exists, then let's just return true immediately
806
-        if ($load_only && $class_exists) {
807
-            return true;
808
-        }
809
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
810
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
811
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
812
-        if ($this->_cache_on && $cache && ! $load_only) {
813
-            // return object if it's already cached
814
-            $cached_class = $this->_get_cached_class($class_name, $class_prefix);
815
-            if ($cached_class !== null) {
816
-                return $cached_class;
817
-            }
818
-        }
819
-        // if the class doesn't already exist.. then we need to try and find the file and load it
820
-        if (! $class_exists) {
821
-            // get full path to file
822
-            $path = $this->_resolve_path($class_name, $type, $file_paths);
823
-            // load the file
824
-            $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
825
-            // if loading failed, or we are only loading a file but NOT instantiating an object
826
-            if (! $loaded || $load_only) {
827
-                // return boolean if only loading, or null if an object was expected
828
-                return $load_only
829
-                    ? $loaded
830
-                    : null;
831
-            }
832
-        }
833
-        // instantiate the requested object
834
-        $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
835
-        if ($this->_cache_on && $cache) {
836
-            // save it for later... kinda like gum  { : $
837
-            $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
838
-        }
839
-        $this->_cache_on = true;
840
-        return $class_obj;
841
-    }
842
-
843
-
844
-
845
-    /**
846
-     * @param string $class_name
847
-     * @param string $default have to specify something, but not anything that will conflict
848
-     * @return mixed|string
849
-     */
850
-    protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
851
-    {
852
-        return isset($this->_class_abbreviations[$class_name])
853
-            ? $this->_class_abbreviations[$class_name]
854
-            : $default;
855
-    }
856
-
857
-    /**
858
-     * attempts to find a cached version of the requested class
859
-     * by looking in the following places:
860
-     *        $this->{$class_abbreviation}            ie:    $this->CART
861
-     *        $this->{$class_name}                        ie:    $this->Some_Class
862
-     *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
863
-     *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
864
-     *
865
-     * @param string $class_name
866
-     * @param string $class_prefix
867
-     * @return mixed
868
-     */
869
-    protected function _get_cached_class($class_name, $class_prefix = '')
870
-    {
871
-        if ($class_name === 'EE_Registry') {
872
-            return $this;
873
-        }
874
-        $class_abbreviation = $this->get_class_abbreviation($class_name);
875
-        $class_name = str_replace('\\', '_', $class_name);
876
-        // check if class has already been loaded, and return it if it has been
877
-        if (isset($this->{$class_abbreviation})) {
878
-            return $this->{$class_abbreviation};
879
-        }
880
-        if (isset ($this->{$class_name})) {
881
-            return $this->{$class_name};
882
-        }
883
-        if (isset ($this->LIB->{$class_name})) {
884
-            return $this->LIB->{$class_name};
885
-        }
886
-        if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
887
-            return $this->addons->{$class_name};
888
-        }
889
-        return null;
890
-    }
891
-
892
-
893
-
894
-    /**
895
-     * removes a cached version of the requested class
896
-     *
897
-     * @param string  $class_name
898
-     * @param boolean $addon
899
-     * @return boolean
900
-     */
901
-    public function clear_cached_class($class_name, $addon = false)
902
-    {
903
-        $class_abbreviation = $this->get_class_abbreviation($class_name);
904
-        $class_name = str_replace('\\', '_', $class_name);
905
-        // check if class has already been loaded, and return it if it has been
906
-        if (isset($this->{$class_abbreviation})) {
907
-            $this->{$class_abbreviation} = null;
908
-            return true;
909
-        }
910
-        if (isset($this->{$class_name})) {
911
-            $this->{$class_name} = null;
912
-            return true;
913
-        }
914
-        if (isset($this->LIB->{$class_name})) {
915
-            unset($this->LIB->{$class_name});
916
-            return true;
917
-        }
918
-        if ($addon && isset($this->addons->{$class_name})) {
919
-            unset($this->addons->{$class_name});
920
-            return true;
921
-        }
922
-        return false;
923
-    }
924
-
925
-
926
-
927
-    /**
928
-     * attempts to find a full valid filepath for the requested class.
929
-     * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
930
-     * then returns that path if the target file has been found and is readable
931
-     *
932
-     * @param string $class_name
933
-     * @param string $type
934
-     * @param array  $file_paths
935
-     * @return string | bool
936
-     */
937
-    protected function _resolve_path($class_name, $type = '', $file_paths = array())
938
-    {
939
-        // make sure $file_paths is an array
940
-        $file_paths = is_array($file_paths)
941
-            ? $file_paths
942
-            : array($file_paths);
943
-        // cycle thru paths
944
-        foreach ($file_paths as $key => $file_path) {
945
-            // convert all separators to proper DS, if no filepath, then use EE_CLASSES
946
-            $file_path = $file_path
947
-                ? str_replace(array('/', '\\'), DS, $file_path)
948
-                : EE_CLASSES;
949
-            // prep file type
950
-            $type = ! empty($type)
951
-                ? trim($type, '.') . '.'
952
-                : '';
953
-            // build full file path
954
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
955
-            //does the file exist and can be read ?
956
-            if (is_readable($file_paths[$key])) {
957
-                return $file_paths[$key];
958
-            }
959
-        }
960
-        return false;
961
-    }
962
-
963
-
964
-
965
-    /**
966
-     * basically just performs a require_once()
967
-     * but with some error handling
968
-     *
969
-     * @param  string $path
970
-     * @param  string $class_name
971
-     * @param  string $type
972
-     * @param  array  $file_paths
973
-     * @return bool
974
-     * @throws EE_Error
975
-     * @throws ReflectionException
976
-     */
977
-    protected function _require_file($path, $class_name, $type = '', $file_paths = array())
978
-    {
979
-        $this->resolve_legacy_class_parent($class_name);
980
-        // don't give up! you gotta...
981
-        try {
982
-            //does the file exist and can it be read ?
983
-            if (! $path) {
984
-                // just in case the file has already been autoloaded,
985
-                // but discrepancies in the naming schema are preventing it from
986
-                // being loaded via one of the EE_Registry::load_*() methods,
987
-                // then let's try one last hail mary before throwing an exception
988
-                // and call class_exists() again, but with autoloading turned ON
989
-                if(class_exists($class_name)) {
990
-                    return true;
991
-                }
992
-                // so sorry, can't find the file
993
-                throw new EE_Error (
994
-                    sprintf(
995
-                        esc_html__(
996
-                            'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s',
997
-                            'event_espresso'
998
-                        ),
999
-                        trim($type, '.'),
1000
-                        $class_name,
1001
-                        '<br />' . implode(',<br />', $file_paths)
1002
-                    )
1003
-                );
1004
-            }
1005
-            // get the file
1006
-            require_once($path);
1007
-            // if the class isn't already declared somewhere
1008
-            if (class_exists($class_name, false) === false) {
1009
-                // so sorry, not a class
1010
-                throw new EE_Error(
1011
-                    sprintf(
1012
-                        esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
1013
-                        $type,
1014
-                        $path,
1015
-                        $class_name
1016
-                    )
1017
-                );
1018
-            }
1019
-        } catch (EE_Error $e) {
1020
-            $e->get_error();
1021
-            return false;
1022
-        }
1023
-        return true;
1024
-    }
1025
-
1026
-
1027
-
1028
-    /**
1029
-     * Some of our legacy classes that extended a parent class would simply use a require() statement
1030
-     * before their class declaration in order to ensure that the parent class was loaded.
1031
-     * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class,
1032
-     * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist.
1033
-     *
1034
-     * @param string $class_name
1035
-     */
1036
-    protected function resolve_legacy_class_parent($class_name = '')
1037
-    {
1038
-        try {
1039
-            $legacy_parent_class_map = array(
1040
-                'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php'
1041
-            );
1042
-            if(isset($legacy_parent_class_map[$class_name])) {
1043
-                require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name];
1044
-            }
1045
-        } catch (Exception $exception) {
1046
-        }
1047
-    }
1048
-
1049
-
1050
-
1051
-    /**
1052
-     * _create_object
1053
-     * Attempts to instantiate the requested class via any of the
1054
-     * commonly used instantiation methods employed throughout EE.
1055
-     * The priority for instantiation is as follows:
1056
-     *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
1057
-     *        - model objects via their 'new_instance_from_db' method
1058
-     *        - model objects via their 'new_instance' method
1059
-     *        - "singleton" classes" via their 'instance' method
1060
-     *    - standard instantiable classes via their __constructor
1061
-     * Prior to instantiation, if the classname exists in the dependency_map,
1062
-     * then the constructor for the requested class will be examined to determine
1063
-     * if any dependencies exist, and if they can be injected.
1064
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1065
-     *
1066
-     * @param string $class_name
1067
-     * @param array  $arguments
1068
-     * @param string $type
1069
-     * @param bool   $from_db
1070
-     * @return null|object
1071
-     * @throws EE_Error
1072
-     * @throws ReflectionException
1073
-     */
1074
-    protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
1075
-    {
1076
-        // create reflection
1077
-        $reflector = $this->get_ReflectionClass($class_name);
1078
-        // make sure arguments are an array
1079
-        $arguments = is_array($arguments)
1080
-            ? $arguments
1081
-            : array($arguments);
1082
-        // and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1083
-        // else wrap it in an additional array so that it doesn't get split into multiple parameters
1084
-        $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1085
-            ? $arguments
1086
-            : array($arguments);
1087
-        // attempt to inject dependencies ?
1088
-        if ($this->_dependency_map->has($class_name)) {
1089
-            $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1090
-        }
1091
-        // instantiate the class if possible
1092
-        if ($reflector->isAbstract()) {
1093
-            // nothing to instantiate, loading file was enough
1094
-            // does not throw an exception so $instantiation_mode is unused
1095
-            // $instantiation_mode = "1) no constructor abstract class";
1096
-            return true;
1097
-        }
1098
-        if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) {
1099
-            // no constructor = static methods only... nothing to instantiate, loading file was enough
1100
-            // $instantiation_mode = "2) no constructor but instantiable";
1101
-            return $reflector->newInstance();
1102
-        }
1103
-        if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1104
-            // $instantiation_mode = "3) new_instance_from_db()";
1105
-            return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1106
-        }
1107
-        if (method_exists($class_name, 'new_instance')) {
1108
-            // $instantiation_mode = "4) new_instance()";
1109
-            return call_user_func_array(array($class_name, 'new_instance'), $arguments);
1110
-        }
1111
-        if (method_exists($class_name, 'instance')) {
1112
-            // $instantiation_mode = "5) instance()";
1113
-            return call_user_func_array(array($class_name, 'instance'), $arguments);
1114
-        }
1115
-        if ($reflector->isInstantiable()) {
1116
-            // $instantiation_mode = "6) constructor";
1117
-            return $reflector->newInstanceArgs($arguments);
1118
-        }
1119
-        // heh ? something's not right !
1120
-        throw new EE_Error(
1121
-            sprintf(
1122
-                __('The %s file %s could not be instantiated.', 'event_espresso'),
1123
-                $type,
1124
-                $class_name
1125
-            )
1126
-        );
1127
-    }
1128
-
1129
-
1130
-
1131
-    /**
1132
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1133
-     * @param array $array
1134
-     * @return bool
1135
-     */
1136
-    protected function _array_is_numerically_and_sequentially_indexed(array $array)
1137
-    {
1138
-        return ! empty($array)
1139
-            ? array_keys($array) === range(0, count($array) - 1)
1140
-            : true;
1141
-    }
1142
-
1143
-
1144
-
1145
-    /**
1146
-     * getReflectionClass
1147
-     * checks if a ReflectionClass object has already been generated for a class
1148
-     * and returns that instead of creating a new one
1149
-     *
1150
-     * @param string $class_name
1151
-     * @return ReflectionClass
1152
-     * @throws ReflectionException
1153
-     */
1154
-    public function get_ReflectionClass($class_name)
1155
-    {
1156
-        if (
1157
-            ! isset($this->_reflectors[$class_name])
1158
-            || ! $this->_reflectors[$class_name] instanceof ReflectionClass
1159
-        ) {
1160
-            $this->_reflectors[$class_name] = new ReflectionClass($class_name);
1161
-        }
1162
-        return $this->_reflectors[$class_name];
1163
-    }
1164
-
1165
-
1166
-
1167
-    /**
1168
-     * _resolve_dependencies
1169
-     * examines the constructor for the requested class to determine
1170
-     * if any dependencies exist, and if they can be injected.
1171
-     * If so, then those classes will be added to the array of arguments passed to the constructor
1172
-     * PLZ NOTE: this is achieved by type hinting the constructor params
1173
-     * For example:
1174
-     *        if attempting to load a class "Foo" with the following constructor:
1175
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
1176
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
1177
-     *        but only IF they are NOT already present in the incoming arguments array,
1178
-     *        and the correct classes can be loaded
1179
-     *
1180
-     * @param ReflectionClass $reflector
1181
-     * @param string          $class_name
1182
-     * @param array           $arguments
1183
-     * @return array
1184
-     * @throws EE_Error
1185
-     * @throws ReflectionException
1186
-     */
1187
-    protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1188
-    {
1189
-        // let's examine the constructor
1190
-        $constructor = $reflector->getConstructor();
1191
-        // whu? huh? nothing?
1192
-        if (! $constructor) {
1193
-            return $arguments;
1194
-        }
1195
-        // get constructor parameters
1196
-        $params = $constructor->getParameters();
1197
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1198
-        $argument_keys = array_keys($arguments);
1199
-        // now loop thru all of the constructors expected parameters
1200
-        foreach ($params as $index => $param) {
1201
-            // is this a dependency for a specific class ?
1202
-            $param_class = $param->getClass()
1203
-                ? $param->getClass()->name
1204
-                : null;
1205
-            // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1206
-            $param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1207
-                ? $this->_dependency_map->get_alias($param_class, $class_name)
1208
-                : $param_class;
1209
-            if (
1210
-                // param is not even a class
1211
-                $param_class === null
1212
-                // and something already exists in the incoming arguments for this param
1213
-                && array_key_exists($index, $argument_keys)
1214
-                && array_key_exists($argument_keys[$index], $arguments)
1215
-            ) {
1216
-                // so let's skip this argument and move on to the next
1217
-                continue;
1218
-            }
1219
-            if (
1220
-                // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1221
-                $param_class !== null
1222
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1223
-                && $arguments[$argument_keys[$index]] instanceof $param_class
1224
-            ) {
1225
-                // skip this argument and move on to the next
1226
-                continue;
1227
-            }
1228
-            if (
1229
-                // parameter is type hinted as a class, and should be injected
1230
-                $param_class !== null
1231
-                && $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1232
-            ) {
1233
-                $arguments = $this->_resolve_dependency(
1234
-                    $class_name,
1235
-                    $param_class,
1236
-                    $arguments,
1237
-                    $index,
1238
-                    $argument_keys
1239
-                );
1240
-            } else {
1241
-                try {
1242
-                    $arguments[$index] = $param->isDefaultValueAvailable()
1243
-                        ? $param->getDefaultValue()
1244
-                        : null;
1245
-                } catch (ReflectionException $e) {
1246
-                    throw new ReflectionException(
1247
-                        sprintf(
1248
-                            esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'),
1249
-                            $e->getMessage(),
1250
-                            $param->getName(),
1251
-                            $class_name
1252
-                        )
1253
-                    );
1254
-                }
1255
-            }
1256
-        }
1257
-        return $arguments;
1258
-    }
1259
-
1260
-
1261
-
1262
-    /**
1263
-     * @param string $class_name
1264
-     * @param string $param_class
1265
-     * @param array  $arguments
1266
-     * @param mixed  $index
1267
-     * @param array  $argument_keys
1268
-     * @return array
1269
-     * @throws EE_Error
1270
-     * @throws ReflectionException
1271
-     * @throws InvalidArgumentException
1272
-     * @throws InvalidInterfaceException
1273
-     * @throws InvalidDataTypeException
1274
-     */
1275
-    protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys)
1276
-    {
1277
-        $dependency = null;
1278
-        // should dependency be loaded from cache ?
1279
-        $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1280
-            $class_name,
1281
-            $param_class
1282
-        );
1283
-        $cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1284
-        // we might have a dependency...
1285
-        // let's MAYBE try and find it in our cache if that's what's been requested
1286
-        $cached_class = $cache_on
1287
-            ? $this->_get_cached_class($param_class)
1288
-            : null;
1289
-        // and grab it if it exists
1290
-        if ($cached_class instanceof $param_class) {
1291
-            $dependency = $cached_class;
1292
-        } else if ($param_class !== $class_name) {
1293
-            // obtain the loader method from the dependency map
1294
-            $loader = $this->_dependency_map->class_loader($param_class);
1295
-            // is loader a custom closure ?
1296
-            if ($loader instanceof Closure) {
1297
-                $dependency = $loader($arguments);
1298
-            } else {
1299
-                // set the cache on property for the recursive loading call
1300
-                $this->_cache_on = $cache_on;
1301
-                // if not, then let's try and load it via the registry
1302
-                if ($loader && method_exists($this, $loader)) {
1303
-                    $dependency = $this->{$loader}($param_class);
1304
-                } else {
1305
-                    $dependency = LoaderFactory::getLoader()->load(
1306
-                        $param_class,
1307
-                        array(),
1308
-                        $cache_on
1309
-                    );
1310
-                }
1311
-            }
1312
-        }
1313
-        // did we successfully find the correct dependency ?
1314
-        if ($dependency instanceof $param_class) {
1315
-            // then let's inject it into the incoming array of arguments at the correct location
1316
-            $arguments[$index] = $dependency;
1317
-        }
1318
-        return $arguments;
1319
-    }
1320
-
1321
-
1322
-
1323
-    /**
1324
-     * _set_cached_class
1325
-     * attempts to cache the instantiated class locally
1326
-     * in one of the following places, in the following order:
1327
-     *        $this->{class_abbreviation}   ie:    $this->CART
1328
-     *        $this->{$class_name}          ie:    $this->Some_Class
1329
-     *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1330
-     *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1331
-     *
1332
-     * @param object $class_obj
1333
-     * @param string $class_name
1334
-     * @param string $class_prefix
1335
-     * @param bool   $from_db
1336
-     * @return void
1337
-     */
1338
-    protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1339
-    {
1340
-        if ($class_name === 'EE_Registry' || empty($class_obj)) {
1341
-            return;
1342
-        }
1343
-        // return newly instantiated class
1344
-        $class_abbreviation = $this->get_class_abbreviation($class_name, '');
1345
-        if ($class_abbreviation) {
1346
-            $this->{$class_abbreviation} = $class_obj;
1347
-            return;
1348
-        }
1349
-        $class_name = str_replace('\\', '_', $class_name);
1350
-        if (property_exists($this, $class_name)) {
1351
-            $this->{$class_name} = $class_obj;
1352
-            return;
1353
-        }
1354
-        if ($class_prefix === 'addon') {
1355
-            $this->addons->{$class_name} = $class_obj;
1356
-            return;
1357
-        }
1358
-        if (! $from_db) {
1359
-            $this->LIB->{$class_name} = $class_obj;
1360
-        }
1361
-    }
1362
-
1363
-
1364
-
1365
-    /**
1366
-     * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1367
-     *
1368
-     * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1369
-     *                          in the EE_Dependency_Map::$_class_loaders array,
1370
-     *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1371
-     * @param array  $arguments
1372
-     * @return object
1373
-     */
1374
-    public static function factory($classname, $arguments = array())
1375
-    {
1376
-        $loader = self::instance()->_dependency_map->class_loader($classname);
1377
-        if ($loader instanceof Closure) {
1378
-            return $loader($arguments);
1379
-        }
1380
-        if (method_exists(self::instance(), $loader)) {
1381
-            return self::instance()->{$loader}($classname, $arguments);
1382
-        }
1383
-        return null;
1384
-    }
1385
-
1386
-
1387
-
1388
-    /**
1389
-     * Gets the addon by its class name
1390
-     *
1391
-     * @param string $class_name
1392
-     * @return EE_Addon
1393
-     */
1394
-    public function getAddon($class_name)
1395
-    {
1396
-        $class_name = str_replace('\\', '_', $class_name);
1397
-        return $this->addons->{$class_name};
1398
-    }
1399
-
1400
-
1401
-    /**
1402
-     * removes the addon from the internal cache
1403
-     *
1404
-     * @param string $class_name
1405
-     * @return void
1406
-     */
1407
-    public function removeAddon($class_name)
1408
-    {
1409
-        $class_name = str_replace('\\', '_', $class_name);
1410
-        unset($this->addons->{$class_name});
1411
-    }
1412
-
1413
-
1414
-
1415
-    /**
1416
-     * Gets the addon by its name/slug (not classname. For that, just
1417
-     * use the get_addon() method above
1418
-     *
1419
-     * @param string $name
1420
-     * @return EE_Addon
1421
-     */
1422
-    public function get_addon_by_name($name)
1423
-    {
1424
-        foreach ($this->addons as $addon) {
1425
-            if ($addon->name() === $name) {
1426
-                return $addon;
1427
-            }
1428
-        }
1429
-        return null;
1430
-    }
1431
-
1432
-
1433
-
1434
-    /**
1435
-     * Gets an array of all the registered addons, where the keys are their names.
1436
-     * (ie, what each returns for their name() function)
1437
-     * They're already available on EE_Registry::instance()->addons as properties,
1438
-     * where each property's name is the addon's classname,
1439
-     * So if you just want to get the addon by classname,
1440
-     * OR use the get_addon() method above.
1441
-     * PLEASE  NOTE:
1442
-     * addons with Fully Qualified Class Names
1443
-     * have had the namespace separators converted to underscores,
1444
-     * so a classname like Fully\Qualified\ClassName
1445
-     * would have been converted to Fully_Qualified_ClassName
1446
-     *
1447
-     * @return EE_Addon[] where the KEYS are the addon's name()
1448
-     */
1449
-    public function get_addons_by_name()
1450
-    {
1451
-        $addons = array();
1452
-        foreach ($this->addons as $addon) {
1453
-            $addons[$addon->name()] = $addon;
1454
-        }
1455
-        return $addons;
1456
-    }
1457
-
1458
-
1459
-    /**
1460
-     * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1461
-     * a stale copy of it around
1462
-     *
1463
-     * @param string $model_name
1464
-     * @return \EEM_Base
1465
-     * @throws \EE_Error
1466
-     */
1467
-    public function reset_model($model_name)
1468
-    {
1469
-        $model_class_name = strpos($model_name, 'EEM_') !== 0
1470
-            ? "EEM_{$model_name}"
1471
-            : $model_name;
1472
-        if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1473
-            return null;
1474
-        }
1475
-        //get that model reset it and make sure we nuke the old reference to it
1476
-        if ($this->LIB->{$model_class_name} instanceof $model_class_name
1477
-            && is_callable(
1478
-                array($model_class_name, 'reset')
1479
-            )) {
1480
-            $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1481
-        } else {
1482
-            throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1483
-        }
1484
-        return $this->LIB->{$model_class_name};
1485
-    }
1486
-
1487
-
1488
-
1489
-    /**
1490
-     * Resets the registry.
1491
-     * The criteria for what gets reset is based on what can be shared between sites on the same request when
1492
-     * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1493
-     * - $_dependency_map
1494
-     * - $_class_abbreviations
1495
-     * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1496
-     * - $REQ:  Still on the same request so no need to change.
1497
-     * - $CAP: There is no site specific state in the EE_Capability class.
1498
-     * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1499
-     * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1500
-     * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1501
-     *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1502
-     *             switch or on the restore.
1503
-     * - $modules
1504
-     * - $shortcodes
1505
-     * - $widgets
1506
-     *
1507
-     * @param boolean $hard             [deprecated]
1508
-     * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1509
-     *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1510
-     *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1511
-     * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1512
-     *                                  client
1513
-     *                                  code instead can just change the model context to a different blog id if
1514
-     *                                  necessary
1515
-     * @return EE_Registry
1516
-     * @throws EE_Error
1517
-     * @throws ReflectionException
1518
-     */
1519
-    public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1520
-    {
1521
-        $instance = self::instance();
1522
-        $instance->_cache_on = true;
1523
-        // reset some "special" classes
1524
-        EEH_Activation::reset();
1525
-        $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1526
-        $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1527
-        $instance->CART = null;
1528
-        $instance->MRM = null;
1529
-        $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1530
-        //messages reset
1531
-        EED_Messages::reset();
1532
-        //handle of objects cached on LIB
1533
-        foreach (array('LIB', 'modules') as $cache) {
1534
-            foreach ($instance->{$cache} as $class_name => $class) {
1535
-                if (self::_reset_and_unset_object($class, $reset_models)) {
1536
-                    unset($instance->{$cache}->{$class_name});
1537
-                }
1538
-            }
1539
-        }
1540
-        return $instance;
1541
-    }
1542
-
1543
-
1544
-
1545
-    /**
1546
-     * if passed object implements ResettableInterface, then call it's reset() method
1547
-     * if passed object implements InterminableInterface, then return false,
1548
-     * to indicate that it should NOT be cleared from the Registry cache
1549
-     *
1550
-     * @param      $object
1551
-     * @param bool $reset_models
1552
-     * @return bool returns true if cached object should be unset
1553
-     */
1554
-    private static function _reset_and_unset_object($object, $reset_models)
1555
-    {
1556
-        if (! is_object($object)) {
1557
-            // don't unset anything that's not an object
1558
-            return false;
1559
-        }
1560
-        if ($object instanceof EED_Module) {
1561
-            $object::reset();
1562
-            // don't unset modules
1563
-            return false;
1564
-        }
1565
-        if ($object instanceof ResettableInterface) {
1566
-            if ($object instanceof EEM_Base) {
1567
-                if ($reset_models) {
1568
-                    $object->reset();
1569
-                    return true;
1570
-                }
1571
-                return false;
1572
-            }
1573
-            $object->reset();
1574
-            return true;
1575
-        }
1576
-        if (! $object instanceof InterminableInterface) {
1577
-            return true;
1578
-        }
1579
-        return false;
1580
-    }
1581
-
1582
-
1583
-
1584
-    /**
1585
-     * Gets all the custom post type models defined
1586
-     *
1587
-     * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1588
-     */
1589
-    public function cpt_models()
1590
-    {
1591
-        $cpt_models = array();
1592
-        foreach ($this->non_abstract_db_models as $short_name => $classname) {
1593
-            if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1594
-                $cpt_models[$short_name] = $classname;
1595
-            }
1596
-        }
1597
-        return $cpt_models;
1598
-    }
1599
-
1600
-
1601
-
1602
-    /**
1603
-     * @return \EE_Config
1604
-     */
1605
-    public static function CFG()
1606
-    {
1607
-        return self::instance()->CFG;
1608
-    }
26
+	/**
27
+	 * @var EE_Registry $_instance
28
+	 */
29
+	private static $_instance;
30
+
31
+	/**
32
+	 * @var EE_Dependency_Map $_dependency_map
33
+	 */
34
+	protected $_dependency_map;
35
+
36
+	/**
37
+	 * @var array $_class_abbreviations
38
+	 */
39
+	protected $_class_abbreviations = array();
40
+
41
+	/**
42
+	 * @var CommandBusInterface $BUS
43
+	 */
44
+	public $BUS;
45
+
46
+	/**
47
+	 * @var EE_Cart $CART
48
+	 */
49
+	public $CART;
50
+
51
+	/**
52
+	 * @var EE_Config $CFG
53
+	 */
54
+	public $CFG;
55
+
56
+	/**
57
+	 * @var EE_Network_Config $NET_CFG
58
+	 */
59
+	public $NET_CFG;
60
+
61
+	/**
62
+	 * StdClass object for storing library classes in
63
+	 *
64
+	 * @var StdClass $LIB
65
+	 */
66
+	public $LIB;
67
+
68
+	/**
69
+	 * @var EE_Request_Handler $REQ
70
+	 */
71
+	public $REQ;
72
+
73
+	/**
74
+	 * @var EE_Session $SSN
75
+	 */
76
+	public $SSN;
77
+
78
+	/**
79
+	 * @since 4.5.0
80
+	 * @var EE_Capabilities $CAP
81
+	 */
82
+	public $CAP;
83
+
84
+	/**
85
+	 * @since 4.9.0
86
+	 * @var EE_Message_Resource_Manager $MRM
87
+	 */
88
+	public $MRM;
89
+
90
+
91
+	/**
92
+	 * @var Registry $AssetsRegistry
93
+	 */
94
+	public $AssetsRegistry;
95
+
96
+	/**
97
+	 * StdClass object for holding addons which have registered themselves to work with EE core
98
+	 *
99
+	 * @var EE_Addon[] $addons
100
+	 */
101
+	public $addons;
102
+
103
+	/**
104
+	 * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
105
+	 *
106
+	 * @var EEM_Base[] $models
107
+	 */
108
+	public $models = array();
109
+
110
+	/**
111
+	 * @var EED_Module[] $modules
112
+	 */
113
+	public $modules;
114
+
115
+	/**
116
+	 * @var EES_Shortcode[] $shortcodes
117
+	 */
118
+	public $shortcodes;
119
+
120
+	/**
121
+	 * @var WP_Widget[] $widgets
122
+	 */
123
+	public $widgets;
124
+
125
+	/**
126
+	 * this is an array of all implemented model names (i.e. not the parent abstract models, or models
127
+	 * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
128
+	 * Keys are model "short names" (eg "Event") as used in model relations, and values are
129
+	 * classnames (eg "EEM_Event")
130
+	 *
131
+	 * @var array $non_abstract_db_models
132
+	 */
133
+	public $non_abstract_db_models = array();
134
+
135
+
136
+	/**
137
+	 * internationalization for JS strings
138
+	 *    usage:   EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' );
139
+	 *    in js file:  var translatedString = eei18n.string_key;
140
+	 *
141
+	 * @var array $i18n_js_strings
142
+	 */
143
+	public static $i18n_js_strings = array();
144
+
145
+
146
+	/**
147
+	 * $main_file - path to espresso.php
148
+	 *
149
+	 * @var array $main_file
150
+	 */
151
+	public $main_file;
152
+
153
+	/**
154
+	 * array of ReflectionClass objects where the key is the class name
155
+	 *
156
+	 * @var ReflectionClass[] $_reflectors
157
+	 */
158
+	public $_reflectors;
159
+
160
+	/**
161
+	 * boolean flag to indicate whether or not to load/save dependencies from/to the cache
162
+	 *
163
+	 * @var boolean $_cache_on
164
+	 */
165
+	protected $_cache_on = true;
166
+
167
+
168
+
169
+	/**
170
+	 * @singleton method used to instantiate class object
171
+	 * @param  EE_Dependency_Map $dependency_map
172
+	 * @return EE_Registry instance
173
+	 * @throws InvalidArgumentException
174
+	 * @throws InvalidInterfaceException
175
+	 * @throws InvalidDataTypeException
176
+	 */
177
+	public static function instance(EE_Dependency_Map $dependency_map = null)
178
+	{
179
+		// check if class object is instantiated
180
+		if (! self::$_instance instanceof EE_Registry) {
181
+			self::$_instance = new self($dependency_map);
182
+		}
183
+		return self::$_instance;
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * protected constructor to prevent direct creation
190
+	 *
191
+	 * @Constructor
192
+	 * @param  EE_Dependency_Map $dependency_map
193
+	 * @throws InvalidDataTypeException
194
+	 * @throws InvalidInterfaceException
195
+	 * @throws InvalidArgumentException
196
+	 */
197
+	protected function __construct(EE_Dependency_Map $dependency_map)
198
+	{
199
+		$this->_dependency_map = $dependency_map;
200
+		// $registry_container = new RegistryContainer();
201
+		$this->LIB = new RegistryContainer();
202
+		$this->addons = new RegistryContainer();
203
+		$this->modules = new RegistryContainer();
204
+		$this->shortcodes = new RegistryContainer();
205
+		$this->widgets = new RegistryContainer();
206
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
207
+	}
208
+
209
+
210
+
211
+	/**
212
+	 * initialize
213
+	 *
214
+	 * @throws EE_Error
215
+	 * @throws ReflectionException
216
+	 */
217
+	public function initialize()
218
+	{
219
+		$this->_class_abbreviations = apply_filters(
220
+			'FHEE__EE_Registry____construct___class_abbreviations',
221
+			array(
222
+				'EE_Config'                                       => 'CFG',
223
+				'EE_Session'                                      => 'SSN',
224
+				'EE_Capabilities'                                 => 'CAP',
225
+				'EE_Cart'                                         => 'CART',
226
+				'EE_Network_Config'                               => 'NET_CFG',
227
+				'EE_Request_Handler'                              => 'REQ',
228
+				'EE_Message_Resource_Manager'                     => 'MRM',
229
+				'EventEspresso\core\services\commands\CommandBus' => 'BUS',
230
+				'EventEspresso\core\services\assets\Registry'     => 'AssetsRegistry',
231
+			)
232
+		);
233
+		$this->load_core('Base', array(), true);
234
+		// add our request and response objects to the cache
235
+		$request_loader = $this->_dependency_map->class_loader(
236
+			'EventEspresso\core\services\request\Request'
237
+		);
238
+		$this->_set_cached_class(
239
+			$request_loader(),
240
+			'EventEspresso\core\services\request\Request'
241
+		);
242
+		$response_loader = $this->_dependency_map->class_loader(
243
+			'EventEspresso\core\services\request\Response'
244
+		);
245
+		$this->_set_cached_class(
246
+			$response_loader(),
247
+			'EventEspresso\core\services\request\Response'
248
+		);
249
+		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
250
+	}
251
+
252
+
253
+
254
+	/**
255
+	 * @return void
256
+	 */
257
+	public function init()
258
+	{
259
+		// Get current page protocol
260
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
261
+		// Output admin-ajax.php URL with same protocol as current page
262
+		self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
263
+		self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
264
+	}
265
+
266
+
267
+
268
+	/**
269
+	 * localize_i18n_js_strings
270
+	 *
271
+	 * @return string
272
+	 */
273
+	public static function localize_i18n_js_strings()
274
+	{
275
+		$i18n_js_strings = (array)self::$i18n_js_strings;
276
+		foreach ($i18n_js_strings as $key => $value) {
277
+			if (is_scalar($value)) {
278
+				$i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
279
+			}
280
+		}
281
+		return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * @param mixed string | EED_Module $module
288
+	 * @throws EE_Error
289
+	 * @throws ReflectionException
290
+	 */
291
+	public function add_module($module)
292
+	{
293
+		if ($module instanceof EED_Module) {
294
+			$module_class = get_class($module);
295
+			$this->modules->{$module_class} = $module;
296
+		} else {
297
+			if ( ! class_exists('EE_Module_Request_Router', false)) {
298
+				$this->load_core('Module_Request_Router');
299
+			}
300
+			EE_Module_Request_Router::module_factory($module);
301
+		}
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * @param string $module_name
308
+	 * @return mixed EED_Module | NULL
309
+	 */
310
+	public function get_module($module_name = '')
311
+	{
312
+		return isset($this->modules->{$module_name})
313
+			? $this->modules->{$module_name}
314
+			: null;
315
+	}
316
+
317
+
318
+
319
+	/**
320
+	 * loads core classes - must be singletons
321
+	 *
322
+	 * @param string $class_name - simple class name ie: session
323
+	 * @param mixed  $arguments
324
+	 * @param bool   $load_only
325
+	 * @return mixed
326
+	 * @throws EE_Error
327
+	 * @throws ReflectionException
328
+	 */
329
+	public function load_core($class_name, $arguments = array(), $load_only = false)
330
+	{
331
+		$core_paths = apply_filters(
332
+			'FHEE__EE_Registry__load_core__core_paths',
333
+			array(
334
+				EE_CORE,
335
+				EE_ADMIN,
336
+				EE_CPTS,
337
+				EE_CORE . 'data_migration_scripts' . DS,
338
+				EE_CORE . 'capabilities' . DS,
339
+				EE_CORE . 'request_stack' . DS,
340
+				EE_CORE . 'middleware' . DS,
341
+			)
342
+		);
343
+		// retrieve instantiated class
344
+		return $this->_load(
345
+			$core_paths,
346
+			'EE_',
347
+			$class_name,
348
+			'core',
349
+			$arguments,
350
+			false,
351
+			true,
352
+			$load_only
353
+		);
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * loads service classes
360
+	 *
361
+	 * @param string $class_name - simple class name ie: session
362
+	 * @param mixed  $arguments
363
+	 * @param bool   $load_only
364
+	 * @return mixed
365
+	 * @throws EE_Error
366
+	 * @throws ReflectionException
367
+	 */
368
+	public function load_service($class_name, $arguments = array(), $load_only = false)
369
+	{
370
+		$service_paths = apply_filters(
371
+			'FHEE__EE_Registry__load_service__service_paths',
372
+			array(
373
+				EE_CORE . 'services' . DS,
374
+			)
375
+		);
376
+		// retrieve instantiated class
377
+		return $this->_load(
378
+			$service_paths,
379
+			'EE_',
380
+			$class_name,
381
+			'class',
382
+			$arguments,
383
+			false,
384
+			true,
385
+			$load_only
386
+		);
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 * loads data_migration_scripts
393
+	 *
394
+	 * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
395
+	 * @param mixed  $arguments
396
+	 * @return EE_Data_Migration_Script_Base|mixed
397
+	 * @throws EE_Error
398
+	 * @throws ReflectionException
399
+	 */
400
+	public function load_dms($class_name, $arguments = array())
401
+	{
402
+		// retrieve instantiated class
403
+		return $this->_load(
404
+			EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(),
405
+			'EE_DMS_',
406
+			$class_name,
407
+			'dms',
408
+			$arguments,
409
+			false,
410
+			false
411
+		);
412
+	}
413
+
414
+
415
+
416
+	/**
417
+	 * loads object creating classes - must be singletons
418
+	 *
419
+	 * @param string $class_name - simple class name ie: attendee
420
+	 * @param mixed  $arguments  - an array of arguments to pass to the class
421
+	 * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to
422
+	 *                           instantiate
423
+	 * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then
424
+	 *                           set this to FALSE (ie. when instantiating model objects from client in a loop)
425
+	 * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate
426
+	 *                           (default)
427
+	 * @return EE_Base_Class | bool
428
+	 * @throws EE_Error
429
+	 * @throws ReflectionException
430
+	 */
431
+	public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
432
+	{
433
+		$paths = apply_filters(
434
+			'FHEE__EE_Registry__load_class__paths', array(
435
+			EE_CORE,
436
+			EE_CLASSES,
437
+			EE_BUSINESS,
438
+		)
439
+		);
440
+		// retrieve instantiated class
441
+		return $this->_load(
442
+			$paths,
443
+			'EE_',
444
+			$class_name,
445
+			'class',
446
+			$arguments,
447
+			$from_db,
448
+			$cache,
449
+			$load_only
450
+		);
451
+	}
452
+
453
+
454
+
455
+	/**
456
+	 * loads helper classes - must be singletons
457
+	 *
458
+	 * @param string $class_name - simple class name ie: price
459
+	 * @param mixed  $arguments
460
+	 * @param bool   $load_only
461
+	 * @return EEH_Base | bool
462
+	 * @throws EE_Error
463
+	 * @throws ReflectionException
464
+	 */
465
+	public function load_helper($class_name, $arguments = array(), $load_only = true)
466
+	{
467
+		// todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
468
+		$helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
469
+		// retrieve instantiated class
470
+		return $this->_load(
471
+			$helper_paths,
472
+			'EEH_',
473
+			$class_name,
474
+			'helper',
475
+			$arguments,
476
+			false,
477
+			true,
478
+			$load_only
479
+		);
480
+	}
481
+
482
+
483
+
484
+	/**
485
+	 * loads core classes - must be singletons
486
+	 *
487
+	 * @param string $class_name - simple class name ie: session
488
+	 * @param mixed  $arguments
489
+	 * @param bool   $load_only
490
+	 * @param bool   $cache      whether to cache the object or not.
491
+	 * @return mixed
492
+	 * @throws EE_Error
493
+	 * @throws ReflectionException
494
+	 */
495
+	public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
496
+	{
497
+		$paths = array(
498
+			EE_LIBRARIES,
499
+			EE_LIBRARIES . 'messages' . DS,
500
+			EE_LIBRARIES . 'shortcodes' . DS,
501
+			EE_LIBRARIES . 'qtips' . DS,
502
+			EE_LIBRARIES . 'payment_methods' . DS,
503
+		);
504
+		// retrieve instantiated class
505
+		return $this->_load(
506
+			$paths,
507
+			'EE_',
508
+			$class_name,
509
+			'lib',
510
+			$arguments,
511
+			false,
512
+			$cache,
513
+			$load_only
514
+		);
515
+	}
516
+
517
+
518
+
519
+	/**
520
+	 * loads model classes - must be singletons
521
+	 *
522
+	 * @param string $class_name - simple class name ie: price
523
+	 * @param mixed  $arguments
524
+	 * @param bool   $load_only
525
+	 * @return EEM_Base | bool
526
+	 * @throws EE_Error
527
+	 * @throws ReflectionException
528
+	 */
529
+	public function load_model($class_name, $arguments = array(), $load_only = false)
530
+	{
531
+		$paths = apply_filters(
532
+			'FHEE__EE_Registry__load_model__paths', array(
533
+			EE_MODELS,
534
+			EE_CORE,
535
+		)
536
+		);
537
+		// retrieve instantiated class
538
+		return $this->_load(
539
+			$paths,
540
+			'EEM_',
541
+			$class_name,
542
+			'model',
543
+			$arguments,
544
+			false,
545
+			true,
546
+			$load_only
547
+		);
548
+	}
549
+
550
+
551
+
552
+	/**
553
+	 * loads model classes - must be singletons
554
+	 *
555
+	 * @param string $class_name - simple class name ie: price
556
+	 * @param mixed  $arguments
557
+	 * @param bool   $load_only
558
+	 * @return mixed | bool
559
+	 * @throws EE_Error
560
+	 * @throws ReflectionException
561
+	 */
562
+	public function load_model_class($class_name, $arguments = array(), $load_only = true)
563
+	{
564
+		$paths = array(
565
+			EE_MODELS . 'fields' . DS,
566
+			EE_MODELS . 'helpers' . DS,
567
+			EE_MODELS . 'relations' . DS,
568
+			EE_MODELS . 'strategies' . DS,
569
+		);
570
+		// retrieve instantiated class
571
+		return $this->_load(
572
+			$paths,
573
+			'EE_',
574
+			$class_name,
575
+			'',
576
+			$arguments,
577
+			false,
578
+			true,
579
+			$load_only
580
+		);
581
+	}
582
+
583
+
584
+
585
+	/**
586
+	 * Determines if $model_name is the name of an actual EE model.
587
+	 *
588
+	 * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
589
+	 * @return boolean
590
+	 */
591
+	public function is_model_name($model_name)
592
+	{
593
+		return isset($this->models[$model_name]);
594
+	}
595
+
596
+
597
+
598
+	/**
599
+	 * generic class loader
600
+	 *
601
+	 * @param string $path_to_file - directory path to file location, not including filename
602
+	 * @param string $file_name    - file name  ie:  my_file.php, including extension
603
+	 * @param string $type         - file type - core? class? helper? model?
604
+	 * @param mixed  $arguments
605
+	 * @param bool   $load_only
606
+	 * @return mixed
607
+	 * @throws EE_Error
608
+	 * @throws ReflectionException
609
+	 */
610
+	public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
611
+	{
612
+		// retrieve instantiated class
613
+		return $this->_load(
614
+			$path_to_file,
615
+			'',
616
+			$file_name,
617
+			$type,
618
+			$arguments,
619
+			false,
620
+			true,
621
+			$load_only
622
+		);
623
+	}
624
+
625
+
626
+
627
+	/**
628
+	 * @param string $path_to_file - directory path to file location, not including filename
629
+	 * @param string $class_name   - full class name  ie:  My_Class
630
+	 * @param string $type         - file type - core? class? helper? model?
631
+	 * @param mixed  $arguments
632
+	 * @param bool   $load_only
633
+	 * @return bool|EE_Addon|object
634
+	 * @throws EE_Error
635
+	 * @throws ReflectionException
636
+	 */
637
+	public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
638
+	{
639
+		// retrieve instantiated class
640
+		return $this->_load(
641
+			$path_to_file,
642
+			'addon',
643
+			$class_name,
644
+			$type,
645
+			$arguments,
646
+			false,
647
+			true,
648
+			$load_only
649
+		);
650
+	}
651
+
652
+
653
+
654
+	/**
655
+	 * instantiates, caches, and automatically resolves dependencies
656
+	 * for classes that use a Fully Qualified Class Name.
657
+	 * if the class is not capable of being loaded using PSR-4 autoloading,
658
+	 * then you need to use one of the existing load_*() methods
659
+	 * which can resolve the classname and filepath from the passed arguments
660
+	 *
661
+	 * @param bool|string $class_name   Fully Qualified Class Name
662
+	 * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
663
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
664
+	 * @param bool        $from_db      some classes are instantiated from the db
665
+	 *                                  and thus call a different method to instantiate
666
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
667
+	 * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
668
+	 * @return bool|null|mixed          null = failure to load or instantiate class object.
669
+	 *                                  object = class loaded and instantiated successfully.
670
+	 *                                  bool = fail or success when $load_only is true
671
+	 * @throws EE_Error
672
+	 * @throws ReflectionException
673
+	 */
674
+	public function create(
675
+		$class_name = false,
676
+		$arguments = array(),
677
+		$cache = false,
678
+		$from_db = false,
679
+		$load_only = false,
680
+		$addon = false
681
+	) {
682
+		$class_name = ltrim($class_name, '\\');
683
+		$class_name = $this->_dependency_map->get_alias($class_name);
684
+		$class_exists = $this->loadOrVerifyClassExists($class_name, $arguments);
685
+		// if a non-FQCN was passed, then verifyClassExists() might return an object
686
+		// or it could return null if the class just could not be found anywhere
687
+		if ($class_exists instanceof $class_name || $class_exists === null){
688
+			// either way, return the results
689
+			return $class_exists;
690
+		}
691
+		$class_name = $class_exists;
692
+		// if we're only loading the class and it already exists, then let's just return true immediately
693
+		if ($load_only) {
694
+			return true;
695
+		}
696
+		$addon = $addon
697
+			? 'addon'
698
+			: '';
699
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
700
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
701
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
702
+		if ($this->_cache_on && $cache && ! $load_only) {
703
+			// return object if it's already cached
704
+			$cached_class = $this->_get_cached_class($class_name, $addon);
705
+			if ($cached_class !== null) {
706
+				return $cached_class;
707
+			}
708
+		}
709
+		// obtain the loader method from the dependency map
710
+		$loader = $this->_dependency_map->class_loader($class_name);
711
+		// instantiate the requested object
712
+		if ($loader instanceof Closure) {
713
+			$class_obj = $loader($arguments);
714
+		} else if ($loader && method_exists($this, $loader)) {
715
+			$class_obj = $this->{$loader}($class_name, $arguments);
716
+		} else {
717
+			$class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
718
+		}
719
+		if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) {
720
+			// save it for later... kinda like gum  { : $
721
+			$this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
722
+		}
723
+		$this->_cache_on = true;
724
+		return $class_obj;
725
+	}
726
+
727
+
728
+
729
+	/**
730
+	 * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs
731
+	 *
732
+	 * @param string $class_name
733
+	 * @param array  $arguments
734
+	 * @param int    $attempt
735
+	 * @return mixed
736
+	 */
737
+	private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) {
738
+		if (is_object($class_name) || class_exists($class_name)) {
739
+			return $class_name;
740
+		}
741
+		switch ($attempt) {
742
+			case 1:
743
+				// if it's a FQCN then maybe the class is registered with a preceding \
744
+				$class_name = strpos($class_name, '\\') !== false
745
+					? '\\' . ltrim($class_name, '\\')
746
+					: $class_name;
747
+				break;
748
+			case 2:
749
+				//
750
+				$loader = $this->_dependency_map->class_loader($class_name);
751
+				if ($loader && method_exists($this, $loader)) {
752
+					return $this->{$loader}($class_name, $arguments);
753
+				}
754
+				break;
755
+			case 3:
756
+			default;
757
+				return null;
758
+		}
759
+		$attempt++;
760
+		return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt);
761
+	}
762
+
763
+
764
+
765
+	/**
766
+	 * instantiates, caches, and injects dependencies for classes
767
+	 *
768
+	 * @param array       $file_paths   an array of paths to folders to look in
769
+	 * @param string      $class_prefix EE  or EEM or... ???
770
+	 * @param bool|string $class_name   $class name
771
+	 * @param string      $type         file type - core? class? helper? model?
772
+	 * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
773
+	 * @param bool        $from_db      some classes are instantiated from the db
774
+	 *                                  and thus call a different method to instantiate
775
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
776
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
777
+	 * @return bool|null|object null = failure to load or instantiate class object.
778
+	 *                                  object = class loaded and instantiated successfully.
779
+	 *                                  bool = fail or success when $load_only is true
780
+	 * @throws EE_Error
781
+	 * @throws ReflectionException
782
+	 */
783
+	protected function _load(
784
+		$file_paths = array(),
785
+		$class_prefix = 'EE_',
786
+		$class_name = false,
787
+		$type = 'class',
788
+		$arguments = array(),
789
+		$from_db = false,
790
+		$cache = true,
791
+		$load_only = false
792
+	) {
793
+		$class_name = ltrim($class_name, '\\');
794
+		// strip php file extension
795
+		$class_name = str_replace('.php', '', trim($class_name));
796
+		// does the class have a prefix ?
797
+		if (! empty($class_prefix) && $class_prefix !== 'addon') {
798
+			// make sure $class_prefix is uppercase
799
+			$class_prefix = strtoupper(trim($class_prefix));
800
+			// add class prefix ONCE!!!
801
+			$class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
802
+		}
803
+		$class_name = $this->_dependency_map->get_alias($class_name);
804
+		$class_exists = class_exists($class_name, false);
805
+		// if we're only loading the class and it already exists, then let's just return true immediately
806
+		if ($load_only && $class_exists) {
807
+			return true;
808
+		}
809
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
810
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
811
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
812
+		if ($this->_cache_on && $cache && ! $load_only) {
813
+			// return object if it's already cached
814
+			$cached_class = $this->_get_cached_class($class_name, $class_prefix);
815
+			if ($cached_class !== null) {
816
+				return $cached_class;
817
+			}
818
+		}
819
+		// if the class doesn't already exist.. then we need to try and find the file and load it
820
+		if (! $class_exists) {
821
+			// get full path to file
822
+			$path = $this->_resolve_path($class_name, $type, $file_paths);
823
+			// load the file
824
+			$loaded = $this->_require_file($path, $class_name, $type, $file_paths);
825
+			// if loading failed, or we are only loading a file but NOT instantiating an object
826
+			if (! $loaded || $load_only) {
827
+				// return boolean if only loading, or null if an object was expected
828
+				return $load_only
829
+					? $loaded
830
+					: null;
831
+			}
832
+		}
833
+		// instantiate the requested object
834
+		$class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
835
+		if ($this->_cache_on && $cache) {
836
+			// save it for later... kinda like gum  { : $
837
+			$this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
838
+		}
839
+		$this->_cache_on = true;
840
+		return $class_obj;
841
+	}
842
+
843
+
844
+
845
+	/**
846
+	 * @param string $class_name
847
+	 * @param string $default have to specify something, but not anything that will conflict
848
+	 * @return mixed|string
849
+	 */
850
+	protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS')
851
+	{
852
+		return isset($this->_class_abbreviations[$class_name])
853
+			? $this->_class_abbreviations[$class_name]
854
+			: $default;
855
+	}
856
+
857
+	/**
858
+	 * attempts to find a cached version of the requested class
859
+	 * by looking in the following places:
860
+	 *        $this->{$class_abbreviation}            ie:    $this->CART
861
+	 *        $this->{$class_name}                        ie:    $this->Some_Class
862
+	 *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
863
+	 *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
864
+	 *
865
+	 * @param string $class_name
866
+	 * @param string $class_prefix
867
+	 * @return mixed
868
+	 */
869
+	protected function _get_cached_class($class_name, $class_prefix = '')
870
+	{
871
+		if ($class_name === 'EE_Registry') {
872
+			return $this;
873
+		}
874
+		$class_abbreviation = $this->get_class_abbreviation($class_name);
875
+		$class_name = str_replace('\\', '_', $class_name);
876
+		// check if class has already been loaded, and return it if it has been
877
+		if (isset($this->{$class_abbreviation})) {
878
+			return $this->{$class_abbreviation};
879
+		}
880
+		if (isset ($this->{$class_name})) {
881
+			return $this->{$class_name};
882
+		}
883
+		if (isset ($this->LIB->{$class_name})) {
884
+			return $this->LIB->{$class_name};
885
+		}
886
+		if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) {
887
+			return $this->addons->{$class_name};
888
+		}
889
+		return null;
890
+	}
891
+
892
+
893
+
894
+	/**
895
+	 * removes a cached version of the requested class
896
+	 *
897
+	 * @param string  $class_name
898
+	 * @param boolean $addon
899
+	 * @return boolean
900
+	 */
901
+	public function clear_cached_class($class_name, $addon = false)
902
+	{
903
+		$class_abbreviation = $this->get_class_abbreviation($class_name);
904
+		$class_name = str_replace('\\', '_', $class_name);
905
+		// check if class has already been loaded, and return it if it has been
906
+		if (isset($this->{$class_abbreviation})) {
907
+			$this->{$class_abbreviation} = null;
908
+			return true;
909
+		}
910
+		if (isset($this->{$class_name})) {
911
+			$this->{$class_name} = null;
912
+			return true;
913
+		}
914
+		if (isset($this->LIB->{$class_name})) {
915
+			unset($this->LIB->{$class_name});
916
+			return true;
917
+		}
918
+		if ($addon && isset($this->addons->{$class_name})) {
919
+			unset($this->addons->{$class_name});
920
+			return true;
921
+		}
922
+		return false;
923
+	}
924
+
925
+
926
+
927
+	/**
928
+	 * attempts to find a full valid filepath for the requested class.
929
+	 * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
930
+	 * then returns that path if the target file has been found and is readable
931
+	 *
932
+	 * @param string $class_name
933
+	 * @param string $type
934
+	 * @param array  $file_paths
935
+	 * @return string | bool
936
+	 */
937
+	protected function _resolve_path($class_name, $type = '', $file_paths = array())
938
+	{
939
+		// make sure $file_paths is an array
940
+		$file_paths = is_array($file_paths)
941
+			? $file_paths
942
+			: array($file_paths);
943
+		// cycle thru paths
944
+		foreach ($file_paths as $key => $file_path) {
945
+			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
946
+			$file_path = $file_path
947
+				? str_replace(array('/', '\\'), DS, $file_path)
948
+				: EE_CLASSES;
949
+			// prep file type
950
+			$type = ! empty($type)
951
+				? trim($type, '.') . '.'
952
+				: '';
953
+			// build full file path
954
+			$file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
955
+			//does the file exist and can be read ?
956
+			if (is_readable($file_paths[$key])) {
957
+				return $file_paths[$key];
958
+			}
959
+		}
960
+		return false;
961
+	}
962
+
963
+
964
+
965
+	/**
966
+	 * basically just performs a require_once()
967
+	 * but with some error handling
968
+	 *
969
+	 * @param  string $path
970
+	 * @param  string $class_name
971
+	 * @param  string $type
972
+	 * @param  array  $file_paths
973
+	 * @return bool
974
+	 * @throws EE_Error
975
+	 * @throws ReflectionException
976
+	 */
977
+	protected function _require_file($path, $class_name, $type = '', $file_paths = array())
978
+	{
979
+		$this->resolve_legacy_class_parent($class_name);
980
+		// don't give up! you gotta...
981
+		try {
982
+			//does the file exist and can it be read ?
983
+			if (! $path) {
984
+				// just in case the file has already been autoloaded,
985
+				// but discrepancies in the naming schema are preventing it from
986
+				// being loaded via one of the EE_Registry::load_*() methods,
987
+				// then let's try one last hail mary before throwing an exception
988
+				// and call class_exists() again, but with autoloading turned ON
989
+				if(class_exists($class_name)) {
990
+					return true;
991
+				}
992
+				// so sorry, can't find the file
993
+				throw new EE_Error (
994
+					sprintf(
995
+						esc_html__(
996
+							'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s',
997
+							'event_espresso'
998
+						),
999
+						trim($type, '.'),
1000
+						$class_name,
1001
+						'<br />' . implode(',<br />', $file_paths)
1002
+					)
1003
+				);
1004
+			}
1005
+			// get the file
1006
+			require_once($path);
1007
+			// if the class isn't already declared somewhere
1008
+			if (class_exists($class_name, false) === false) {
1009
+				// so sorry, not a class
1010
+				throw new EE_Error(
1011
+					sprintf(
1012
+						esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
1013
+						$type,
1014
+						$path,
1015
+						$class_name
1016
+					)
1017
+				);
1018
+			}
1019
+		} catch (EE_Error $e) {
1020
+			$e->get_error();
1021
+			return false;
1022
+		}
1023
+		return true;
1024
+	}
1025
+
1026
+
1027
+
1028
+	/**
1029
+	 * Some of our legacy classes that extended a parent class would simply use a require() statement
1030
+	 * before their class declaration in order to ensure that the parent class was loaded.
1031
+	 * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class,
1032
+	 * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist.
1033
+	 *
1034
+	 * @param string $class_name
1035
+	 */
1036
+	protected function resolve_legacy_class_parent($class_name = '')
1037
+	{
1038
+		try {
1039
+			$legacy_parent_class_map = array(
1040
+				'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php'
1041
+			);
1042
+			if(isset($legacy_parent_class_map[$class_name])) {
1043
+				require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name];
1044
+			}
1045
+		} catch (Exception $exception) {
1046
+		}
1047
+	}
1048
+
1049
+
1050
+
1051
+	/**
1052
+	 * _create_object
1053
+	 * Attempts to instantiate the requested class via any of the
1054
+	 * commonly used instantiation methods employed throughout EE.
1055
+	 * The priority for instantiation is as follows:
1056
+	 *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
1057
+	 *        - model objects via their 'new_instance_from_db' method
1058
+	 *        - model objects via their 'new_instance' method
1059
+	 *        - "singleton" classes" via their 'instance' method
1060
+	 *    - standard instantiable classes via their __constructor
1061
+	 * Prior to instantiation, if the classname exists in the dependency_map,
1062
+	 * then the constructor for the requested class will be examined to determine
1063
+	 * if any dependencies exist, and if they can be injected.
1064
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1065
+	 *
1066
+	 * @param string $class_name
1067
+	 * @param array  $arguments
1068
+	 * @param string $type
1069
+	 * @param bool   $from_db
1070
+	 * @return null|object
1071
+	 * @throws EE_Error
1072
+	 * @throws ReflectionException
1073
+	 */
1074
+	protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
1075
+	{
1076
+		// create reflection
1077
+		$reflector = $this->get_ReflectionClass($class_name);
1078
+		// make sure arguments are an array
1079
+		$arguments = is_array($arguments)
1080
+			? $arguments
1081
+			: array($arguments);
1082
+		// and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
1083
+		// else wrap it in an additional array so that it doesn't get split into multiple parameters
1084
+		$arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
1085
+			? $arguments
1086
+			: array($arguments);
1087
+		// attempt to inject dependencies ?
1088
+		if ($this->_dependency_map->has($class_name)) {
1089
+			$arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
1090
+		}
1091
+		// instantiate the class if possible
1092
+		if ($reflector->isAbstract()) {
1093
+			// nothing to instantiate, loading file was enough
1094
+			// does not throw an exception so $instantiation_mode is unused
1095
+			// $instantiation_mode = "1) no constructor abstract class";
1096
+			return true;
1097
+		}
1098
+		if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) {
1099
+			// no constructor = static methods only... nothing to instantiate, loading file was enough
1100
+			// $instantiation_mode = "2) no constructor but instantiable";
1101
+			return $reflector->newInstance();
1102
+		}
1103
+		if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
1104
+			// $instantiation_mode = "3) new_instance_from_db()";
1105
+			return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
1106
+		}
1107
+		if (method_exists($class_name, 'new_instance')) {
1108
+			// $instantiation_mode = "4) new_instance()";
1109
+			return call_user_func_array(array($class_name, 'new_instance'), $arguments);
1110
+		}
1111
+		if (method_exists($class_name, 'instance')) {
1112
+			// $instantiation_mode = "5) instance()";
1113
+			return call_user_func_array(array($class_name, 'instance'), $arguments);
1114
+		}
1115
+		if ($reflector->isInstantiable()) {
1116
+			// $instantiation_mode = "6) constructor";
1117
+			return $reflector->newInstanceArgs($arguments);
1118
+		}
1119
+		// heh ? something's not right !
1120
+		throw new EE_Error(
1121
+			sprintf(
1122
+				__('The %s file %s could not be instantiated.', 'event_espresso'),
1123
+				$type,
1124
+				$class_name
1125
+			)
1126
+		);
1127
+	}
1128
+
1129
+
1130
+
1131
+	/**
1132
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
1133
+	 * @param array $array
1134
+	 * @return bool
1135
+	 */
1136
+	protected function _array_is_numerically_and_sequentially_indexed(array $array)
1137
+	{
1138
+		return ! empty($array)
1139
+			? array_keys($array) === range(0, count($array) - 1)
1140
+			: true;
1141
+	}
1142
+
1143
+
1144
+
1145
+	/**
1146
+	 * getReflectionClass
1147
+	 * checks if a ReflectionClass object has already been generated for a class
1148
+	 * and returns that instead of creating a new one
1149
+	 *
1150
+	 * @param string $class_name
1151
+	 * @return ReflectionClass
1152
+	 * @throws ReflectionException
1153
+	 */
1154
+	public function get_ReflectionClass($class_name)
1155
+	{
1156
+		if (
1157
+			! isset($this->_reflectors[$class_name])
1158
+			|| ! $this->_reflectors[$class_name] instanceof ReflectionClass
1159
+		) {
1160
+			$this->_reflectors[$class_name] = new ReflectionClass($class_name);
1161
+		}
1162
+		return $this->_reflectors[$class_name];
1163
+	}
1164
+
1165
+
1166
+
1167
+	/**
1168
+	 * _resolve_dependencies
1169
+	 * examines the constructor for the requested class to determine
1170
+	 * if any dependencies exist, and if they can be injected.
1171
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
1172
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
1173
+	 * For example:
1174
+	 *        if attempting to load a class "Foo" with the following constructor:
1175
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
1176
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
1177
+	 *        but only IF they are NOT already present in the incoming arguments array,
1178
+	 *        and the correct classes can be loaded
1179
+	 *
1180
+	 * @param ReflectionClass $reflector
1181
+	 * @param string          $class_name
1182
+	 * @param array           $arguments
1183
+	 * @return array
1184
+	 * @throws EE_Error
1185
+	 * @throws ReflectionException
1186
+	 */
1187
+	protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
1188
+	{
1189
+		// let's examine the constructor
1190
+		$constructor = $reflector->getConstructor();
1191
+		// whu? huh? nothing?
1192
+		if (! $constructor) {
1193
+			return $arguments;
1194
+		}
1195
+		// get constructor parameters
1196
+		$params = $constructor->getParameters();
1197
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
1198
+		$argument_keys = array_keys($arguments);
1199
+		// now loop thru all of the constructors expected parameters
1200
+		foreach ($params as $index => $param) {
1201
+			// is this a dependency for a specific class ?
1202
+			$param_class = $param->getClass()
1203
+				? $param->getClass()->name
1204
+				: null;
1205
+			// BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime)
1206
+			$param_class = $this->_dependency_map->has_alias($param_class, $class_name)
1207
+				? $this->_dependency_map->get_alias($param_class, $class_name)
1208
+				: $param_class;
1209
+			if (
1210
+				// param is not even a class
1211
+				$param_class === null
1212
+				// and something already exists in the incoming arguments for this param
1213
+				&& array_key_exists($index, $argument_keys)
1214
+				&& array_key_exists($argument_keys[$index], $arguments)
1215
+			) {
1216
+				// so let's skip this argument and move on to the next
1217
+				continue;
1218
+			}
1219
+			if (
1220
+				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
1221
+				$param_class !== null
1222
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
1223
+				&& $arguments[$argument_keys[$index]] instanceof $param_class
1224
+			) {
1225
+				// skip this argument and move on to the next
1226
+				continue;
1227
+			}
1228
+			if (
1229
+				// parameter is type hinted as a class, and should be injected
1230
+				$param_class !== null
1231
+				&& $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1232
+			) {
1233
+				$arguments = $this->_resolve_dependency(
1234
+					$class_name,
1235
+					$param_class,
1236
+					$arguments,
1237
+					$index,
1238
+					$argument_keys
1239
+				);
1240
+			} else {
1241
+				try {
1242
+					$arguments[$index] = $param->isDefaultValueAvailable()
1243
+						? $param->getDefaultValue()
1244
+						: null;
1245
+				} catch (ReflectionException $e) {
1246
+					throw new ReflectionException(
1247
+						sprintf(
1248
+							esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'),
1249
+							$e->getMessage(),
1250
+							$param->getName(),
1251
+							$class_name
1252
+						)
1253
+					);
1254
+				}
1255
+			}
1256
+		}
1257
+		return $arguments;
1258
+	}
1259
+
1260
+
1261
+
1262
+	/**
1263
+	 * @param string $class_name
1264
+	 * @param string $param_class
1265
+	 * @param array  $arguments
1266
+	 * @param mixed  $index
1267
+	 * @param array  $argument_keys
1268
+	 * @return array
1269
+	 * @throws EE_Error
1270
+	 * @throws ReflectionException
1271
+	 * @throws InvalidArgumentException
1272
+	 * @throws InvalidInterfaceException
1273
+	 * @throws InvalidDataTypeException
1274
+	 */
1275
+	protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys)
1276
+	{
1277
+		$dependency = null;
1278
+		// should dependency be loaded from cache ?
1279
+		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency(
1280
+			$class_name,
1281
+			$param_class
1282
+		);
1283
+		$cache_on = $cache_on !== EE_Dependency_Map::load_new_object;
1284
+		// we might have a dependency...
1285
+		// let's MAYBE try and find it in our cache if that's what's been requested
1286
+		$cached_class = $cache_on
1287
+			? $this->_get_cached_class($param_class)
1288
+			: null;
1289
+		// and grab it if it exists
1290
+		if ($cached_class instanceof $param_class) {
1291
+			$dependency = $cached_class;
1292
+		} else if ($param_class !== $class_name) {
1293
+			// obtain the loader method from the dependency map
1294
+			$loader = $this->_dependency_map->class_loader($param_class);
1295
+			// is loader a custom closure ?
1296
+			if ($loader instanceof Closure) {
1297
+				$dependency = $loader($arguments);
1298
+			} else {
1299
+				// set the cache on property for the recursive loading call
1300
+				$this->_cache_on = $cache_on;
1301
+				// if not, then let's try and load it via the registry
1302
+				if ($loader && method_exists($this, $loader)) {
1303
+					$dependency = $this->{$loader}($param_class);
1304
+				} else {
1305
+					$dependency = LoaderFactory::getLoader()->load(
1306
+						$param_class,
1307
+						array(),
1308
+						$cache_on
1309
+					);
1310
+				}
1311
+			}
1312
+		}
1313
+		// did we successfully find the correct dependency ?
1314
+		if ($dependency instanceof $param_class) {
1315
+			// then let's inject it into the incoming array of arguments at the correct location
1316
+			$arguments[$index] = $dependency;
1317
+		}
1318
+		return $arguments;
1319
+	}
1320
+
1321
+
1322
+
1323
+	/**
1324
+	 * _set_cached_class
1325
+	 * attempts to cache the instantiated class locally
1326
+	 * in one of the following places, in the following order:
1327
+	 *        $this->{class_abbreviation}   ie:    $this->CART
1328
+	 *        $this->{$class_name}          ie:    $this->Some_Class
1329
+	 *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1330
+	 *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1331
+	 *
1332
+	 * @param object $class_obj
1333
+	 * @param string $class_name
1334
+	 * @param string $class_prefix
1335
+	 * @param bool   $from_db
1336
+	 * @return void
1337
+	 */
1338
+	protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1339
+	{
1340
+		if ($class_name === 'EE_Registry' || empty($class_obj)) {
1341
+			return;
1342
+		}
1343
+		// return newly instantiated class
1344
+		$class_abbreviation = $this->get_class_abbreviation($class_name, '');
1345
+		if ($class_abbreviation) {
1346
+			$this->{$class_abbreviation} = $class_obj;
1347
+			return;
1348
+		}
1349
+		$class_name = str_replace('\\', '_', $class_name);
1350
+		if (property_exists($this, $class_name)) {
1351
+			$this->{$class_name} = $class_obj;
1352
+			return;
1353
+		}
1354
+		if ($class_prefix === 'addon') {
1355
+			$this->addons->{$class_name} = $class_obj;
1356
+			return;
1357
+		}
1358
+		if (! $from_db) {
1359
+			$this->LIB->{$class_name} = $class_obj;
1360
+		}
1361
+	}
1362
+
1363
+
1364
+
1365
+	/**
1366
+	 * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1367
+	 *
1368
+	 * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1369
+	 *                          in the EE_Dependency_Map::$_class_loaders array,
1370
+	 *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1371
+	 * @param array  $arguments
1372
+	 * @return object
1373
+	 */
1374
+	public static function factory($classname, $arguments = array())
1375
+	{
1376
+		$loader = self::instance()->_dependency_map->class_loader($classname);
1377
+		if ($loader instanceof Closure) {
1378
+			return $loader($arguments);
1379
+		}
1380
+		if (method_exists(self::instance(), $loader)) {
1381
+			return self::instance()->{$loader}($classname, $arguments);
1382
+		}
1383
+		return null;
1384
+	}
1385
+
1386
+
1387
+
1388
+	/**
1389
+	 * Gets the addon by its class name
1390
+	 *
1391
+	 * @param string $class_name
1392
+	 * @return EE_Addon
1393
+	 */
1394
+	public function getAddon($class_name)
1395
+	{
1396
+		$class_name = str_replace('\\', '_', $class_name);
1397
+		return $this->addons->{$class_name};
1398
+	}
1399
+
1400
+
1401
+	/**
1402
+	 * removes the addon from the internal cache
1403
+	 *
1404
+	 * @param string $class_name
1405
+	 * @return void
1406
+	 */
1407
+	public function removeAddon($class_name)
1408
+	{
1409
+		$class_name = str_replace('\\', '_', $class_name);
1410
+		unset($this->addons->{$class_name});
1411
+	}
1412
+
1413
+
1414
+
1415
+	/**
1416
+	 * Gets the addon by its name/slug (not classname. For that, just
1417
+	 * use the get_addon() method above
1418
+	 *
1419
+	 * @param string $name
1420
+	 * @return EE_Addon
1421
+	 */
1422
+	public function get_addon_by_name($name)
1423
+	{
1424
+		foreach ($this->addons as $addon) {
1425
+			if ($addon->name() === $name) {
1426
+				return $addon;
1427
+			}
1428
+		}
1429
+		return null;
1430
+	}
1431
+
1432
+
1433
+
1434
+	/**
1435
+	 * Gets an array of all the registered addons, where the keys are their names.
1436
+	 * (ie, what each returns for their name() function)
1437
+	 * They're already available on EE_Registry::instance()->addons as properties,
1438
+	 * where each property's name is the addon's classname,
1439
+	 * So if you just want to get the addon by classname,
1440
+	 * OR use the get_addon() method above.
1441
+	 * PLEASE  NOTE:
1442
+	 * addons with Fully Qualified Class Names
1443
+	 * have had the namespace separators converted to underscores,
1444
+	 * so a classname like Fully\Qualified\ClassName
1445
+	 * would have been converted to Fully_Qualified_ClassName
1446
+	 *
1447
+	 * @return EE_Addon[] where the KEYS are the addon's name()
1448
+	 */
1449
+	public function get_addons_by_name()
1450
+	{
1451
+		$addons = array();
1452
+		foreach ($this->addons as $addon) {
1453
+			$addons[$addon->name()] = $addon;
1454
+		}
1455
+		return $addons;
1456
+	}
1457
+
1458
+
1459
+	/**
1460
+	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1461
+	 * a stale copy of it around
1462
+	 *
1463
+	 * @param string $model_name
1464
+	 * @return \EEM_Base
1465
+	 * @throws \EE_Error
1466
+	 */
1467
+	public function reset_model($model_name)
1468
+	{
1469
+		$model_class_name = strpos($model_name, 'EEM_') !== 0
1470
+			? "EEM_{$model_name}"
1471
+			: $model_name;
1472
+		if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1473
+			return null;
1474
+		}
1475
+		//get that model reset it and make sure we nuke the old reference to it
1476
+		if ($this->LIB->{$model_class_name} instanceof $model_class_name
1477
+			&& is_callable(
1478
+				array($model_class_name, 'reset')
1479
+			)) {
1480
+			$this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1481
+		} else {
1482
+			throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1483
+		}
1484
+		return $this->LIB->{$model_class_name};
1485
+	}
1486
+
1487
+
1488
+
1489
+	/**
1490
+	 * Resets the registry.
1491
+	 * The criteria for what gets reset is based on what can be shared between sites on the same request when
1492
+	 * switch_to_blog is used in a multisite install.  Here is a list of things that are NOT reset.
1493
+	 * - $_dependency_map
1494
+	 * - $_class_abbreviations
1495
+	 * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1496
+	 * - $REQ:  Still on the same request so no need to change.
1497
+	 * - $CAP: There is no site specific state in the EE_Capability class.
1498
+	 * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only
1499
+	 * one Session can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1500
+	 * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1501
+	 *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1502
+	 *             switch or on the restore.
1503
+	 * - $modules
1504
+	 * - $shortcodes
1505
+	 * - $widgets
1506
+	 *
1507
+	 * @param boolean $hard             [deprecated]
1508
+	 * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1509
+	 *                                  or just reset without re-instantiating (handy to set to FALSE if you're not
1510
+	 *                                  sure if you CAN currently reinstantiate the singletons at the moment)
1511
+	 * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so
1512
+	 *                                  client
1513
+	 *                                  code instead can just change the model context to a different blog id if
1514
+	 *                                  necessary
1515
+	 * @return EE_Registry
1516
+	 * @throws EE_Error
1517
+	 * @throws ReflectionException
1518
+	 */
1519
+	public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1520
+	{
1521
+		$instance = self::instance();
1522
+		$instance->_cache_on = true;
1523
+		// reset some "special" classes
1524
+		EEH_Activation::reset();
1525
+		$hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard);
1526
+		$instance->CFG = EE_Config::reset($hard, $reinstantiate);
1527
+		$instance->CART = null;
1528
+		$instance->MRM = null;
1529
+		$instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry');
1530
+		//messages reset
1531
+		EED_Messages::reset();
1532
+		//handle of objects cached on LIB
1533
+		foreach (array('LIB', 'modules') as $cache) {
1534
+			foreach ($instance->{$cache} as $class_name => $class) {
1535
+				if (self::_reset_and_unset_object($class, $reset_models)) {
1536
+					unset($instance->{$cache}->{$class_name});
1537
+				}
1538
+			}
1539
+		}
1540
+		return $instance;
1541
+	}
1542
+
1543
+
1544
+
1545
+	/**
1546
+	 * if passed object implements ResettableInterface, then call it's reset() method
1547
+	 * if passed object implements InterminableInterface, then return false,
1548
+	 * to indicate that it should NOT be cleared from the Registry cache
1549
+	 *
1550
+	 * @param      $object
1551
+	 * @param bool $reset_models
1552
+	 * @return bool returns true if cached object should be unset
1553
+	 */
1554
+	private static function _reset_and_unset_object($object, $reset_models)
1555
+	{
1556
+		if (! is_object($object)) {
1557
+			// don't unset anything that's not an object
1558
+			return false;
1559
+		}
1560
+		if ($object instanceof EED_Module) {
1561
+			$object::reset();
1562
+			// don't unset modules
1563
+			return false;
1564
+		}
1565
+		if ($object instanceof ResettableInterface) {
1566
+			if ($object instanceof EEM_Base) {
1567
+				if ($reset_models) {
1568
+					$object->reset();
1569
+					return true;
1570
+				}
1571
+				return false;
1572
+			}
1573
+			$object->reset();
1574
+			return true;
1575
+		}
1576
+		if (! $object instanceof InterminableInterface) {
1577
+			return true;
1578
+		}
1579
+		return false;
1580
+	}
1581
+
1582
+
1583
+
1584
+	/**
1585
+	 * Gets all the custom post type models defined
1586
+	 *
1587
+	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1588
+	 */
1589
+	public function cpt_models()
1590
+	{
1591
+		$cpt_models = array();
1592
+		foreach ($this->non_abstract_db_models as $short_name => $classname) {
1593
+			if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1594
+				$cpt_models[$short_name] = $classname;
1595
+			}
1596
+		}
1597
+		return $cpt_models;
1598
+	}
1599
+
1600
+
1601
+
1602
+	/**
1603
+	 * @return \EE_Config
1604
+	 */
1605
+	public static function CFG()
1606
+	{
1607
+		return self::instance()->CFG;
1608
+	}
1609 1609
 
1610 1610
 
1611 1611
 }
Please login to merge, or discard this patch.
core/services/loaders/CoreLoader.php 1 patch
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -33,115 +33,115 @@
 block discarded – undo
33 33
 class CoreLoader implements LoaderDecoratorInterface
34 34
 {
35 35
 
36
-    /**
37
-     * @var EE_Registry|CoffeeShop $generator
38
-     */
39
-    private $generator;
40
-
41
-
42
-
43
-    /**
44
-     * CoreLoader constructor.
45
-     *
46
-     * @param EE_Registry|CoffeeShop $generator
47
-     * @throws InvalidArgumentException
48
-     */
49
-    public function __construct($generator)
50
-    {
51
-        if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
52
-            throw new InvalidArgumentException(
53
-                esc_html__(
54
-                    'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
55
-                    'event_espresso'
56
-                )
57
-            );
58
-        }
59
-        $this->generator = $generator;
60
-    }
61
-
62
-
63
-
64
-    /**
65
-     * Calls the appropriate loading method from the installed generator;
66
-     * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method
67
-     * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(),
68
-     * but NOT to the class being instantiated.
69
-     * This is done by adding the parameters to the $arguments array as follows:
70
-     *  array(
71
-     *      'EE_Registry::create(from_db)'   => true, // boolean value, default = false
72
-     *      'EE_Registry::create(load_only)' => true, // boolean value, default = false
73
-     *      'EE_Registry::create(addon)'     => true, // boolean value, default = false
74
-     *  )
75
-     *
76
-     * @param string $fqcn
77
-     * @param array  $arguments
78
-     * @param bool   $shared
79
-     * @return mixed
80
-     * @throws OutOfBoundsException
81
-     * @throws ServiceExistsException
82
-     * @throws InstantiationException
83
-     * @throws InvalidIdentifierException
84
-     * @throws InvalidDataTypeException
85
-     * @throws InvalidClassException
86
-     * @throws EE_Error
87
-     * @throws ServiceNotFoundException
88
-     * @throws ReflectionException
89
-     */
90
-    public function load($fqcn, $arguments = array(), $shared = true)
91
-    {
92
-        $shared = filter_var($shared, FILTER_VALIDATE_BOOLEAN);
93
-        if($this->generator instanceof EE_Registry) {
94
-            // check if additional EE_Registry::create() arguments have been passed
95
-            // from_db
96
-            $from_db = isset($arguments['EE_Registry::create(from_db)'])
97
-                ? filter_var($arguments['EE_Registry::create(from_db)'], FILTER_VALIDATE_BOOLEAN)
98
-                : false;
99
-            // load_only
100
-            $load_only = isset($arguments['EE_Registry::create(load_only)'])
101
-                ? filter_var($arguments['EE_Registry::create(load_only)'], FILTER_VALIDATE_BOOLEAN)
102
-                : false;
103
-            // addon
104
-            $addon = isset($arguments['EE_Registry::create(addon)'])
105
-                ? filter_var($arguments['EE_Registry::create(addon)'], FILTER_VALIDATE_BOOLEAN)
106
-                : false;
107
-            unset(
108
-                $arguments['EE_Registry::create(from_db)'],
109
-                $arguments['EE_Registry::create(load_only)'],
110
-                $arguments['EE_Registry::create(addon)']
111
-            );
112
-            // addons need to be cached on EE_Registry
113
-            $shared = $addon ? true : $shared;
114
-            return $this->generator->create(
115
-                $fqcn,
116
-                $arguments,
117
-                $shared,
118
-                $from_db,
119
-                $load_only,
120
-                $addon
121
-            );
122
-        }
123
-        return $this->generator->brew(
124
-            $fqcn,
125
-            $arguments,
126
-            $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW
127
-        );
128
-
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     * calls reset() on generator if method exists
135
-     *
136
-     * @throws EE_Error
137
-     * @throws ReflectionException
138
-     */
139
-    public function reset()
140
-    {
141
-        if ($this->generator instanceof ResettableInterface) {
142
-            $this->generator->reset();
143
-        }
144
-    }
36
+	/**
37
+	 * @var EE_Registry|CoffeeShop $generator
38
+	 */
39
+	private $generator;
40
+
41
+
42
+
43
+	/**
44
+	 * CoreLoader constructor.
45
+	 *
46
+	 * @param EE_Registry|CoffeeShop $generator
47
+	 * @throws InvalidArgumentException
48
+	 */
49
+	public function __construct($generator)
50
+	{
51
+		if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
52
+			throw new InvalidArgumentException(
53
+				esc_html__(
54
+					'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
55
+					'event_espresso'
56
+				)
57
+			);
58
+		}
59
+		$this->generator = $generator;
60
+	}
61
+
62
+
63
+
64
+	/**
65
+	 * Calls the appropriate loading method from the installed generator;
66
+	 * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method
67
+	 * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(),
68
+	 * but NOT to the class being instantiated.
69
+	 * This is done by adding the parameters to the $arguments array as follows:
70
+	 *  array(
71
+	 *      'EE_Registry::create(from_db)'   => true, // boolean value, default = false
72
+	 *      'EE_Registry::create(load_only)' => true, // boolean value, default = false
73
+	 *      'EE_Registry::create(addon)'     => true, // boolean value, default = false
74
+	 *  )
75
+	 *
76
+	 * @param string $fqcn
77
+	 * @param array  $arguments
78
+	 * @param bool   $shared
79
+	 * @return mixed
80
+	 * @throws OutOfBoundsException
81
+	 * @throws ServiceExistsException
82
+	 * @throws InstantiationException
83
+	 * @throws InvalidIdentifierException
84
+	 * @throws InvalidDataTypeException
85
+	 * @throws InvalidClassException
86
+	 * @throws EE_Error
87
+	 * @throws ServiceNotFoundException
88
+	 * @throws ReflectionException
89
+	 */
90
+	public function load($fqcn, $arguments = array(), $shared = true)
91
+	{
92
+		$shared = filter_var($shared, FILTER_VALIDATE_BOOLEAN);
93
+		if($this->generator instanceof EE_Registry) {
94
+			// check if additional EE_Registry::create() arguments have been passed
95
+			// from_db
96
+			$from_db = isset($arguments['EE_Registry::create(from_db)'])
97
+				? filter_var($arguments['EE_Registry::create(from_db)'], FILTER_VALIDATE_BOOLEAN)
98
+				: false;
99
+			// load_only
100
+			$load_only = isset($arguments['EE_Registry::create(load_only)'])
101
+				? filter_var($arguments['EE_Registry::create(load_only)'], FILTER_VALIDATE_BOOLEAN)
102
+				: false;
103
+			// addon
104
+			$addon = isset($arguments['EE_Registry::create(addon)'])
105
+				? filter_var($arguments['EE_Registry::create(addon)'], FILTER_VALIDATE_BOOLEAN)
106
+				: false;
107
+			unset(
108
+				$arguments['EE_Registry::create(from_db)'],
109
+				$arguments['EE_Registry::create(load_only)'],
110
+				$arguments['EE_Registry::create(addon)']
111
+			);
112
+			// addons need to be cached on EE_Registry
113
+			$shared = $addon ? true : $shared;
114
+			return $this->generator->create(
115
+				$fqcn,
116
+				$arguments,
117
+				$shared,
118
+				$from_db,
119
+				$load_only,
120
+				$addon
121
+			);
122
+		}
123
+		return $this->generator->brew(
124
+			$fqcn,
125
+			$arguments,
126
+			$shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW
127
+		);
128
+
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 * calls reset() on generator if method exists
135
+	 *
136
+	 * @throws EE_Error
137
+	 * @throws ReflectionException
138
+	 */
139
+	public function reset()
140
+	{
141
+		if ($this->generator instanceof ResettableInterface) {
142
+			$this->generator->reset();
143
+		}
144
+	}
145 145
 
146 146
 }
147 147
 // End of file CoreLoader.php
Please login to merge, or discard this patch.
core/services/loaders/CachingLoader.php 2 patches
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -22,171 +22,171 @@
 block discarded – undo
22 22
 class CachingLoader extends CachingLoaderDecorator
23 23
 {
24 24
 
25
-    /**
26
-     * @var CollectionInterface $cache
27
-     */
28
-    protected $cache;
29
-
30
-    /**
31
-     * @var string $identifier
32
-     */
33
-    protected $identifier;
34
-
35
-
36
-
37
-    /**
38
-     * CachingLoader constructor.
39
-     *
40
-     * @param LoaderDecoratorInterface $loader
41
-     * @param CollectionInterface      $cache
42
-     * @param string                   $identifier
43
-     * @throws InvalidDataTypeException
44
-     */
45
-    public function __construct(
46
-        LoaderDecoratorInterface $loader,
47
-        CollectionInterface $cache,
48
-        $identifier = ''
49
-    ) {
50
-        parent::__construct($loader);
51
-        $this->cache = $cache;
52
-        $this->setIdentifier($identifier);
53
-        if ($this->identifier !== '') {
54
-            // to only clear this cache, and assuming an identifier has been set, simply do the following:
55
-            // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER');
56
-            // where "IDENTIFIER" = the string that was set during construction
57
-            add_action(
58
-                "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}",
59
-                array($this, 'reset')
60
-            );
61
-        }
62
-        // to clear ALL caches, simply do the following:
63
-        // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache');
64
-        add_action(
65
-            'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache',
66
-            array($this, 'reset')
67
-        );
68
-    }
69
-
70
-
71
-
72
-    /**
73
-     * @return string
74
-     */
75
-    public function identifier()
76
-    {
77
-        return $this->identifier;
78
-    }
79
-
80
-
81
-
82
-    /**
83
-     * @param string $identifier
84
-     * @throws InvalidDataTypeException
85
-     */
86
-    private function setIdentifier($identifier)
87
-    {
88
-        if (! is_string($identifier)) {
89
-            throw new InvalidDataTypeException('$identifier', $identifier, 'string');
90
-        }
91
-        $this->identifier = $identifier;
92
-    }
93
-
94
-
95
-    /**
96
-     * @param string $fqcn
97
-     * @param mixed  $object
98
-     * @return bool
99
-     * @throws InvalidArgumentException
100
-     */
101
-    public function share($fqcn, $object)
102
-    {
103
-        if ($object instanceof $fqcn) {
104
-            return $this->cache->add($object, md5($fqcn));
105
-        }
106
-        throw new InvalidArgumentException(
107
-            sprintf(
108
-                esc_html__(
109
-                    'The supplied class name "%1$s" must match the class of the supplied object.',
110
-                    'event_espresso'
111
-                ),
112
-                $fqcn
113
-            )
114
-        );
115
-    }
116
-
117
-
118
-    /**
119
-     * @param string $fqcn
120
-     * @param array  $arguments
121
-     * @param bool   $shared
122
-     * @return mixed
123
-     */
124
-    public function load($fqcn, $arguments = array(), $shared = true)
125
-    {
126
-        $fqcn = ltrim($fqcn, '\\');
127
-        // caching can be turned off via the following code:
128
-        // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
129
-        if(
130
-            apply_filters(
131
-                'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
132
-                false,
133
-                $this
134
-            )
135
-        ){
136
-            // even though $shared might be true, caching could be bypassed for whatever reason,
137
-            // so we don't want the core loader to cache anything, therefore caching is turned off
138
-            return $this->loader->load($fqcn, $arguments, false);
139
-        }
140
-        $identifier = md5($fqcn . $this->getIdentifierForArgument($arguments));
141
-        if ($this->cache->has($identifier)) {
142
-            return $this->cache->get($identifier);
143
-        }
144
-        $object = $this->loader->load($fqcn, $arguments, $shared);
145
-        if ($object instanceof $fqcn) {
146
-            $this->cache->add($object, $identifier);
147
-        }
148
-        return $object;
149
-    }
150
-
151
-
152
-
153
-    /**
154
-     * empties cache and calls reset() on loader if method exists
155
-     */
156
-    public function reset()
157
-    {
158
-        $this->cache->trashAndDetachAll();
159
-        $this->loader->reset();
160
-    }
161
-
162
-
163
-
164
-    /**
165
-     * build a string representation of a class' arguments
166
-     * (mostly because Closures can't be serialized)
167
-     *
168
-     * @param array $arguments
169
-     * @return string
170
-     */
171
-    private function getIdentifierForArgument(array $arguments)
172
-    {
173
-        $identifier = '';
174
-        foreach ($arguments as $argument) {
175
-            switch (true) {
176
-                case is_object($argument) :
177
-                case $argument instanceof Closure :
178
-                    $identifier .= spl_object_hash($argument);
179
-                    break;
180
-                case is_array($argument) :
181
-                    $identifier .= $this->getIdentifierForArgument($argument);
182
-                    break;
183
-                default :
184
-                    $identifier .= $argument;
185
-                    break;
186
-            }
187
-        }
188
-        return $identifier;
189
-    }
25
+	/**
26
+	 * @var CollectionInterface $cache
27
+	 */
28
+	protected $cache;
29
+
30
+	/**
31
+	 * @var string $identifier
32
+	 */
33
+	protected $identifier;
34
+
35
+
36
+
37
+	/**
38
+	 * CachingLoader constructor.
39
+	 *
40
+	 * @param LoaderDecoratorInterface $loader
41
+	 * @param CollectionInterface      $cache
42
+	 * @param string                   $identifier
43
+	 * @throws InvalidDataTypeException
44
+	 */
45
+	public function __construct(
46
+		LoaderDecoratorInterface $loader,
47
+		CollectionInterface $cache,
48
+		$identifier = ''
49
+	) {
50
+		parent::__construct($loader);
51
+		$this->cache = $cache;
52
+		$this->setIdentifier($identifier);
53
+		if ($this->identifier !== '') {
54
+			// to only clear this cache, and assuming an identifier has been set, simply do the following:
55
+			// do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER');
56
+			// where "IDENTIFIER" = the string that was set during construction
57
+			add_action(
58
+				"AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}",
59
+				array($this, 'reset')
60
+			);
61
+		}
62
+		// to clear ALL caches, simply do the following:
63
+		// do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache');
64
+		add_action(
65
+			'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache',
66
+			array($this, 'reset')
67
+		);
68
+	}
69
+
70
+
71
+
72
+	/**
73
+	 * @return string
74
+	 */
75
+	public function identifier()
76
+	{
77
+		return $this->identifier;
78
+	}
79
+
80
+
81
+
82
+	/**
83
+	 * @param string $identifier
84
+	 * @throws InvalidDataTypeException
85
+	 */
86
+	private function setIdentifier($identifier)
87
+	{
88
+		if (! is_string($identifier)) {
89
+			throw new InvalidDataTypeException('$identifier', $identifier, 'string');
90
+		}
91
+		$this->identifier = $identifier;
92
+	}
93
+
94
+
95
+	/**
96
+	 * @param string $fqcn
97
+	 * @param mixed  $object
98
+	 * @return bool
99
+	 * @throws InvalidArgumentException
100
+	 */
101
+	public function share($fqcn, $object)
102
+	{
103
+		if ($object instanceof $fqcn) {
104
+			return $this->cache->add($object, md5($fqcn));
105
+		}
106
+		throw new InvalidArgumentException(
107
+			sprintf(
108
+				esc_html__(
109
+					'The supplied class name "%1$s" must match the class of the supplied object.',
110
+					'event_espresso'
111
+				),
112
+				$fqcn
113
+			)
114
+		);
115
+	}
116
+
117
+
118
+	/**
119
+	 * @param string $fqcn
120
+	 * @param array  $arguments
121
+	 * @param bool   $shared
122
+	 * @return mixed
123
+	 */
124
+	public function load($fqcn, $arguments = array(), $shared = true)
125
+	{
126
+		$fqcn = ltrim($fqcn, '\\');
127
+		// caching can be turned off via the following code:
128
+		// add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
129
+		if(
130
+			apply_filters(
131
+				'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
132
+				false,
133
+				$this
134
+			)
135
+		){
136
+			// even though $shared might be true, caching could be bypassed for whatever reason,
137
+			// so we don't want the core loader to cache anything, therefore caching is turned off
138
+			return $this->loader->load($fqcn, $arguments, false);
139
+		}
140
+		$identifier = md5($fqcn . $this->getIdentifierForArgument($arguments));
141
+		if ($this->cache->has($identifier)) {
142
+			return $this->cache->get($identifier);
143
+		}
144
+		$object = $this->loader->load($fqcn, $arguments, $shared);
145
+		if ($object instanceof $fqcn) {
146
+			$this->cache->add($object, $identifier);
147
+		}
148
+		return $object;
149
+	}
150
+
151
+
152
+
153
+	/**
154
+	 * empties cache and calls reset() on loader if method exists
155
+	 */
156
+	public function reset()
157
+	{
158
+		$this->cache->trashAndDetachAll();
159
+		$this->loader->reset();
160
+	}
161
+
162
+
163
+
164
+	/**
165
+	 * build a string representation of a class' arguments
166
+	 * (mostly because Closures can't be serialized)
167
+	 *
168
+	 * @param array $arguments
169
+	 * @return string
170
+	 */
171
+	private function getIdentifierForArgument(array $arguments)
172
+	{
173
+		$identifier = '';
174
+		foreach ($arguments as $argument) {
175
+			switch (true) {
176
+				case is_object($argument) :
177
+				case $argument instanceof Closure :
178
+					$identifier .= spl_object_hash($argument);
179
+					break;
180
+				case is_array($argument) :
181
+					$identifier .= $this->getIdentifierForArgument($argument);
182
+					break;
183
+				default :
184
+					$identifier .= $argument;
185
+					break;
186
+			}
187
+		}
188
+		return $identifier;
189
+	}
190 190
 
191 191
 
192 192
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      */
86 86
     private function setIdentifier($identifier)
87 87
     {
88
-        if (! is_string($identifier)) {
88
+        if ( ! is_string($identifier)) {
89 89
             throw new InvalidDataTypeException('$identifier', $identifier, 'string');
90 90
         }
91 91
         $this->identifier = $identifier;
@@ -126,18 +126,18 @@  discard block
 block discarded – undo
126 126
         $fqcn = ltrim($fqcn, '\\');
127 127
         // caching can be turned off via the following code:
128 128
         // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
129
-        if(
129
+        if (
130 130
             apply_filters(
131 131
                 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
132 132
                 false,
133 133
                 $this
134 134
             )
135
-        ){
135
+        ) {
136 136
             // even though $shared might be true, caching could be bypassed for whatever reason,
137 137
             // so we don't want the core loader to cache anything, therefore caching is turned off
138 138
             return $this->loader->load($fqcn, $arguments, false);
139 139
         }
140
-        $identifier = md5($fqcn . $this->getIdentifierForArgument($arguments));
140
+        $identifier = md5($fqcn.$this->getIdentifierForArgument($arguments));
141 141
         if ($this->cache->has($identifier)) {
142 142
             return $this->cache->get($identifier);
143 143
         }
Please login to merge, or discard this patch.
core/EE_System.core.php 2 patches
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
         EE_Maintenance_Mode $maintenance_mode = null
141 141
     ) {
142 142
         // check if class object is instantiated
143
-        if (! self::$_instance instanceof EE_System) {
143
+        if ( ! self::$_instance instanceof EE_System) {
144 144
             self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
145 145
         }
146 146
         return self::$_instance;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
         $this->capabilities = $this->loader->getShared('EE_Capabilities');
260 260
         add_action(
261 261
             'AHEE__EE_Capabilities__init_caps__before_initialization',
262
-            function ()
262
+            function()
263 263
             {
264 264
                 LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
265 265
             }
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
     {
304 304
         // set autoloaders for all of the classes implementing EEI_Plugin_API
305 305
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
306
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
306
+        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
307 307
         $this->loader->getShared('EE_Request_Handler');
308 308
     }
309 309
 
@@ -323,14 +323,14 @@  discard block
 block discarded – undo
323 323
         $load_callback,
324 324
         $plugin_file_constant
325 325
     ) {
326
-        if (! defined($version_constant)) {
326
+        if ( ! defined($version_constant)) {
327 327
             return;
328 328
         }
329 329
         $addon_version = constant($version_constant);
330 330
         if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
331 331
             remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
332
-            if (! function_exists('deactivate_plugins')) {
333
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
332
+            if ( ! function_exists('deactivate_plugins')) {
333
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
334 334
             }
335 335
             deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
336 336
             unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
                     $addon_name,
344 344
                     $min_version_required
345 345
                 ),
346
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
346
+                __FILE__, __FUNCTION__."({$addon_name})", __LINE__
347 347
             );
348 348
             EE_Error::get_notices(false, true);
349 349
         }
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
                 true
394 394
             )
395 395
         ) {
396
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
396
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php';
397 397
         }
398 398
         do_action('AHEE__EE_System__load_espresso_addons__complete');
399 399
     }
@@ -500,11 +500,11 @@  discard block
 block discarded – undo
500 500
     private function fix_espresso_db_upgrade_option($espresso_db_update = null)
501 501
     {
502 502
         do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
-        if (! $espresso_db_update) {
503
+        if ( ! $espresso_db_update) {
504 504
             $espresso_db_update = get_option('espresso_db_update');
505 505
         }
506 506
         // check that option is an array
507
-        if (! is_array($espresso_db_update)) {
507
+        if ( ! is_array($espresso_db_update)) {
508 508
             // if option is FALSE, then it never existed
509 509
             if ($espresso_db_update === false) {
510 510
                 // make $espresso_db_update an array and save option with autoload OFF
@@ -524,10 +524,10 @@  discard block
 block discarded – undo
524 524
                     //so it must be numerically-indexed, where values are versions installed...
525 525
                     //fix it!
526 526
                     $version_string                         = $should_be_array;
527
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
527
+                    $corrected_db_update[$version_string] = array('unknown-date');
528 528
                 } else {
529 529
                     //ok it checks out
530
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
530
+                    $corrected_db_update[$should_be_version_string] = $should_be_array;
531 531
                 }
532 532
             }
533 533
             $espresso_db_update = $corrected_db_update;
@@ -609,13 +609,13 @@  discard block
 block discarded – undo
609 609
      */
610 610
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
611 611
     {
612
-        if (! $version_history) {
612
+        if ( ! $version_history) {
613 613
             $version_history = $this->fix_espresso_db_upgrade_option($version_history);
614 614
         }
615 615
         if ($current_version_to_add === null) {
616 616
             $current_version_to_add = espresso_version();
617 617
         }
618
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
618
+        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
619 619
         // re-save
620 620
         return update_option('espresso_db_update', $version_history);
621 621
     }
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
         if ($activation_history_for_addon) {
709 709
             //it exists, so this isn't a completely new install
710 710
             //check if this version already in that list of previously installed versions
711
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
711
+            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
712 712
                 //it a version we haven't seen before
713 713
                 if ($version_is_higher === 1) {
714 714
                     $req_type = EE_System::req_type_upgrade;
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
             foreach ($activation_history as $version => $times_activated) {
789 789
                 //check there is a record of when this version was activated. Otherwise,
790 790
                 //mark it as unknown
791
-                if (! $times_activated) {
791
+                if ( ! $times_activated) {
792 792
                     $times_activated = array('unknown-date');
793 793
                 }
794 794
                 if (is_string($times_activated)) {
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
     private function _parse_model_names()
890 890
     {
891 891
         //get all the files in the EE_MODELS folder that end in .model.php
892
-        $models                 = glob(EE_MODELS . '*.model.php');
892
+        $models                 = glob(EE_MODELS.'*.model.php');
893 893
         $model_names            = array();
894 894
         $non_abstract_db_models = array();
895 895
         foreach ($models as $model) {
@@ -898,9 +898,9 @@  discard block
 block discarded – undo
898 898
             $short_name      = str_replace('EEM_', '', $classname);
899 899
             $reflectionClass = new ReflectionClass($classname);
900 900
             if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
901
-                $non_abstract_db_models[ $short_name ] = $classname;
901
+                $non_abstract_db_models[$short_name] = $classname;
902 902
             }
903
-            $model_names[ $short_name ] = $classname;
903
+            $model_names[$short_name] = $classname;
904 904
         }
905 905
         $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
906 906
         $this->registry->non_abstract_db_models = apply_filters(
@@ -919,8 +919,8 @@  discard block
 block discarded – undo
919 919
      */
920 920
     private function _maybe_brew_regular()
921 921
     {
922
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
923
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
922
+        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) {
923
+            require_once EE_CAFF_PATH.'brewing_regular.php';
924 924
         }
925 925
     }
926 926
 
@@ -973,17 +973,17 @@  discard block
 block discarded – undo
973 973
         $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
974 974
             'AHEE__EE_System__register_shortcodes_modules_and_addons'
975 975
         );
976
-        if (! empty($class_names)) {
976
+        if ( ! empty($class_names)) {
977 977
             $msg = __(
978 978
                 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
979 979
                 'event_espresso'
980 980
             );
981 981
             $msg .= '<ul>';
982 982
             foreach ($class_names as $class_name) {
983
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
983
+                $msg .= '<li><b>Event Espresso - '.str_replace(
984 984
                         array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
985 985
                         $class_name
986
-                    ) . '</b></li>';
986
+                    ).'</b></li>';
987 987
             }
988 988
             $msg .= '</ul>';
989 989
             $msg .= __(
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
     private function _deactivate_incompatible_addons()
1055 1055
     {
1056 1056
         $incompatible_addons = get_option('ee_incompatible_addons', array());
1057
-        if (! empty($incompatible_addons)) {
1057
+        if ( ! empty($incompatible_addons)) {
1058 1058
             $active_plugins = get_option('active_plugins', array());
1059 1059
             foreach ($active_plugins as $active_plugin) {
1060 1060
                 foreach ($incompatible_addons as $incompatible_addon) {
@@ -1149,10 +1149,10 @@  discard block
 block discarded – undo
1149 1149
         do_action('AHEE__EE_System__core_loaded_and_ready');
1150 1150
         // load_espresso_template_tags
1151 1151
         if (
1152
-            is_readable(EE_PUBLIC . 'template_tags.php')
1152
+            is_readable(EE_PUBLIC.'template_tags.php')
1153 1153
             && ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isFeed())
1154 1154
         ) {
1155
-            require_once EE_PUBLIC . 'template_tags.php';
1155
+            require_once EE_PUBLIC.'template_tags.php';
1156 1156
         }
1157 1157
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1158 1158
         if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
@@ -1216,13 +1216,13 @@  discard block
 block discarded – undo
1216 1216
     public static function do_not_cache()
1217 1217
     {
1218 1218
         // set no cache constants
1219
-        if (! defined('DONOTCACHEPAGE')) {
1219
+        if ( ! defined('DONOTCACHEPAGE')) {
1220 1220
             define('DONOTCACHEPAGE', true);
1221 1221
         }
1222
-        if (! defined('DONOTCACHCEOBJECT')) {
1222
+        if ( ! defined('DONOTCACHCEOBJECT')) {
1223 1223
             define('DONOTCACHCEOBJECT', true);
1224 1224
         }
1225
-        if (! defined('DONOTCACHEDB')) {
1225
+        if ( ! defined('DONOTCACHEDB')) {
1226 1226
             define('DONOTCACHEDB', true);
1227 1227
         }
1228 1228
         // add no cache headers
Please login to merge, or discard this patch.
Indentation   +1253 added lines, -1253 removed lines patch added patch discarded remove patch
@@ -24,1259 +24,1259 @@
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
29
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
30
-     */
31
-    const req_type_normal = 0;
32
-
33
-    /**
34
-     * Indicates this is a brand new installation of EE so we should install
35
-     * tables and default data etc
36
-     */
37
-    const req_type_new_activation = 1;
38
-
39
-    /**
40
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
41
-     * and we just exited maintenance mode). We MUST check the database is setup properly
42
-     * and that default data is setup too
43
-     */
44
-    const req_type_reactivation = 2;
45
-
46
-    /**
47
-     * indicates that EE has been upgraded since its previous request.
48
-     * We may have data migration scripts to call and will want to trigger maintenance mode
49
-     */
50
-    const req_type_upgrade = 3;
51
-
52
-    /**
53
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
54
-     */
55
-    const req_type_downgrade = 4;
56
-
57
-    /**
58
-     * @deprecated since version 4.6.0.dev.006
59
-     * Now whenever a new_activation is detected the request type is still just
60
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
61
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
62
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
63
-     * (Specifically, when the migration manager indicates migrations are finished
64
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
65
-     */
66
-    const req_type_activation_but_not_installed = 5;
67
-
68
-    /**
69
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
70
-     */
71
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
72
-
73
-
74
-    /**
75
-     * @var EE_System $_instance
76
-     */
77
-    private static $_instance;
78
-
79
-    /**
80
-     * @var EE_Registry $registry
81
-     */
82
-    private $registry;
83
-
84
-    /**
85
-     * @var LoaderInterface $loader
86
-     */
87
-    private $loader;
88
-
89
-    /**
90
-     * @var EE_Capabilities $capabilities
91
-     */
92
-    private $capabilities;
93
-
94
-    /**
95
-     * @var RequestInterface $request
96
-     */
97
-    private $request;
98
-
99
-    /**
100
-     * @var EE_Maintenance_Mode $maintenance_mode
101
-     */
102
-    private $maintenance_mode;
103
-
104
-    /**
105
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
106
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
107
-     *
108
-     * @var int $_req_type
109
-     */
110
-    private $_req_type;
111
-
112
-    /**
113
-     * Whether or not there was a non-micro version change in EE core version during this request
114
-     *
115
-     * @var boolean $_major_version_change
116
-     */
117
-    private $_major_version_change = false;
118
-
119
-    /**
120
-     * A Context DTO dedicated solely to identifying the current request type.
121
-     *
122
-     * @var RequestTypeContextCheckerInterface $request_type
123
-     */
124
-    private $request_type;
125
-
126
-
127
-
128
-    /**
129
-     * @singleton method used to instantiate class object
130
-     * @param EE_Registry|null         $registry
131
-     * @param LoaderInterface|null     $loader
132
-     * @param RequestInterface|null          $request
133
-     * @param EE_Maintenance_Mode|null $maintenance_mode
134
-     * @return EE_System
135
-     */
136
-    public static function instance(
137
-        EE_Registry $registry = null,
138
-        LoaderInterface $loader = null,
139
-        RequestInterface $request = null,
140
-        EE_Maintenance_Mode $maintenance_mode = null
141
-    ) {
142
-        // check if class object is instantiated
143
-        if (! self::$_instance instanceof EE_System) {
144
-            self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
145
-        }
146
-        return self::$_instance;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * resets the instance and returns it
153
-     *
154
-     * @return EE_System
155
-     */
156
-    public static function reset()
157
-    {
158
-        self::$_instance->_req_type = null;
159
-        //make sure none of the old hooks are left hanging around
160
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
161
-        //we need to reset the migration manager in order for it to detect DMSs properly
162
-        EE_Data_Migration_Manager::reset();
163
-        self::instance()->detect_activations_or_upgrades();
164
-        self::instance()->perform_activations_upgrades_and_migrations();
165
-        return self::instance();
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     * sets hooks for running rest of system
172
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
173
-     * starting EE Addons from any other point may lead to problems
174
-     *
175
-     * @param EE_Registry         $registry
176
-     * @param LoaderInterface     $loader
177
-     * @param RequestInterface          $request
178
-     * @param EE_Maintenance_Mode $maintenance_mode
179
-     */
180
-    private function __construct(
181
-        EE_Registry $registry,
182
-        LoaderInterface $loader,
183
-        RequestInterface $request,
184
-        EE_Maintenance_Mode $maintenance_mode
185
-    ) {
186
-        $this->registry         = $registry;
187
-        $this->loader           = $loader;
188
-        $this->request          = $request;
189
-        $this->maintenance_mode = $maintenance_mode;
190
-        do_action('AHEE__EE_System__construct__begin', $this);
191
-        add_action(
192
-            'AHEE__EE_Bootstrap__load_espresso_addons',
193
-            array($this, 'loadCapabilities'),
194
-            5
195
-        );
196
-        add_action(
197
-            'AHEE__EE_Bootstrap__load_espresso_addons',
198
-            array($this, 'loadCommandBus'),
199
-            7
200
-        );
201
-        add_action(
202
-            'AHEE__EE_Bootstrap__load_espresso_addons',
203
-            array($this, 'loadPluginApi'),
204
-            9
205
-        );
206
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
207
-        add_action(
208
-            'AHEE__EE_Bootstrap__load_espresso_addons',
209
-            array($this, 'load_espresso_addons')
210
-        );
211
-        // when an ee addon is activated, we want to call the core hook(s) again
212
-        // because the newly-activated addon didn't get a chance to run at all
213
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
214
-        // detect whether install or upgrade
215
-        add_action(
216
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
217
-            array($this, 'detect_activations_or_upgrades'),
218
-            3
219
-        );
220
-        // load EE_Config, EE_Textdomain, etc
221
-        add_action(
222
-            'AHEE__EE_Bootstrap__load_core_configuration',
223
-            array($this, 'load_core_configuration'),
224
-            5
225
-        );
226
-        // load EE_Config, EE_Textdomain, etc
227
-        add_action(
228
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
229
-            array($this, 'register_shortcodes_modules_and_widgets'),
230
-            7
231
-        );
232
-        // you wanna get going? I wanna get going... let's get going!
233
-        add_action(
234
-            'AHEE__EE_Bootstrap__brew_espresso',
235
-            array($this, 'brew_espresso'),
236
-            9
237
-        );
238
-        //other housekeeping
239
-        //exclude EE critical pages from wp_list_pages
240
-        add_filter(
241
-            'wp_list_pages_excludes',
242
-            array($this, 'remove_pages_from_wp_list_pages'),
243
-            10
244
-        );
245
-        // ALL EE Addons should use the following hook point to attach their initial setup too
246
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
247
-        do_action('AHEE__EE_System__construct__complete', $this);
248
-    }
249
-
250
-
251
-    /**
252
-     * load and setup EE_Capabilities
253
-     *
254
-     * @return void
255
-     * @throws EE_Error
256
-     */
257
-    public function loadCapabilities()
258
-    {
259
-        $this->capabilities = $this->loader->getShared('EE_Capabilities');
260
-        add_action(
261
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
262
-            function ()
263
-            {
264
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
265
-            }
266
-        );
267
-    }
268
-
269
-
270
-
271
-    /**
272
-     * create and cache the CommandBus, and also add middleware
273
-     * The CapChecker middleware requires the use of EE_Capabilities
274
-     * which is why we need to load the CommandBus after Caps are set up
275
-     *
276
-     * @return void
277
-     * @throws EE_Error
278
-     */
279
-    public function loadCommandBus()
280
-    {
281
-        $this->loader->getShared(
282
-            'CommandBusInterface',
283
-            array(
284
-                null,
285
-                apply_filters(
286
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
287
-                    array(
288
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
289
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
290
-                    )
291
-                ),
292
-            )
293
-        );
294
-    }
295
-
296
-
297
-
298
-    /**
299
-     * @return void
300
-     * @throws EE_Error
301
-     */
302
-    public function loadPluginApi()
303
-    {
304
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
305
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
306
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
307
-        $this->loader->getShared('EE_Request_Handler');
308
-    }
309
-
310
-
311
-    /**
312
-     * @param string $addon_name
313
-     * @param string $version_constant
314
-     * @param string $min_version_required
315
-     * @param string $load_callback
316
-     * @param string $plugin_file_constant
317
-     * @return void
318
-     */
319
-    private function deactivateIncompatibleAddon(
320
-        $addon_name,
321
-        $version_constant,
322
-        $min_version_required,
323
-        $load_callback,
324
-        $plugin_file_constant
325
-    ) {
326
-        if (! defined($version_constant)) {
327
-            return;
328
-        }
329
-        $addon_version = constant($version_constant);
330
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
331
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
332
-            if (! function_exists('deactivate_plugins')) {
333
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
334
-            }
335
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
336
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
337
-            EE_Error::add_error(
338
-                sprintf(
339
-                    esc_html__(
340
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
341
-                        'event_espresso'
342
-                    ),
343
-                    $addon_name,
344
-                    $min_version_required
345
-                ),
346
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
347
-            );
348
-            EE_Error::get_notices(false, true);
349
-        }
350
-    }
351
-
352
-
353
-    /**
354
-     * load_espresso_addons
355
-     * allow addons to load first so that they can set hooks for running DMS's, etc
356
-     * this is hooked into both:
357
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
358
-     *        which runs during the WP 'plugins_loaded' action at priority 5
359
-     *    and the WP 'activate_plugin' hook point
360
-     *
361
-     * @access public
362
-     * @return void
363
-     */
364
-    public function load_espresso_addons()
365
-    {
366
-        $this->deactivateIncompatibleAddon(
367
-            'Wait Lists',
368
-            'EE_WAIT_LISTS_VERSION',
369
-            '1.0.0.beta.074',
370
-            'load_espresso_wait_lists',
371
-            'EE_WAIT_LISTS_PLUGIN_FILE'
372
-        );
373
-        $this->deactivateIncompatibleAddon(
374
-            'Automated Upcoming Event Notifications',
375
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
376
-            '1.0.0.beta.091',
377
-            'load_espresso_automated_upcoming_event_notification',
378
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
379
-        );
380
-        do_action('AHEE__EE_System__load_espresso_addons');
381
-        //if the WP API basic auth plugin isn't already loaded, load it now.
382
-        //We want it for mobile apps. Just include the entire plugin
383
-        //also, don't load the basic auth when a plugin is getting activated, because
384
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
385
-        //and causes a fatal error
386
-        if (
387
-            $this->request->getRequestParam('activate') !== 'true'
388
-            && ! function_exists('json_basic_auth_handler')
389
-            && ! function_exists('json_basic_auth_error')
390
-            && ! in_array(
391
-                $this->request->getRequestParam('action'),
392
-                array('activate', 'activate-selected'),
393
-                true
394
-            )
395
-        ) {
396
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
397
-        }
398
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * detect_activations_or_upgrades
405
-     * Checks for activation or upgrade of core first;
406
-     * then also checks if any registered addons have been activated or upgraded
407
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
408
-     * which runs during the WP 'plugins_loaded' action at priority 3
409
-     *
410
-     * @access public
411
-     * @return void
412
-     */
413
-    public function detect_activations_or_upgrades()
414
-    {
415
-        //first off: let's make sure to handle core
416
-        $this->detect_if_activation_or_upgrade();
417
-        foreach ($this->registry->addons as $addon) {
418
-            if ($addon instanceof EE_Addon) {
419
-                //detect teh request type for that addon
420
-                $addon->detect_activation_or_upgrade();
421
-            }
422
-        }
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * detect_if_activation_or_upgrade
429
-     * Takes care of detecting whether this is a brand new install or code upgrade,
430
-     * and either setting up the DB or setting up maintenance mode etc.
431
-     *
432
-     * @access public
433
-     * @return void
434
-     */
435
-    public function detect_if_activation_or_upgrade()
436
-    {
437
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
438
-        // check if db has been updated, or if its a brand-new installation
439
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
440
-        $request_type       = $this->detect_req_type($espresso_db_update);
441
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
442
-        switch ($request_type) {
443
-            case EE_System::req_type_new_activation:
444
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
445
-                $this->_handle_core_version_change($espresso_db_update);
446
-                break;
447
-            case EE_System::req_type_reactivation:
448
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
449
-                $this->_handle_core_version_change($espresso_db_update);
450
-                break;
451
-            case EE_System::req_type_upgrade:
452
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
453
-                //migrations may be required now that we've upgraded
454
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
455
-                $this->_handle_core_version_change($espresso_db_update);
456
-                //				echo "done upgrade";die;
457
-                break;
458
-            case EE_System::req_type_downgrade:
459
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
460
-                //its possible migrations are no longer required
461
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
462
-                $this->_handle_core_version_change($espresso_db_update);
463
-                break;
464
-            case EE_System::req_type_normal:
465
-            default:
466
-                break;
467
-        }
468
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
469
-    }
470
-
471
-
472
-
473
-    /**
474
-     * Updates the list of installed versions and sets hooks for
475
-     * initializing the database later during the request
476
-     *
477
-     * @param array $espresso_db_update
478
-     */
479
-    private function _handle_core_version_change($espresso_db_update)
480
-    {
481
-        $this->update_list_of_installed_versions($espresso_db_update);
482
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
483
-        add_action(
484
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
485
-            array($this, 'initialize_db_if_no_migrations_required')
486
-        );
487
-    }
488
-
489
-
490
-
491
-    /**
492
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
493
-     * information about what versions of EE have been installed and activated,
494
-     * NOT necessarily the state of the database
495
-     *
496
-     * @param mixed $espresso_db_update           the value of the WordPress option.
497
-     *                                            If not supplied, fetches it from the options table
498
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
499
-     */
500
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
501
-    {
502
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
-        if (! $espresso_db_update) {
504
-            $espresso_db_update = get_option('espresso_db_update');
505
-        }
506
-        // check that option is an array
507
-        if (! is_array($espresso_db_update)) {
508
-            // if option is FALSE, then it never existed
509
-            if ($espresso_db_update === false) {
510
-                // make $espresso_db_update an array and save option with autoload OFF
511
-                $espresso_db_update = array();
512
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
513
-            } else {
514
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
515
-                $espresso_db_update = array($espresso_db_update => array());
516
-                update_option('espresso_db_update', $espresso_db_update);
517
-            }
518
-        } else {
519
-            $corrected_db_update = array();
520
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
521
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
522
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
523
-                    //the key is an int, and the value IS NOT an array
524
-                    //so it must be numerically-indexed, where values are versions installed...
525
-                    //fix it!
526
-                    $version_string                         = $should_be_array;
527
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
528
-                } else {
529
-                    //ok it checks out
530
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
531
-                }
532
-            }
533
-            $espresso_db_update = $corrected_db_update;
534
-            update_option('espresso_db_update', $espresso_db_update);
535
-        }
536
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
537
-        return $espresso_db_update;
538
-    }
539
-
540
-
541
-
542
-    /**
543
-     * Does the traditional work of setting up the plugin's database and adding default data.
544
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
545
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
546
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
547
-     * so that it will be done when migrations are finished
548
-     *
549
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
550
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
551
-     *                                       This is a resource-intensive job
552
-     *                                       so we prefer to only do it when necessary
553
-     * @return void
554
-     * @throws EE_Error
555
-     */
556
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
557
-    {
558
-        $request_type = $this->detect_req_type();
559
-        //only initialize system if we're not in maintenance mode.
560
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
561
-            update_option('ee_flush_rewrite_rules', true);
562
-            if ($verify_schema) {
563
-                EEH_Activation::initialize_db_and_folders();
564
-            }
565
-            EEH_Activation::initialize_db_content();
566
-            EEH_Activation::system_initialization();
567
-            if ($initialize_addons_too) {
568
-                $this->initialize_addons();
569
-            }
570
-        } else {
571
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
572
-        }
573
-        if ($request_type === EE_System::req_type_new_activation
574
-            || $request_type === EE_System::req_type_reactivation
575
-            || (
576
-                $request_type === EE_System::req_type_upgrade
577
-                && $this->is_major_version_change()
578
-            )
579
-        ) {
580
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
581
-        }
582
-    }
583
-
584
-
585
-
586
-    /**
587
-     * Initializes the db for all registered addons
588
-     *
589
-     * @throws EE_Error
590
-     */
591
-    public function initialize_addons()
592
-    {
593
-        //foreach registered addon, make sure its db is up-to-date too
594
-        foreach ($this->registry->addons as $addon) {
595
-            if ($addon instanceof EE_Addon) {
596
-                $addon->initialize_db_if_no_migrations_required();
597
-            }
598
-        }
599
-    }
600
-
601
-
602
-
603
-    /**
604
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
605
-     *
606
-     * @param    array  $version_history
607
-     * @param    string $current_version_to_add version to be added to the version history
608
-     * @return    boolean success as to whether or not this option was changed
609
-     */
610
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
611
-    {
612
-        if (! $version_history) {
613
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
614
-        }
615
-        if ($current_version_to_add === null) {
616
-            $current_version_to_add = espresso_version();
617
-        }
618
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
619
-        // re-save
620
-        return update_option('espresso_db_update', $version_history);
621
-    }
622
-
623
-
624
-
625
-    /**
626
-     * Detects if the current version indicated in the has existed in the list of
627
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
628
-     *
629
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
630
-     *                                  If not supplied, fetches it from the options table.
631
-     *                                  Also, caches its result so later parts of the code can also know whether
632
-     *                                  there's been an update or not. This way we can add the current version to
633
-     *                                  espresso_db_update, but still know if this is a new install or not
634
-     * @return int one of the constants on EE_System::req_type_
635
-     */
636
-    public function detect_req_type($espresso_db_update = null)
637
-    {
638
-        if ($this->_req_type === null) {
639
-            $espresso_db_update          = ! empty($espresso_db_update)
640
-                ? $espresso_db_update
641
-                : $this->fix_espresso_db_upgrade_option();
642
-            $this->_req_type             = EE_System::detect_req_type_given_activation_history(
643
-                $espresso_db_update,
644
-                'ee_espresso_activation', espresso_version()
645
-            );
646
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
647
-            $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
648
-        }
649
-        return $this->_req_type;
650
-    }
651
-
652
-
653
-
654
-    /**
655
-     * Returns whether or not there was a non-micro version change (ie, change in either
656
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
657
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
658
-     *
659
-     * @param $activation_history
660
-     * @return bool
661
-     */
662
-    private function _detect_major_version_change($activation_history)
663
-    {
664
-        $previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
665
-        $previous_version_parts = explode('.', $previous_version);
666
-        $current_version_parts  = explode('.', espresso_version());
667
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
668
-               && ($previous_version_parts[0] !== $current_version_parts[0]
669
-                   || $previous_version_parts[1] !== $current_version_parts[1]
670
-               );
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     * Returns true if either the major or minor version of EE changed during this request.
677
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
678
-     *
679
-     * @return bool
680
-     */
681
-    public function is_major_version_change()
682
-    {
683
-        return $this->_major_version_change;
684
-    }
685
-
686
-
687
-
688
-    /**
689
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
690
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
691
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
692
-     * just activated to (for core that will always be espresso_version())
693
-     *
694
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
695
-     *                                                 ee plugin. for core that's 'espresso_db_update'
696
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
697
-     *                                                 indicate that this plugin was just activated
698
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
699
-     *                                                 espresso_version())
700
-     * @return int one of the constants on EE_System::req_type_*
701
-     */
702
-    public static function detect_req_type_given_activation_history(
703
-        $activation_history_for_addon,
704
-        $activation_indicator_option_name,
705
-        $version_to_upgrade_to
706
-    ) {
707
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
708
-        if ($activation_history_for_addon) {
709
-            //it exists, so this isn't a completely new install
710
-            //check if this version already in that list of previously installed versions
711
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
712
-                //it a version we haven't seen before
713
-                if ($version_is_higher === 1) {
714
-                    $req_type = EE_System::req_type_upgrade;
715
-                } else {
716
-                    $req_type = EE_System::req_type_downgrade;
717
-                }
718
-                delete_option($activation_indicator_option_name);
719
-            } else {
720
-                // its not an update. maybe a reactivation?
721
-                if (get_option($activation_indicator_option_name, false)) {
722
-                    if ($version_is_higher === -1) {
723
-                        $req_type = EE_System::req_type_downgrade;
724
-                    } elseif ($version_is_higher === 0) {
725
-                        //we've seen this version before, but it's an activation. must be a reactivation
726
-                        $req_type = EE_System::req_type_reactivation;
727
-                    } else {//$version_is_higher === 1
728
-                        $req_type = EE_System::req_type_upgrade;
729
-                    }
730
-                    delete_option($activation_indicator_option_name);
731
-                } else {
732
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
733
-                    if ($version_is_higher === -1) {
734
-                        $req_type = EE_System::req_type_downgrade;
735
-                    } elseif ($version_is_higher === 0) {
736
-                        //we've seen this version before and it's not an activation. its normal request
737
-                        $req_type = EE_System::req_type_normal;
738
-                    } else {//$version_is_higher === 1
739
-                        $req_type = EE_System::req_type_upgrade;
740
-                    }
741
-                }
742
-            }
743
-        } else {
744
-            //brand new install
745
-            $req_type = EE_System::req_type_new_activation;
746
-            delete_option($activation_indicator_option_name);
747
-        }
748
-        return $req_type;
749
-    }
750
-
751
-
752
-
753
-    /**
754
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
755
-     * the $activation_history_for_addon
756
-     *
757
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
758
-     *                                             sometimes containing 'unknown-date'
759
-     * @param string $version_to_upgrade_to        (current version)
760
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
761
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
762
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
763
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
764
-     */
765
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
766
-    {
767
-        //find the most recently-activated version
768
-        $most_recently_active_version =
769
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
770
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
771
-    }
772
-
773
-
774
-
775
-    /**
776
-     * Gets the most recently active version listed in the activation history,
777
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
778
-     *
779
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
780
-     *                                   sometimes containing 'unknown-date'
781
-     * @return string
782
-     */
783
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
784
-    {
785
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
786
-        $most_recently_active_version            = '0.0.0.dev.000';
787
-        if (is_array($activation_history)) {
788
-            foreach ($activation_history as $version => $times_activated) {
789
-                //check there is a record of when this version was activated. Otherwise,
790
-                //mark it as unknown
791
-                if (! $times_activated) {
792
-                    $times_activated = array('unknown-date');
793
-                }
794
-                if (is_string($times_activated)) {
795
-                    $times_activated = array($times_activated);
796
-                }
797
-                foreach ($times_activated as $an_activation) {
798
-                    if ($an_activation !== 'unknown-date'
799
-                        && $an_activation
800
-                           > $most_recently_active_version_activation) {
801
-                        $most_recently_active_version            = $version;
802
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
803
-                            ? '1970-01-01 00:00:00'
804
-                            : $an_activation;
805
-                    }
806
-                }
807
-            }
808
-        }
809
-        return $most_recently_active_version;
810
-    }
811
-
812
-
813
-
814
-    /**
815
-     * This redirects to the about EE page after activation
816
-     *
817
-     * @return void
818
-     */
819
-    public function redirect_to_about_ee()
820
-    {
821
-        $notices = EE_Error::get_notices(false);
822
-        //if current user is an admin and it's not an ajax or rest request
823
-        if (
824
-            ! isset($notices['errors'])
825
-            && $this->request->isAdmin()
826
-            && apply_filters(
827
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
828
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
829
-            )
830
-        ) {
831
-            $query_params = array('page' => 'espresso_about');
832
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
833
-                $query_params['new_activation'] = true;
834
-            }
835
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
836
-                $query_params['reactivation'] = true;
837
-            }
838
-            $url = add_query_arg($query_params, admin_url('admin.php'));
839
-            wp_safe_redirect($url);
840
-            exit();
841
-        }
842
-    }
843
-
844
-
845
-
846
-    /**
847
-     * load_core_configuration
848
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
849
-     * which runs during the WP 'plugins_loaded' action at priority 5
850
-     *
851
-     * @return void
852
-     * @throws ReflectionException
853
-     */
854
-    public function load_core_configuration()
855
-    {
856
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
857
-        $this->loader->getShared('EE_Load_Textdomain');
858
-        //load textdomain
859
-        EE_Load_Textdomain::load_textdomain();
860
-        // load and setup EE_Config and EE_Network_Config
861
-        $config = $this->loader->getShared('EE_Config');
862
-        $this->loader->getShared('EE_Network_Config');
863
-        // setup autoloaders
864
-        // enable logging?
865
-        if ($config->admin->use_full_logging) {
866
-            $this->loader->getShared('EE_Log');
867
-        }
868
-        // check for activation errors
869
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
870
-        if ($activation_errors) {
871
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
872
-            update_option('ee_plugin_activation_errors', false);
873
-        }
874
-        // get model names
875
-        $this->_parse_model_names();
876
-        //load caf stuff a chance to play during the activation process too.
877
-        $this->_maybe_brew_regular();
878
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
879
-    }
880
-
881
-
882
-
883
-    /**
884
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
885
-     *
886
-     * @return void
887
-     * @throws ReflectionException
888
-     */
889
-    private function _parse_model_names()
890
-    {
891
-        //get all the files in the EE_MODELS folder that end in .model.php
892
-        $models                 = glob(EE_MODELS . '*.model.php');
893
-        $model_names            = array();
894
-        $non_abstract_db_models = array();
895
-        foreach ($models as $model) {
896
-            // get model classname
897
-            $classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
898
-            $short_name      = str_replace('EEM_', '', $classname);
899
-            $reflectionClass = new ReflectionClass($classname);
900
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
901
-                $non_abstract_db_models[ $short_name ] = $classname;
902
-            }
903
-            $model_names[ $short_name ] = $classname;
904
-        }
905
-        $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
906
-        $this->registry->non_abstract_db_models = apply_filters(
907
-            'FHEE__EE_System__parse_implemented_model_names',
908
-            $non_abstract_db_models
909
-        );
910
-    }
911
-
912
-
913
-
914
-    /**
915
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
916
-     * that need to be setup before our EE_System launches.
917
-     *
918
-     * @return void
919
-     */
920
-    private function _maybe_brew_regular()
921
-    {
922
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
923
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
924
-        }
925
-    }
926
-
927
-
928
-
929
-    /**
930
-     * register_shortcodes_modules_and_widgets
931
-     * generate lists of shortcodes and modules, then verify paths and classes
932
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
933
-     * which runs during the WP 'plugins_loaded' action at priority 7
934
-     *
935
-     * @access public
936
-     * @return void
937
-     * @throws Exception
938
-     */
939
-    public function register_shortcodes_modules_and_widgets()
940
-    {
941
-        if ($this->request->isFrontend() || $this->request->isIframe()) {
942
-            try {
943
-                // load, register, and add shortcodes the new way
944
-                $this->loader->getShared(
945
-                    'EventEspresso\core\services\shortcodes\ShortcodesManager',
946
-                    array(
947
-                        // and the old way, but we'll put it under control of the new system
948
-                        EE_Config::getLegacyShortcodesManager(),
949
-                    )
950
-                );
951
-            } catch (Exception $exception) {
952
-                new ExceptionStackTraceDisplay($exception);
953
-            }
954
-        }
955
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
956
-        // check for addons using old hook point
957
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
958
-            $this->_incompatible_addon_error();
959
-        }
960
-    }
961
-
962
-
963
-
964
-    /**
965
-     * _incompatible_addon_error
966
-     *
967
-     * @access public
968
-     * @return void
969
-     */
970
-    private function _incompatible_addon_error()
971
-    {
972
-        // get array of classes hooking into here
973
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
974
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
975
-        );
976
-        if (! empty($class_names)) {
977
-            $msg = __(
978
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
979
-                'event_espresso'
980
-            );
981
-            $msg .= '<ul>';
982
-            foreach ($class_names as $class_name) {
983
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
984
-                        array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
985
-                        $class_name
986
-                    ) . '</b></li>';
987
-            }
988
-            $msg .= '</ul>';
989
-            $msg .= __(
990
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
991
-                'event_espresso'
992
-            );
993
-            // save list of incompatible addons to wp-options for later use
994
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
995
-            if (is_admin()) {
996
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
997
-            }
998
-        }
999
-    }
1000
-
1001
-
1002
-
1003
-    /**
1004
-     * brew_espresso
1005
-     * begins the process of setting hooks for initializing EE in the correct order
1006
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1007
-     * which runs during the WP 'plugins_loaded' action at priority 9
1008
-     *
1009
-     * @return void
1010
-     */
1011
-    public function brew_espresso()
1012
-    {
1013
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1014
-        // load some final core systems
1015
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
1016
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1017
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
1018
-        add_action('init', array($this, 'load_controllers'), 7);
1019
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
1020
-        add_action('init', array($this, 'initialize'), 10);
1021
-        add_action('init', array($this, 'initialize_last'), 100);
1022
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1023
-            // pew pew pew
1024
-            $this->loader->getShared('EE_PUE');
1025
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1026
-        }
1027
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1028
-    }
1029
-
1030
-
1031
-
1032
-    /**
1033
-     *    set_hooks_for_core
1034
-     *
1035
-     * @access public
1036
-     * @return    void
1037
-     * @throws EE_Error
1038
-     */
1039
-    public function set_hooks_for_core()
1040
-    {
1041
-        $this->_deactivate_incompatible_addons();
1042
-        do_action('AHEE__EE_System__set_hooks_for_core');
1043
-        //caps need to be initialized on every request so that capability maps are set.
1044
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1045
-        $this->registry->CAP->init_caps();
1046
-    }
1047
-
1048
-
1049
-
1050
-    /**
1051
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1052
-     * deactivates any addons considered incompatible with the current version of EE
1053
-     */
1054
-    private function _deactivate_incompatible_addons()
1055
-    {
1056
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
1057
-        if (! empty($incompatible_addons)) {
1058
-            $active_plugins = get_option('active_plugins', array());
1059
-            foreach ($active_plugins as $active_plugin) {
1060
-                foreach ($incompatible_addons as $incompatible_addon) {
1061
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1062
-                        unset($_GET['activate']);
1063
-                        espresso_deactivate_plugin($active_plugin);
1064
-                    }
1065
-                }
1066
-            }
1067
-        }
1068
-    }
1069
-
1070
-
1071
-
1072
-    /**
1073
-     *    perform_activations_upgrades_and_migrations
1074
-     *
1075
-     * @access public
1076
-     * @return    void
1077
-     */
1078
-    public function perform_activations_upgrades_and_migrations()
1079
-    {
1080
-        //first check if we had previously attempted to setup EE's directories but failed
1081
-        if ($this->request->isActivation() && EEH_Activation::upload_directories_incomplete()) {
1082
-            EEH_Activation::create_upload_directories();
1083
-        }
1084
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1085
-    }
1086
-
1087
-
1088
-
1089
-    /**
1090
-     *    load_CPTs_and_session
1091
-     *
1092
-     * @access public
1093
-     * @return    void
1094
-     */
1095
-    public function load_CPTs_and_session()
1096
-    {
1097
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1098
-        // register Custom Post Types
1099
-        $this->loader->getShared('EE_Register_CPTs');
1100
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1101
-    }
1102
-
1103
-
1104
-
1105
-    /**
1106
-     * load_controllers
1107
-     * this is the best place to load any additional controllers that needs access to EE core.
1108
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1109
-     * time
1110
-     *
1111
-     * @access public
1112
-     * @return void
1113
-     */
1114
-    public function load_controllers()
1115
-    {
1116
-        do_action('AHEE__EE_System__load_controllers__start');
1117
-        // let's get it started
1118
-        if (
1119
-            ! $this->maintenance_mode->level()
1120
-            && ($this->request->isFrontend() || $this->request->isFrontAjax())
1121
-        ) {
1122
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1123
-            $this->loader->getShared('EE_Front_Controller');
1124
-        } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1125
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1126
-            $this->loader->getShared('EE_Admin');
1127
-        }
1128
-        do_action('AHEE__EE_System__load_controllers__complete');
1129
-    }
1130
-
1131
-
1132
-
1133
-    /**
1134
-     * core_loaded_and_ready
1135
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1136
-     *
1137
-     * @access public
1138
-     * @return void
1139
-     */
1140
-    public function core_loaded_and_ready()
1141
-    {
1142
-        if (
1143
-            $this->request->isAdmin()
1144
-            || $this->request->isEeAjax()
1145
-            || $this->request->isFrontend()
1146
-        ) {
1147
-            $this->loader->getShared('EE_Session');
1148
-        }
1149
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1150
-        // load_espresso_template_tags
1151
-        if (
1152
-            is_readable(EE_PUBLIC . 'template_tags.php')
1153
-            && ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isFeed())
1154
-        ) {
1155
-            require_once EE_PUBLIC . 'template_tags.php';
1156
-        }
1157
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1158
-        if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1159
-            $this->loader->getShared('EventEspresso\core\services\assets\Registry');
1160
-        }
1161
-    }
1162
-
1163
-
1164
-
1165
-    /**
1166
-     * initialize
1167
-     * this is the best place to begin initializing client code
1168
-     *
1169
-     * @access public
1170
-     * @return void
1171
-     */
1172
-    public function initialize()
1173
-    {
1174
-        do_action('AHEE__EE_System__initialize');
1175
-    }
1176
-
1177
-
1178
-
1179
-    /**
1180
-     * initialize_last
1181
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1182
-     * initialize has done so
1183
-     *
1184
-     * @access public
1185
-     * @return void
1186
-     */
1187
-    public function initialize_last()
1188
-    {
1189
-        do_action('AHEE__EE_System__initialize_last');
1190
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1191
-    }
1192
-
1193
-
1194
-
1195
-    /**
1196
-     * @return void
1197
-     * @throws EE_Error
1198
-     */
1199
-    public function addEspressoToolbar()
1200
-    {
1201
-        $this->loader->getShared(
1202
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1203
-            array($this->registry->CAP)
1204
-        );
1205
-    }
1206
-
1207
-
1208
-
1209
-    /**
1210
-     * do_not_cache
1211
-     * sets no cache headers and defines no cache constants for WP plugins
1212
-     *
1213
-     * @access public
1214
-     * @return void
1215
-     */
1216
-    public static function do_not_cache()
1217
-    {
1218
-        // set no cache constants
1219
-        if (! defined('DONOTCACHEPAGE')) {
1220
-            define('DONOTCACHEPAGE', true);
1221
-        }
1222
-        if (! defined('DONOTCACHCEOBJECT')) {
1223
-            define('DONOTCACHCEOBJECT', true);
1224
-        }
1225
-        if (! defined('DONOTCACHEDB')) {
1226
-            define('DONOTCACHEDB', true);
1227
-        }
1228
-        // add no cache headers
1229
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1230
-        // plus a little extra for nginx and Google Chrome
1231
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1232
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1233
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1234
-    }
1235
-
1236
-
1237
-
1238
-    /**
1239
-     *    extra_nocache_headers
1240
-     *
1241
-     * @access    public
1242
-     * @param $headers
1243
-     * @return    array
1244
-     */
1245
-    public static function extra_nocache_headers($headers)
1246
-    {
1247
-        // for NGINX
1248
-        $headers['X-Accel-Expires'] = 0;
1249
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1250
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1251
-        return $headers;
1252
-    }
1253
-
1254
-
1255
-
1256
-    /**
1257
-     *    nocache_headers
1258
-     *
1259
-     * @access    public
1260
-     * @return    void
1261
-     */
1262
-    public static function nocache_headers()
1263
-    {
1264
-        nocache_headers();
1265
-    }
1266
-
1267
-
1268
-
1269
-    /**
1270
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1271
-     * never returned with the function.
1272
-     *
1273
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1274
-     * @return array
1275
-     */
1276
-    public function remove_pages_from_wp_list_pages($exclude_array)
1277
-    {
1278
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1279
-    }
27
+	/**
28
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
29
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
30
+	 */
31
+	const req_type_normal = 0;
32
+
33
+	/**
34
+	 * Indicates this is a brand new installation of EE so we should install
35
+	 * tables and default data etc
36
+	 */
37
+	const req_type_new_activation = 1;
38
+
39
+	/**
40
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
41
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
42
+	 * and that default data is setup too
43
+	 */
44
+	const req_type_reactivation = 2;
45
+
46
+	/**
47
+	 * indicates that EE has been upgraded since its previous request.
48
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
49
+	 */
50
+	const req_type_upgrade = 3;
51
+
52
+	/**
53
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
54
+	 */
55
+	const req_type_downgrade = 4;
56
+
57
+	/**
58
+	 * @deprecated since version 4.6.0.dev.006
59
+	 * Now whenever a new_activation is detected the request type is still just
60
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
61
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
62
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
63
+	 * (Specifically, when the migration manager indicates migrations are finished
64
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
65
+	 */
66
+	const req_type_activation_but_not_installed = 5;
67
+
68
+	/**
69
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
70
+	 */
71
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
72
+
73
+
74
+	/**
75
+	 * @var EE_System $_instance
76
+	 */
77
+	private static $_instance;
78
+
79
+	/**
80
+	 * @var EE_Registry $registry
81
+	 */
82
+	private $registry;
83
+
84
+	/**
85
+	 * @var LoaderInterface $loader
86
+	 */
87
+	private $loader;
88
+
89
+	/**
90
+	 * @var EE_Capabilities $capabilities
91
+	 */
92
+	private $capabilities;
93
+
94
+	/**
95
+	 * @var RequestInterface $request
96
+	 */
97
+	private $request;
98
+
99
+	/**
100
+	 * @var EE_Maintenance_Mode $maintenance_mode
101
+	 */
102
+	private $maintenance_mode;
103
+
104
+	/**
105
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
106
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
107
+	 *
108
+	 * @var int $_req_type
109
+	 */
110
+	private $_req_type;
111
+
112
+	/**
113
+	 * Whether or not there was a non-micro version change in EE core version during this request
114
+	 *
115
+	 * @var boolean $_major_version_change
116
+	 */
117
+	private $_major_version_change = false;
118
+
119
+	/**
120
+	 * A Context DTO dedicated solely to identifying the current request type.
121
+	 *
122
+	 * @var RequestTypeContextCheckerInterface $request_type
123
+	 */
124
+	private $request_type;
125
+
126
+
127
+
128
+	/**
129
+	 * @singleton method used to instantiate class object
130
+	 * @param EE_Registry|null         $registry
131
+	 * @param LoaderInterface|null     $loader
132
+	 * @param RequestInterface|null          $request
133
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
134
+	 * @return EE_System
135
+	 */
136
+	public static function instance(
137
+		EE_Registry $registry = null,
138
+		LoaderInterface $loader = null,
139
+		RequestInterface $request = null,
140
+		EE_Maintenance_Mode $maintenance_mode = null
141
+	) {
142
+		// check if class object is instantiated
143
+		if (! self::$_instance instanceof EE_System) {
144
+			self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
145
+		}
146
+		return self::$_instance;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * resets the instance and returns it
153
+	 *
154
+	 * @return EE_System
155
+	 */
156
+	public static function reset()
157
+	{
158
+		self::$_instance->_req_type = null;
159
+		//make sure none of the old hooks are left hanging around
160
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
161
+		//we need to reset the migration manager in order for it to detect DMSs properly
162
+		EE_Data_Migration_Manager::reset();
163
+		self::instance()->detect_activations_or_upgrades();
164
+		self::instance()->perform_activations_upgrades_and_migrations();
165
+		return self::instance();
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 * sets hooks for running rest of system
172
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
173
+	 * starting EE Addons from any other point may lead to problems
174
+	 *
175
+	 * @param EE_Registry         $registry
176
+	 * @param LoaderInterface     $loader
177
+	 * @param RequestInterface          $request
178
+	 * @param EE_Maintenance_Mode $maintenance_mode
179
+	 */
180
+	private function __construct(
181
+		EE_Registry $registry,
182
+		LoaderInterface $loader,
183
+		RequestInterface $request,
184
+		EE_Maintenance_Mode $maintenance_mode
185
+	) {
186
+		$this->registry         = $registry;
187
+		$this->loader           = $loader;
188
+		$this->request          = $request;
189
+		$this->maintenance_mode = $maintenance_mode;
190
+		do_action('AHEE__EE_System__construct__begin', $this);
191
+		add_action(
192
+			'AHEE__EE_Bootstrap__load_espresso_addons',
193
+			array($this, 'loadCapabilities'),
194
+			5
195
+		);
196
+		add_action(
197
+			'AHEE__EE_Bootstrap__load_espresso_addons',
198
+			array($this, 'loadCommandBus'),
199
+			7
200
+		);
201
+		add_action(
202
+			'AHEE__EE_Bootstrap__load_espresso_addons',
203
+			array($this, 'loadPluginApi'),
204
+			9
205
+		);
206
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
207
+		add_action(
208
+			'AHEE__EE_Bootstrap__load_espresso_addons',
209
+			array($this, 'load_espresso_addons')
210
+		);
211
+		// when an ee addon is activated, we want to call the core hook(s) again
212
+		// because the newly-activated addon didn't get a chance to run at all
213
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
214
+		// detect whether install or upgrade
215
+		add_action(
216
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
217
+			array($this, 'detect_activations_or_upgrades'),
218
+			3
219
+		);
220
+		// load EE_Config, EE_Textdomain, etc
221
+		add_action(
222
+			'AHEE__EE_Bootstrap__load_core_configuration',
223
+			array($this, 'load_core_configuration'),
224
+			5
225
+		);
226
+		// load EE_Config, EE_Textdomain, etc
227
+		add_action(
228
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
229
+			array($this, 'register_shortcodes_modules_and_widgets'),
230
+			7
231
+		);
232
+		// you wanna get going? I wanna get going... let's get going!
233
+		add_action(
234
+			'AHEE__EE_Bootstrap__brew_espresso',
235
+			array($this, 'brew_espresso'),
236
+			9
237
+		);
238
+		//other housekeeping
239
+		//exclude EE critical pages from wp_list_pages
240
+		add_filter(
241
+			'wp_list_pages_excludes',
242
+			array($this, 'remove_pages_from_wp_list_pages'),
243
+			10
244
+		);
245
+		// ALL EE Addons should use the following hook point to attach their initial setup too
246
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
247
+		do_action('AHEE__EE_System__construct__complete', $this);
248
+	}
249
+
250
+
251
+	/**
252
+	 * load and setup EE_Capabilities
253
+	 *
254
+	 * @return void
255
+	 * @throws EE_Error
256
+	 */
257
+	public function loadCapabilities()
258
+	{
259
+		$this->capabilities = $this->loader->getShared('EE_Capabilities');
260
+		add_action(
261
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
262
+			function ()
263
+			{
264
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
265
+			}
266
+		);
267
+	}
268
+
269
+
270
+
271
+	/**
272
+	 * create and cache the CommandBus, and also add middleware
273
+	 * The CapChecker middleware requires the use of EE_Capabilities
274
+	 * which is why we need to load the CommandBus after Caps are set up
275
+	 *
276
+	 * @return void
277
+	 * @throws EE_Error
278
+	 */
279
+	public function loadCommandBus()
280
+	{
281
+		$this->loader->getShared(
282
+			'CommandBusInterface',
283
+			array(
284
+				null,
285
+				apply_filters(
286
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
287
+					array(
288
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
289
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
290
+					)
291
+				),
292
+			)
293
+		);
294
+	}
295
+
296
+
297
+
298
+	/**
299
+	 * @return void
300
+	 * @throws EE_Error
301
+	 */
302
+	public function loadPluginApi()
303
+	{
304
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
305
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
306
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
307
+		$this->loader->getShared('EE_Request_Handler');
308
+	}
309
+
310
+
311
+	/**
312
+	 * @param string $addon_name
313
+	 * @param string $version_constant
314
+	 * @param string $min_version_required
315
+	 * @param string $load_callback
316
+	 * @param string $plugin_file_constant
317
+	 * @return void
318
+	 */
319
+	private function deactivateIncompatibleAddon(
320
+		$addon_name,
321
+		$version_constant,
322
+		$min_version_required,
323
+		$load_callback,
324
+		$plugin_file_constant
325
+	) {
326
+		if (! defined($version_constant)) {
327
+			return;
328
+		}
329
+		$addon_version = constant($version_constant);
330
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
331
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
332
+			if (! function_exists('deactivate_plugins')) {
333
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
334
+			}
335
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
336
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
337
+			EE_Error::add_error(
338
+				sprintf(
339
+					esc_html__(
340
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
341
+						'event_espresso'
342
+					),
343
+					$addon_name,
344
+					$min_version_required
345
+				),
346
+				__FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
347
+			);
348
+			EE_Error::get_notices(false, true);
349
+		}
350
+	}
351
+
352
+
353
+	/**
354
+	 * load_espresso_addons
355
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
356
+	 * this is hooked into both:
357
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
358
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
359
+	 *    and the WP 'activate_plugin' hook point
360
+	 *
361
+	 * @access public
362
+	 * @return void
363
+	 */
364
+	public function load_espresso_addons()
365
+	{
366
+		$this->deactivateIncompatibleAddon(
367
+			'Wait Lists',
368
+			'EE_WAIT_LISTS_VERSION',
369
+			'1.0.0.beta.074',
370
+			'load_espresso_wait_lists',
371
+			'EE_WAIT_LISTS_PLUGIN_FILE'
372
+		);
373
+		$this->deactivateIncompatibleAddon(
374
+			'Automated Upcoming Event Notifications',
375
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
376
+			'1.0.0.beta.091',
377
+			'load_espresso_automated_upcoming_event_notification',
378
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
379
+		);
380
+		do_action('AHEE__EE_System__load_espresso_addons');
381
+		//if the WP API basic auth plugin isn't already loaded, load it now.
382
+		//We want it for mobile apps. Just include the entire plugin
383
+		//also, don't load the basic auth when a plugin is getting activated, because
384
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
385
+		//and causes a fatal error
386
+		if (
387
+			$this->request->getRequestParam('activate') !== 'true'
388
+			&& ! function_exists('json_basic_auth_handler')
389
+			&& ! function_exists('json_basic_auth_error')
390
+			&& ! in_array(
391
+				$this->request->getRequestParam('action'),
392
+				array('activate', 'activate-selected'),
393
+				true
394
+			)
395
+		) {
396
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
397
+		}
398
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * detect_activations_or_upgrades
405
+	 * Checks for activation or upgrade of core first;
406
+	 * then also checks if any registered addons have been activated or upgraded
407
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
408
+	 * which runs during the WP 'plugins_loaded' action at priority 3
409
+	 *
410
+	 * @access public
411
+	 * @return void
412
+	 */
413
+	public function detect_activations_or_upgrades()
414
+	{
415
+		//first off: let's make sure to handle core
416
+		$this->detect_if_activation_or_upgrade();
417
+		foreach ($this->registry->addons as $addon) {
418
+			if ($addon instanceof EE_Addon) {
419
+				//detect teh request type for that addon
420
+				$addon->detect_activation_or_upgrade();
421
+			}
422
+		}
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 * detect_if_activation_or_upgrade
429
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
430
+	 * and either setting up the DB or setting up maintenance mode etc.
431
+	 *
432
+	 * @access public
433
+	 * @return void
434
+	 */
435
+	public function detect_if_activation_or_upgrade()
436
+	{
437
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
438
+		// check if db has been updated, or if its a brand-new installation
439
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
440
+		$request_type       = $this->detect_req_type($espresso_db_update);
441
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
442
+		switch ($request_type) {
443
+			case EE_System::req_type_new_activation:
444
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
445
+				$this->_handle_core_version_change($espresso_db_update);
446
+				break;
447
+			case EE_System::req_type_reactivation:
448
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
449
+				$this->_handle_core_version_change($espresso_db_update);
450
+				break;
451
+			case EE_System::req_type_upgrade:
452
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
453
+				//migrations may be required now that we've upgraded
454
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
455
+				$this->_handle_core_version_change($espresso_db_update);
456
+				//				echo "done upgrade";die;
457
+				break;
458
+			case EE_System::req_type_downgrade:
459
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
460
+				//its possible migrations are no longer required
461
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
462
+				$this->_handle_core_version_change($espresso_db_update);
463
+				break;
464
+			case EE_System::req_type_normal:
465
+			default:
466
+				break;
467
+		}
468
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
469
+	}
470
+
471
+
472
+
473
+	/**
474
+	 * Updates the list of installed versions and sets hooks for
475
+	 * initializing the database later during the request
476
+	 *
477
+	 * @param array $espresso_db_update
478
+	 */
479
+	private function _handle_core_version_change($espresso_db_update)
480
+	{
481
+		$this->update_list_of_installed_versions($espresso_db_update);
482
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
483
+		add_action(
484
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
485
+			array($this, 'initialize_db_if_no_migrations_required')
486
+		);
487
+	}
488
+
489
+
490
+
491
+	/**
492
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
493
+	 * information about what versions of EE have been installed and activated,
494
+	 * NOT necessarily the state of the database
495
+	 *
496
+	 * @param mixed $espresso_db_update           the value of the WordPress option.
497
+	 *                                            If not supplied, fetches it from the options table
498
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
499
+	 */
500
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
501
+	{
502
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
+		if (! $espresso_db_update) {
504
+			$espresso_db_update = get_option('espresso_db_update');
505
+		}
506
+		// check that option is an array
507
+		if (! is_array($espresso_db_update)) {
508
+			// if option is FALSE, then it never existed
509
+			if ($espresso_db_update === false) {
510
+				// make $espresso_db_update an array and save option with autoload OFF
511
+				$espresso_db_update = array();
512
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
513
+			} else {
514
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
515
+				$espresso_db_update = array($espresso_db_update => array());
516
+				update_option('espresso_db_update', $espresso_db_update);
517
+			}
518
+		} else {
519
+			$corrected_db_update = array();
520
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
521
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
522
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
523
+					//the key is an int, and the value IS NOT an array
524
+					//so it must be numerically-indexed, where values are versions installed...
525
+					//fix it!
526
+					$version_string                         = $should_be_array;
527
+					$corrected_db_update[ $version_string ] = array('unknown-date');
528
+				} else {
529
+					//ok it checks out
530
+					$corrected_db_update[ $should_be_version_string ] = $should_be_array;
531
+				}
532
+			}
533
+			$espresso_db_update = $corrected_db_update;
534
+			update_option('espresso_db_update', $espresso_db_update);
535
+		}
536
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
537
+		return $espresso_db_update;
538
+	}
539
+
540
+
541
+
542
+	/**
543
+	 * Does the traditional work of setting up the plugin's database and adding default data.
544
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
545
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
546
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
547
+	 * so that it will be done when migrations are finished
548
+	 *
549
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
550
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
551
+	 *                                       This is a resource-intensive job
552
+	 *                                       so we prefer to only do it when necessary
553
+	 * @return void
554
+	 * @throws EE_Error
555
+	 */
556
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
557
+	{
558
+		$request_type = $this->detect_req_type();
559
+		//only initialize system if we're not in maintenance mode.
560
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
561
+			update_option('ee_flush_rewrite_rules', true);
562
+			if ($verify_schema) {
563
+				EEH_Activation::initialize_db_and_folders();
564
+			}
565
+			EEH_Activation::initialize_db_content();
566
+			EEH_Activation::system_initialization();
567
+			if ($initialize_addons_too) {
568
+				$this->initialize_addons();
569
+			}
570
+		} else {
571
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
572
+		}
573
+		if ($request_type === EE_System::req_type_new_activation
574
+			|| $request_type === EE_System::req_type_reactivation
575
+			|| (
576
+				$request_type === EE_System::req_type_upgrade
577
+				&& $this->is_major_version_change()
578
+			)
579
+		) {
580
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
581
+		}
582
+	}
583
+
584
+
585
+
586
+	/**
587
+	 * Initializes the db for all registered addons
588
+	 *
589
+	 * @throws EE_Error
590
+	 */
591
+	public function initialize_addons()
592
+	{
593
+		//foreach registered addon, make sure its db is up-to-date too
594
+		foreach ($this->registry->addons as $addon) {
595
+			if ($addon instanceof EE_Addon) {
596
+				$addon->initialize_db_if_no_migrations_required();
597
+			}
598
+		}
599
+	}
600
+
601
+
602
+
603
+	/**
604
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
605
+	 *
606
+	 * @param    array  $version_history
607
+	 * @param    string $current_version_to_add version to be added to the version history
608
+	 * @return    boolean success as to whether or not this option was changed
609
+	 */
610
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
611
+	{
612
+		if (! $version_history) {
613
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
614
+		}
615
+		if ($current_version_to_add === null) {
616
+			$current_version_to_add = espresso_version();
617
+		}
618
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
619
+		// re-save
620
+		return update_option('espresso_db_update', $version_history);
621
+	}
622
+
623
+
624
+
625
+	/**
626
+	 * Detects if the current version indicated in the has existed in the list of
627
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
628
+	 *
629
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
630
+	 *                                  If not supplied, fetches it from the options table.
631
+	 *                                  Also, caches its result so later parts of the code can also know whether
632
+	 *                                  there's been an update or not. This way we can add the current version to
633
+	 *                                  espresso_db_update, but still know if this is a new install or not
634
+	 * @return int one of the constants on EE_System::req_type_
635
+	 */
636
+	public function detect_req_type($espresso_db_update = null)
637
+	{
638
+		if ($this->_req_type === null) {
639
+			$espresso_db_update          = ! empty($espresso_db_update)
640
+				? $espresso_db_update
641
+				: $this->fix_espresso_db_upgrade_option();
642
+			$this->_req_type             = EE_System::detect_req_type_given_activation_history(
643
+				$espresso_db_update,
644
+				'ee_espresso_activation', espresso_version()
645
+			);
646
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
647
+			$this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
648
+		}
649
+		return $this->_req_type;
650
+	}
651
+
652
+
653
+
654
+	/**
655
+	 * Returns whether or not there was a non-micro version change (ie, change in either
656
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
657
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
658
+	 *
659
+	 * @param $activation_history
660
+	 * @return bool
661
+	 */
662
+	private function _detect_major_version_change($activation_history)
663
+	{
664
+		$previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
665
+		$previous_version_parts = explode('.', $previous_version);
666
+		$current_version_parts  = explode('.', espresso_version());
667
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
668
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
669
+				   || $previous_version_parts[1] !== $current_version_parts[1]
670
+			   );
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 * Returns true if either the major or minor version of EE changed during this request.
677
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
678
+	 *
679
+	 * @return bool
680
+	 */
681
+	public function is_major_version_change()
682
+	{
683
+		return $this->_major_version_change;
684
+	}
685
+
686
+
687
+
688
+	/**
689
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
690
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
691
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
692
+	 * just activated to (for core that will always be espresso_version())
693
+	 *
694
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
695
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
696
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
697
+	 *                                                 indicate that this plugin was just activated
698
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
699
+	 *                                                 espresso_version())
700
+	 * @return int one of the constants on EE_System::req_type_*
701
+	 */
702
+	public static function detect_req_type_given_activation_history(
703
+		$activation_history_for_addon,
704
+		$activation_indicator_option_name,
705
+		$version_to_upgrade_to
706
+	) {
707
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
708
+		if ($activation_history_for_addon) {
709
+			//it exists, so this isn't a completely new install
710
+			//check if this version already in that list of previously installed versions
711
+			if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
712
+				//it a version we haven't seen before
713
+				if ($version_is_higher === 1) {
714
+					$req_type = EE_System::req_type_upgrade;
715
+				} else {
716
+					$req_type = EE_System::req_type_downgrade;
717
+				}
718
+				delete_option($activation_indicator_option_name);
719
+			} else {
720
+				// its not an update. maybe a reactivation?
721
+				if (get_option($activation_indicator_option_name, false)) {
722
+					if ($version_is_higher === -1) {
723
+						$req_type = EE_System::req_type_downgrade;
724
+					} elseif ($version_is_higher === 0) {
725
+						//we've seen this version before, but it's an activation. must be a reactivation
726
+						$req_type = EE_System::req_type_reactivation;
727
+					} else {//$version_is_higher === 1
728
+						$req_type = EE_System::req_type_upgrade;
729
+					}
730
+					delete_option($activation_indicator_option_name);
731
+				} else {
732
+					//we've seen this version before and the activation indicate doesn't show it was just activated
733
+					if ($version_is_higher === -1) {
734
+						$req_type = EE_System::req_type_downgrade;
735
+					} elseif ($version_is_higher === 0) {
736
+						//we've seen this version before and it's not an activation. its normal request
737
+						$req_type = EE_System::req_type_normal;
738
+					} else {//$version_is_higher === 1
739
+						$req_type = EE_System::req_type_upgrade;
740
+					}
741
+				}
742
+			}
743
+		} else {
744
+			//brand new install
745
+			$req_type = EE_System::req_type_new_activation;
746
+			delete_option($activation_indicator_option_name);
747
+		}
748
+		return $req_type;
749
+	}
750
+
751
+
752
+
753
+	/**
754
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
755
+	 * the $activation_history_for_addon
756
+	 *
757
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
758
+	 *                                             sometimes containing 'unknown-date'
759
+	 * @param string $version_to_upgrade_to        (current version)
760
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
761
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
762
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
763
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
764
+	 */
765
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
766
+	{
767
+		//find the most recently-activated version
768
+		$most_recently_active_version =
769
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
770
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
771
+	}
772
+
773
+
774
+
775
+	/**
776
+	 * Gets the most recently active version listed in the activation history,
777
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
778
+	 *
779
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
780
+	 *                                   sometimes containing 'unknown-date'
781
+	 * @return string
782
+	 */
783
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
784
+	{
785
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
786
+		$most_recently_active_version            = '0.0.0.dev.000';
787
+		if (is_array($activation_history)) {
788
+			foreach ($activation_history as $version => $times_activated) {
789
+				//check there is a record of when this version was activated. Otherwise,
790
+				//mark it as unknown
791
+				if (! $times_activated) {
792
+					$times_activated = array('unknown-date');
793
+				}
794
+				if (is_string($times_activated)) {
795
+					$times_activated = array($times_activated);
796
+				}
797
+				foreach ($times_activated as $an_activation) {
798
+					if ($an_activation !== 'unknown-date'
799
+						&& $an_activation
800
+						   > $most_recently_active_version_activation) {
801
+						$most_recently_active_version            = $version;
802
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
803
+							? '1970-01-01 00:00:00'
804
+							: $an_activation;
805
+					}
806
+				}
807
+			}
808
+		}
809
+		return $most_recently_active_version;
810
+	}
811
+
812
+
813
+
814
+	/**
815
+	 * This redirects to the about EE page after activation
816
+	 *
817
+	 * @return void
818
+	 */
819
+	public function redirect_to_about_ee()
820
+	{
821
+		$notices = EE_Error::get_notices(false);
822
+		//if current user is an admin and it's not an ajax or rest request
823
+		if (
824
+			! isset($notices['errors'])
825
+			&& $this->request->isAdmin()
826
+			&& apply_filters(
827
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
828
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
829
+			)
830
+		) {
831
+			$query_params = array('page' => 'espresso_about');
832
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
833
+				$query_params['new_activation'] = true;
834
+			}
835
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
836
+				$query_params['reactivation'] = true;
837
+			}
838
+			$url = add_query_arg($query_params, admin_url('admin.php'));
839
+			wp_safe_redirect($url);
840
+			exit();
841
+		}
842
+	}
843
+
844
+
845
+
846
+	/**
847
+	 * load_core_configuration
848
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
849
+	 * which runs during the WP 'plugins_loaded' action at priority 5
850
+	 *
851
+	 * @return void
852
+	 * @throws ReflectionException
853
+	 */
854
+	public function load_core_configuration()
855
+	{
856
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
857
+		$this->loader->getShared('EE_Load_Textdomain');
858
+		//load textdomain
859
+		EE_Load_Textdomain::load_textdomain();
860
+		// load and setup EE_Config and EE_Network_Config
861
+		$config = $this->loader->getShared('EE_Config');
862
+		$this->loader->getShared('EE_Network_Config');
863
+		// setup autoloaders
864
+		// enable logging?
865
+		if ($config->admin->use_full_logging) {
866
+			$this->loader->getShared('EE_Log');
867
+		}
868
+		// check for activation errors
869
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
870
+		if ($activation_errors) {
871
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
872
+			update_option('ee_plugin_activation_errors', false);
873
+		}
874
+		// get model names
875
+		$this->_parse_model_names();
876
+		//load caf stuff a chance to play during the activation process too.
877
+		$this->_maybe_brew_regular();
878
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
879
+	}
880
+
881
+
882
+
883
+	/**
884
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
885
+	 *
886
+	 * @return void
887
+	 * @throws ReflectionException
888
+	 */
889
+	private function _parse_model_names()
890
+	{
891
+		//get all the files in the EE_MODELS folder that end in .model.php
892
+		$models                 = glob(EE_MODELS . '*.model.php');
893
+		$model_names            = array();
894
+		$non_abstract_db_models = array();
895
+		foreach ($models as $model) {
896
+			// get model classname
897
+			$classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
898
+			$short_name      = str_replace('EEM_', '', $classname);
899
+			$reflectionClass = new ReflectionClass($classname);
900
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
901
+				$non_abstract_db_models[ $short_name ] = $classname;
902
+			}
903
+			$model_names[ $short_name ] = $classname;
904
+		}
905
+		$this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
906
+		$this->registry->non_abstract_db_models = apply_filters(
907
+			'FHEE__EE_System__parse_implemented_model_names',
908
+			$non_abstract_db_models
909
+		);
910
+	}
911
+
912
+
913
+
914
+	/**
915
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
916
+	 * that need to be setup before our EE_System launches.
917
+	 *
918
+	 * @return void
919
+	 */
920
+	private function _maybe_brew_regular()
921
+	{
922
+		if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
923
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
924
+		}
925
+	}
926
+
927
+
928
+
929
+	/**
930
+	 * register_shortcodes_modules_and_widgets
931
+	 * generate lists of shortcodes and modules, then verify paths and classes
932
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
933
+	 * which runs during the WP 'plugins_loaded' action at priority 7
934
+	 *
935
+	 * @access public
936
+	 * @return void
937
+	 * @throws Exception
938
+	 */
939
+	public function register_shortcodes_modules_and_widgets()
940
+	{
941
+		if ($this->request->isFrontend() || $this->request->isIframe()) {
942
+			try {
943
+				// load, register, and add shortcodes the new way
944
+				$this->loader->getShared(
945
+					'EventEspresso\core\services\shortcodes\ShortcodesManager',
946
+					array(
947
+						// and the old way, but we'll put it under control of the new system
948
+						EE_Config::getLegacyShortcodesManager(),
949
+					)
950
+				);
951
+			} catch (Exception $exception) {
952
+				new ExceptionStackTraceDisplay($exception);
953
+			}
954
+		}
955
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
956
+		// check for addons using old hook point
957
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
958
+			$this->_incompatible_addon_error();
959
+		}
960
+	}
961
+
962
+
963
+
964
+	/**
965
+	 * _incompatible_addon_error
966
+	 *
967
+	 * @access public
968
+	 * @return void
969
+	 */
970
+	private function _incompatible_addon_error()
971
+	{
972
+		// get array of classes hooking into here
973
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
974
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
975
+		);
976
+		if (! empty($class_names)) {
977
+			$msg = __(
978
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
979
+				'event_espresso'
980
+			);
981
+			$msg .= '<ul>';
982
+			foreach ($class_names as $class_name) {
983
+				$msg .= '<li><b>Event Espresso - ' . str_replace(
984
+						array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
985
+						$class_name
986
+					) . '</b></li>';
987
+			}
988
+			$msg .= '</ul>';
989
+			$msg .= __(
990
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
991
+				'event_espresso'
992
+			);
993
+			// save list of incompatible addons to wp-options for later use
994
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
995
+			if (is_admin()) {
996
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
997
+			}
998
+		}
999
+	}
1000
+
1001
+
1002
+
1003
+	/**
1004
+	 * brew_espresso
1005
+	 * begins the process of setting hooks for initializing EE in the correct order
1006
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1007
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1008
+	 *
1009
+	 * @return void
1010
+	 */
1011
+	public function brew_espresso()
1012
+	{
1013
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1014
+		// load some final core systems
1015
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
1016
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1017
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
1018
+		add_action('init', array($this, 'load_controllers'), 7);
1019
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
1020
+		add_action('init', array($this, 'initialize'), 10);
1021
+		add_action('init', array($this, 'initialize_last'), 100);
1022
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1023
+			// pew pew pew
1024
+			$this->loader->getShared('EE_PUE');
1025
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1026
+		}
1027
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1028
+	}
1029
+
1030
+
1031
+
1032
+	/**
1033
+	 *    set_hooks_for_core
1034
+	 *
1035
+	 * @access public
1036
+	 * @return    void
1037
+	 * @throws EE_Error
1038
+	 */
1039
+	public function set_hooks_for_core()
1040
+	{
1041
+		$this->_deactivate_incompatible_addons();
1042
+		do_action('AHEE__EE_System__set_hooks_for_core');
1043
+		//caps need to be initialized on every request so that capability maps are set.
1044
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1045
+		$this->registry->CAP->init_caps();
1046
+	}
1047
+
1048
+
1049
+
1050
+	/**
1051
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1052
+	 * deactivates any addons considered incompatible with the current version of EE
1053
+	 */
1054
+	private function _deactivate_incompatible_addons()
1055
+	{
1056
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
1057
+		if (! empty($incompatible_addons)) {
1058
+			$active_plugins = get_option('active_plugins', array());
1059
+			foreach ($active_plugins as $active_plugin) {
1060
+				foreach ($incompatible_addons as $incompatible_addon) {
1061
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1062
+						unset($_GET['activate']);
1063
+						espresso_deactivate_plugin($active_plugin);
1064
+					}
1065
+				}
1066
+			}
1067
+		}
1068
+	}
1069
+
1070
+
1071
+
1072
+	/**
1073
+	 *    perform_activations_upgrades_and_migrations
1074
+	 *
1075
+	 * @access public
1076
+	 * @return    void
1077
+	 */
1078
+	public function perform_activations_upgrades_and_migrations()
1079
+	{
1080
+		//first check if we had previously attempted to setup EE's directories but failed
1081
+		if ($this->request->isActivation() && EEH_Activation::upload_directories_incomplete()) {
1082
+			EEH_Activation::create_upload_directories();
1083
+		}
1084
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1085
+	}
1086
+
1087
+
1088
+
1089
+	/**
1090
+	 *    load_CPTs_and_session
1091
+	 *
1092
+	 * @access public
1093
+	 * @return    void
1094
+	 */
1095
+	public function load_CPTs_and_session()
1096
+	{
1097
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1098
+		// register Custom Post Types
1099
+		$this->loader->getShared('EE_Register_CPTs');
1100
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1101
+	}
1102
+
1103
+
1104
+
1105
+	/**
1106
+	 * load_controllers
1107
+	 * this is the best place to load any additional controllers that needs access to EE core.
1108
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1109
+	 * time
1110
+	 *
1111
+	 * @access public
1112
+	 * @return void
1113
+	 */
1114
+	public function load_controllers()
1115
+	{
1116
+		do_action('AHEE__EE_System__load_controllers__start');
1117
+		// let's get it started
1118
+		if (
1119
+			! $this->maintenance_mode->level()
1120
+			&& ($this->request->isFrontend() || $this->request->isFrontAjax())
1121
+		) {
1122
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1123
+			$this->loader->getShared('EE_Front_Controller');
1124
+		} elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1125
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1126
+			$this->loader->getShared('EE_Admin');
1127
+		}
1128
+		do_action('AHEE__EE_System__load_controllers__complete');
1129
+	}
1130
+
1131
+
1132
+
1133
+	/**
1134
+	 * core_loaded_and_ready
1135
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1136
+	 *
1137
+	 * @access public
1138
+	 * @return void
1139
+	 */
1140
+	public function core_loaded_and_ready()
1141
+	{
1142
+		if (
1143
+			$this->request->isAdmin()
1144
+			|| $this->request->isEeAjax()
1145
+			|| $this->request->isFrontend()
1146
+		) {
1147
+			$this->loader->getShared('EE_Session');
1148
+		}
1149
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1150
+		// load_espresso_template_tags
1151
+		if (
1152
+			is_readable(EE_PUBLIC . 'template_tags.php')
1153
+			&& ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isFeed())
1154
+		) {
1155
+			require_once EE_PUBLIC . 'template_tags.php';
1156
+		}
1157
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1158
+		if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1159
+			$this->loader->getShared('EventEspresso\core\services\assets\Registry');
1160
+		}
1161
+	}
1162
+
1163
+
1164
+
1165
+	/**
1166
+	 * initialize
1167
+	 * this is the best place to begin initializing client code
1168
+	 *
1169
+	 * @access public
1170
+	 * @return void
1171
+	 */
1172
+	public function initialize()
1173
+	{
1174
+		do_action('AHEE__EE_System__initialize');
1175
+	}
1176
+
1177
+
1178
+
1179
+	/**
1180
+	 * initialize_last
1181
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1182
+	 * initialize has done so
1183
+	 *
1184
+	 * @access public
1185
+	 * @return void
1186
+	 */
1187
+	public function initialize_last()
1188
+	{
1189
+		do_action('AHEE__EE_System__initialize_last');
1190
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1191
+	}
1192
+
1193
+
1194
+
1195
+	/**
1196
+	 * @return void
1197
+	 * @throws EE_Error
1198
+	 */
1199
+	public function addEspressoToolbar()
1200
+	{
1201
+		$this->loader->getShared(
1202
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1203
+			array($this->registry->CAP)
1204
+		);
1205
+	}
1206
+
1207
+
1208
+
1209
+	/**
1210
+	 * do_not_cache
1211
+	 * sets no cache headers and defines no cache constants for WP plugins
1212
+	 *
1213
+	 * @access public
1214
+	 * @return void
1215
+	 */
1216
+	public static function do_not_cache()
1217
+	{
1218
+		// set no cache constants
1219
+		if (! defined('DONOTCACHEPAGE')) {
1220
+			define('DONOTCACHEPAGE', true);
1221
+		}
1222
+		if (! defined('DONOTCACHCEOBJECT')) {
1223
+			define('DONOTCACHCEOBJECT', true);
1224
+		}
1225
+		if (! defined('DONOTCACHEDB')) {
1226
+			define('DONOTCACHEDB', true);
1227
+		}
1228
+		// add no cache headers
1229
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1230
+		// plus a little extra for nginx and Google Chrome
1231
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1232
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1233
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1234
+	}
1235
+
1236
+
1237
+
1238
+	/**
1239
+	 *    extra_nocache_headers
1240
+	 *
1241
+	 * @access    public
1242
+	 * @param $headers
1243
+	 * @return    array
1244
+	 */
1245
+	public static function extra_nocache_headers($headers)
1246
+	{
1247
+		// for NGINX
1248
+		$headers['X-Accel-Expires'] = 0;
1249
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1250
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1251
+		return $headers;
1252
+	}
1253
+
1254
+
1255
+
1256
+	/**
1257
+	 *    nocache_headers
1258
+	 *
1259
+	 * @access    public
1260
+	 * @return    void
1261
+	 */
1262
+	public static function nocache_headers()
1263
+	{
1264
+		nocache_headers();
1265
+	}
1266
+
1267
+
1268
+
1269
+	/**
1270
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1271
+	 * never returned with the function.
1272
+	 *
1273
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1274
+	 * @return array
1275
+	 */
1276
+	public function remove_pages_from_wp_list_pages($exclude_array)
1277
+	{
1278
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1279
+	}
1280 1280
 
1281 1281
 
1282 1282
 
Please login to merge, or discard this patch.