Completed
Branch BUG/pantheon-session-fatal-2 (dc6a1f)
by
unknown
199:51 queued 131:59
created
core/libraries/rest_api/controllers/model/Read.php 2 patches
Indentation   +1346 added lines, -1346 removed lines patch added patch discarded remove patch
@@ -40,1350 +40,1350 @@
 block discarded – undo
40 40
 {
41 41
 
42 42
 
43
-    /**
44
-     * @var CalculatedModelFields
45
-     */
46
-    protected $fields_calculator;
47
-
48
-
49
-    /**
50
-     * Read constructor.
51
-     * @param CalculatedModelFields $fields_calculator
52
-     */
53
-    public function __construct(CalculatedModelFields $fields_calculator)
54
-    {
55
-        parent::__construct();
56
-        $this->fields_calculator = $fields_calculator;
57
-    }
58
-
59
-
60
-    /**
61
-     * Handles requests to get all (or a filtered subset) of entities for a particular model
62
-     *
63
-     * @param WP_REST_Request $request
64
-     * @param string $version
65
-     * @param string $model_name
66
-     * @return WP_REST_Response|WP_Error
67
-     * @throws InvalidArgumentException
68
-     * @throws InvalidDataTypeException
69
-     * @throws InvalidInterfaceException
70
-     */
71
-    public static function handleRequestGetAll(WP_REST_Request $request, $version, $model_name)
72
-    {
73
-        $controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read');
74
-        try {
75
-            $controller->setRequestedVersion($version);
76
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
77
-                return $controller->sendResponse(
78
-                    new WP_Error(
79
-                        'endpoint_parsing_error',
80
-                        sprintf(
81
-                            __(
82
-                                'There is no model for endpoint %s. Please contact event espresso support',
83
-                                'event_espresso'
84
-                            ),
85
-                            $model_name
86
-                        )
87
-                    )
88
-                );
89
-            }
90
-            return $controller->sendResponse(
91
-                $controller->getEntitiesFromModel(
92
-                    $controller->getModelVersionInfo()->loadModel($model_name),
93
-                    $request
94
-                )
95
-            );
96
-        } catch (Exception $e) {
97
-            return $controller->sendResponse($e);
98
-        }
99
-    }
100
-
101
-
102
-    /**
103
-     * Prepares and returns schema for any OPTIONS request.
104
-     *
105
-     * @param string $version The API endpoint version being used.
106
-     * @param string $model_name Something like `Event` or `Registration`
107
-     * @return array
108
-     * @throws InvalidArgumentException
109
-     * @throws InvalidDataTypeException
110
-     * @throws InvalidInterfaceException
111
-     */
112
-    public static function handleSchemaRequest($version, $model_name)
113
-    {
114
-        $controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read');
115
-        try {
116
-            $controller->setRequestedVersion($version);
117
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
118
-                return array();
119
-            }
120
-            // get the model for this version
121
-            $model = $controller->getModelVersionInfo()->loadModel($model_name);
122
-            $model_schema = new JsonModelSchema($model, LoaderFactory::getLoader()->getShared('EventEspresso\core\libraries\rest_api\CalculatedModelFields'));
123
-            return $model_schema->getModelSchemaForRelations(
124
-                $controller->getModelVersionInfo()->relationSettings($model),
125
-                $controller->customizeSchemaForRestResponse(
126
-                    $model,
127
-                    $model_schema->getModelSchemaForFields(
128
-                        $controller->getModelVersionInfo()->fieldsOnModelInThisVersion($model),
129
-                        $model_schema->getInitialSchemaStructure()
130
-                    )
131
-                )
132
-            );
133
-        } catch (Exception $e) {
134
-            return array();
135
-        }
136
-    }
137
-
138
-
139
-    /**
140
-     * This loops through each field in the given schema for the model and does the following:
141
-     * - add any extra fields that are REST API specific and related to existing fields.
142
-     * - transform default values into the correct format for a REST API response.
143
-     *
144
-     * @param EEM_Base $model
145
-     * @param array    $schema
146
-     * @return array  The final schema.
147
-     */
148
-    protected function customizeSchemaForRestResponse(EEM_Base $model, array $schema)
149
-    {
150
-        foreach ($this->getModelVersionInfo()->fieldsOnModelInThisVersion($model) as $field_name => $field) {
151
-            $schema = $this->translateDefaultsForRestResponse(
152
-                $field_name,
153
-                $field,
154
-                $this->maybeAddExtraFieldsToSchema($field_name, $field, $schema)
155
-            );
156
-        }
157
-        return $schema;
158
-    }
159
-
160
-
161
-    /**
162
-     * This is used to ensure that the 'default' value set in the schema response is formatted correctly for the REST
163
-     * response.
164
-     *
165
-     * @param                      $field_name
166
-     * @param EE_Model_Field_Base  $field
167
-     * @param array                $schema
168
-     * @return array
169
-     * @throws ObjectDetectedException if a default value has a PHP object, which should never do (and if we
170
-     * did, let's know about it ASAP, so let the exception bubble up)
171
-     */
172
-    protected function translateDefaultsForRestResponse($field_name, EE_Model_Field_Base $field, array $schema)
173
-    {
174
-        if (isset($schema['properties'][ $field_name ]['default'])) {
175
-            if (is_array($schema['properties'][ $field_name ]['default'])) {
176
-                foreach ($schema['properties'][ $field_name ]['default'] as $default_key => $default_value) {
177
-                    if ($default_key === 'raw') {
178
-                        $schema['properties'][ $field_name ]['default'][ $default_key ] =
179
-                            ModelDataTranslator::prepareFieldValueForJson(
180
-                                $field,
181
-                                $default_value,
182
-                                $this->getModelVersionInfo()->requestedVersion()
183
-                            );
184
-                    }
185
-                }
186
-            } else {
187
-                $schema['properties'][ $field_name ]['default'] = ModelDataTranslator::prepareFieldValueForJson(
188
-                    $field,
189
-                    $schema['properties'][ $field_name ]['default'],
190
-                    $this->getModelVersionInfo()->requestedVersion()
191
-                );
192
-            }
193
-        }
194
-        return $schema;
195
-    }
196
-
197
-
198
-    /**
199
-     * Adds additional fields to the schema
200
-     * The REST API returns a GMT value field for each datetime field in the resource.  Thus the description about this
201
-     * needs to be added to the schema.
202
-     *
203
-     * @param                      $field_name
204
-     * @param EE_Model_Field_Base  $field
205
-     * @param array                $schema
206
-     * @return array
207
-     */
208
-    protected function maybeAddExtraFieldsToSchema($field_name, EE_Model_Field_Base $field, array $schema)
209
-    {
210
-        if ($field instanceof EE_Datetime_Field) {
211
-            $schema['properties'][ $field_name . '_gmt' ] = $field->getSchema();
212
-            // modify the description
213
-            $schema['properties'][ $field_name . '_gmt' ]['description'] = sprintf(
214
-                esc_html__('%s - the value for this field is in GMT.', 'event_espresso'),
215
-                wp_specialchars_decode($field->get_nicename(), ENT_QUOTES)
216
-            );
217
-        }
218
-        return $schema;
219
-    }
220
-
221
-
222
-    /**
223
-     * Used to figure out the route from the request when a `WP_REST_Request` object is not available
224
-     *
225
-     * @return string
226
-     */
227
-    protected function getRouteFromRequest()
228
-    {
229
-        if (isset($GLOBALS['wp'])
230
-            && $GLOBALS['wp'] instanceof \WP
231
-            && isset($GLOBALS['wp']->query_vars['rest_route'])
232
-        ) {
233
-            return $GLOBALS['wp']->query_vars['rest_route'];
234
-        } else {
235
-            return isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/';
236
-        }
237
-    }
238
-
239
-
240
-    /**
241
-     * Gets a single entity related to the model indicated in the path and its id
242
-     *
243
-     * @param WP_REST_Request $request
244
-     * @param string $version
245
-     * @param string $model_name
246
-     * @return WP_REST_Response|WP_Error
247
-     * @throws InvalidDataTypeException
248
-     * @throws InvalidInterfaceException
249
-     * @throws InvalidArgumentException
250
-     */
251
-    public static function handleRequestGetOne(WP_REST_Request $request, $version, $model_name)
252
-    {
253
-        $controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read');
254
-        try {
255
-            $controller->setRequestedVersion($version);
256
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
257
-                return $controller->sendResponse(
258
-                    new WP_Error(
259
-                        'endpoint_parsing_error',
260
-                        sprintf(
261
-                            __(
262
-                                'There is no model for endpoint %s. Please contact event espresso support',
263
-                                'event_espresso'
264
-                            ),
265
-                            $model_name
266
-                        )
267
-                    )
268
-                );
269
-            }
270
-            return $controller->sendResponse(
271
-                $controller->getEntityFromModel(
272
-                    $controller->getModelVersionInfo()->loadModel($model_name),
273
-                    $request
274
-                )
275
-            );
276
-        } catch (Exception $e) {
277
-            return $controller->sendResponse($e);
278
-        }
279
-    }
280
-
281
-
282
-    /**
283
-     * Gets all the related entities (or if its a belongs-to relation just the one)
284
-     * to the item with the given id
285
-     *
286
-     * @param WP_REST_Request $request
287
-     * @param string $version
288
-     * @param string $model_name
289
-     * @param string $related_model_name
290
-     * @return WP_REST_Response|WP_Error
291
-     * @throws InvalidDataTypeException
292
-     * @throws InvalidInterfaceException
293
-     * @throws InvalidArgumentException
294
-     */
295
-    public static function handleRequestGetRelated(
296
-        WP_REST_Request $request,
297
-        $version,
298
-        $model_name,
299
-        $related_model_name
300
-    ) {
301
-        $controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read');
302
-        try {
303
-            $controller->setRequestedVersion($version);
304
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
305
-                return $controller->sendResponse(
306
-                    new WP_Error(
307
-                        'endpoint_parsing_error',
308
-                        sprintf(
309
-                            __(
310
-                                'There is no model for endpoint %s. Please contact event espresso support',
311
-                                'event_espresso'
312
-                            ),
313
-                            $model_name
314
-                        )
315
-                    )
316
-                );
317
-            }
318
-            $main_model = $controller->getModelVersionInfo()->loadModel($model_name);
319
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($related_model_name)) {
320
-                return $controller->sendResponse(
321
-                    new WP_Error(
322
-                        'endpoint_parsing_error',
323
-                        sprintf(
324
-                            __(
325
-                                'There is no model for endpoint %s. Please contact event espresso support',
326
-                                'event_espresso'
327
-                            ),
328
-                            $related_model_name
329
-                        )
330
-                    )
331
-                );
332
-            }
333
-            return $controller->sendResponse(
334
-                $controller->getEntitiesFromRelation(
335
-                    $request->get_param('id'),
336
-                    $main_model->related_settings_for($related_model_name),
337
-                    $request
338
-                )
339
-            );
340
-        } catch (Exception $e) {
341
-            return $controller->sendResponse($e);
342
-        }
343
-    }
344
-
345
-
346
-    /**
347
-     * Gets a collection for the given model and filters
348
-     *
349
-     * @param EEM_Base        $model
350
-     * @param WP_REST_Request $request
351
-     * @return array|WP_Error
352
-     */
353
-    public function getEntitiesFromModel($model, $request)
354
-    {
355
-        $query_params = $this->createModelQueryParams($model, $request->get_params());
356
-        if (! Capabilities::currentUserHasPartialAccessTo($model, $query_params['caps'])) {
357
-            $model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
358
-            return new WP_Error(
359
-                sprintf('rest_%s_cannot_list', $model_name_plural),
360
-                sprintf(
361
-                    __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'),
362
-                    $model_name_plural,
363
-                    Capabilities::getMissingPermissionsString($model, $query_params['caps'])
364
-                ),
365
-                array('status' => 403)
366
-            );
367
-        }
368
-        if (! $request->get_header('no_rest_headers')) {
369
-            $this->setHeadersFromQueryParams($model, $query_params);
370
-        }
371
-        /** @type array $results */
372
-        $results = $model->get_all_wpdb_results($query_params);
373
-        $nice_results = array();
374
-        foreach ($results as $result) {
375
-            $nice_results[] = $this->createEntityFromWpdbResult(
376
-                $model,
377
-                $result,
378
-                $request
379
-            );
380
-        }
381
-        return $nice_results;
382
-    }
383
-
384
-
385
-    /**
386
-     * Gets the collection for given relation object
387
-     * The same as Read::get_entities_from_model(), except if the relation
388
-     * is a HABTM relation, in which case it merges any non-foreign-key fields from
389
-     * the join-model-object into the results
390
-     *
391
-     * @param array                   $primary_model_query_params query params for finding the item from which
392
-     *                                                            relations will be based
393
-     * @param \EE_Model_Relation_Base $relation
394
-     * @param WP_REST_Request         $request
395
-     * @return WP_Error|array
396
-     * @throws RestException
397
-     */
398
-    protected function getEntitiesFromRelationUsingModelQueryParams($primary_model_query_params, $relation, $request)
399
-    {
400
-        $context = $this->validateContext($request->get_param('caps'));
401
-        $model = $relation->get_this_model();
402
-        $related_model = $relation->get_other_model();
403
-        if (! isset($primary_model_query_params[0])) {
404
-            $primary_model_query_params[0] = array();
405
-        }
406
-        // check if they can access the 1st model object
407
-        $primary_model_query_params = array(
408
-            0       => $primary_model_query_params[0],
409
-            'limit' => 1,
410
-        );
411
-        if ($model instanceof \EEM_Soft_Delete_Base) {
412
-            $primary_model_query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included(
413
-                $primary_model_query_params
414
-            );
415
-        }
416
-        $restricted_query_params = $primary_model_query_params;
417
-        $restricted_query_params['caps'] = $context;
418
-        $this->setDebugInfo('main model query params', $restricted_query_params);
419
-        $this->setDebugInfo('missing caps', Capabilities::getMissingPermissionsString($related_model, $context));
420
-        if (! (
421
-            Capabilities::currentUserHasPartialAccessTo($related_model, $context)
422
-            && $model->exists($restricted_query_params)
423
-        )
424
-        ) {
425
-            if ($relation instanceof EE_Belongs_To_Relation) {
426
-                $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name());
427
-            } else {
428
-                $related_model_name_maybe_plural = EEH_Inflector::pluralize_and_lower(
429
-                    $related_model->get_this_model_name()
430
-                );
431
-            }
432
-            return new WP_Error(
433
-                sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural),
434
-                sprintf(
435
-                    __(
436
-                        'Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s',
437
-                        'event_espresso'
438
-                    ),
439
-                    $related_model_name_maybe_plural,
440
-                    $relation->get_this_model()->get_this_model_name(),
441
-                    implode(
442
-                        ',',
443
-                        array_keys(
444
-                            Capabilities::getMissingPermissions($related_model, $context)
445
-                        )
446
-                    )
447
-                ),
448
-                array('status' => 403)
449
-            );
450
-        }
451
-        $query_params = $this->createModelQueryParams($relation->get_other_model(), $request->get_params());
452
-        foreach ($primary_model_query_params[0] as $where_condition_key => $where_condition_value) {
453
-            $query_params[0][ $relation->get_this_model()->get_this_model_name()
454
-                              . '.'
455
-                              . $where_condition_key ] = $where_condition_value;
456
-        }
457
-        $query_params['default_where_conditions'] = 'none';
458
-        $query_params['caps'] = $context;
459
-        if (! $request->get_header('no_rest_headers')) {
460
-            $this->setHeadersFromQueryParams($relation->get_other_model(), $query_params);
461
-        }
462
-        /** @type array $results */
463
-        $results = $relation->get_other_model()->get_all_wpdb_results($query_params);
464
-        $nice_results = array();
465
-        foreach ($results as $result) {
466
-            $nice_result = $this->createEntityFromWpdbResult(
467
-                $relation->get_other_model(),
468
-                $result,
469
-                $request
470
-            );
471
-            if ($relation instanceof \EE_HABTM_Relation) {
472
-                // put the unusual stuff (properties from the HABTM relation) first, and make sure
473
-                // if there are conflicts we prefer the properties from the main model
474
-                $join_model_result = $this->createEntityFromWpdbResult(
475
-                    $relation->get_join_model(),
476
-                    $result,
477
-                    $request
478
-                );
479
-                $joined_result = array_merge($nice_result, $join_model_result);
480
-                // but keep the meta stuff from the main model
481
-                if (isset($nice_result['meta'])) {
482
-                    $joined_result['meta'] = $nice_result['meta'];
483
-                }
484
-                $nice_result = $joined_result;
485
-            }
486
-            $nice_results[] = $nice_result;
487
-        }
488
-        if ($relation instanceof EE_Belongs_To_Relation) {
489
-            return array_shift($nice_results);
490
-        } else {
491
-            return $nice_results;
492
-        }
493
-    }
494
-
495
-
496
-    /**
497
-     * Gets the collection for given relation object
498
-     * The same as Read::get_entities_from_model(), except if the relation
499
-     * is a HABTM relation, in which case it merges any non-foreign-key fields from
500
-     * the join-model-object into the results
501
-     *
502
-     * @param string                  $id the ID of the thing we are fetching related stuff from
503
-     * @param \EE_Model_Relation_Base $relation
504
-     * @param WP_REST_Request         $request
505
-     * @return array|WP_Error
506
-     * @throws EE_Error
507
-     */
508
-    public function getEntitiesFromRelation($id, $relation, $request)
509
-    {
510
-        if (! $relation->get_this_model()->has_primary_key_field()) {
511
-            throw new EE_Error(
512
-                sprintf(
513
-                    __(
514
-                    // @codingStandardsIgnoreStart
515
-                        'Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s',
516
-                        // @codingStandardsIgnoreEnd
517
-                        'event_espresso'
518
-                    ),
519
-                    $relation->get_this_model()->get_this_model_name()
520
-                )
521
-            );
522
-        }
523
-        return $this->getEntitiesFromRelationUsingModelQueryParams(
524
-            array(
525
-                array(
526
-                    $relation->get_this_model()->primary_key_name() => $id,
527
-                ),
528
-            ),
529
-            $relation,
530
-            $request
531
-        );
532
-    }
533
-
534
-
535
-    /**
536
-     * Sets the headers that are based on the model and query params,
537
-     * like the total records. This should only be called on the original request
538
-     * from the client, not on subsequent internal
539
-     *
540
-     * @param EEM_Base $model
541
-     * @param array    $query_params
542
-     * @return void
543
-     */
544
-    protected function setHeadersFromQueryParams($model, $query_params)
545
-    {
546
-        $this->setDebugInfo('model query params', $query_params);
547
-        $this->setDebugInfo(
548
-            'missing caps',
549
-            Capabilities::getMissingPermissionsString($model, $query_params['caps'])
550
-        );
551
-        // normally the limit to a 2-part array, where the 2nd item is the limit
552
-        if (! isset($query_params['limit'])) {
553
-            $query_params['limit'] = EED_Core_Rest_Api::get_default_query_limit();
554
-        }
555
-        if (is_array($query_params['limit'])) {
556
-            $limit_parts = $query_params['limit'];
557
-        } else {
558
-            $limit_parts = explode(',', $query_params['limit']);
559
-            if (count($limit_parts) == 1) {
560
-                $limit_parts = array(0, $limit_parts[0]);
561
-            }
562
-        }
563
-        // remove the group by and having parts of the query, as those will
564
-        // make the sql query return an array of values, instead of just a single value
565
-        unset($query_params['group_by'], $query_params['having'], $query_params['limit']);
566
-        $count = $model->count($query_params, null, true);
567
-        $pages = $count / $limit_parts[1];
568
-        $this->setResponseHeader('Total', $count, false);
569
-        $this->setResponseHeader('PageSize', $limit_parts[1], false);
570
-        $this->setResponseHeader('TotalPages', ceil($pages), false);
571
-    }
572
-
573
-
574
-    /**
575
-     * Changes database results into REST API entities
576
-     *
577
-     * @param EEM_Base        $model
578
-     * @param array           $db_row     like results from $wpdb->get_results()
579
-     * @param WP_REST_Request $rest_request
580
-     * @param string          $deprecated no longer used
581
-     * @return array ready for being converted into json for sending to client
582
-     */
583
-    public function createEntityFromWpdbResult($model, $db_row, $rest_request, $deprecated = null)
584
-    {
585
-        if (! $rest_request instanceof WP_REST_Request) {
586
-            // ok so this was called in the old style, where the 3rd arg was
587
-            // $include, and the 4th arg was $context
588
-            // now setup the request just to avoid fatal errors, although we won't be able
589
-            // to truly make use of it because it's kinda devoid of info
590
-            $rest_request = new WP_REST_Request();
591
-            $rest_request->set_param('include', $rest_request);
592
-            $rest_request->set_param('caps', $deprecated);
593
-        }
594
-        if ($rest_request->get_param('caps') == null) {
595
-            $rest_request->set_param('caps', EEM_Base::caps_read);
596
-        }
597
-        $entity_array = $this->createBareEntityFromWpdbResults($model, $db_row);
598
-        $entity_array = $this->addExtraFields($model, $db_row, $entity_array);
599
-        $entity_array['_links'] = $this->getEntityLinks($model, $db_row, $entity_array);
600
-        $entity_array['_calculated_fields'] = $this->getEntityCalculations($model, $db_row, $rest_request);
601
-        $entity_array = apply_filters(
602
-            'FHEE__Read__create_entity_from_wpdb_results__entity_before_including_requested_models',
603
-            $entity_array,
604
-            $model,
605
-            $rest_request->get_param('caps'),
606
-            $rest_request,
607
-            $this
608
-        );
609
-        $entity_array = $this->includeRequestedModels($model, $rest_request, $entity_array, $db_row);
610
-        $entity_array = apply_filters(
611
-            'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal',
612
-            $entity_array,
613
-            $model,
614
-            $rest_request->get_param('caps'),
615
-            $rest_request,
616
-            $this
617
-        );
618
-        $result_without_inaccessible_fields = Capabilities::filterOutInaccessibleEntityFields(
619
-            $entity_array,
620
-            $model,
621
-            $rest_request->get_param('caps'),
622
-            $this->getModelVersionInfo(),
623
-            $model->get_index_primary_key_string(
624
-                $model->deduce_fields_n_values_from_cols_n_values($db_row)
625
-            )
626
-        );
627
-        $this->setDebugInfo(
628
-            'inaccessible fields',
629
-            array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields))
630
-        );
631
-        return apply_filters(
632
-            'FHEE__Read__create_entity_from_wpdb_results__entity_return',
633
-            $result_without_inaccessible_fields,
634
-            $model,
635
-            $rest_request->get_param('caps')
636
-        );
637
-    }
638
-
639
-
640
-    /**
641
-     * Creates a REST entity array (JSON object we're going to return in the response, but
642
-     * for now still a PHP array, but soon enough we'll call json_encode on it, don't worry),
643
-     * from $wpdb->get_row( $sql, ARRAY_A)
644
-     *
645
-     * @param EEM_Base $model
646
-     * @param array    $db_row
647
-     * @return array entity mostly ready for converting to JSON and sending in the response
648
-     */
649
-    protected function createBareEntityFromWpdbResults(EEM_Base $model, $db_row)
650
-    {
651
-        $result = $model->deduce_fields_n_values_from_cols_n_values($db_row);
652
-        $result = array_intersect_key(
653
-            $result,
654
-            $this->getModelVersionInfo()->fieldsOnModelInThisVersion($model)
655
-        );
656
-        // if this is a CPT, we need to set the global $post to it,
657
-        // otherwise shortcodes etc won't work properly while rendering it
658
-        if ($model instanceof \EEM_CPT_Base) {
659
-            $do_chevy_shuffle = true;
660
-        } else {
661
-            $do_chevy_shuffle = false;
662
-        }
663
-        if ($do_chevy_shuffle) {
664
-            global $post;
665
-            $old_post = $post;
666
-            $post = get_post($result[ $model->primary_key_name() ]);
667
-            if (! $post instanceof \WP_Post) {
668
-                // well that's weird, because $result is what we JUST fetched from the database
669
-                throw new RestException(
670
-                    'error_fetching_post_from_database_results',
671
-                    esc_html__(
672
-                        'An item was retrieved from the database but it\'s not a WP_Post like it should be.',
673
-                        'event_espresso'
674
-                    )
675
-                );
676
-            }
677
-            $model_object_classname = 'EE_' . $model->get_this_model_name();
678
-            $post->{$model_object_classname} = \EE_Registry::instance()->load_class(
679
-                $model_object_classname,
680
-                $result,
681
-                false,
682
-                false
683
-            );
684
-        }
685
-        foreach ($result as $field_name => $field_value) {
686
-            $field_obj = $model->field_settings_for($field_name);
687
-            if ($this->isSubclassOfOne($field_obj, $this->getModelVersionInfo()->fieldsIgnored())) {
688
-                unset($result[ $field_name ]);
689
-            } elseif ($this->isSubclassOfOne(
690
-                $field_obj,
691
-                $this->getModelVersionInfo()->fieldsThatHaveRenderedFormat()
692
-            )
693
-            ) {
694
-                $result[ $field_name ] = array(
695
-                    'raw'      => $this->prepareFieldObjValueForJson($field_obj, $field_value),
696
-                    'rendered' => $this->prepareFieldObjValueForJson($field_obj, $field_value, 'pretty'),
697
-                );
698
-            } elseif ($this->isSubclassOfOne(
699
-                $field_obj,
700
-                $this->getModelVersionInfo()->fieldsThatHavePrettyFormat()
701
-            )
702
-            ) {
703
-                $result[ $field_name ] = array(
704
-                    'raw'    => $this->prepareFieldObjValueForJson($field_obj, $field_value),
705
-                    'pretty' => $this->prepareFieldObjValueForJson($field_obj, $field_value, 'pretty'),
706
-                );
707
-            } elseif ($field_obj instanceof \EE_Datetime_Field) {
708
-                $field_value = $field_obj->prepare_for_set_from_db($field_value);
709
-                // if the value is null, but we're not supposed to permit null, then set to the field's default
710
-                if (is_null($field_value)) {
711
-                    $field_value = $field_obj->getDefaultDateTimeObj();
712
-                }
713
-                if (is_null($field_value)) {
714
-                    $gmt_date = $local_date = ModelDataTranslator::prepareFieldValuesForJson(
715
-                        $field_obj,
716
-                        $field_value,
717
-                        $this->getModelVersionInfo()->requestedVersion()
718
-                    );
719
-                } else {
720
-                    $timezone = $field_value->getTimezone();
721
-                    EEH_DTT_Helper::setTimezone($field_value, new DateTimeZone('UTC'));
722
-                    $gmt_date = ModelDataTranslator::prepareFieldValuesForJson(
723
-                        $field_obj,
724
-                        $field_value,
725
-                        $this->getModelVersionInfo()->requestedVersion()
726
-                    );
727
-                    EEH_DTT_Helper::setTimezone($field_value, $timezone);
728
-                    $local_date = ModelDataTranslator::prepareFieldValuesForJson(
729
-                        $field_obj,
730
-                        $field_value,
731
-                        $this->getModelVersionInfo()->requestedVersion()
732
-                    );
733
-                }
734
-                $result[ $field_name . '_gmt' ] = $gmt_date;
735
-                $result[ $field_name ] = $local_date;
736
-            } else {
737
-                $result[ $field_name ] = $this->prepareFieldObjValueForJson($field_obj, $field_value);
738
-            }
739
-        }
740
-        if ($do_chevy_shuffle) {
741
-            $post = $old_post;
742
-        }
743
-        return $result;
744
-    }
745
-
746
-
747
-    /**
748
-     * Takes a value all the way from the DB representation, to the model object's representation, to the
749
-     * user-facing PHP representation, to the REST API representation. (Assumes you've already taken from the DB
750
-     * representation using $field_obj->prepare_for_set_from_db())
751
-     *
752
-     * @param EE_Model_Field_Base $field_obj
753
-     * @param mixed               $value  as it's stored on a model object
754
-     * @param string              $format valid values are 'normal' (default), 'pretty', 'datetime_obj'
755
-     * @return mixed
756
-     * @throws ObjectDetectedException if $value contains a PHP object
757
-     */
758
-    protected function prepareFieldObjValueForJson(EE_Model_Field_Base $field_obj, $value, $format = 'normal')
759
-    {
760
-        $value = $field_obj->prepare_for_set_from_db($value);
761
-        switch ($format) {
762
-            case 'pretty':
763
-                $value = $field_obj->prepare_for_pretty_echoing($value);
764
-                break;
765
-            case 'normal':
766
-            default:
767
-                $value = $field_obj->prepare_for_get($value);
768
-                break;
769
-        }
770
-        return ModelDataTranslator::prepareFieldValuesForJson(
771
-            $field_obj,
772
-            $value,
773
-            $this->getModelVersionInfo()->requestedVersion()
774
-        );
775
-    }
776
-
777
-
778
-    /**
779
-     * Adds a few extra fields to the entity response
780
-     *
781
-     * @param EEM_Base $model
782
-     * @param array    $db_row
783
-     * @param array    $entity_array
784
-     * @return array modified entity
785
-     */
786
-    protected function addExtraFields(EEM_Base $model, $db_row, $entity_array)
787
-    {
788
-        if ($model instanceof EEM_CPT_Base) {
789
-            $entity_array['link'] = get_permalink($db_row[ $model->get_primary_key_field()->get_qualified_column() ]);
790
-        }
791
-        return $entity_array;
792
-    }
793
-
794
-
795
-    /**
796
-     * Gets links we want to add to the response
797
-     *
798
-     * @global \WP_REST_Server $wp_rest_server
799
-     * @param EEM_Base         $model
800
-     * @param array            $db_row
801
-     * @param array            $entity_array
802
-     * @return array the _links item in the entity
803
-     */
804
-    protected function getEntityLinks($model, $db_row, $entity_array)
805
-    {
806
-        // add basic links
807
-        $links = array();
808
-        if ($model->has_primary_key_field()) {
809
-            $links['self'] = array(
810
-                array(
811
-                    'href' => $this->getVersionedLinkTo(
812
-                        EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
813
-                        . '/'
814
-                        . $entity_array[ $model->primary_key_name() ]
815
-                    ),
816
-                ),
817
-            );
818
-        }
819
-        $links['collection'] = array(
820
-            array(
821
-                'href' => $this->getVersionedLinkTo(
822
-                    EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
823
-                ),
824
-            ),
825
-        );
826
-        // add links to related models
827
-        if ($model->has_primary_key_field()) {
828
-            foreach ($this->getModelVersionInfo()->relationSettings($model) as $relation_name => $relation_obj) {
829
-                $related_model_part = Read::getRelatedEntityName($relation_name, $relation_obj);
830
-                $links[ EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part ] = array(
831
-                    array(
832
-                        'href'   => $this->getVersionedLinkTo(
833
-                            EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
834
-                            . '/'
835
-                            . $entity_array[ $model->primary_key_name() ]
836
-                            . '/'
837
-                            . $related_model_part
838
-                        ),
839
-                        'single' => $relation_obj instanceof EE_Belongs_To_Relation ? true : false,
840
-                    ),
841
-                );
842
-            }
843
-        }
844
-        return $links;
845
-    }
846
-
847
-
848
-    /**
849
-     * Adds the included models indicated in the request to the entity provided
850
-     *
851
-     * @param EEM_Base        $model
852
-     * @param WP_REST_Request $rest_request
853
-     * @param array           $entity_array
854
-     * @param array           $db_row
855
-     * @return array the modified entity
856
-     */
857
-    protected function includeRequestedModels(
858
-        EEM_Base $model,
859
-        WP_REST_Request $rest_request,
860
-        $entity_array,
861
-        $db_row = array()
862
-    ) {
863
-        // if $db_row not included, hope the entity array has what we need
864
-        if (! $db_row) {
865
-            $db_row = $entity_array;
866
-        }
867
-        $includes_for_this_model = $this->explodeAndGetItemsPrefixedWith($rest_request->get_param('include'), '');
868
-        $includes_for_this_model = $this->removeModelNamesFromArray($includes_for_this_model);
869
-        // if they passed in * or didn't specify any includes, return everything
870
-        if (! in_array('*', $includes_for_this_model)
871
-            && ! empty($includes_for_this_model)
872
-        ) {
873
-            if ($model->has_primary_key_field()) {
874
-                // always include the primary key. ya just gotta know that at least
875
-                $includes_for_this_model[] = $model->primary_key_name();
876
-            }
877
-            if ($this->explodeAndGetItemsPrefixedWith($rest_request->get_param('calculate'), '')) {
878
-                $includes_for_this_model[] = '_calculated_fields';
879
-            }
880
-            $entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model));
881
-        }
882
-        $relation_settings = $this->getModelVersionInfo()->relationSettings($model);
883
-        foreach ($relation_settings as $relation_name => $relation_obj) {
884
-            $related_fields_to_include = $this->explodeAndGetItemsPrefixedWith(
885
-                $rest_request->get_param('include'),
886
-                $relation_name
887
-            );
888
-            $related_fields_to_calculate = $this->explodeAndGetItemsPrefixedWith(
889
-                $rest_request->get_param('calculate'),
890
-                $relation_name
891
-            );
892
-            // did they specify they wanted to include a related model, or
893
-            // specific fields from a related model?
894
-            // or did they specify to calculate a field from a related model?
895
-            if ($related_fields_to_include || $related_fields_to_calculate) {
896
-                // if so, we should include at least some part of the related model
897
-                $pretend_related_request = new WP_REST_Request();
898
-                $pretend_related_request->set_query_params(
899
-                    array(
900
-                        'caps'      => $rest_request->get_param('caps'),
901
-                        'include'   => $related_fields_to_include,
902
-                        'calculate' => $related_fields_to_calculate,
903
-                    )
904
-                );
905
-                $pretend_related_request->add_header('no_rest_headers', true);
906
-                $primary_model_query_params = $model->alter_query_params_to_restrict_by_ID(
907
-                    $model->get_index_primary_key_string(
908
-                        $model->deduce_fields_n_values_from_cols_n_values($db_row)
909
-                    )
910
-                );
911
-                $related_results = $this->getEntitiesFromRelationUsingModelQueryParams(
912
-                    $primary_model_query_params,
913
-                    $relation_obj,
914
-                    $pretend_related_request
915
-                );
916
-                $entity_array[ Read::getRelatedEntityName($relation_name, $relation_obj) ] = $related_results
917
-                                                                                             instanceof
918
-                                                                                             WP_Error
919
-                    ? null
920
-                    : $related_results;
921
-            }
922
-        }
923
-        return $entity_array;
924
-    }
925
-
926
-
927
-    /**
928
-     * Returns a new array with all the names of models removed. Eg
929
-     * array( 'Event', 'Datetime.*', 'foobar' ) would become array( 'Datetime.*', 'foobar' )
930
-     *
931
-     * @param array $arr
932
-     * @return array
933
-     */
934
-    private function removeModelNamesFromArray($arr)
935
-    {
936
-        return array_diff($arr, array_keys(EE_Registry::instance()->non_abstract_db_models));
937
-    }
938
-
939
-
940
-    /**
941
-     * Gets the calculated fields for the response
942
-     *
943
-     * @param EEM_Base        $model
944
-     * @param array           $wpdb_row
945
-     * @param WP_REST_Request $rest_request
946
-     * @return \stdClass the _calculations item in the entity
947
-     * @throws ObjectDetectedException if a default value has a PHP object, which should never do (and if we
948
-     * did, let's know about it ASAP, so let the exception bubble up)
949
-     */
950
-    protected function getEntityCalculations($model, $wpdb_row, $rest_request)
951
-    {
952
-        $calculated_fields = $this->explodeAndGetItemsPrefixedWith(
953
-            $rest_request->get_param('calculate'),
954
-            ''
955
-        );
956
-        // note: setting calculate=* doesn't do anything
957
-        $calculated_fields_to_return = new \stdClass();
958
-        foreach ($calculated_fields as $field_to_calculate) {
959
-            try {
960
-                $calculated_fields_to_return->$field_to_calculate = ModelDataTranslator::prepareFieldValueForJson(
961
-                    null,
962
-                    $this->fields_calculator->retrieveCalculatedFieldValue(
963
-                        $model,
964
-                        $field_to_calculate,
965
-                        $wpdb_row,
966
-                        $rest_request,
967
-                        $this
968
-                    ),
969
-                    $this->getModelVersionInfo()->requestedVersion()
970
-                );
971
-            } catch (RestException $e) {
972
-                // if we don't have permission to read it, just leave it out. but let devs know about the problem
973
-                $this->setResponseHeader(
974
-                    'Notices-Field-Calculation-Errors['
975
-                    . $e->getStringCode()
976
-                    . ']['
977
-                    . $model->get_this_model_name()
978
-                    . ']['
979
-                    . $field_to_calculate
980
-                    . ']',
981
-                    $e->getMessage(),
982
-                    true
983
-                );
984
-            }
985
-        }
986
-        return $calculated_fields_to_return;
987
-    }
988
-
989
-
990
-    /**
991
-     * Gets the full URL to the resource, taking the requested version into account
992
-     *
993
-     * @param string $link_part_after_version_and_slash eg "events/10/datetimes"
994
-     * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes"
995
-     */
996
-    public function getVersionedLinkTo($link_part_after_version_and_slash)
997
-    {
998
-        return rest_url(
999
-            EED_Core_Rest_Api::get_versioned_route_to(
1000
-                $link_part_after_version_and_slash,
1001
-                $this->getModelVersionInfo()->requestedVersion()
1002
-            )
1003
-        );
1004
-    }
1005
-
1006
-
1007
-    /**
1008
-     * Gets the correct lowercase name for the relation in the API according
1009
-     * to the relation's type
1010
-     *
1011
-     * @param string                  $relation_name
1012
-     * @param \EE_Model_Relation_Base $relation_obj
1013
-     * @return string
1014
-     */
1015
-    public static function getRelatedEntityName($relation_name, $relation_obj)
1016
-    {
1017
-        if ($relation_obj instanceof EE_Belongs_To_Relation) {
1018
-            return strtolower($relation_name);
1019
-        } else {
1020
-            return EEH_Inflector::pluralize_and_lower($relation_name);
1021
-        }
1022
-    }
1023
-
1024
-
1025
-    /**
1026
-     * Gets the one model object with the specified id for the specified model
1027
-     *
1028
-     * @param EEM_Base        $model
1029
-     * @param WP_REST_Request $request
1030
-     * @return array|WP_Error
1031
-     */
1032
-    public function getEntityFromModel($model, $request)
1033
-    {
1034
-        $context = $this->validateContext($request->get_param('caps'));
1035
-        return $this->getOneOrReportPermissionError($model, $request, $context);
1036
-    }
1037
-
1038
-
1039
-    /**
1040
-     * If a context is provided which isn't valid, maybe it was added in a future
1041
-     * version so just treat it as a default read
1042
-     *
1043
-     * @param string $context
1044
-     * @return string array key of EEM_Base::cap_contexts_to_cap_action_map()
1045
-     */
1046
-    public function validateContext($context)
1047
-    {
1048
-        if (! $context) {
1049
-            $context = EEM_Base::caps_read;
1050
-        }
1051
-        $valid_contexts = EEM_Base::valid_cap_contexts();
1052
-        if (in_array($context, $valid_contexts)) {
1053
-            return $context;
1054
-        } else {
1055
-            return EEM_Base::caps_read;
1056
-        }
1057
-    }
1058
-
1059
-
1060
-    /**
1061
-     * Verifies the passed in value is an allowable default where conditions value.
1062
-     *
1063
-     * @param $default_query_params
1064
-     * @return string
1065
-     */
1066
-    public function validateDefaultQueryParams($default_query_params)
1067
-    {
1068
-        $valid_default_where_conditions_for_api_calls = array(
1069
-            EEM_Base::default_where_conditions_all,
1070
-            EEM_Base::default_where_conditions_minimum_all,
1071
-            EEM_Base::default_where_conditions_minimum_others,
1072
-        );
1073
-        if (! $default_query_params) {
1074
-            $default_query_params = EEM_Base::default_where_conditions_all;
1075
-        }
1076
-        if (in_array(
1077
-            $default_query_params,
1078
-            $valid_default_where_conditions_for_api_calls,
1079
-            true
1080
-        )) {
1081
-            return $default_query_params;
1082
-        } else {
1083
-            return EEM_Base::default_where_conditions_all;
1084
-        }
1085
-    }
1086
-
1087
-
1088
-    /**
1089
-     * Translates API filter get parameter into $query_params array used by EEM_Base::get_all().
1090
-     * Note: right now the query parameter keys for fields (and related fields)
1091
-     * can be left as-is, but it's quite possible this will change someday.
1092
-     * Also, this method's contents might be candidate for moving to Model_Data_Translator
1093
-     *
1094
-     * @param EEM_Base $model
1095
-     * @param array    $query_parameters  from $_GET parameter @see Read:handle_request_get_all
1096
-     * @return array like what EEM_Base::get_all() expects or FALSE to indicate
1097
-     *                                    that absolutely no results should be returned
1098
-     * @throws EE_Error
1099
-     * @throws RestException
1100
-     */
1101
-    public function createModelQueryParams($model, $query_parameters)
1102
-    {
1103
-        $model_query_params = array();
1104
-        if (isset($query_parameters['where'])) {
1105
-            $model_query_params[0] = ModelDataTranslator::prepareConditionsQueryParamsForModels(
1106
-                $query_parameters['where'],
1107
-                $model,
1108
-                $this->getModelVersionInfo()->requestedVersion()
1109
-            );
1110
-        }
1111
-        if (isset($query_parameters['order_by'])) {
1112
-            $order_by = $query_parameters['order_by'];
1113
-        } elseif (isset($query_parameters['orderby'])) {
1114
-            $order_by = $query_parameters['orderby'];
1115
-        } else {
1116
-            $order_by = null;
1117
-        }
1118
-        if ($order_by !== null) {
1119
-            if (is_array($order_by)) {
1120
-                $order_by = ModelDataTranslator::prepareFieldNamesInArrayKeysFromJson($order_by);
1121
-            } else {
1122
-                // it's a single item
1123
-                $order_by = ModelDataTranslator::prepareFieldNameFromJson($order_by);
1124
-            }
1125
-            $model_query_params['order_by'] = $order_by;
1126
-        }
1127
-        if (isset($query_parameters['group_by'])) {
1128
-            $group_by = $query_parameters['group_by'];
1129
-        } elseif (isset($query_parameters['groupby'])) {
1130
-            $group_by = $query_parameters['groupby'];
1131
-        } else {
1132
-            $group_by = array_keys($model->get_combined_primary_key_fields());
1133
-        }
1134
-        // make sure they're all real names
1135
-        if (is_array($group_by)) {
1136
-            $group_by = ModelDataTranslator::prepareFieldNamesFromJson($group_by);
1137
-        }
1138
-        if ($group_by !== null) {
1139
-            $model_query_params['group_by'] = $group_by;
1140
-        }
1141
-        if (isset($query_parameters['having'])) {
1142
-            $model_query_params['having'] = ModelDataTranslator::prepareConditionsQueryParamsForModels(
1143
-                $query_parameters['having'],
1144
-                $model,
1145
-                $this->getModelVersionInfo()->requestedVersion()
1146
-            );
1147
-        }
1148
-        if (isset($query_parameters['order'])) {
1149
-            $model_query_params['order'] = $query_parameters['order'];
1150
-        }
1151
-        if (isset($query_parameters['mine'])) {
1152
-            $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params);
1153
-        }
1154
-        if (isset($query_parameters['limit'])) {
1155
-            // limit should be either a string like '23' or '23,43', or an array with two items in it
1156
-            if (! is_array($query_parameters['limit'])) {
1157
-                $limit_array = explode(',', (string) $query_parameters['limit']);
1158
-            } else {
1159
-                $limit_array = $query_parameters['limit'];
1160
-            }
1161
-            $sanitized_limit = array();
1162
-            foreach ($limit_array as $key => $limit_part) {
1163
-                if ($this->debug_mode && (! is_numeric($limit_part) || count($sanitized_limit) > 2)) {
1164
-                    throw new EE_Error(
1165
-                        sprintf(
1166
-                            __(
1167
-                            // @codingStandardsIgnoreStart
1168
-                                'An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.',
1169
-                                // @codingStandardsIgnoreEnd
1170
-                                'event_espresso'
1171
-                            ),
1172
-                            wp_json_encode($query_parameters['limit'])
1173
-                        )
1174
-                    );
1175
-                }
1176
-                $sanitized_limit[] = (int) $limit_part;
1177
-            }
1178
-            $model_query_params['limit'] = implode(',', $sanitized_limit);
1179
-        } else {
1180
-            $model_query_params['limit'] = EED_Core_Rest_Api::get_default_query_limit();
1181
-        }
1182
-        if (isset($query_parameters['caps'])) {
1183
-            $model_query_params['caps'] = $this->validateContext($query_parameters['caps']);
1184
-        } else {
1185
-            $model_query_params['caps'] = EEM_Base::caps_read;
1186
-        }
1187
-        if (isset($query_parameters['default_where_conditions'])) {
1188
-            $model_query_params['default_where_conditions'] = $this->validateDefaultQueryParams(
1189
-                $query_parameters['default_where_conditions']
1190
-            );
1191
-        }
1192
-        return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model);
1193
-    }
1194
-
1195
-
1196
-    /**
1197
-     * Changes the REST-style query params for use in the models
1198
-     *
1199
-     * @deprecated
1200
-     * @param EEM_Base $model
1201
-     * @param array    $query_params sub-array from @see EEM_Base::get_all()
1202
-     * @return array
1203
-     */
1204
-    public function prepareRestQueryParamsKeyForModels($model, $query_params)
1205
-    {
1206
-        $model_ready_query_params = array();
1207
-        foreach ($query_params as $key => $value) {
1208
-            if (is_array($value)) {
1209
-                $model_ready_query_params[ $key ] = $this->prepareRestQueryParamsKeyForModels($model, $value);
1210
-            } else {
1211
-                $model_ready_query_params[ $key ] = $value;
1212
-            }
1213
-        }
1214
-        return $model_ready_query_params;
1215
-    }
1216
-
1217
-
1218
-    /**
1219
-     * @deprecated instead use ModelDataTranslator::prepareFieldValuesFromJson()
1220
-     * @param $model
1221
-     * @param $query_params
1222
-     * @return array
1223
-     */
1224
-    public function prepareRestQueryParamsValuesForModels($model, $query_params)
1225
-    {
1226
-        $model_ready_query_params = array();
1227
-        foreach ($query_params as $key => $value) {
1228
-            if (is_array($value)) {
1229
-                $model_ready_query_params[ $key ] = $this->prepareRestQueryParamsValuesForModels($model, $value);
1230
-            } else {
1231
-                $model_ready_query_params[ $key ] = $value;
1232
-            }
1233
-        }
1234
-        return $model_ready_query_params;
1235
-    }
1236
-
1237
-
1238
-    /**
1239
-     * Explodes the string on commas, and only returns items with $prefix followed by a period.
1240
-     * If no prefix is specified, returns items with no period.
1241
-     *
1242
-     * @param string|array $string_to_explode eg "jibba,jabba, blah, blah, blah" or array('jibba', 'jabba' )
1243
-     * @param string       $prefix            "Event" or "foobar"
1244
-     * @return array $string_to_exploded exploded on COMMAS, and if a prefix was specified
1245
-     *                                        we only return strings starting with that and a period; if no prefix was
1246
-     *                                        specified we return all items containing NO periods
1247
-     */
1248
-    public function explodeAndGetItemsPrefixedWith($string_to_explode, $prefix)
1249
-    {
1250
-        if (is_string($string_to_explode)) {
1251
-            $exploded_contents = explode(',', $string_to_explode);
1252
-        } elseif (is_array($string_to_explode)) {
1253
-            $exploded_contents = $string_to_explode;
1254
-        } else {
1255
-            $exploded_contents = array();
1256
-        }
1257
-        // if the string was empty, we want an empty array
1258
-        $exploded_contents = array_filter($exploded_contents);
1259
-        $contents_with_prefix = array();
1260
-        foreach ($exploded_contents as $item) {
1261
-            $item = trim($item);
1262
-            // if no prefix was provided, so we look for items with no "." in them
1263
-            if (! $prefix) {
1264
-                // does this item have a period?
1265
-                if (strpos($item, '.') === false) {
1266
-                    // if not, then its what we're looking for
1267
-                    $contents_with_prefix[] = $item;
1268
-                }
1269
-            } elseif (strpos($item, $prefix . '.') === 0) {
1270
-                // this item has the prefix and a period, grab it
1271
-                $contents_with_prefix[] = substr(
1272
-                    $item,
1273
-                    strpos($item, $prefix . '.') + strlen($prefix . '.')
1274
-                );
1275
-            } elseif ($item === $prefix) {
1276
-                // this item is JUST the prefix
1277
-                // so let's grab everything after, which is a blank string
1278
-                $contents_with_prefix[] = '';
1279
-            }
1280
-        }
1281
-        return $contents_with_prefix;
1282
-    }
1283
-
1284
-
1285
-    /**
1286
-     * @deprecated since 4.8.36.rc.001 You should instead use Read::explode_and_get_items_prefixed_with.
1287
-     * Deprecated because its return values were really quite confusing- sometimes it returned
1288
-     * an empty array (when the include string was blank or '*') or sometimes it returned
1289
-     * array('*') (when you provided a model and a model of that kind was found).
1290
-     * Parses the $include_string so we fetch all the field names relating to THIS model
1291
-     * (ie have NO period in them), or for the provided model (ie start with the model
1292
-     * name and then a period).
1293
-     * @param string $include_string @see Read:handle_request_get_all
1294
-     * @param string $model_name
1295
-     * @return array of fields for this model. If $model_name is provided, then
1296
-     *                               the fields for that model, with the model's name removed from each.
1297
-     *                               If $include_string was blank or '*' returns an empty array
1298
-     */
1299
-    public function extractIncludesForThisModel($include_string, $model_name = null)
1300
-    {
1301
-        if (is_array($include_string)) {
1302
-            $include_string = implode(',', $include_string);
1303
-        }
1304
-        if ($include_string === '*' || $include_string === '') {
1305
-            return array();
1306
-        }
1307
-        $includes = explode(',', $include_string);
1308
-        $extracted_fields_to_include = array();
1309
-        if ($model_name) {
1310
-            foreach ($includes as $field_to_include) {
1311
-                $field_to_include = trim($field_to_include);
1312
-                if (strpos($field_to_include, $model_name . '.') === 0) {
1313
-                    // found the model name at the exact start
1314
-                    $field_sans_model_name = str_replace($model_name . '.', '', $field_to_include);
1315
-                    $extracted_fields_to_include[] = $field_sans_model_name;
1316
-                } elseif ($field_to_include == $model_name) {
1317
-                    $extracted_fields_to_include[] = '*';
1318
-                }
1319
-            }
1320
-        } else {
1321
-            // look for ones with no period
1322
-            foreach ($includes as $field_to_include) {
1323
-                $field_to_include = trim($field_to_include);
1324
-                if (strpos($field_to_include, '.') === false
1325
-                    && ! $this->getModelVersionInfo()->isModelNameInThisVersion($field_to_include)
1326
-                ) {
1327
-                    $extracted_fields_to_include[] = $field_to_include;
1328
-                }
1329
-            }
1330
-        }
1331
-        return $extracted_fields_to_include;
1332
-    }
1333
-
1334
-
1335
-    /**
1336
-     * Gets the single item using the model according to the request in the context given, otherwise
1337
-     * returns that it's inaccessible to the current user
1338
-     *
1339
-     * @param EEM_Base        $model
1340
-     * @param WP_REST_Request $request
1341
-     * @param null            $context
1342
-     * @return array|WP_Error
1343
-     */
1344
-    public function getOneOrReportPermissionError(EEM_Base $model, WP_REST_Request $request, $context = null)
1345
-    {
1346
-        $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1);
1347
-        if ($model instanceof \EEM_Soft_Delete_Base) {
1348
-            $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params);
1349
-        }
1350
-        $restricted_query_params = $query_params;
1351
-        $restricted_query_params['caps'] = $context;
1352
-        $this->setDebugInfo('model query params', $restricted_query_params);
1353
-        $model_rows = $model->get_all_wpdb_results($restricted_query_params);
1354
-        if (! empty($model_rows)) {
1355
-            return $this->createEntityFromWpdbResult(
1356
-                $model,
1357
-                array_shift($model_rows),
1358
-                $request
1359
-            );
1360
-        } else {
1361
-            // ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities
1362
-            $lowercase_model_name = strtolower($model->get_this_model_name());
1363
-            $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params);
1364
-            if (! empty($model_rows_found_sans_restrictions)) {
1365
-                // you got shafted- it existed but we didn't want to tell you!
1366
-                return new WP_Error(
1367
-                    'rest_user_cannot_' . $context,
1368
-                    sprintf(
1369
-                        __('Sorry, you cannot %1$s this %2$s. Missing permissions are: %3$s', 'event_espresso'),
1370
-                        $context,
1371
-                        strtolower($model->get_this_model_name()),
1372
-                        Capabilities::getMissingPermissionsString(
1373
-                            $model,
1374
-                            $context
1375
-                        )
1376
-                    ),
1377
-                    array('status' => 403)
1378
-                );
1379
-            } else {
1380
-                // it's not you. It just doesn't exist
1381
-                return new WP_Error(
1382
-                    sprintf('rest_%s_invalid_id', $lowercase_model_name),
1383
-                    sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name),
1384
-                    array('status' => 404)
1385
-                );
1386
-            }
1387
-        }
1388
-    }
43
+	/**
44
+	 * @var CalculatedModelFields
45
+	 */
46
+	protected $fields_calculator;
47
+
48
+
49
+	/**
50
+	 * Read constructor.
51
+	 * @param CalculatedModelFields $fields_calculator
52
+	 */
53
+	public function __construct(CalculatedModelFields $fields_calculator)
54
+	{
55
+		parent::__construct();
56
+		$this->fields_calculator = $fields_calculator;
57
+	}
58
+
59
+
60
+	/**
61
+	 * Handles requests to get all (or a filtered subset) of entities for a particular model
62
+	 *
63
+	 * @param WP_REST_Request $request
64
+	 * @param string $version
65
+	 * @param string $model_name
66
+	 * @return WP_REST_Response|WP_Error
67
+	 * @throws InvalidArgumentException
68
+	 * @throws InvalidDataTypeException
69
+	 * @throws InvalidInterfaceException
70
+	 */
71
+	public static function handleRequestGetAll(WP_REST_Request $request, $version, $model_name)
72
+	{
73
+		$controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read');
74
+		try {
75
+			$controller->setRequestedVersion($version);
76
+			if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
77
+				return $controller->sendResponse(
78
+					new WP_Error(
79
+						'endpoint_parsing_error',
80
+						sprintf(
81
+							__(
82
+								'There is no model for endpoint %s. Please contact event espresso support',
83
+								'event_espresso'
84
+							),
85
+							$model_name
86
+						)
87
+					)
88
+				);
89
+			}
90
+			return $controller->sendResponse(
91
+				$controller->getEntitiesFromModel(
92
+					$controller->getModelVersionInfo()->loadModel($model_name),
93
+					$request
94
+				)
95
+			);
96
+		} catch (Exception $e) {
97
+			return $controller->sendResponse($e);
98
+		}
99
+	}
100
+
101
+
102
+	/**
103
+	 * Prepares and returns schema for any OPTIONS request.
104
+	 *
105
+	 * @param string $version The API endpoint version being used.
106
+	 * @param string $model_name Something like `Event` or `Registration`
107
+	 * @return array
108
+	 * @throws InvalidArgumentException
109
+	 * @throws InvalidDataTypeException
110
+	 * @throws InvalidInterfaceException
111
+	 */
112
+	public static function handleSchemaRequest($version, $model_name)
113
+	{
114
+		$controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read');
115
+		try {
116
+			$controller->setRequestedVersion($version);
117
+			if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
118
+				return array();
119
+			}
120
+			// get the model for this version
121
+			$model = $controller->getModelVersionInfo()->loadModel($model_name);
122
+			$model_schema = new JsonModelSchema($model, LoaderFactory::getLoader()->getShared('EventEspresso\core\libraries\rest_api\CalculatedModelFields'));
123
+			return $model_schema->getModelSchemaForRelations(
124
+				$controller->getModelVersionInfo()->relationSettings($model),
125
+				$controller->customizeSchemaForRestResponse(
126
+					$model,
127
+					$model_schema->getModelSchemaForFields(
128
+						$controller->getModelVersionInfo()->fieldsOnModelInThisVersion($model),
129
+						$model_schema->getInitialSchemaStructure()
130
+					)
131
+				)
132
+			);
133
+		} catch (Exception $e) {
134
+			return array();
135
+		}
136
+	}
137
+
138
+
139
+	/**
140
+	 * This loops through each field in the given schema for the model and does the following:
141
+	 * - add any extra fields that are REST API specific and related to existing fields.
142
+	 * - transform default values into the correct format for a REST API response.
143
+	 *
144
+	 * @param EEM_Base $model
145
+	 * @param array    $schema
146
+	 * @return array  The final schema.
147
+	 */
148
+	protected function customizeSchemaForRestResponse(EEM_Base $model, array $schema)
149
+	{
150
+		foreach ($this->getModelVersionInfo()->fieldsOnModelInThisVersion($model) as $field_name => $field) {
151
+			$schema = $this->translateDefaultsForRestResponse(
152
+				$field_name,
153
+				$field,
154
+				$this->maybeAddExtraFieldsToSchema($field_name, $field, $schema)
155
+			);
156
+		}
157
+		return $schema;
158
+	}
159
+
160
+
161
+	/**
162
+	 * This is used to ensure that the 'default' value set in the schema response is formatted correctly for the REST
163
+	 * response.
164
+	 *
165
+	 * @param                      $field_name
166
+	 * @param EE_Model_Field_Base  $field
167
+	 * @param array                $schema
168
+	 * @return array
169
+	 * @throws ObjectDetectedException if a default value has a PHP object, which should never do (and if we
170
+	 * did, let's know about it ASAP, so let the exception bubble up)
171
+	 */
172
+	protected function translateDefaultsForRestResponse($field_name, EE_Model_Field_Base $field, array $schema)
173
+	{
174
+		if (isset($schema['properties'][ $field_name ]['default'])) {
175
+			if (is_array($schema['properties'][ $field_name ]['default'])) {
176
+				foreach ($schema['properties'][ $field_name ]['default'] as $default_key => $default_value) {
177
+					if ($default_key === 'raw') {
178
+						$schema['properties'][ $field_name ]['default'][ $default_key ] =
179
+							ModelDataTranslator::prepareFieldValueForJson(
180
+								$field,
181
+								$default_value,
182
+								$this->getModelVersionInfo()->requestedVersion()
183
+							);
184
+					}
185
+				}
186
+			} else {
187
+				$schema['properties'][ $field_name ]['default'] = ModelDataTranslator::prepareFieldValueForJson(
188
+					$field,
189
+					$schema['properties'][ $field_name ]['default'],
190
+					$this->getModelVersionInfo()->requestedVersion()
191
+				);
192
+			}
193
+		}
194
+		return $schema;
195
+	}
196
+
197
+
198
+	/**
199
+	 * Adds additional fields to the schema
200
+	 * The REST API returns a GMT value field for each datetime field in the resource.  Thus the description about this
201
+	 * needs to be added to the schema.
202
+	 *
203
+	 * @param                      $field_name
204
+	 * @param EE_Model_Field_Base  $field
205
+	 * @param array                $schema
206
+	 * @return array
207
+	 */
208
+	protected function maybeAddExtraFieldsToSchema($field_name, EE_Model_Field_Base $field, array $schema)
209
+	{
210
+		if ($field instanceof EE_Datetime_Field) {
211
+			$schema['properties'][ $field_name . '_gmt' ] = $field->getSchema();
212
+			// modify the description
213
+			$schema['properties'][ $field_name . '_gmt' ]['description'] = sprintf(
214
+				esc_html__('%s - the value for this field is in GMT.', 'event_espresso'),
215
+				wp_specialchars_decode($field->get_nicename(), ENT_QUOTES)
216
+			);
217
+		}
218
+		return $schema;
219
+	}
220
+
221
+
222
+	/**
223
+	 * Used to figure out the route from the request when a `WP_REST_Request` object is not available
224
+	 *
225
+	 * @return string
226
+	 */
227
+	protected function getRouteFromRequest()
228
+	{
229
+		if (isset($GLOBALS['wp'])
230
+			&& $GLOBALS['wp'] instanceof \WP
231
+			&& isset($GLOBALS['wp']->query_vars['rest_route'])
232
+		) {
233
+			return $GLOBALS['wp']->query_vars['rest_route'];
234
+		} else {
235
+			return isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/';
236
+		}
237
+	}
238
+
239
+
240
+	/**
241
+	 * Gets a single entity related to the model indicated in the path and its id
242
+	 *
243
+	 * @param WP_REST_Request $request
244
+	 * @param string $version
245
+	 * @param string $model_name
246
+	 * @return WP_REST_Response|WP_Error
247
+	 * @throws InvalidDataTypeException
248
+	 * @throws InvalidInterfaceException
249
+	 * @throws InvalidArgumentException
250
+	 */
251
+	public static function handleRequestGetOne(WP_REST_Request $request, $version, $model_name)
252
+	{
253
+		$controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read');
254
+		try {
255
+			$controller->setRequestedVersion($version);
256
+			if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
257
+				return $controller->sendResponse(
258
+					new WP_Error(
259
+						'endpoint_parsing_error',
260
+						sprintf(
261
+							__(
262
+								'There is no model for endpoint %s. Please contact event espresso support',
263
+								'event_espresso'
264
+							),
265
+							$model_name
266
+						)
267
+					)
268
+				);
269
+			}
270
+			return $controller->sendResponse(
271
+				$controller->getEntityFromModel(
272
+					$controller->getModelVersionInfo()->loadModel($model_name),
273
+					$request
274
+				)
275
+			);
276
+		} catch (Exception $e) {
277
+			return $controller->sendResponse($e);
278
+		}
279
+	}
280
+
281
+
282
+	/**
283
+	 * Gets all the related entities (or if its a belongs-to relation just the one)
284
+	 * to the item with the given id
285
+	 *
286
+	 * @param WP_REST_Request $request
287
+	 * @param string $version
288
+	 * @param string $model_name
289
+	 * @param string $related_model_name
290
+	 * @return WP_REST_Response|WP_Error
291
+	 * @throws InvalidDataTypeException
292
+	 * @throws InvalidInterfaceException
293
+	 * @throws InvalidArgumentException
294
+	 */
295
+	public static function handleRequestGetRelated(
296
+		WP_REST_Request $request,
297
+		$version,
298
+		$model_name,
299
+		$related_model_name
300
+	) {
301
+		$controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read');
302
+		try {
303
+			$controller->setRequestedVersion($version);
304
+			if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
305
+				return $controller->sendResponse(
306
+					new WP_Error(
307
+						'endpoint_parsing_error',
308
+						sprintf(
309
+							__(
310
+								'There is no model for endpoint %s. Please contact event espresso support',
311
+								'event_espresso'
312
+							),
313
+							$model_name
314
+						)
315
+					)
316
+				);
317
+			}
318
+			$main_model = $controller->getModelVersionInfo()->loadModel($model_name);
319
+			if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($related_model_name)) {
320
+				return $controller->sendResponse(
321
+					new WP_Error(
322
+						'endpoint_parsing_error',
323
+						sprintf(
324
+							__(
325
+								'There is no model for endpoint %s. Please contact event espresso support',
326
+								'event_espresso'
327
+							),
328
+							$related_model_name
329
+						)
330
+					)
331
+				);
332
+			}
333
+			return $controller->sendResponse(
334
+				$controller->getEntitiesFromRelation(
335
+					$request->get_param('id'),
336
+					$main_model->related_settings_for($related_model_name),
337
+					$request
338
+				)
339
+			);
340
+		} catch (Exception $e) {
341
+			return $controller->sendResponse($e);
342
+		}
343
+	}
344
+
345
+
346
+	/**
347
+	 * Gets a collection for the given model and filters
348
+	 *
349
+	 * @param EEM_Base        $model
350
+	 * @param WP_REST_Request $request
351
+	 * @return array|WP_Error
352
+	 */
353
+	public function getEntitiesFromModel($model, $request)
354
+	{
355
+		$query_params = $this->createModelQueryParams($model, $request->get_params());
356
+		if (! Capabilities::currentUserHasPartialAccessTo($model, $query_params['caps'])) {
357
+			$model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
358
+			return new WP_Error(
359
+				sprintf('rest_%s_cannot_list', $model_name_plural),
360
+				sprintf(
361
+					__('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'),
362
+					$model_name_plural,
363
+					Capabilities::getMissingPermissionsString($model, $query_params['caps'])
364
+				),
365
+				array('status' => 403)
366
+			);
367
+		}
368
+		if (! $request->get_header('no_rest_headers')) {
369
+			$this->setHeadersFromQueryParams($model, $query_params);
370
+		}
371
+		/** @type array $results */
372
+		$results = $model->get_all_wpdb_results($query_params);
373
+		$nice_results = array();
374
+		foreach ($results as $result) {
375
+			$nice_results[] = $this->createEntityFromWpdbResult(
376
+				$model,
377
+				$result,
378
+				$request
379
+			);
380
+		}
381
+		return $nice_results;
382
+	}
383
+
384
+
385
+	/**
386
+	 * Gets the collection for given relation object
387
+	 * The same as Read::get_entities_from_model(), except if the relation
388
+	 * is a HABTM relation, in which case it merges any non-foreign-key fields from
389
+	 * the join-model-object into the results
390
+	 *
391
+	 * @param array                   $primary_model_query_params query params for finding the item from which
392
+	 *                                                            relations will be based
393
+	 * @param \EE_Model_Relation_Base $relation
394
+	 * @param WP_REST_Request         $request
395
+	 * @return WP_Error|array
396
+	 * @throws RestException
397
+	 */
398
+	protected function getEntitiesFromRelationUsingModelQueryParams($primary_model_query_params, $relation, $request)
399
+	{
400
+		$context = $this->validateContext($request->get_param('caps'));
401
+		$model = $relation->get_this_model();
402
+		$related_model = $relation->get_other_model();
403
+		if (! isset($primary_model_query_params[0])) {
404
+			$primary_model_query_params[0] = array();
405
+		}
406
+		// check if they can access the 1st model object
407
+		$primary_model_query_params = array(
408
+			0       => $primary_model_query_params[0],
409
+			'limit' => 1,
410
+		);
411
+		if ($model instanceof \EEM_Soft_Delete_Base) {
412
+			$primary_model_query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included(
413
+				$primary_model_query_params
414
+			);
415
+		}
416
+		$restricted_query_params = $primary_model_query_params;
417
+		$restricted_query_params['caps'] = $context;
418
+		$this->setDebugInfo('main model query params', $restricted_query_params);
419
+		$this->setDebugInfo('missing caps', Capabilities::getMissingPermissionsString($related_model, $context));
420
+		if (! (
421
+			Capabilities::currentUserHasPartialAccessTo($related_model, $context)
422
+			&& $model->exists($restricted_query_params)
423
+		)
424
+		) {
425
+			if ($relation instanceof EE_Belongs_To_Relation) {
426
+				$related_model_name_maybe_plural = strtolower($related_model->get_this_model_name());
427
+			} else {
428
+				$related_model_name_maybe_plural = EEH_Inflector::pluralize_and_lower(
429
+					$related_model->get_this_model_name()
430
+				);
431
+			}
432
+			return new WP_Error(
433
+				sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural),
434
+				sprintf(
435
+					__(
436
+						'Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s',
437
+						'event_espresso'
438
+					),
439
+					$related_model_name_maybe_plural,
440
+					$relation->get_this_model()->get_this_model_name(),
441
+					implode(
442
+						',',
443
+						array_keys(
444
+							Capabilities::getMissingPermissions($related_model, $context)
445
+						)
446
+					)
447
+				),
448
+				array('status' => 403)
449
+			);
450
+		}
451
+		$query_params = $this->createModelQueryParams($relation->get_other_model(), $request->get_params());
452
+		foreach ($primary_model_query_params[0] as $where_condition_key => $where_condition_value) {
453
+			$query_params[0][ $relation->get_this_model()->get_this_model_name()
454
+							  . '.'
455
+							  . $where_condition_key ] = $where_condition_value;
456
+		}
457
+		$query_params['default_where_conditions'] = 'none';
458
+		$query_params['caps'] = $context;
459
+		if (! $request->get_header('no_rest_headers')) {
460
+			$this->setHeadersFromQueryParams($relation->get_other_model(), $query_params);
461
+		}
462
+		/** @type array $results */
463
+		$results = $relation->get_other_model()->get_all_wpdb_results($query_params);
464
+		$nice_results = array();
465
+		foreach ($results as $result) {
466
+			$nice_result = $this->createEntityFromWpdbResult(
467
+				$relation->get_other_model(),
468
+				$result,
469
+				$request
470
+			);
471
+			if ($relation instanceof \EE_HABTM_Relation) {
472
+				// put the unusual stuff (properties from the HABTM relation) first, and make sure
473
+				// if there are conflicts we prefer the properties from the main model
474
+				$join_model_result = $this->createEntityFromWpdbResult(
475
+					$relation->get_join_model(),
476
+					$result,
477
+					$request
478
+				);
479
+				$joined_result = array_merge($nice_result, $join_model_result);
480
+				// but keep the meta stuff from the main model
481
+				if (isset($nice_result['meta'])) {
482
+					$joined_result['meta'] = $nice_result['meta'];
483
+				}
484
+				$nice_result = $joined_result;
485
+			}
486
+			$nice_results[] = $nice_result;
487
+		}
488
+		if ($relation instanceof EE_Belongs_To_Relation) {
489
+			return array_shift($nice_results);
490
+		} else {
491
+			return $nice_results;
492
+		}
493
+	}
494
+
495
+
496
+	/**
497
+	 * Gets the collection for given relation object
498
+	 * The same as Read::get_entities_from_model(), except if the relation
499
+	 * is a HABTM relation, in which case it merges any non-foreign-key fields from
500
+	 * the join-model-object into the results
501
+	 *
502
+	 * @param string                  $id the ID of the thing we are fetching related stuff from
503
+	 * @param \EE_Model_Relation_Base $relation
504
+	 * @param WP_REST_Request         $request
505
+	 * @return array|WP_Error
506
+	 * @throws EE_Error
507
+	 */
508
+	public function getEntitiesFromRelation($id, $relation, $request)
509
+	{
510
+		if (! $relation->get_this_model()->has_primary_key_field()) {
511
+			throw new EE_Error(
512
+				sprintf(
513
+					__(
514
+					// @codingStandardsIgnoreStart
515
+						'Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s',
516
+						// @codingStandardsIgnoreEnd
517
+						'event_espresso'
518
+					),
519
+					$relation->get_this_model()->get_this_model_name()
520
+				)
521
+			);
522
+		}
523
+		return $this->getEntitiesFromRelationUsingModelQueryParams(
524
+			array(
525
+				array(
526
+					$relation->get_this_model()->primary_key_name() => $id,
527
+				),
528
+			),
529
+			$relation,
530
+			$request
531
+		);
532
+	}
533
+
534
+
535
+	/**
536
+	 * Sets the headers that are based on the model and query params,
537
+	 * like the total records. This should only be called on the original request
538
+	 * from the client, not on subsequent internal
539
+	 *
540
+	 * @param EEM_Base $model
541
+	 * @param array    $query_params
542
+	 * @return void
543
+	 */
544
+	protected function setHeadersFromQueryParams($model, $query_params)
545
+	{
546
+		$this->setDebugInfo('model query params', $query_params);
547
+		$this->setDebugInfo(
548
+			'missing caps',
549
+			Capabilities::getMissingPermissionsString($model, $query_params['caps'])
550
+		);
551
+		// normally the limit to a 2-part array, where the 2nd item is the limit
552
+		if (! isset($query_params['limit'])) {
553
+			$query_params['limit'] = EED_Core_Rest_Api::get_default_query_limit();
554
+		}
555
+		if (is_array($query_params['limit'])) {
556
+			$limit_parts = $query_params['limit'];
557
+		} else {
558
+			$limit_parts = explode(',', $query_params['limit']);
559
+			if (count($limit_parts) == 1) {
560
+				$limit_parts = array(0, $limit_parts[0]);
561
+			}
562
+		}
563
+		// remove the group by and having parts of the query, as those will
564
+		// make the sql query return an array of values, instead of just a single value
565
+		unset($query_params['group_by'], $query_params['having'], $query_params['limit']);
566
+		$count = $model->count($query_params, null, true);
567
+		$pages = $count / $limit_parts[1];
568
+		$this->setResponseHeader('Total', $count, false);
569
+		$this->setResponseHeader('PageSize', $limit_parts[1], false);
570
+		$this->setResponseHeader('TotalPages', ceil($pages), false);
571
+	}
572
+
573
+
574
+	/**
575
+	 * Changes database results into REST API entities
576
+	 *
577
+	 * @param EEM_Base        $model
578
+	 * @param array           $db_row     like results from $wpdb->get_results()
579
+	 * @param WP_REST_Request $rest_request
580
+	 * @param string          $deprecated no longer used
581
+	 * @return array ready for being converted into json for sending to client
582
+	 */
583
+	public function createEntityFromWpdbResult($model, $db_row, $rest_request, $deprecated = null)
584
+	{
585
+		if (! $rest_request instanceof WP_REST_Request) {
586
+			// ok so this was called in the old style, where the 3rd arg was
587
+			// $include, and the 4th arg was $context
588
+			// now setup the request just to avoid fatal errors, although we won't be able
589
+			// to truly make use of it because it's kinda devoid of info
590
+			$rest_request = new WP_REST_Request();
591
+			$rest_request->set_param('include', $rest_request);
592
+			$rest_request->set_param('caps', $deprecated);
593
+		}
594
+		if ($rest_request->get_param('caps') == null) {
595
+			$rest_request->set_param('caps', EEM_Base::caps_read);
596
+		}
597
+		$entity_array = $this->createBareEntityFromWpdbResults($model, $db_row);
598
+		$entity_array = $this->addExtraFields($model, $db_row, $entity_array);
599
+		$entity_array['_links'] = $this->getEntityLinks($model, $db_row, $entity_array);
600
+		$entity_array['_calculated_fields'] = $this->getEntityCalculations($model, $db_row, $rest_request);
601
+		$entity_array = apply_filters(
602
+			'FHEE__Read__create_entity_from_wpdb_results__entity_before_including_requested_models',
603
+			$entity_array,
604
+			$model,
605
+			$rest_request->get_param('caps'),
606
+			$rest_request,
607
+			$this
608
+		);
609
+		$entity_array = $this->includeRequestedModels($model, $rest_request, $entity_array, $db_row);
610
+		$entity_array = apply_filters(
611
+			'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal',
612
+			$entity_array,
613
+			$model,
614
+			$rest_request->get_param('caps'),
615
+			$rest_request,
616
+			$this
617
+		);
618
+		$result_without_inaccessible_fields = Capabilities::filterOutInaccessibleEntityFields(
619
+			$entity_array,
620
+			$model,
621
+			$rest_request->get_param('caps'),
622
+			$this->getModelVersionInfo(),
623
+			$model->get_index_primary_key_string(
624
+				$model->deduce_fields_n_values_from_cols_n_values($db_row)
625
+			)
626
+		);
627
+		$this->setDebugInfo(
628
+			'inaccessible fields',
629
+			array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields))
630
+		);
631
+		return apply_filters(
632
+			'FHEE__Read__create_entity_from_wpdb_results__entity_return',
633
+			$result_without_inaccessible_fields,
634
+			$model,
635
+			$rest_request->get_param('caps')
636
+		);
637
+	}
638
+
639
+
640
+	/**
641
+	 * Creates a REST entity array (JSON object we're going to return in the response, but
642
+	 * for now still a PHP array, but soon enough we'll call json_encode on it, don't worry),
643
+	 * from $wpdb->get_row( $sql, ARRAY_A)
644
+	 *
645
+	 * @param EEM_Base $model
646
+	 * @param array    $db_row
647
+	 * @return array entity mostly ready for converting to JSON and sending in the response
648
+	 */
649
+	protected function createBareEntityFromWpdbResults(EEM_Base $model, $db_row)
650
+	{
651
+		$result = $model->deduce_fields_n_values_from_cols_n_values($db_row);
652
+		$result = array_intersect_key(
653
+			$result,
654
+			$this->getModelVersionInfo()->fieldsOnModelInThisVersion($model)
655
+		);
656
+		// if this is a CPT, we need to set the global $post to it,
657
+		// otherwise shortcodes etc won't work properly while rendering it
658
+		if ($model instanceof \EEM_CPT_Base) {
659
+			$do_chevy_shuffle = true;
660
+		} else {
661
+			$do_chevy_shuffle = false;
662
+		}
663
+		if ($do_chevy_shuffle) {
664
+			global $post;
665
+			$old_post = $post;
666
+			$post = get_post($result[ $model->primary_key_name() ]);
667
+			if (! $post instanceof \WP_Post) {
668
+				// well that's weird, because $result is what we JUST fetched from the database
669
+				throw new RestException(
670
+					'error_fetching_post_from_database_results',
671
+					esc_html__(
672
+						'An item was retrieved from the database but it\'s not a WP_Post like it should be.',
673
+						'event_espresso'
674
+					)
675
+				);
676
+			}
677
+			$model_object_classname = 'EE_' . $model->get_this_model_name();
678
+			$post->{$model_object_classname} = \EE_Registry::instance()->load_class(
679
+				$model_object_classname,
680
+				$result,
681
+				false,
682
+				false
683
+			);
684
+		}
685
+		foreach ($result as $field_name => $field_value) {
686
+			$field_obj = $model->field_settings_for($field_name);
687
+			if ($this->isSubclassOfOne($field_obj, $this->getModelVersionInfo()->fieldsIgnored())) {
688
+				unset($result[ $field_name ]);
689
+			} elseif ($this->isSubclassOfOne(
690
+				$field_obj,
691
+				$this->getModelVersionInfo()->fieldsThatHaveRenderedFormat()
692
+			)
693
+			) {
694
+				$result[ $field_name ] = array(
695
+					'raw'      => $this->prepareFieldObjValueForJson($field_obj, $field_value),
696
+					'rendered' => $this->prepareFieldObjValueForJson($field_obj, $field_value, 'pretty'),
697
+				);
698
+			} elseif ($this->isSubclassOfOne(
699
+				$field_obj,
700
+				$this->getModelVersionInfo()->fieldsThatHavePrettyFormat()
701
+			)
702
+			) {
703
+				$result[ $field_name ] = array(
704
+					'raw'    => $this->prepareFieldObjValueForJson($field_obj, $field_value),
705
+					'pretty' => $this->prepareFieldObjValueForJson($field_obj, $field_value, 'pretty'),
706
+				);
707
+			} elseif ($field_obj instanceof \EE_Datetime_Field) {
708
+				$field_value = $field_obj->prepare_for_set_from_db($field_value);
709
+				// if the value is null, but we're not supposed to permit null, then set to the field's default
710
+				if (is_null($field_value)) {
711
+					$field_value = $field_obj->getDefaultDateTimeObj();
712
+				}
713
+				if (is_null($field_value)) {
714
+					$gmt_date = $local_date = ModelDataTranslator::prepareFieldValuesForJson(
715
+						$field_obj,
716
+						$field_value,
717
+						$this->getModelVersionInfo()->requestedVersion()
718
+					);
719
+				} else {
720
+					$timezone = $field_value->getTimezone();
721
+					EEH_DTT_Helper::setTimezone($field_value, new DateTimeZone('UTC'));
722
+					$gmt_date = ModelDataTranslator::prepareFieldValuesForJson(
723
+						$field_obj,
724
+						$field_value,
725
+						$this->getModelVersionInfo()->requestedVersion()
726
+					);
727
+					EEH_DTT_Helper::setTimezone($field_value, $timezone);
728
+					$local_date = ModelDataTranslator::prepareFieldValuesForJson(
729
+						$field_obj,
730
+						$field_value,
731
+						$this->getModelVersionInfo()->requestedVersion()
732
+					);
733
+				}
734
+				$result[ $field_name . '_gmt' ] = $gmt_date;
735
+				$result[ $field_name ] = $local_date;
736
+			} else {
737
+				$result[ $field_name ] = $this->prepareFieldObjValueForJson($field_obj, $field_value);
738
+			}
739
+		}
740
+		if ($do_chevy_shuffle) {
741
+			$post = $old_post;
742
+		}
743
+		return $result;
744
+	}
745
+
746
+
747
+	/**
748
+	 * Takes a value all the way from the DB representation, to the model object's representation, to the
749
+	 * user-facing PHP representation, to the REST API representation. (Assumes you've already taken from the DB
750
+	 * representation using $field_obj->prepare_for_set_from_db())
751
+	 *
752
+	 * @param EE_Model_Field_Base $field_obj
753
+	 * @param mixed               $value  as it's stored on a model object
754
+	 * @param string              $format valid values are 'normal' (default), 'pretty', 'datetime_obj'
755
+	 * @return mixed
756
+	 * @throws ObjectDetectedException if $value contains a PHP object
757
+	 */
758
+	protected function prepareFieldObjValueForJson(EE_Model_Field_Base $field_obj, $value, $format = 'normal')
759
+	{
760
+		$value = $field_obj->prepare_for_set_from_db($value);
761
+		switch ($format) {
762
+			case 'pretty':
763
+				$value = $field_obj->prepare_for_pretty_echoing($value);
764
+				break;
765
+			case 'normal':
766
+			default:
767
+				$value = $field_obj->prepare_for_get($value);
768
+				break;
769
+		}
770
+		return ModelDataTranslator::prepareFieldValuesForJson(
771
+			$field_obj,
772
+			$value,
773
+			$this->getModelVersionInfo()->requestedVersion()
774
+		);
775
+	}
776
+
777
+
778
+	/**
779
+	 * Adds a few extra fields to the entity response
780
+	 *
781
+	 * @param EEM_Base $model
782
+	 * @param array    $db_row
783
+	 * @param array    $entity_array
784
+	 * @return array modified entity
785
+	 */
786
+	protected function addExtraFields(EEM_Base $model, $db_row, $entity_array)
787
+	{
788
+		if ($model instanceof EEM_CPT_Base) {
789
+			$entity_array['link'] = get_permalink($db_row[ $model->get_primary_key_field()->get_qualified_column() ]);
790
+		}
791
+		return $entity_array;
792
+	}
793
+
794
+
795
+	/**
796
+	 * Gets links we want to add to the response
797
+	 *
798
+	 * @global \WP_REST_Server $wp_rest_server
799
+	 * @param EEM_Base         $model
800
+	 * @param array            $db_row
801
+	 * @param array            $entity_array
802
+	 * @return array the _links item in the entity
803
+	 */
804
+	protected function getEntityLinks($model, $db_row, $entity_array)
805
+	{
806
+		// add basic links
807
+		$links = array();
808
+		if ($model->has_primary_key_field()) {
809
+			$links['self'] = array(
810
+				array(
811
+					'href' => $this->getVersionedLinkTo(
812
+						EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
813
+						. '/'
814
+						. $entity_array[ $model->primary_key_name() ]
815
+					),
816
+				),
817
+			);
818
+		}
819
+		$links['collection'] = array(
820
+			array(
821
+				'href' => $this->getVersionedLinkTo(
822
+					EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
823
+				),
824
+			),
825
+		);
826
+		// add links to related models
827
+		if ($model->has_primary_key_field()) {
828
+			foreach ($this->getModelVersionInfo()->relationSettings($model) as $relation_name => $relation_obj) {
829
+				$related_model_part = Read::getRelatedEntityName($relation_name, $relation_obj);
830
+				$links[ EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part ] = array(
831
+					array(
832
+						'href'   => $this->getVersionedLinkTo(
833
+							EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
834
+							. '/'
835
+							. $entity_array[ $model->primary_key_name() ]
836
+							. '/'
837
+							. $related_model_part
838
+						),
839
+						'single' => $relation_obj instanceof EE_Belongs_To_Relation ? true : false,
840
+					),
841
+				);
842
+			}
843
+		}
844
+		return $links;
845
+	}
846
+
847
+
848
+	/**
849
+	 * Adds the included models indicated in the request to the entity provided
850
+	 *
851
+	 * @param EEM_Base        $model
852
+	 * @param WP_REST_Request $rest_request
853
+	 * @param array           $entity_array
854
+	 * @param array           $db_row
855
+	 * @return array the modified entity
856
+	 */
857
+	protected function includeRequestedModels(
858
+		EEM_Base $model,
859
+		WP_REST_Request $rest_request,
860
+		$entity_array,
861
+		$db_row = array()
862
+	) {
863
+		// if $db_row not included, hope the entity array has what we need
864
+		if (! $db_row) {
865
+			$db_row = $entity_array;
866
+		}
867
+		$includes_for_this_model = $this->explodeAndGetItemsPrefixedWith($rest_request->get_param('include'), '');
868
+		$includes_for_this_model = $this->removeModelNamesFromArray($includes_for_this_model);
869
+		// if they passed in * or didn't specify any includes, return everything
870
+		if (! in_array('*', $includes_for_this_model)
871
+			&& ! empty($includes_for_this_model)
872
+		) {
873
+			if ($model->has_primary_key_field()) {
874
+				// always include the primary key. ya just gotta know that at least
875
+				$includes_for_this_model[] = $model->primary_key_name();
876
+			}
877
+			if ($this->explodeAndGetItemsPrefixedWith($rest_request->get_param('calculate'), '')) {
878
+				$includes_for_this_model[] = '_calculated_fields';
879
+			}
880
+			$entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model));
881
+		}
882
+		$relation_settings = $this->getModelVersionInfo()->relationSettings($model);
883
+		foreach ($relation_settings as $relation_name => $relation_obj) {
884
+			$related_fields_to_include = $this->explodeAndGetItemsPrefixedWith(
885
+				$rest_request->get_param('include'),
886
+				$relation_name
887
+			);
888
+			$related_fields_to_calculate = $this->explodeAndGetItemsPrefixedWith(
889
+				$rest_request->get_param('calculate'),
890
+				$relation_name
891
+			);
892
+			// did they specify they wanted to include a related model, or
893
+			// specific fields from a related model?
894
+			// or did they specify to calculate a field from a related model?
895
+			if ($related_fields_to_include || $related_fields_to_calculate) {
896
+				// if so, we should include at least some part of the related model
897
+				$pretend_related_request = new WP_REST_Request();
898
+				$pretend_related_request->set_query_params(
899
+					array(
900
+						'caps'      => $rest_request->get_param('caps'),
901
+						'include'   => $related_fields_to_include,
902
+						'calculate' => $related_fields_to_calculate,
903
+					)
904
+				);
905
+				$pretend_related_request->add_header('no_rest_headers', true);
906
+				$primary_model_query_params = $model->alter_query_params_to_restrict_by_ID(
907
+					$model->get_index_primary_key_string(
908
+						$model->deduce_fields_n_values_from_cols_n_values($db_row)
909
+					)
910
+				);
911
+				$related_results = $this->getEntitiesFromRelationUsingModelQueryParams(
912
+					$primary_model_query_params,
913
+					$relation_obj,
914
+					$pretend_related_request
915
+				);
916
+				$entity_array[ Read::getRelatedEntityName($relation_name, $relation_obj) ] = $related_results
917
+																							 instanceof
918
+																							 WP_Error
919
+					? null
920
+					: $related_results;
921
+			}
922
+		}
923
+		return $entity_array;
924
+	}
925
+
926
+
927
+	/**
928
+	 * Returns a new array with all the names of models removed. Eg
929
+	 * array( 'Event', 'Datetime.*', 'foobar' ) would become array( 'Datetime.*', 'foobar' )
930
+	 *
931
+	 * @param array $arr
932
+	 * @return array
933
+	 */
934
+	private function removeModelNamesFromArray($arr)
935
+	{
936
+		return array_diff($arr, array_keys(EE_Registry::instance()->non_abstract_db_models));
937
+	}
938
+
939
+
940
+	/**
941
+	 * Gets the calculated fields for the response
942
+	 *
943
+	 * @param EEM_Base        $model
944
+	 * @param array           $wpdb_row
945
+	 * @param WP_REST_Request $rest_request
946
+	 * @return \stdClass the _calculations item in the entity
947
+	 * @throws ObjectDetectedException if a default value has a PHP object, which should never do (and if we
948
+	 * did, let's know about it ASAP, so let the exception bubble up)
949
+	 */
950
+	protected function getEntityCalculations($model, $wpdb_row, $rest_request)
951
+	{
952
+		$calculated_fields = $this->explodeAndGetItemsPrefixedWith(
953
+			$rest_request->get_param('calculate'),
954
+			''
955
+		);
956
+		// note: setting calculate=* doesn't do anything
957
+		$calculated_fields_to_return = new \stdClass();
958
+		foreach ($calculated_fields as $field_to_calculate) {
959
+			try {
960
+				$calculated_fields_to_return->$field_to_calculate = ModelDataTranslator::prepareFieldValueForJson(
961
+					null,
962
+					$this->fields_calculator->retrieveCalculatedFieldValue(
963
+						$model,
964
+						$field_to_calculate,
965
+						$wpdb_row,
966
+						$rest_request,
967
+						$this
968
+					),
969
+					$this->getModelVersionInfo()->requestedVersion()
970
+				);
971
+			} catch (RestException $e) {
972
+				// if we don't have permission to read it, just leave it out. but let devs know about the problem
973
+				$this->setResponseHeader(
974
+					'Notices-Field-Calculation-Errors['
975
+					. $e->getStringCode()
976
+					. ']['
977
+					. $model->get_this_model_name()
978
+					. ']['
979
+					. $field_to_calculate
980
+					. ']',
981
+					$e->getMessage(),
982
+					true
983
+				);
984
+			}
985
+		}
986
+		return $calculated_fields_to_return;
987
+	}
988
+
989
+
990
+	/**
991
+	 * Gets the full URL to the resource, taking the requested version into account
992
+	 *
993
+	 * @param string $link_part_after_version_and_slash eg "events/10/datetimes"
994
+	 * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes"
995
+	 */
996
+	public function getVersionedLinkTo($link_part_after_version_and_slash)
997
+	{
998
+		return rest_url(
999
+			EED_Core_Rest_Api::get_versioned_route_to(
1000
+				$link_part_after_version_and_slash,
1001
+				$this->getModelVersionInfo()->requestedVersion()
1002
+			)
1003
+		);
1004
+	}
1005
+
1006
+
1007
+	/**
1008
+	 * Gets the correct lowercase name for the relation in the API according
1009
+	 * to the relation's type
1010
+	 *
1011
+	 * @param string                  $relation_name
1012
+	 * @param \EE_Model_Relation_Base $relation_obj
1013
+	 * @return string
1014
+	 */
1015
+	public static function getRelatedEntityName($relation_name, $relation_obj)
1016
+	{
1017
+		if ($relation_obj instanceof EE_Belongs_To_Relation) {
1018
+			return strtolower($relation_name);
1019
+		} else {
1020
+			return EEH_Inflector::pluralize_and_lower($relation_name);
1021
+		}
1022
+	}
1023
+
1024
+
1025
+	/**
1026
+	 * Gets the one model object with the specified id for the specified model
1027
+	 *
1028
+	 * @param EEM_Base        $model
1029
+	 * @param WP_REST_Request $request
1030
+	 * @return array|WP_Error
1031
+	 */
1032
+	public function getEntityFromModel($model, $request)
1033
+	{
1034
+		$context = $this->validateContext($request->get_param('caps'));
1035
+		return $this->getOneOrReportPermissionError($model, $request, $context);
1036
+	}
1037
+
1038
+
1039
+	/**
1040
+	 * If a context is provided which isn't valid, maybe it was added in a future
1041
+	 * version so just treat it as a default read
1042
+	 *
1043
+	 * @param string $context
1044
+	 * @return string array key of EEM_Base::cap_contexts_to_cap_action_map()
1045
+	 */
1046
+	public function validateContext($context)
1047
+	{
1048
+		if (! $context) {
1049
+			$context = EEM_Base::caps_read;
1050
+		}
1051
+		$valid_contexts = EEM_Base::valid_cap_contexts();
1052
+		if (in_array($context, $valid_contexts)) {
1053
+			return $context;
1054
+		} else {
1055
+			return EEM_Base::caps_read;
1056
+		}
1057
+	}
1058
+
1059
+
1060
+	/**
1061
+	 * Verifies the passed in value is an allowable default where conditions value.
1062
+	 *
1063
+	 * @param $default_query_params
1064
+	 * @return string
1065
+	 */
1066
+	public function validateDefaultQueryParams($default_query_params)
1067
+	{
1068
+		$valid_default_where_conditions_for_api_calls = array(
1069
+			EEM_Base::default_where_conditions_all,
1070
+			EEM_Base::default_where_conditions_minimum_all,
1071
+			EEM_Base::default_where_conditions_minimum_others,
1072
+		);
1073
+		if (! $default_query_params) {
1074
+			$default_query_params = EEM_Base::default_where_conditions_all;
1075
+		}
1076
+		if (in_array(
1077
+			$default_query_params,
1078
+			$valid_default_where_conditions_for_api_calls,
1079
+			true
1080
+		)) {
1081
+			return $default_query_params;
1082
+		} else {
1083
+			return EEM_Base::default_where_conditions_all;
1084
+		}
1085
+	}
1086
+
1087
+
1088
+	/**
1089
+	 * Translates API filter get parameter into $query_params array used by EEM_Base::get_all().
1090
+	 * Note: right now the query parameter keys for fields (and related fields)
1091
+	 * can be left as-is, but it's quite possible this will change someday.
1092
+	 * Also, this method's contents might be candidate for moving to Model_Data_Translator
1093
+	 *
1094
+	 * @param EEM_Base $model
1095
+	 * @param array    $query_parameters  from $_GET parameter @see Read:handle_request_get_all
1096
+	 * @return array like what EEM_Base::get_all() expects or FALSE to indicate
1097
+	 *                                    that absolutely no results should be returned
1098
+	 * @throws EE_Error
1099
+	 * @throws RestException
1100
+	 */
1101
+	public function createModelQueryParams($model, $query_parameters)
1102
+	{
1103
+		$model_query_params = array();
1104
+		if (isset($query_parameters['where'])) {
1105
+			$model_query_params[0] = ModelDataTranslator::prepareConditionsQueryParamsForModels(
1106
+				$query_parameters['where'],
1107
+				$model,
1108
+				$this->getModelVersionInfo()->requestedVersion()
1109
+			);
1110
+		}
1111
+		if (isset($query_parameters['order_by'])) {
1112
+			$order_by = $query_parameters['order_by'];
1113
+		} elseif (isset($query_parameters['orderby'])) {
1114
+			$order_by = $query_parameters['orderby'];
1115
+		} else {
1116
+			$order_by = null;
1117
+		}
1118
+		if ($order_by !== null) {
1119
+			if (is_array($order_by)) {
1120
+				$order_by = ModelDataTranslator::prepareFieldNamesInArrayKeysFromJson($order_by);
1121
+			} else {
1122
+				// it's a single item
1123
+				$order_by = ModelDataTranslator::prepareFieldNameFromJson($order_by);
1124
+			}
1125
+			$model_query_params['order_by'] = $order_by;
1126
+		}
1127
+		if (isset($query_parameters['group_by'])) {
1128
+			$group_by = $query_parameters['group_by'];
1129
+		} elseif (isset($query_parameters['groupby'])) {
1130
+			$group_by = $query_parameters['groupby'];
1131
+		} else {
1132
+			$group_by = array_keys($model->get_combined_primary_key_fields());
1133
+		}
1134
+		// make sure they're all real names
1135
+		if (is_array($group_by)) {
1136
+			$group_by = ModelDataTranslator::prepareFieldNamesFromJson($group_by);
1137
+		}
1138
+		if ($group_by !== null) {
1139
+			$model_query_params['group_by'] = $group_by;
1140
+		}
1141
+		if (isset($query_parameters['having'])) {
1142
+			$model_query_params['having'] = ModelDataTranslator::prepareConditionsQueryParamsForModels(
1143
+				$query_parameters['having'],
1144
+				$model,
1145
+				$this->getModelVersionInfo()->requestedVersion()
1146
+			);
1147
+		}
1148
+		if (isset($query_parameters['order'])) {
1149
+			$model_query_params['order'] = $query_parameters['order'];
1150
+		}
1151
+		if (isset($query_parameters['mine'])) {
1152
+			$model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params);
1153
+		}
1154
+		if (isset($query_parameters['limit'])) {
1155
+			// limit should be either a string like '23' or '23,43', or an array with two items in it
1156
+			if (! is_array($query_parameters['limit'])) {
1157
+				$limit_array = explode(',', (string) $query_parameters['limit']);
1158
+			} else {
1159
+				$limit_array = $query_parameters['limit'];
1160
+			}
1161
+			$sanitized_limit = array();
1162
+			foreach ($limit_array as $key => $limit_part) {
1163
+				if ($this->debug_mode && (! is_numeric($limit_part) || count($sanitized_limit) > 2)) {
1164
+					throw new EE_Error(
1165
+						sprintf(
1166
+							__(
1167
+							// @codingStandardsIgnoreStart
1168
+								'An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.',
1169
+								// @codingStandardsIgnoreEnd
1170
+								'event_espresso'
1171
+							),
1172
+							wp_json_encode($query_parameters['limit'])
1173
+						)
1174
+					);
1175
+				}
1176
+				$sanitized_limit[] = (int) $limit_part;
1177
+			}
1178
+			$model_query_params['limit'] = implode(',', $sanitized_limit);
1179
+		} else {
1180
+			$model_query_params['limit'] = EED_Core_Rest_Api::get_default_query_limit();
1181
+		}
1182
+		if (isset($query_parameters['caps'])) {
1183
+			$model_query_params['caps'] = $this->validateContext($query_parameters['caps']);
1184
+		} else {
1185
+			$model_query_params['caps'] = EEM_Base::caps_read;
1186
+		}
1187
+		if (isset($query_parameters['default_where_conditions'])) {
1188
+			$model_query_params['default_where_conditions'] = $this->validateDefaultQueryParams(
1189
+				$query_parameters['default_where_conditions']
1190
+			);
1191
+		}
1192
+		return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model);
1193
+	}
1194
+
1195
+
1196
+	/**
1197
+	 * Changes the REST-style query params for use in the models
1198
+	 *
1199
+	 * @deprecated
1200
+	 * @param EEM_Base $model
1201
+	 * @param array    $query_params sub-array from @see EEM_Base::get_all()
1202
+	 * @return array
1203
+	 */
1204
+	public function prepareRestQueryParamsKeyForModels($model, $query_params)
1205
+	{
1206
+		$model_ready_query_params = array();
1207
+		foreach ($query_params as $key => $value) {
1208
+			if (is_array($value)) {
1209
+				$model_ready_query_params[ $key ] = $this->prepareRestQueryParamsKeyForModels($model, $value);
1210
+			} else {
1211
+				$model_ready_query_params[ $key ] = $value;
1212
+			}
1213
+		}
1214
+		return $model_ready_query_params;
1215
+	}
1216
+
1217
+
1218
+	/**
1219
+	 * @deprecated instead use ModelDataTranslator::prepareFieldValuesFromJson()
1220
+	 * @param $model
1221
+	 * @param $query_params
1222
+	 * @return array
1223
+	 */
1224
+	public function prepareRestQueryParamsValuesForModels($model, $query_params)
1225
+	{
1226
+		$model_ready_query_params = array();
1227
+		foreach ($query_params as $key => $value) {
1228
+			if (is_array($value)) {
1229
+				$model_ready_query_params[ $key ] = $this->prepareRestQueryParamsValuesForModels($model, $value);
1230
+			} else {
1231
+				$model_ready_query_params[ $key ] = $value;
1232
+			}
1233
+		}
1234
+		return $model_ready_query_params;
1235
+	}
1236
+
1237
+
1238
+	/**
1239
+	 * Explodes the string on commas, and only returns items with $prefix followed by a period.
1240
+	 * If no prefix is specified, returns items with no period.
1241
+	 *
1242
+	 * @param string|array $string_to_explode eg "jibba,jabba, blah, blah, blah" or array('jibba', 'jabba' )
1243
+	 * @param string       $prefix            "Event" or "foobar"
1244
+	 * @return array $string_to_exploded exploded on COMMAS, and if a prefix was specified
1245
+	 *                                        we only return strings starting with that and a period; if no prefix was
1246
+	 *                                        specified we return all items containing NO periods
1247
+	 */
1248
+	public function explodeAndGetItemsPrefixedWith($string_to_explode, $prefix)
1249
+	{
1250
+		if (is_string($string_to_explode)) {
1251
+			$exploded_contents = explode(',', $string_to_explode);
1252
+		} elseif (is_array($string_to_explode)) {
1253
+			$exploded_contents = $string_to_explode;
1254
+		} else {
1255
+			$exploded_contents = array();
1256
+		}
1257
+		// if the string was empty, we want an empty array
1258
+		$exploded_contents = array_filter($exploded_contents);
1259
+		$contents_with_prefix = array();
1260
+		foreach ($exploded_contents as $item) {
1261
+			$item = trim($item);
1262
+			// if no prefix was provided, so we look for items with no "." in them
1263
+			if (! $prefix) {
1264
+				// does this item have a period?
1265
+				if (strpos($item, '.') === false) {
1266
+					// if not, then its what we're looking for
1267
+					$contents_with_prefix[] = $item;
1268
+				}
1269
+			} elseif (strpos($item, $prefix . '.') === 0) {
1270
+				// this item has the prefix and a period, grab it
1271
+				$contents_with_prefix[] = substr(
1272
+					$item,
1273
+					strpos($item, $prefix . '.') + strlen($prefix . '.')
1274
+				);
1275
+			} elseif ($item === $prefix) {
1276
+				// this item is JUST the prefix
1277
+				// so let's grab everything after, which is a blank string
1278
+				$contents_with_prefix[] = '';
1279
+			}
1280
+		}
1281
+		return $contents_with_prefix;
1282
+	}
1283
+
1284
+
1285
+	/**
1286
+	 * @deprecated since 4.8.36.rc.001 You should instead use Read::explode_and_get_items_prefixed_with.
1287
+	 * Deprecated because its return values were really quite confusing- sometimes it returned
1288
+	 * an empty array (when the include string was blank or '*') or sometimes it returned
1289
+	 * array('*') (when you provided a model and a model of that kind was found).
1290
+	 * Parses the $include_string so we fetch all the field names relating to THIS model
1291
+	 * (ie have NO period in them), or for the provided model (ie start with the model
1292
+	 * name and then a period).
1293
+	 * @param string $include_string @see Read:handle_request_get_all
1294
+	 * @param string $model_name
1295
+	 * @return array of fields for this model. If $model_name is provided, then
1296
+	 *                               the fields for that model, with the model's name removed from each.
1297
+	 *                               If $include_string was blank or '*' returns an empty array
1298
+	 */
1299
+	public function extractIncludesForThisModel($include_string, $model_name = null)
1300
+	{
1301
+		if (is_array($include_string)) {
1302
+			$include_string = implode(',', $include_string);
1303
+		}
1304
+		if ($include_string === '*' || $include_string === '') {
1305
+			return array();
1306
+		}
1307
+		$includes = explode(',', $include_string);
1308
+		$extracted_fields_to_include = array();
1309
+		if ($model_name) {
1310
+			foreach ($includes as $field_to_include) {
1311
+				$field_to_include = trim($field_to_include);
1312
+				if (strpos($field_to_include, $model_name . '.') === 0) {
1313
+					// found the model name at the exact start
1314
+					$field_sans_model_name = str_replace($model_name . '.', '', $field_to_include);
1315
+					$extracted_fields_to_include[] = $field_sans_model_name;
1316
+				} elseif ($field_to_include == $model_name) {
1317
+					$extracted_fields_to_include[] = '*';
1318
+				}
1319
+			}
1320
+		} else {
1321
+			// look for ones with no period
1322
+			foreach ($includes as $field_to_include) {
1323
+				$field_to_include = trim($field_to_include);
1324
+				if (strpos($field_to_include, '.') === false
1325
+					&& ! $this->getModelVersionInfo()->isModelNameInThisVersion($field_to_include)
1326
+				) {
1327
+					$extracted_fields_to_include[] = $field_to_include;
1328
+				}
1329
+			}
1330
+		}
1331
+		return $extracted_fields_to_include;
1332
+	}
1333
+
1334
+
1335
+	/**
1336
+	 * Gets the single item using the model according to the request in the context given, otherwise
1337
+	 * returns that it's inaccessible to the current user
1338
+	 *
1339
+	 * @param EEM_Base        $model
1340
+	 * @param WP_REST_Request $request
1341
+	 * @param null            $context
1342
+	 * @return array|WP_Error
1343
+	 */
1344
+	public function getOneOrReportPermissionError(EEM_Base $model, WP_REST_Request $request, $context = null)
1345
+	{
1346
+		$query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1);
1347
+		if ($model instanceof \EEM_Soft_Delete_Base) {
1348
+			$query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params);
1349
+		}
1350
+		$restricted_query_params = $query_params;
1351
+		$restricted_query_params['caps'] = $context;
1352
+		$this->setDebugInfo('model query params', $restricted_query_params);
1353
+		$model_rows = $model->get_all_wpdb_results($restricted_query_params);
1354
+		if (! empty($model_rows)) {
1355
+			return $this->createEntityFromWpdbResult(
1356
+				$model,
1357
+				array_shift($model_rows),
1358
+				$request
1359
+			);
1360
+		} else {
1361
+			// ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities
1362
+			$lowercase_model_name = strtolower($model->get_this_model_name());
1363
+			$model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params);
1364
+			if (! empty($model_rows_found_sans_restrictions)) {
1365
+				// you got shafted- it existed but we didn't want to tell you!
1366
+				return new WP_Error(
1367
+					'rest_user_cannot_' . $context,
1368
+					sprintf(
1369
+						__('Sorry, you cannot %1$s this %2$s. Missing permissions are: %3$s', 'event_espresso'),
1370
+						$context,
1371
+						strtolower($model->get_this_model_name()),
1372
+						Capabilities::getMissingPermissionsString(
1373
+							$model,
1374
+							$context
1375
+						)
1376
+					),
1377
+					array('status' => 403)
1378
+				);
1379
+			} else {
1380
+				// it's not you. It just doesn't exist
1381
+				return new WP_Error(
1382
+					sprintf('rest_%s_invalid_id', $lowercase_model_name),
1383
+					sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name),
1384
+					array('status' => 404)
1385
+				);
1386
+			}
1387
+		}
1388
+	}
1389 1389
 }
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
         $controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read');
74 74
         try {
75 75
             $controller->setRequestedVersion($version);
76
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
76
+            if ( ! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
77 77
                 return $controller->sendResponse(
78 78
                     new WP_Error(
79 79
                         'endpoint_parsing_error',
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         $controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read');
115 115
         try {
116 116
             $controller->setRequestedVersion($version);
117
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
117
+            if ( ! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
118 118
                 return array();
119 119
             }
120 120
             // get the model for this version
@@ -171,11 +171,11 @@  discard block
 block discarded – undo
171 171
      */
172 172
     protected function translateDefaultsForRestResponse($field_name, EE_Model_Field_Base $field, array $schema)
173 173
     {
174
-        if (isset($schema['properties'][ $field_name ]['default'])) {
175
-            if (is_array($schema['properties'][ $field_name ]['default'])) {
176
-                foreach ($schema['properties'][ $field_name ]['default'] as $default_key => $default_value) {
174
+        if (isset($schema['properties'][$field_name]['default'])) {
175
+            if (is_array($schema['properties'][$field_name]['default'])) {
176
+                foreach ($schema['properties'][$field_name]['default'] as $default_key => $default_value) {
177 177
                     if ($default_key === 'raw') {
178
-                        $schema['properties'][ $field_name ]['default'][ $default_key ] =
178
+                        $schema['properties'][$field_name]['default'][$default_key] =
179 179
                             ModelDataTranslator::prepareFieldValueForJson(
180 180
                                 $field,
181 181
                                 $default_value,
@@ -184,9 +184,9 @@  discard block
 block discarded – undo
184 184
                     }
185 185
                 }
186 186
             } else {
187
-                $schema['properties'][ $field_name ]['default'] = ModelDataTranslator::prepareFieldValueForJson(
187
+                $schema['properties'][$field_name]['default'] = ModelDataTranslator::prepareFieldValueForJson(
188 188
                     $field,
189
-                    $schema['properties'][ $field_name ]['default'],
189
+                    $schema['properties'][$field_name]['default'],
190 190
                     $this->getModelVersionInfo()->requestedVersion()
191 191
                 );
192 192
             }
@@ -208,9 +208,9 @@  discard block
 block discarded – undo
208 208
     protected function maybeAddExtraFieldsToSchema($field_name, EE_Model_Field_Base $field, array $schema)
209 209
     {
210 210
         if ($field instanceof EE_Datetime_Field) {
211
-            $schema['properties'][ $field_name . '_gmt' ] = $field->getSchema();
211
+            $schema['properties'][$field_name.'_gmt'] = $field->getSchema();
212 212
             // modify the description
213
-            $schema['properties'][ $field_name . '_gmt' ]['description'] = sprintf(
213
+            $schema['properties'][$field_name.'_gmt']['description'] = sprintf(
214 214
                 esc_html__('%s - the value for this field is in GMT.', 'event_espresso'),
215 215
                 wp_specialchars_decode($field->get_nicename(), ENT_QUOTES)
216 216
             );
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
         $controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read');
254 254
         try {
255 255
             $controller->setRequestedVersion($version);
256
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
256
+            if ( ! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
257 257
                 return $controller->sendResponse(
258 258
                     new WP_Error(
259 259
                         'endpoint_parsing_error',
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
         $controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read');
302 302
         try {
303 303
             $controller->setRequestedVersion($version);
304
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
304
+            if ( ! $controller->getModelVersionInfo()->isModelNameInThisVersion($model_name)) {
305 305
                 return $controller->sendResponse(
306 306
                     new WP_Error(
307 307
                         'endpoint_parsing_error',
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
                 );
317 317
             }
318 318
             $main_model = $controller->getModelVersionInfo()->loadModel($model_name);
319
-            if (! $controller->getModelVersionInfo()->isModelNameInThisVersion($related_model_name)) {
319
+            if ( ! $controller->getModelVersionInfo()->isModelNameInThisVersion($related_model_name)) {
320 320
                 return $controller->sendResponse(
321 321
                     new WP_Error(
322 322
                         'endpoint_parsing_error',
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
     public function getEntitiesFromModel($model, $request)
354 354
     {
355 355
         $query_params = $this->createModelQueryParams($model, $request->get_params());
356
-        if (! Capabilities::currentUserHasPartialAccessTo($model, $query_params['caps'])) {
356
+        if ( ! Capabilities::currentUserHasPartialAccessTo($model, $query_params['caps'])) {
357 357
             $model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
358 358
             return new WP_Error(
359 359
                 sprintf('rest_%s_cannot_list', $model_name_plural),
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
                 array('status' => 403)
366 366
             );
367 367
         }
368
-        if (! $request->get_header('no_rest_headers')) {
368
+        if ( ! $request->get_header('no_rest_headers')) {
369 369
             $this->setHeadersFromQueryParams($model, $query_params);
370 370
         }
371 371
         /** @type array $results */
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
         $context = $this->validateContext($request->get_param('caps'));
401 401
         $model = $relation->get_this_model();
402 402
         $related_model = $relation->get_other_model();
403
-        if (! isset($primary_model_query_params[0])) {
403
+        if ( ! isset($primary_model_query_params[0])) {
404 404
             $primary_model_query_params[0] = array();
405 405
         }
406 406
         // check if they can access the 1st model object
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
         $restricted_query_params['caps'] = $context;
418 418
         $this->setDebugInfo('main model query params', $restricted_query_params);
419 419
         $this->setDebugInfo('missing caps', Capabilities::getMissingPermissionsString($related_model, $context));
420
-        if (! (
420
+        if ( ! (
421 421
             Capabilities::currentUserHasPartialAccessTo($related_model, $context)
422 422
             && $model->exists($restricted_query_params)
423 423
         )
@@ -450,13 +450,13 @@  discard block
 block discarded – undo
450 450
         }
451 451
         $query_params = $this->createModelQueryParams($relation->get_other_model(), $request->get_params());
452 452
         foreach ($primary_model_query_params[0] as $where_condition_key => $where_condition_value) {
453
-            $query_params[0][ $relation->get_this_model()->get_this_model_name()
453
+            $query_params[0][$relation->get_this_model()->get_this_model_name()
454 454
                               . '.'
455
-                              . $where_condition_key ] = $where_condition_value;
455
+                              . $where_condition_key] = $where_condition_value;
456 456
         }
457 457
         $query_params['default_where_conditions'] = 'none';
458 458
         $query_params['caps'] = $context;
459
-        if (! $request->get_header('no_rest_headers')) {
459
+        if ( ! $request->get_header('no_rest_headers')) {
460 460
             $this->setHeadersFromQueryParams($relation->get_other_model(), $query_params);
461 461
         }
462 462
         /** @type array $results */
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
      */
508 508
     public function getEntitiesFromRelation($id, $relation, $request)
509 509
     {
510
-        if (! $relation->get_this_model()->has_primary_key_field()) {
510
+        if ( ! $relation->get_this_model()->has_primary_key_field()) {
511 511
             throw new EE_Error(
512 512
                 sprintf(
513 513
                     __(
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
             Capabilities::getMissingPermissionsString($model, $query_params['caps'])
550 550
         );
551 551
         // normally the limit to a 2-part array, where the 2nd item is the limit
552
-        if (! isset($query_params['limit'])) {
552
+        if ( ! isset($query_params['limit'])) {
553 553
             $query_params['limit'] = EED_Core_Rest_Api::get_default_query_limit();
554 554
         }
555 555
         if (is_array($query_params['limit'])) {
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
      */
583 583
     public function createEntityFromWpdbResult($model, $db_row, $rest_request, $deprecated = null)
584 584
     {
585
-        if (! $rest_request instanceof WP_REST_Request) {
585
+        if ( ! $rest_request instanceof WP_REST_Request) {
586 586
             // ok so this was called in the old style, where the 3rd arg was
587 587
             // $include, and the 4th arg was $context
588 588
             // now setup the request just to avoid fatal errors, although we won't be able
@@ -663,8 +663,8 @@  discard block
 block discarded – undo
663 663
         if ($do_chevy_shuffle) {
664 664
             global $post;
665 665
             $old_post = $post;
666
-            $post = get_post($result[ $model->primary_key_name() ]);
667
-            if (! $post instanceof \WP_Post) {
666
+            $post = get_post($result[$model->primary_key_name()]);
667
+            if ( ! $post instanceof \WP_Post) {
668 668
                 // well that's weird, because $result is what we JUST fetched from the database
669 669
                 throw new RestException(
670 670
                     'error_fetching_post_from_database_results',
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
                     )
675 675
                 );
676 676
             }
677
-            $model_object_classname = 'EE_' . $model->get_this_model_name();
677
+            $model_object_classname = 'EE_'.$model->get_this_model_name();
678 678
             $post->{$model_object_classname} = \EE_Registry::instance()->load_class(
679 679
                 $model_object_classname,
680 680
                 $result,
@@ -685,13 +685,13 @@  discard block
 block discarded – undo
685 685
         foreach ($result as $field_name => $field_value) {
686 686
             $field_obj = $model->field_settings_for($field_name);
687 687
             if ($this->isSubclassOfOne($field_obj, $this->getModelVersionInfo()->fieldsIgnored())) {
688
-                unset($result[ $field_name ]);
688
+                unset($result[$field_name]);
689 689
             } elseif ($this->isSubclassOfOne(
690 690
                 $field_obj,
691 691
                 $this->getModelVersionInfo()->fieldsThatHaveRenderedFormat()
692 692
             )
693 693
             ) {
694
-                $result[ $field_name ] = array(
694
+                $result[$field_name] = array(
695 695
                     'raw'      => $this->prepareFieldObjValueForJson($field_obj, $field_value),
696 696
                     'rendered' => $this->prepareFieldObjValueForJson($field_obj, $field_value, 'pretty'),
697 697
                 );
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
                 $this->getModelVersionInfo()->fieldsThatHavePrettyFormat()
701 701
             )
702 702
             ) {
703
-                $result[ $field_name ] = array(
703
+                $result[$field_name] = array(
704 704
                     'raw'    => $this->prepareFieldObjValueForJson($field_obj, $field_value),
705 705
                     'pretty' => $this->prepareFieldObjValueForJson($field_obj, $field_value, 'pretty'),
706 706
                 );
@@ -731,10 +731,10 @@  discard block
 block discarded – undo
731 731
                         $this->getModelVersionInfo()->requestedVersion()
732 732
                     );
733 733
                 }
734
-                $result[ $field_name . '_gmt' ] = $gmt_date;
735
-                $result[ $field_name ] = $local_date;
734
+                $result[$field_name.'_gmt'] = $gmt_date;
735
+                $result[$field_name] = $local_date;
736 736
             } else {
737
-                $result[ $field_name ] = $this->prepareFieldObjValueForJson($field_obj, $field_value);
737
+                $result[$field_name] = $this->prepareFieldObjValueForJson($field_obj, $field_value);
738 738
             }
739 739
         }
740 740
         if ($do_chevy_shuffle) {
@@ -786,7 +786,7 @@  discard block
 block discarded – undo
786 786
     protected function addExtraFields(EEM_Base $model, $db_row, $entity_array)
787 787
     {
788 788
         if ($model instanceof EEM_CPT_Base) {
789
-            $entity_array['link'] = get_permalink($db_row[ $model->get_primary_key_field()->get_qualified_column() ]);
789
+            $entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]);
790 790
         }
791 791
         return $entity_array;
792 792
     }
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
                     'href' => $this->getVersionedLinkTo(
812 812
                         EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
813 813
                         . '/'
814
-                        . $entity_array[ $model->primary_key_name() ]
814
+                        . $entity_array[$model->primary_key_name()]
815 815
                     ),
816 816
                 ),
817 817
             );
@@ -827,12 +827,12 @@  discard block
 block discarded – undo
827 827
         if ($model->has_primary_key_field()) {
828 828
             foreach ($this->getModelVersionInfo()->relationSettings($model) as $relation_name => $relation_obj) {
829 829
                 $related_model_part = Read::getRelatedEntityName($relation_name, $relation_obj);
830
-                $links[ EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part ] = array(
830
+                $links[EED_Core_Rest_Api::ee_api_link_namespace.$related_model_part] = array(
831 831
                     array(
832 832
                         'href'   => $this->getVersionedLinkTo(
833 833
                             EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
834 834
                             . '/'
835
-                            . $entity_array[ $model->primary_key_name() ]
835
+                            . $entity_array[$model->primary_key_name()]
836 836
                             . '/'
837 837
                             . $related_model_part
838 838
                         ),
@@ -861,13 +861,13 @@  discard block
 block discarded – undo
861 861
         $db_row = array()
862 862
     ) {
863 863
         // if $db_row not included, hope the entity array has what we need
864
-        if (! $db_row) {
864
+        if ( ! $db_row) {
865 865
             $db_row = $entity_array;
866 866
         }
867 867
         $includes_for_this_model = $this->explodeAndGetItemsPrefixedWith($rest_request->get_param('include'), '');
868 868
         $includes_for_this_model = $this->removeModelNamesFromArray($includes_for_this_model);
869 869
         // if they passed in * or didn't specify any includes, return everything
870
-        if (! in_array('*', $includes_for_this_model)
870
+        if ( ! in_array('*', $includes_for_this_model)
871 871
             && ! empty($includes_for_this_model)
872 872
         ) {
873 873
             if ($model->has_primary_key_field()) {
@@ -913,7 +913,7 @@  discard block
 block discarded – undo
913 913
                     $relation_obj,
914 914
                     $pretend_related_request
915 915
                 );
916
-                $entity_array[ Read::getRelatedEntityName($relation_name, $relation_obj) ] = $related_results
916
+                $entity_array[Read::getRelatedEntityName($relation_name, $relation_obj)] = $related_results
917 917
                                                                                              instanceof
918 918
                                                                                              WP_Error
919 919
                     ? null
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
      */
1046 1046
     public function validateContext($context)
1047 1047
     {
1048
-        if (! $context) {
1048
+        if ( ! $context) {
1049 1049
             $context = EEM_Base::caps_read;
1050 1050
         }
1051 1051
         $valid_contexts = EEM_Base::valid_cap_contexts();
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
             EEM_Base::default_where_conditions_minimum_all,
1071 1071
             EEM_Base::default_where_conditions_minimum_others,
1072 1072
         );
1073
-        if (! $default_query_params) {
1073
+        if ( ! $default_query_params) {
1074 1074
             $default_query_params = EEM_Base::default_where_conditions_all;
1075 1075
         }
1076 1076
         if (in_array(
@@ -1153,14 +1153,14 @@  discard block
 block discarded – undo
1153 1153
         }
1154 1154
         if (isset($query_parameters['limit'])) {
1155 1155
             // limit should be either a string like '23' or '23,43', or an array with two items in it
1156
-            if (! is_array($query_parameters['limit'])) {
1156
+            if ( ! is_array($query_parameters['limit'])) {
1157 1157
                 $limit_array = explode(',', (string) $query_parameters['limit']);
1158 1158
             } else {
1159 1159
                 $limit_array = $query_parameters['limit'];
1160 1160
             }
1161 1161
             $sanitized_limit = array();
1162 1162
             foreach ($limit_array as $key => $limit_part) {
1163
-                if ($this->debug_mode && (! is_numeric($limit_part) || count($sanitized_limit) > 2)) {
1163
+                if ($this->debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) {
1164 1164
                     throw new EE_Error(
1165 1165
                         sprintf(
1166 1166
                             __(
@@ -1206,9 +1206,9 @@  discard block
 block discarded – undo
1206 1206
         $model_ready_query_params = array();
1207 1207
         foreach ($query_params as $key => $value) {
1208 1208
             if (is_array($value)) {
1209
-                $model_ready_query_params[ $key ] = $this->prepareRestQueryParamsKeyForModels($model, $value);
1209
+                $model_ready_query_params[$key] = $this->prepareRestQueryParamsKeyForModels($model, $value);
1210 1210
             } else {
1211
-                $model_ready_query_params[ $key ] = $value;
1211
+                $model_ready_query_params[$key] = $value;
1212 1212
             }
1213 1213
         }
1214 1214
         return $model_ready_query_params;
@@ -1226,9 +1226,9 @@  discard block
 block discarded – undo
1226 1226
         $model_ready_query_params = array();
1227 1227
         foreach ($query_params as $key => $value) {
1228 1228
             if (is_array($value)) {
1229
-                $model_ready_query_params[ $key ] = $this->prepareRestQueryParamsValuesForModels($model, $value);
1229
+                $model_ready_query_params[$key] = $this->prepareRestQueryParamsValuesForModels($model, $value);
1230 1230
             } else {
1231
-                $model_ready_query_params[ $key ] = $value;
1231
+                $model_ready_query_params[$key] = $value;
1232 1232
             }
1233 1233
         }
1234 1234
         return $model_ready_query_params;
@@ -1260,17 +1260,17 @@  discard block
 block discarded – undo
1260 1260
         foreach ($exploded_contents as $item) {
1261 1261
             $item = trim($item);
1262 1262
             // if no prefix was provided, so we look for items with no "." in them
1263
-            if (! $prefix) {
1263
+            if ( ! $prefix) {
1264 1264
                 // does this item have a period?
1265 1265
                 if (strpos($item, '.') === false) {
1266 1266
                     // if not, then its what we're looking for
1267 1267
                     $contents_with_prefix[] = $item;
1268 1268
                 }
1269
-            } elseif (strpos($item, $prefix . '.') === 0) {
1269
+            } elseif (strpos($item, $prefix.'.') === 0) {
1270 1270
                 // this item has the prefix and a period, grab it
1271 1271
                 $contents_with_prefix[] = substr(
1272 1272
                     $item,
1273
-                    strpos($item, $prefix . '.') + strlen($prefix . '.')
1273
+                    strpos($item, $prefix.'.') + strlen($prefix.'.')
1274 1274
                 );
1275 1275
             } elseif ($item === $prefix) {
1276 1276
                 // this item is JUST the prefix
@@ -1309,9 +1309,9 @@  discard block
 block discarded – undo
1309 1309
         if ($model_name) {
1310 1310
             foreach ($includes as $field_to_include) {
1311 1311
                 $field_to_include = trim($field_to_include);
1312
-                if (strpos($field_to_include, $model_name . '.') === 0) {
1312
+                if (strpos($field_to_include, $model_name.'.') === 0) {
1313 1313
                     // found the model name at the exact start
1314
-                    $field_sans_model_name = str_replace($model_name . '.', '', $field_to_include);
1314
+                    $field_sans_model_name = str_replace($model_name.'.', '', $field_to_include);
1315 1315
                     $extracted_fields_to_include[] = $field_sans_model_name;
1316 1316
                 } elseif ($field_to_include == $model_name) {
1317 1317
                     $extracted_fields_to_include[] = '*';
@@ -1351,7 +1351,7 @@  discard block
 block discarded – undo
1351 1351
         $restricted_query_params['caps'] = $context;
1352 1352
         $this->setDebugInfo('model query params', $restricted_query_params);
1353 1353
         $model_rows = $model->get_all_wpdb_results($restricted_query_params);
1354
-        if (! empty($model_rows)) {
1354
+        if ( ! empty($model_rows)) {
1355 1355
             return $this->createEntityFromWpdbResult(
1356 1356
                 $model,
1357 1357
                 array_shift($model_rows),
@@ -1361,10 +1361,10 @@  discard block
 block discarded – undo
1361 1361
             // ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities
1362 1362
             $lowercase_model_name = strtolower($model->get_this_model_name());
1363 1363
             $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params);
1364
-            if (! empty($model_rows_found_sans_restrictions)) {
1364
+            if ( ! empty($model_rows_found_sans_restrictions)) {
1365 1365
                 // you got shafted- it existed but we didn't want to tell you!
1366 1366
                 return new WP_Error(
1367
-                    'rest_user_cannot_' . $context,
1367
+                    'rest_user_cannot_'.$context,
1368 1368
                     sprintf(
1369 1369
                         __('Sorry, you cannot %1$s this %2$s. Missing permissions are: %3$s', 'event_espresso'),
1370 1370
                         $context,
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoTicketSelector.php 2 patches
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -24,92 +24,92 @@
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * the actual shortcode tag that gets registered with WordPress
29
-     *
30
-     * @return string
31
-     */
32
-    public function getTag()
33
-    {
34
-        return 'ESPRESSO_TICKET_SELECTOR';
35
-    }
27
+	/**
28
+	 * the actual shortcode tag that gets registered with WordPress
29
+	 *
30
+	 * @return string
31
+	 */
32
+	public function getTag()
33
+	{
34
+		return 'ESPRESSO_TICKET_SELECTOR';
35
+	}
36 36
 
37 37
 
38
-    /**
39
-     * the time in seconds to cache the results of the processShortcode() method
40
-     * 0 means the processShortcode() results will NOT be cached at all
41
-     *
42
-     * @return int
43
-     */
44
-    public function cacheExpiration()
45
-    {
46
-        return 0;
47
-    }
38
+	/**
39
+	 * the time in seconds to cache the results of the processShortcode() method
40
+	 * 0 means the processShortcode() results will NOT be cached at all
41
+	 *
42
+	 * @return int
43
+	 */
44
+	public function cacheExpiration()
45
+	{
46
+		return 0;
47
+	}
48 48
 
49 49
 
50
-    /**
51
-     * a place for adding any initialization code that needs to run prior to wp_header().
52
-     * this may be required for shortcodes that utilize a corresponding module,
53
-     * and need to enqueue assets for that module
54
-     *
55
-     * @return void
56
-     */
57
-    public function initializeShortcode()
58
-    {
59
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
60
-        $this->shortcodeHasBeenInitialized();
61
-    }
50
+	/**
51
+	 * a place for adding any initialization code that needs to run prior to wp_header().
52
+	 * this may be required for shortcodes that utilize a corresponding module,
53
+	 * and need to enqueue assets for that module
54
+	 *
55
+	 * @return void
56
+	 */
57
+	public function initializeShortcode()
58
+	{
59
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
60
+		$this->shortcodeHasBeenInitialized();
61
+	}
62 62
 
63 63
 
64
-    /**
65
-     * callback that runs when the shortcode is encountered in post content.
66
-     * IMPORTANT !!!
67
-     * remember that shortcode content should be RETURNED and NOT echoed out
68
-     *
69
-     * @param array $attributes
70
-     * @return string
71
-     * @throws InvalidArgumentException
72
-     * @throws EE_Error
73
-     * @throws InvalidDataTypeException
74
-     * @throws InvalidInterfaceException
75
-     * @throws ReflectionException
76
-     * @throws Exception
77
-     */
78
-    public function processShortcode($attributes = array())
79
-    {
80
-        extract($attributes, EXTR_OVERWRITE);
81
-        $event_id = isset($event_id) ? $event_id : 0;
82
-        $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id);
83
-        if (! $event instanceof EE_Event) {
84
-            if (WP_DEBUG === true && current_user_can('edit_pages')) {
85
-                new ExceptionStackTraceDisplay(
86
-                    new InvalidArgumentException(
87
-                        sprintf(
88
-                            esc_html__(
89
-                                'A valid Event ID is required to use the "%1$s" shortcode.%4$sAn Event with an ID of "%2$s" could not be found.%4$sPlease verify that the shortcode added to this post\'s content includes an "%3$s" argument and that its value corresponds to a valid Event ID.',
90
-                                'event_espresso'
91
-                            ),
92
-                            $this->getTag(),
93
-                            $event_id,
94
-                            'event_id',
95
-                            '<br />'
96
-                        )
97
-                    )
98
-                );
99
-                return '';
100
-            }
101
-            return sprintf(
102
-                esc_html__(
103
-                    'An Event with an ID of "%s" could not be found. Please contact the event administrator for assistance.',
104
-                    'event_espresso'
105
-                ),
106
-                $event_id
107
-            );
108
-        }
109
-        ob_start();
110
-        do_action('AHEE_event_details_before_post', $event_id);
111
-        espresso_ticket_selector($event);
112
-        do_action('AHEE_event_details_after_post');
113
-        return ob_get_clean();
114
-    }
64
+	/**
65
+	 * callback that runs when the shortcode is encountered in post content.
66
+	 * IMPORTANT !!!
67
+	 * remember that shortcode content should be RETURNED and NOT echoed out
68
+	 *
69
+	 * @param array $attributes
70
+	 * @return string
71
+	 * @throws InvalidArgumentException
72
+	 * @throws EE_Error
73
+	 * @throws InvalidDataTypeException
74
+	 * @throws InvalidInterfaceException
75
+	 * @throws ReflectionException
76
+	 * @throws Exception
77
+	 */
78
+	public function processShortcode($attributes = array())
79
+	{
80
+		extract($attributes, EXTR_OVERWRITE);
81
+		$event_id = isset($event_id) ? $event_id : 0;
82
+		$event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id);
83
+		if (! $event instanceof EE_Event) {
84
+			if (WP_DEBUG === true && current_user_can('edit_pages')) {
85
+				new ExceptionStackTraceDisplay(
86
+					new InvalidArgumentException(
87
+						sprintf(
88
+							esc_html__(
89
+								'A valid Event ID is required to use the "%1$s" shortcode.%4$sAn Event with an ID of "%2$s" could not be found.%4$sPlease verify that the shortcode added to this post\'s content includes an "%3$s" argument and that its value corresponds to a valid Event ID.',
90
+								'event_espresso'
91
+							),
92
+							$this->getTag(),
93
+							$event_id,
94
+							'event_id',
95
+							'<br />'
96
+						)
97
+					)
98
+				);
99
+				return '';
100
+			}
101
+			return sprintf(
102
+				esc_html__(
103
+					'An Event with an ID of "%s" could not be found. Please contact the event administrator for assistance.',
104
+					'event_espresso'
105
+				),
106
+				$event_id
107
+			);
108
+		}
109
+		ob_start();
110
+		do_action('AHEE_event_details_before_post', $event_id);
111
+		espresso_ticket_selector($event);
112
+		do_action('AHEE_event_details_after_post');
113
+		return ob_get_clean();
114
+	}
115 115
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@
 block discarded – undo
80 80
         extract($attributes, EXTR_OVERWRITE);
81 81
         $event_id = isset($event_id) ? $event_id : 0;
82 82
         $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id);
83
-        if (! $event instanceof EE_Event) {
83
+        if ( ! $event instanceof EE_Event) {
84 84
             if (WP_DEBUG === true && current_user_can('edit_pages')) {
85 85
                 new ExceptionStackTraceDisplay(
86 86
                     new InvalidArgumentException(
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 1 patch
Indentation   +1018 added lines, -1018 removed lines patch added patch discarded remove patch
@@ -20,1022 +20,1022 @@
 block discarded – undo
20 20
 class EE_Dependency_Map
21 21
 {
22 22
 
23
-    /**
24
-     * This means that the requested class dependency is not present in the dependency map
25
-     */
26
-    const not_registered = 0;
27
-
28
-    /**
29
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
30
-     */
31
-    const load_new_object = 1;
32
-
33
-    /**
34
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
35
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
36
-     */
37
-    const load_from_cache = 2;
38
-
39
-    /**
40
-     * When registering a dependency,
41
-     * this indicates to keep any existing dependencies that already exist,
42
-     * and simply discard any new dependencies declared in the incoming data
43
-     */
44
-    const KEEP_EXISTING_DEPENDENCIES = 0;
45
-
46
-    /**
47
-     * When registering a dependency,
48
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
49
-     */
50
-    const OVERWRITE_DEPENDENCIES = 1;
51
-
52
-
53
-    /**
54
-     * @type EE_Dependency_Map $_instance
55
-     */
56
-    protected static $_instance;
57
-
58
-    /**
59
-     * @var ClassInterfaceCache $class_cache
60
-     */
61
-    private $class_cache;
62
-
63
-    /**
64
-     * @type RequestInterface $request
65
-     */
66
-    protected $request;
67
-
68
-    /**
69
-     * @type LegacyRequestInterface $legacy_request
70
-     */
71
-    protected $legacy_request;
72
-
73
-    /**
74
-     * @type ResponseInterface $response
75
-     */
76
-    protected $response;
77
-
78
-    /**
79
-     * @type LoaderInterface $loader
80
-     */
81
-    protected $loader;
82
-
83
-    /**
84
-     * @type array $_dependency_map
85
-     */
86
-    protected $_dependency_map = array();
87
-
88
-    /**
89
-     * @type array $_class_loaders
90
-     */
91
-    protected $_class_loaders = array();
92
-
93
-
94
-    /**
95
-     * EE_Dependency_Map constructor.
96
-     *
97
-     * @param ClassInterfaceCache $class_cache
98
-     */
99
-    protected function __construct(ClassInterfaceCache $class_cache)
100
-    {
101
-        $this->class_cache = $class_cache;
102
-        do_action('EE_Dependency_Map____construct', $this);
103
-    }
104
-
105
-
106
-    /**
107
-     * @return void
108
-     */
109
-    public function initialize()
110
-    {
111
-        $this->_register_core_dependencies();
112
-        $this->_register_core_class_loaders();
113
-        $this->_register_core_aliases();
114
-    }
115
-
116
-
117
-    /**
118
-     * @singleton method used to instantiate class object
119
-     * @param ClassInterfaceCache|null $class_cache
120
-     * @return EE_Dependency_Map
121
-     */
122
-    public static function instance(ClassInterfaceCache $class_cache = null)
123
-    {
124
-        // check if class object is instantiated, and instantiated properly
125
-        if (! self::$_instance instanceof EE_Dependency_Map
126
-            && $class_cache instanceof ClassInterfaceCache
127
-        ) {
128
-            self::$_instance = new EE_Dependency_Map($class_cache);
129
-        }
130
-        return self::$_instance;
131
-    }
132
-
133
-
134
-    /**
135
-     * @param RequestInterface $request
136
-     */
137
-    public function setRequest(RequestInterface $request)
138
-    {
139
-        $this->request = $request;
140
-    }
141
-
142
-
143
-    /**
144
-     * @param LegacyRequestInterface $legacy_request
145
-     */
146
-    public function setLegacyRequest(LegacyRequestInterface $legacy_request)
147
-    {
148
-        $this->legacy_request = $legacy_request;
149
-    }
150
-
151
-
152
-    /**
153
-     * @param ResponseInterface $response
154
-     */
155
-    public function setResponse(ResponseInterface $response)
156
-    {
157
-        $this->response = $response;
158
-    }
159
-
160
-
161
-    /**
162
-     * @param LoaderInterface $loader
163
-     */
164
-    public function setLoader(LoaderInterface $loader)
165
-    {
166
-        $this->loader = $loader;
167
-    }
168
-
169
-
170
-    /**
171
-     * @param string $class
172
-     * @param array  $dependencies
173
-     * @param int    $overwrite
174
-     * @return bool
175
-     */
176
-    public static function register_dependencies(
177
-        $class,
178
-        array $dependencies,
179
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
180
-    ) {
181
-        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
182
-    }
183
-
184
-
185
-    /**
186
-     * Assigns an array of class names and corresponding load sources (new or cached)
187
-     * to the class specified by the first parameter.
188
-     * IMPORTANT !!!
189
-     * The order of elements in the incoming $dependencies array MUST match
190
-     * the order of the constructor parameters for the class in question.
191
-     * This is especially important when overriding any existing dependencies that are registered.
192
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
193
-     *
194
-     * @param string $class
195
-     * @param array  $dependencies
196
-     * @param int    $overwrite
197
-     * @return bool
198
-     */
199
-    public function registerDependencies(
200
-        $class,
201
-        array $dependencies,
202
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
203
-    ) {
204
-        $class = trim($class, '\\');
205
-        $registered = false;
206
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
207
-            self::$_instance->_dependency_map[ $class ] = array();
208
-        }
209
-        // we need to make sure that any aliases used when registering a dependency
210
-        // get resolved to the correct class name
211
-        foreach ($dependencies as $dependency => $load_source) {
212
-            $alias = self::$_instance->getFqnForAlias($dependency);
213
-            if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
214
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
215
-            ) {
216
-                unset($dependencies[ $dependency ]);
217
-                $dependencies[ $alias ] = $load_source;
218
-                $registered = true;
219
-            }
220
-        }
221
-        // now add our two lists of dependencies together.
222
-        // using Union (+=) favours the arrays in precedence from left to right,
223
-        // so $dependencies is NOT overwritten because it is listed first
224
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
225
-        // Union is way faster than array_merge() but should be used with caution...
226
-        // especially with numerically indexed arrays
227
-        $dependencies += self::$_instance->_dependency_map[ $class ];
228
-        // now we need to ensure that the resulting dependencies
229
-        // array only has the entries that are required for the class
230
-        // so first count how many dependencies were originally registered for the class
231
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
232
-        // if that count is non-zero (meaning dependencies were already registered)
233
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
234
-            // then truncate the  final array to match that count
235
-            ? array_slice($dependencies, 0, $dependency_count)
236
-            // otherwise just take the incoming array because nothing previously existed
237
-            : $dependencies;
238
-        return $registered;
239
-    }
240
-
241
-
242
-    /**
243
-     * @param string $class_name
244
-     * @param string $loader
245
-     * @return bool
246
-     * @throws DomainException
247
-     */
248
-    public static function register_class_loader($class_name, $loader = 'load_core')
249
-    {
250
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
251
-            throw new DomainException(
252
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
253
-            );
254
-        }
255
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
256
-        if (! is_callable($loader)
257
-            && (
258
-                strpos($loader, 'load_') !== 0
259
-                || ! method_exists('EE_Registry', $loader)
260
-            )
261
-        ) {
262
-            throw new DomainException(
263
-                sprintf(
264
-                    esc_html__(
265
-                        '"%1$s" is not a valid loader method on EE_Registry.',
266
-                        'event_espresso'
267
-                    ),
268
-                    $loader
269
-                )
270
-            );
271
-        }
272
-        $class_name = self::$_instance->getFqnForAlias($class_name);
273
-        if (! isset(self::$_instance->_class_loaders[ $class_name ])) {
274
-            self::$_instance->_class_loaders[ $class_name ] = $loader;
275
-            return true;
276
-        }
277
-        return false;
278
-    }
279
-
280
-
281
-    /**
282
-     * @return array
283
-     */
284
-    public function dependency_map()
285
-    {
286
-        return $this->_dependency_map;
287
-    }
288
-
289
-
290
-    /**
291
-     * returns TRUE if dependency map contains a listing for the provided class name
292
-     *
293
-     * @param string $class_name
294
-     * @return boolean
295
-     */
296
-    public function has($class_name = '')
297
-    {
298
-        // all legacy models have the same dependencies
299
-        if (strpos($class_name, 'EEM_') === 0) {
300
-            $class_name = 'LEGACY_MODELS';
301
-        }
302
-        return isset($this->_dependency_map[ $class_name ]) ? true : false;
303
-    }
304
-
305
-
306
-    /**
307
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
308
-     *
309
-     * @param string $class_name
310
-     * @param string $dependency
311
-     * @return bool
312
-     */
313
-    public function has_dependency_for_class($class_name = '', $dependency = '')
314
-    {
315
-        // all legacy models have the same dependencies
316
-        if (strpos($class_name, 'EEM_') === 0) {
317
-            $class_name = 'LEGACY_MODELS';
318
-        }
319
-        $dependency = $this->getFqnForAlias($dependency, $class_name);
320
-        return isset($this->_dependency_map[ $class_name ][ $dependency ])
321
-            ? true
322
-            : false;
323
-    }
324
-
325
-
326
-    /**
327
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
328
-     *
329
-     * @param string $class_name
330
-     * @param string $dependency
331
-     * @return int
332
-     */
333
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
334
-    {
335
-        // all legacy models have the same dependencies
336
-        if (strpos($class_name, 'EEM_') === 0) {
337
-            $class_name = 'LEGACY_MODELS';
338
-        }
339
-        $dependency = $this->getFqnForAlias($dependency);
340
-        return $this->has_dependency_for_class($class_name, $dependency)
341
-            ? $this->_dependency_map[ $class_name ][ $dependency ]
342
-            : EE_Dependency_Map::not_registered;
343
-    }
344
-
345
-
346
-    /**
347
-     * @param string $class_name
348
-     * @return string | Closure
349
-     */
350
-    public function class_loader($class_name)
351
-    {
352
-        // all legacy models use load_model()
353
-        if (strpos($class_name, 'EEM_') === 0) {
354
-            return 'load_model';
355
-        }
356
-        // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc
357
-        // perform strpos() first to avoid loading regex every time we load a class
358
-        if (strpos($class_name, 'EE_CPT_') === 0
359
-            && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name)
360
-        ) {
361
-            return 'load_core';
362
-        }
363
-        $class_name = $this->getFqnForAlias($class_name);
364
-        return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : '';
365
-    }
366
-
367
-
368
-    /**
369
-     * @return array
370
-     */
371
-    public function class_loaders()
372
-    {
373
-        return $this->_class_loaders;
374
-    }
375
-
376
-
377
-    /**
378
-     * adds an alias for a classname
379
-     *
380
-     * @param string $fqcn      the class name that should be used (concrete class to replace interface)
381
-     * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
382
-     * @param string $for_class the class that has the dependency (is type hinting for the interface)
383
-     */
384
-    public function add_alias($fqcn, $alias, $for_class = '')
385
-    {
386
-        $this->class_cache->addAlias($fqcn, $alias, $for_class);
387
-    }
388
-
389
-
390
-    /**
391
-     * Returns TRUE if the provided fully qualified name IS an alias
392
-     * WHY?
393
-     * Because if a class is type hinting for a concretion,
394
-     * then why would we need to find another class to supply it?
395
-     * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
396
-     * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
397
-     * Don't go looking for some substitute.
398
-     * Whereas if a class is type hinting for an interface...
399
-     * then we need to find an actual class to use.
400
-     * So the interface IS the alias for some other FQN,
401
-     * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
402
-     * represents some other class.
403
-     *
404
-     * @param string $fqn
405
-     * @param string $for_class
406
-     * @return bool
407
-     */
408
-    public function isAlias($fqn = '', $for_class = '')
409
-    {
410
-        return $this->class_cache->isAlias($fqn, $for_class);
411
-    }
412
-
413
-
414
-    /**
415
-     * Returns a FQN for provided alias if one exists, otherwise returns the original $alias
416
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
417
-     *  for example:
418
-     *      if the following two entries were added to the _aliases array:
419
-     *          array(
420
-     *              'interface_alias'           => 'some\namespace\interface'
421
-     *              'some\namespace\interface'  => 'some\namespace\classname'
422
-     *          )
423
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
424
-     *      to load an instance of 'some\namespace\classname'
425
-     *
426
-     * @param string $alias
427
-     * @param string $for_class
428
-     * @return string
429
-     */
430
-    public function getFqnForAlias($alias = '', $for_class = '')
431
-    {
432
-        return (string) $this->class_cache->getFqnForAlias($alias, $for_class);
433
-    }
434
-
435
-
436
-    /**
437
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
438
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
439
-     * This is done by using the following class constants:
440
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
441
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
442
-     */
443
-    protected function _register_core_dependencies()
444
-    {
445
-        $this->_dependency_map = array(
446
-            'EE_Request_Handler'                                                                                          => array(
447
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
448
-            ),
449
-            'EE_System'                                                                                                   => array(
450
-                'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
451
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
452
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
453
-                'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
454
-            ),
455
-            'EE_Session'                                                                                                  => array(
456
-                'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
457
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
458
-                'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
459
-                'EventEspresso\core\services\session\SessionStartHandler'  => EE_Dependency_Map::load_from_cache,
460
-                'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
461
-            ),
462
-            'EE_Cart'                                                                                                     => array(
463
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
464
-            ),
465
-            'EE_Front_Controller'                                                                                         => array(
466
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
467
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
468
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
469
-            ),
470
-            'EE_Messenger_Collection_Loader'                                                                              => array(
471
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
472
-            ),
473
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
474
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
475
-            ),
476
-            'EE_Message_Resource_Manager'                                                                                 => array(
477
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
478
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
479
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
480
-            ),
481
-            'EE_Message_Factory'                                                                                          => array(
482
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
483
-            ),
484
-            'EE_messages'                                                                                                 => array(
485
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
486
-            ),
487
-            'EE_Messages_Generator'                                                                                       => array(
488
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
489
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
490
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
491
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
492
-            ),
493
-            'EE_Messages_Processor'                                                                                       => array(
494
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
495
-            ),
496
-            'EE_Messages_Queue'                                                                                           => array(
497
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
498
-            ),
499
-            'EE_Messages_Template_Defaults'                                                                               => array(
500
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
501
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
502
-            ),
503
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
504
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
505
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
506
-            ),
507
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
508
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
509
-            ),
510
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
511
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
512
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
513
-            ),
514
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
515
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
516
-            ),
517
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
518
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
519
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
520
-            ),
521
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
522
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
523
-            ),
524
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
525
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
526
-            ),
527
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
528
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
529
-            ),
530
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
531
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
532
-            ),
533
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
534
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
535
-            ),
536
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
537
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
538
-            ),
539
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
540
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
541
-            ),
542
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
543
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
544
-            ),
545
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
546
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
547
-            ),
548
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
549
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
550
-            ),
551
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
552
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
553
-            ),
554
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
555
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
556
-            ),
557
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
558
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
559
-            ),
560
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
561
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
562
-            ),
563
-            'EE_Data_Migration_Class_Base'                                                                                => array(
564
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
565
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
566
-            ),
567
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
568
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
569
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
570
-            ),
571
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
572
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
573
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
574
-            ),
575
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
576
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
577
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
578
-            ),
579
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
580
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
581
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
582
-            ),
583
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
584
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
585
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
586
-            ),
587
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
588
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
589
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
590
-            ),
591
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
592
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
593
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
594
-            ),
595
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
596
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
597
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
598
-            ),
599
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
600
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
601
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
602
-            ),
603
-            'EventEspresso\core\services\assets\I18nRegistry'                                                             => array(
604
-                array(),
605
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
606
-            ),
607
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
608
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
609
-                'EventEspresso\core\services\assets\I18nRegistry'    => EE_Dependency_Map::load_from_cache,
610
-            ),
611
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
612
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
613
-            ),
614
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
615
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
616
-            ),
617
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
618
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
619
-            ),
620
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
621
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
622
-            ),
623
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
624
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
625
-            ),
626
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
627
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
628
-            ),
629
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
630
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
631
-            ),
632
-            'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
633
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
634
-            ),
635
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
636
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
637
-            ),
638
-            'EventEspresso\core\domain\services\validation\email\EmailValidationService'                                  => array(
639
-                'EE_Registration_Config'                     => EE_Dependency_Map::load_from_cache,
640
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
641
-            ),
642
-            'EventEspresso\core\domain\values\EmailAddress'                                                               => array(
643
-                null,
644
-                'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
645
-            ),
646
-            'EventEspresso\core\services\orm\ModelFieldFactory'                                                           => array(
647
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
648
-            ),
649
-            'LEGACY_MODELS'                                                                                               => array(
650
-                null,
651
-                'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
652
-            ),
653
-            'EE_Module_Request_Router'                                                                                    => array(
654
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
655
-            ),
656
-            'EE_Registration_Processor'                                                                                   => array(
657
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
658
-            ),
659
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'                                      => array(
660
-                null,
661
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
662
-                'EventEspresso\core\services\request\Request'                         => EE_Dependency_Map::load_from_cache,
663
-            ),
664
-            'EventEspresso\core\services\licensing\LicenseService'                                                        => array(
665
-                'EventEspresso\core\domain\services\pue\Stats'  => EE_Dependency_Map::load_from_cache,
666
-                'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
667
-            ),
668
-            'EE_Admin_Transactions_List_Table'                                                                            => array(
669
-                null,
670
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
671
-            ),
672
-            'EventEspresso\core\domain\services\pue\Stats'                                                                => array(
673
-                'EventEspresso\core\domain\services\pue\Config'        => EE_Dependency_Map::load_from_cache,
674
-                'EE_Maintenance_Mode'                                  => EE_Dependency_Map::load_from_cache,
675
-                'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache,
676
-            ),
677
-            'EventEspresso\core\domain\services\pue\Config'                                                               => array(
678
-                'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
679
-                'EE_Config'         => EE_Dependency_Map::load_from_cache,
680
-            ),
681
-            'EventEspresso\core\domain\services\pue\StatsGatherer'                                                        => array(
682
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
683
-                'EEM_Event'          => EE_Dependency_Map::load_from_cache,
684
-                'EEM_Datetime'       => EE_Dependency_Map::load_from_cache,
685
-                'EEM_Ticket'         => EE_Dependency_Map::load_from_cache,
686
-                'EEM_Registration'   => EE_Dependency_Map::load_from_cache,
687
-                'EEM_Transaction'    => EE_Dependency_Map::load_from_cache,
688
-                'EE_Config'          => EE_Dependency_Map::load_from_cache,
689
-            ),
690
-            'EventEspresso\core\domain\services\admin\ExitModal'                                                          => array(
691
-                'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache,
692
-            ),
693
-            'EventEspresso\core\domain\services\admin\PluginUpsells'                                                      => array(
694
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
695
-            ),
696
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha'                                    => array(
697
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
698
-                'EE_Session'             => EE_Dependency_Map::load_from_cache,
699
-            ),
700
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings'                                => array(
701
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
702
-            ),
703
-            'EventEspresso\modules\ticket_selector\ProcessTicketSelector'                                                 => array(
704
-                'EE_Core_Config'                                                          => EE_Dependency_Map::load_from_cache,
705
-                'EventEspresso\core\services\request\Request'                             => EE_Dependency_Map::load_from_cache,
706
-                'EE_Session'                                                              => EE_Dependency_Map::load_from_cache,
707
-                'EEM_Ticket'                                                              => EE_Dependency_Map::load_from_cache,
708
-                'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
709
-            ),
710
-            'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'                                     => array(
711
-                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
712
-            ),
713
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'                              => array(
714
-                'EE_Core_Config'                             => EE_Dependency_Map::load_from_cache,
715
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
716
-            ),
717
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'                                => array(
718
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
719
-            ),
720
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'                               => array(
721
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
722
-            ),
723
-            'EE_CPT_Strategy'                                                                                             => array(
724
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
725
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
726
-            ),
727
-            'EventEspresso\core\services\loaders\ObjectIdentifier'                                                        => array(
728
-                'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache,
729
-            ),
730
-            'EventEspresso\core\domain\services\assets\CoreAssetManager'                                                  => array(
731
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
732
-                'EE_Currency_Config'                                 => EE_Dependency_Map::load_from_cache,
733
-                'EE_Template_Config'                                 => EE_Dependency_Map::load_from_cache,
734
-                'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
735
-                'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
736
-            ),
737
-            'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array(
738
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
739
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache
740
-            ),
741
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array(
742
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
743
-            ),
744
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array(
745
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
746
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache
747
-            ),
748
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array(
749
-                'EEM_Checkin' => EE_Dependency_Map::load_from_cache,
750
-            ),
751
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array(
752
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache,
753
-            ),
754
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array(
755
-                'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
756
-            ),
757
-            'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array(
758
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
759
-            ),
760
-            'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array(
761
-                'EEM_Answer' => EE_Dependency_Map::load_from_cache,
762
-                'EEM_Question' => EE_Dependency_Map::load_from_cache,
763
-            ),
764
-            'EventEspresso\core\CPTs\CptQueryModifier' => array(
765
-                null,
766
-                null,
767
-                null,
768
-                'EE_Request_Handler'                          => EE_Dependency_Map::load_from_cache,
769
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
770
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
771
-            ),
772
-            'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array(
773
-                'EE_Registry' => EE_Dependency_Map::load_from_cache,
774
-                'EE_Config' => EE_Dependency_Map::load_from_cache
775
-            ),
776
-            'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => array(
777
-                'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache
778
-            ),
779
-            'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => array(
780
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
781
-            ),
782
-            'EventEspresso\core\libraries\rest_api\controllers\model\Read' => array(
783
-                'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache
784
-            ),
785
-            'EventEspresso\core\libraries\rest_api\calculations\Datetime' => array(
786
-                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
787
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache
788
-            ),
789
-            'EventEspresso\core\libraries\rest_api\calculations\Event' => array(
790
-                'EEM_Event' => EE_Dependency_Map::load_from_cache,
791
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache
792
-            ),
793
-            'EventEspresso\core\libraries\rest_api\calculations\Registration' => array(
794
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache
795
-            ),
796
-            'EventEspresso\core\services\session\SessionStartHandler' => array(
797
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
798
-            ),
799
-        );
800
-    }
801
-
802
-
803
-    /**
804
-     * Registers how core classes are loaded.
805
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
806
-     *        'EE_Request_Handler' => 'load_core'
807
-     *        'EE_Messages_Queue'  => 'load_lib'
808
-     *        'EEH_Debug_Tools'    => 'load_helper'
809
-     * or, if greater control is required, by providing a custom closure. For example:
810
-     *        'Some_Class' => function () {
811
-     *            return new Some_Class();
812
-     *        },
813
-     * This is required for instantiating dependencies
814
-     * where an interface has been type hinted in a class constructor. For example:
815
-     *        'Required_Interface' => function () {
816
-     *            return new A_Class_That_Implements_Required_Interface();
817
-     *        },
818
-     */
819
-    protected function _register_core_class_loaders()
820
-    {
821
-        // for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
822
-        // be used in a closure.
823
-        $request = &$this->request;
824
-        $response = &$this->response;
825
-        $legacy_request = &$this->legacy_request;
826
-        // $loader = &$this->loader;
827
-        $this->_class_loaders = array(
828
-            // load_core
829
-            'EE_Capabilities'                              => 'load_core',
830
-            'EE_Encryption'                                => 'load_core',
831
-            'EE_Front_Controller'                          => 'load_core',
832
-            'EE_Module_Request_Router'                     => 'load_core',
833
-            'EE_Registry'                                  => 'load_core',
834
-            'EE_Request'                                   => function () use (&$legacy_request) {
835
-                return $legacy_request;
836
-            },
837
-            'EventEspresso\core\services\request\Request'  => function () use (&$request) {
838
-                return $request;
839
-            },
840
-            'EventEspresso\core\services\request\Response' => function () use (&$response) {
841
-                return $response;
842
-            },
843
-            'EE_Base'                                      => 'load_core',
844
-            'EE_Request_Handler'                           => 'load_core',
845
-            'EE_Session'                                   => 'load_core',
846
-            'EE_Cron_Tasks'                                => 'load_core',
847
-            'EE_System'                                    => 'load_core',
848
-            'EE_Maintenance_Mode'                          => 'load_core',
849
-            'EE_Register_CPTs'                             => 'load_core',
850
-            'EE_Admin'                                     => 'load_core',
851
-            'EE_CPT_Strategy'                              => 'load_core',
852
-            // load_lib
853
-            'EE_Message_Resource_Manager'                  => 'load_lib',
854
-            'EE_Message_Type_Collection'                   => 'load_lib',
855
-            'EE_Message_Type_Collection_Loader'            => 'load_lib',
856
-            'EE_Messenger_Collection'                      => 'load_lib',
857
-            'EE_Messenger_Collection_Loader'               => 'load_lib',
858
-            'EE_Messages_Processor'                        => 'load_lib',
859
-            'EE_Message_Repository'                        => 'load_lib',
860
-            'EE_Messages_Queue'                            => 'load_lib',
861
-            'EE_Messages_Data_Handler_Collection'          => 'load_lib',
862
-            'EE_Message_Template_Group_Collection'         => 'load_lib',
863
-            'EE_Payment_Method_Manager'                    => 'load_lib',
864
-            'EE_Messages_Generator'                        => function () {
865
-                return EE_Registry::instance()->load_lib(
866
-                    'Messages_Generator',
867
-                    array(),
868
-                    false,
869
-                    false
870
-                );
871
-            },
872
-            'EE_Messages_Template_Defaults'                => function ($arguments = array()) {
873
-                return EE_Registry::instance()->load_lib(
874
-                    'Messages_Template_Defaults',
875
-                    $arguments,
876
-                    false,
877
-                    false
878
-                );
879
-            },
880
-            // load_helper
881
-            'EEH_Parse_Shortcodes'                         => function () {
882
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
883
-                    return new EEH_Parse_Shortcodes();
884
-                }
885
-                return null;
886
-            },
887
-            'EE_Template_Config'                           => function () {
888
-                return EE_Config::instance()->template_settings;
889
-            },
890
-            'EE_Currency_Config'                           => function () {
891
-                return EE_Config::instance()->currency;
892
-            },
893
-            'EE_Registration_Config'                       => function () {
894
-                return EE_Config::instance()->registration;
895
-            },
896
-            'EE_Core_Config'                               => function () {
897
-                return EE_Config::instance()->core;
898
-            },
899
-            'EventEspresso\core\services\loaders\Loader'   => function () {
900
-                return LoaderFactory::getLoader();
901
-            },
902
-            'EE_Network_Config'                            => function () {
903
-                return EE_Network_Config::instance();
904
-            },
905
-            'EE_Config'                                    => function () {
906
-                return EE_Config::instance();
907
-            },
908
-            'EventEspresso\core\domain\Domain'             => function () {
909
-                return DomainFactory::getEventEspressoCoreDomain();
910
-            },
911
-            'EE_Admin_Config'                              => function () {
912
-                return EE_Config::instance()->admin;
913
-            },
914
-        );
915
-    }
916
-
917
-
918
-    /**
919
-     * can be used for supplying alternate names for classes,
920
-     * or for connecting interface names to instantiable classes
921
-     */
922
-    protected function _register_core_aliases()
923
-    {
924
-        $aliases = array(
925
-            'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
926
-            'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
927
-            'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
928
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
929
-            'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
930
-            'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
931
-            'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
932
-            'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
933
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
934
-            'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
935
-            'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
936
-            'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
937
-            'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
938
-            'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
939
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
940
-            'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
941
-            'CreateTransactionCommandHandler'                                              => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
942
-            'CreateAttendeeCommandHandler'                                                 => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
943
-            'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
944
-            'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
945
-            'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
946
-            'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
947
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
948
-            'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
949
-            'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
950
-            'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
951
-            'CommandFactoryInterface'                                                      => 'EventEspresso\core\services\commands\CommandFactoryInterface',
952
-            'EventEspresso\core\services\commands\CommandFactoryInterface'                 => 'EventEspresso\core\services\commands\CommandFactory',
953
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface'        => 'EE_Session',
954
-            'EmailValidatorInterface'                                                      => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
955
-            'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface'  => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
956
-            'NoticeConverterInterface'                                                     => 'EventEspresso\core\services\notices\NoticeConverterInterface',
957
-            'EventEspresso\core\services\notices\NoticeConverterInterface'                 => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
958
-            'NoticesContainerInterface'                                                    => 'EventEspresso\core\services\notices\NoticesContainerInterface',
959
-            'EventEspresso\core\services\notices\NoticesContainerInterface'                => 'EventEspresso\core\services\notices\NoticesContainer',
960
-            'EventEspresso\core\services\request\RequestInterface'                         => 'EventEspresso\core\services\request\Request',
961
-            'EventEspresso\core\services\request\ResponseInterface'                        => 'EventEspresso\core\services\request\Response',
962
-            'EventEspresso\core\domain\DomainInterface'                                    => 'EventEspresso\core\domain\Domain',
963
-        );
964
-        foreach ($aliases as $alias => $fqn) {
965
-            if (is_array($fqn)) {
966
-                foreach ($fqn as $class => $for_class) {
967
-                    $this->class_cache->addAlias($class, $alias, $for_class);
968
-                }
969
-                continue;
970
-            }
971
-            $this->class_cache->addAlias($fqn, $alias);
972
-        }
973
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
974
-            $this->class_cache->addAlias(
975
-                'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
976
-                'EventEspresso\core\services\notices\NoticeConverterInterface'
977
-            );
978
-        }
979
-    }
980
-
981
-
982
-    /**
983
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
984
-     * request Primarily used by unit tests.
985
-     */
986
-    public function reset()
987
-    {
988
-        $this->_register_core_class_loaders();
989
-        $this->_register_core_dependencies();
990
-    }
991
-
992
-
993
-    /**
994
-     * PLZ NOTE: a better name for this method would be is_alias()
995
-     * because it returns TRUE if the provided fully qualified name IS an alias
996
-     * WHY?
997
-     * Because if a class is type hinting for a concretion,
998
-     * then why would we need to find another class to supply it?
999
-     * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
1000
-     * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
1001
-     * Don't go looking for some substitute.
1002
-     * Whereas if a class is type hinting for an interface...
1003
-     * then we need to find an actual class to use.
1004
-     * So the interface IS the alias for some other FQN,
1005
-     * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
1006
-     * represents some other class.
1007
-     *
1008
-     * @deprecated 4.9.62.p
1009
-     * @param string $fqn
1010
-     * @param string $for_class
1011
-     * @return bool
1012
-     */
1013
-    public function has_alias($fqn = '', $for_class = '')
1014
-    {
1015
-        return $this->isAlias($fqn, $for_class);
1016
-    }
1017
-
1018
-
1019
-    /**
1020
-     * PLZ NOTE: a better name for this method would be get_fqn_for_alias()
1021
-     * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias
1022
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
1023
-     *  for example:
1024
-     *      if the following two entries were added to the _aliases array:
1025
-     *          array(
1026
-     *              'interface_alias'           => 'some\namespace\interface'
1027
-     *              'some\namespace\interface'  => 'some\namespace\classname'
1028
-     *          )
1029
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
1030
-     *      to load an instance of 'some\namespace\classname'
1031
-     *
1032
-     * @deprecated 4.9.62.p
1033
-     * @param string $alias
1034
-     * @param string $for_class
1035
-     * @return string
1036
-     */
1037
-    public function get_alias($alias = '', $for_class = '')
1038
-    {
1039
-        return $this->getFqnForAlias($alias, $for_class);
1040
-    }
23
+	/**
24
+	 * This means that the requested class dependency is not present in the dependency map
25
+	 */
26
+	const not_registered = 0;
27
+
28
+	/**
29
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
30
+	 */
31
+	const load_new_object = 1;
32
+
33
+	/**
34
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
35
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
36
+	 */
37
+	const load_from_cache = 2;
38
+
39
+	/**
40
+	 * When registering a dependency,
41
+	 * this indicates to keep any existing dependencies that already exist,
42
+	 * and simply discard any new dependencies declared in the incoming data
43
+	 */
44
+	const KEEP_EXISTING_DEPENDENCIES = 0;
45
+
46
+	/**
47
+	 * When registering a dependency,
48
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
49
+	 */
50
+	const OVERWRITE_DEPENDENCIES = 1;
51
+
52
+
53
+	/**
54
+	 * @type EE_Dependency_Map $_instance
55
+	 */
56
+	protected static $_instance;
57
+
58
+	/**
59
+	 * @var ClassInterfaceCache $class_cache
60
+	 */
61
+	private $class_cache;
62
+
63
+	/**
64
+	 * @type RequestInterface $request
65
+	 */
66
+	protected $request;
67
+
68
+	/**
69
+	 * @type LegacyRequestInterface $legacy_request
70
+	 */
71
+	protected $legacy_request;
72
+
73
+	/**
74
+	 * @type ResponseInterface $response
75
+	 */
76
+	protected $response;
77
+
78
+	/**
79
+	 * @type LoaderInterface $loader
80
+	 */
81
+	protected $loader;
82
+
83
+	/**
84
+	 * @type array $_dependency_map
85
+	 */
86
+	protected $_dependency_map = array();
87
+
88
+	/**
89
+	 * @type array $_class_loaders
90
+	 */
91
+	protected $_class_loaders = array();
92
+
93
+
94
+	/**
95
+	 * EE_Dependency_Map constructor.
96
+	 *
97
+	 * @param ClassInterfaceCache $class_cache
98
+	 */
99
+	protected function __construct(ClassInterfaceCache $class_cache)
100
+	{
101
+		$this->class_cache = $class_cache;
102
+		do_action('EE_Dependency_Map____construct', $this);
103
+	}
104
+
105
+
106
+	/**
107
+	 * @return void
108
+	 */
109
+	public function initialize()
110
+	{
111
+		$this->_register_core_dependencies();
112
+		$this->_register_core_class_loaders();
113
+		$this->_register_core_aliases();
114
+	}
115
+
116
+
117
+	/**
118
+	 * @singleton method used to instantiate class object
119
+	 * @param ClassInterfaceCache|null $class_cache
120
+	 * @return EE_Dependency_Map
121
+	 */
122
+	public static function instance(ClassInterfaceCache $class_cache = null)
123
+	{
124
+		// check if class object is instantiated, and instantiated properly
125
+		if (! self::$_instance instanceof EE_Dependency_Map
126
+			&& $class_cache instanceof ClassInterfaceCache
127
+		) {
128
+			self::$_instance = new EE_Dependency_Map($class_cache);
129
+		}
130
+		return self::$_instance;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @param RequestInterface $request
136
+	 */
137
+	public function setRequest(RequestInterface $request)
138
+	{
139
+		$this->request = $request;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @param LegacyRequestInterface $legacy_request
145
+	 */
146
+	public function setLegacyRequest(LegacyRequestInterface $legacy_request)
147
+	{
148
+		$this->legacy_request = $legacy_request;
149
+	}
150
+
151
+
152
+	/**
153
+	 * @param ResponseInterface $response
154
+	 */
155
+	public function setResponse(ResponseInterface $response)
156
+	{
157
+		$this->response = $response;
158
+	}
159
+
160
+
161
+	/**
162
+	 * @param LoaderInterface $loader
163
+	 */
164
+	public function setLoader(LoaderInterface $loader)
165
+	{
166
+		$this->loader = $loader;
167
+	}
168
+
169
+
170
+	/**
171
+	 * @param string $class
172
+	 * @param array  $dependencies
173
+	 * @param int    $overwrite
174
+	 * @return bool
175
+	 */
176
+	public static function register_dependencies(
177
+		$class,
178
+		array $dependencies,
179
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
180
+	) {
181
+		return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
182
+	}
183
+
184
+
185
+	/**
186
+	 * Assigns an array of class names and corresponding load sources (new or cached)
187
+	 * to the class specified by the first parameter.
188
+	 * IMPORTANT !!!
189
+	 * The order of elements in the incoming $dependencies array MUST match
190
+	 * the order of the constructor parameters for the class in question.
191
+	 * This is especially important when overriding any existing dependencies that are registered.
192
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
193
+	 *
194
+	 * @param string $class
195
+	 * @param array  $dependencies
196
+	 * @param int    $overwrite
197
+	 * @return bool
198
+	 */
199
+	public function registerDependencies(
200
+		$class,
201
+		array $dependencies,
202
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
203
+	) {
204
+		$class = trim($class, '\\');
205
+		$registered = false;
206
+		if (empty(self::$_instance->_dependency_map[ $class ])) {
207
+			self::$_instance->_dependency_map[ $class ] = array();
208
+		}
209
+		// we need to make sure that any aliases used when registering a dependency
210
+		// get resolved to the correct class name
211
+		foreach ($dependencies as $dependency => $load_source) {
212
+			$alias = self::$_instance->getFqnForAlias($dependency);
213
+			if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
214
+				|| ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
215
+			) {
216
+				unset($dependencies[ $dependency ]);
217
+				$dependencies[ $alias ] = $load_source;
218
+				$registered = true;
219
+			}
220
+		}
221
+		// now add our two lists of dependencies together.
222
+		// using Union (+=) favours the arrays in precedence from left to right,
223
+		// so $dependencies is NOT overwritten because it is listed first
224
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
225
+		// Union is way faster than array_merge() but should be used with caution...
226
+		// especially with numerically indexed arrays
227
+		$dependencies += self::$_instance->_dependency_map[ $class ];
228
+		// now we need to ensure that the resulting dependencies
229
+		// array only has the entries that are required for the class
230
+		// so first count how many dependencies were originally registered for the class
231
+		$dependency_count = count(self::$_instance->_dependency_map[ $class ]);
232
+		// if that count is non-zero (meaning dependencies were already registered)
233
+		self::$_instance->_dependency_map[ $class ] = $dependency_count
234
+			// then truncate the  final array to match that count
235
+			? array_slice($dependencies, 0, $dependency_count)
236
+			// otherwise just take the incoming array because nothing previously existed
237
+			: $dependencies;
238
+		return $registered;
239
+	}
240
+
241
+
242
+	/**
243
+	 * @param string $class_name
244
+	 * @param string $loader
245
+	 * @return bool
246
+	 * @throws DomainException
247
+	 */
248
+	public static function register_class_loader($class_name, $loader = 'load_core')
249
+	{
250
+		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
251
+			throw new DomainException(
252
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
253
+			);
254
+		}
255
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
256
+		if (! is_callable($loader)
257
+			&& (
258
+				strpos($loader, 'load_') !== 0
259
+				|| ! method_exists('EE_Registry', $loader)
260
+			)
261
+		) {
262
+			throw new DomainException(
263
+				sprintf(
264
+					esc_html__(
265
+						'"%1$s" is not a valid loader method on EE_Registry.',
266
+						'event_espresso'
267
+					),
268
+					$loader
269
+				)
270
+			);
271
+		}
272
+		$class_name = self::$_instance->getFqnForAlias($class_name);
273
+		if (! isset(self::$_instance->_class_loaders[ $class_name ])) {
274
+			self::$_instance->_class_loaders[ $class_name ] = $loader;
275
+			return true;
276
+		}
277
+		return false;
278
+	}
279
+
280
+
281
+	/**
282
+	 * @return array
283
+	 */
284
+	public function dependency_map()
285
+	{
286
+		return $this->_dependency_map;
287
+	}
288
+
289
+
290
+	/**
291
+	 * returns TRUE if dependency map contains a listing for the provided class name
292
+	 *
293
+	 * @param string $class_name
294
+	 * @return boolean
295
+	 */
296
+	public function has($class_name = '')
297
+	{
298
+		// all legacy models have the same dependencies
299
+		if (strpos($class_name, 'EEM_') === 0) {
300
+			$class_name = 'LEGACY_MODELS';
301
+		}
302
+		return isset($this->_dependency_map[ $class_name ]) ? true : false;
303
+	}
304
+
305
+
306
+	/**
307
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
308
+	 *
309
+	 * @param string $class_name
310
+	 * @param string $dependency
311
+	 * @return bool
312
+	 */
313
+	public function has_dependency_for_class($class_name = '', $dependency = '')
314
+	{
315
+		// all legacy models have the same dependencies
316
+		if (strpos($class_name, 'EEM_') === 0) {
317
+			$class_name = 'LEGACY_MODELS';
318
+		}
319
+		$dependency = $this->getFqnForAlias($dependency, $class_name);
320
+		return isset($this->_dependency_map[ $class_name ][ $dependency ])
321
+			? true
322
+			: false;
323
+	}
324
+
325
+
326
+	/**
327
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
328
+	 *
329
+	 * @param string $class_name
330
+	 * @param string $dependency
331
+	 * @return int
332
+	 */
333
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
334
+	{
335
+		// all legacy models have the same dependencies
336
+		if (strpos($class_name, 'EEM_') === 0) {
337
+			$class_name = 'LEGACY_MODELS';
338
+		}
339
+		$dependency = $this->getFqnForAlias($dependency);
340
+		return $this->has_dependency_for_class($class_name, $dependency)
341
+			? $this->_dependency_map[ $class_name ][ $dependency ]
342
+			: EE_Dependency_Map::not_registered;
343
+	}
344
+
345
+
346
+	/**
347
+	 * @param string $class_name
348
+	 * @return string | Closure
349
+	 */
350
+	public function class_loader($class_name)
351
+	{
352
+		// all legacy models use load_model()
353
+		if (strpos($class_name, 'EEM_') === 0) {
354
+			return 'load_model';
355
+		}
356
+		// EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc
357
+		// perform strpos() first to avoid loading regex every time we load a class
358
+		if (strpos($class_name, 'EE_CPT_') === 0
359
+			&& preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name)
360
+		) {
361
+			return 'load_core';
362
+		}
363
+		$class_name = $this->getFqnForAlias($class_name);
364
+		return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : '';
365
+	}
366
+
367
+
368
+	/**
369
+	 * @return array
370
+	 */
371
+	public function class_loaders()
372
+	{
373
+		return $this->_class_loaders;
374
+	}
375
+
376
+
377
+	/**
378
+	 * adds an alias for a classname
379
+	 *
380
+	 * @param string $fqcn      the class name that should be used (concrete class to replace interface)
381
+	 * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
382
+	 * @param string $for_class the class that has the dependency (is type hinting for the interface)
383
+	 */
384
+	public function add_alias($fqcn, $alias, $for_class = '')
385
+	{
386
+		$this->class_cache->addAlias($fqcn, $alias, $for_class);
387
+	}
388
+
389
+
390
+	/**
391
+	 * Returns TRUE if the provided fully qualified name IS an alias
392
+	 * WHY?
393
+	 * Because if a class is type hinting for a concretion,
394
+	 * then why would we need to find another class to supply it?
395
+	 * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
396
+	 * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
397
+	 * Don't go looking for some substitute.
398
+	 * Whereas if a class is type hinting for an interface...
399
+	 * then we need to find an actual class to use.
400
+	 * So the interface IS the alias for some other FQN,
401
+	 * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
402
+	 * represents some other class.
403
+	 *
404
+	 * @param string $fqn
405
+	 * @param string $for_class
406
+	 * @return bool
407
+	 */
408
+	public function isAlias($fqn = '', $for_class = '')
409
+	{
410
+		return $this->class_cache->isAlias($fqn, $for_class);
411
+	}
412
+
413
+
414
+	/**
415
+	 * Returns a FQN for provided alias if one exists, otherwise returns the original $alias
416
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
417
+	 *  for example:
418
+	 *      if the following two entries were added to the _aliases array:
419
+	 *          array(
420
+	 *              'interface_alias'           => 'some\namespace\interface'
421
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
422
+	 *          )
423
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
424
+	 *      to load an instance of 'some\namespace\classname'
425
+	 *
426
+	 * @param string $alias
427
+	 * @param string $for_class
428
+	 * @return string
429
+	 */
430
+	public function getFqnForAlias($alias = '', $for_class = '')
431
+	{
432
+		return (string) $this->class_cache->getFqnForAlias($alias, $for_class);
433
+	}
434
+
435
+
436
+	/**
437
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
438
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
439
+	 * This is done by using the following class constants:
440
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
441
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
442
+	 */
443
+	protected function _register_core_dependencies()
444
+	{
445
+		$this->_dependency_map = array(
446
+			'EE_Request_Handler'                                                                                          => array(
447
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
448
+			),
449
+			'EE_System'                                                                                                   => array(
450
+				'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
451
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
452
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
453
+				'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
454
+			),
455
+			'EE_Session'                                                                                                  => array(
456
+				'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
457
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
458
+				'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
459
+				'EventEspresso\core\services\session\SessionStartHandler'  => EE_Dependency_Map::load_from_cache,
460
+				'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
461
+			),
462
+			'EE_Cart'                                                                                                     => array(
463
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
464
+			),
465
+			'EE_Front_Controller'                                                                                         => array(
466
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
467
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
468
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
469
+			),
470
+			'EE_Messenger_Collection_Loader'                                                                              => array(
471
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
472
+			),
473
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
474
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
475
+			),
476
+			'EE_Message_Resource_Manager'                                                                                 => array(
477
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
478
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
479
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
480
+			),
481
+			'EE_Message_Factory'                                                                                          => array(
482
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
483
+			),
484
+			'EE_messages'                                                                                                 => array(
485
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
486
+			),
487
+			'EE_Messages_Generator'                                                                                       => array(
488
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
489
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
490
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
491
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
492
+			),
493
+			'EE_Messages_Processor'                                                                                       => array(
494
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
495
+			),
496
+			'EE_Messages_Queue'                                                                                           => array(
497
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
498
+			),
499
+			'EE_Messages_Template_Defaults'                                                                               => array(
500
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
501
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
502
+			),
503
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
504
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
505
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
506
+			),
507
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
508
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
509
+			),
510
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
511
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
512
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
513
+			),
514
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
515
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
516
+			),
517
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
518
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
519
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
520
+			),
521
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
522
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
523
+			),
524
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
525
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
526
+			),
527
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
528
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
529
+			),
530
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
531
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
532
+			),
533
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
534
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
535
+			),
536
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
537
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
538
+			),
539
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
540
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
541
+			),
542
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
543
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
544
+			),
545
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
546
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
547
+			),
548
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
549
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
550
+			),
551
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
552
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
553
+			),
554
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
555
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
556
+			),
557
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
558
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
559
+			),
560
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
561
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
562
+			),
563
+			'EE_Data_Migration_Class_Base'                                                                                => array(
564
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
565
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
566
+			),
567
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
568
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
569
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
570
+			),
571
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
572
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
573
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
574
+			),
575
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
576
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
577
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
578
+			),
579
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
580
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
581
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
582
+			),
583
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
584
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
585
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
586
+			),
587
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
588
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
589
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
590
+			),
591
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
592
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
593
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
594
+			),
595
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
596
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
597
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
598
+			),
599
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
600
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
601
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
602
+			),
603
+			'EventEspresso\core\services\assets\I18nRegistry'                                                             => array(
604
+				array(),
605
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
606
+			),
607
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
608
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
609
+				'EventEspresso\core\services\assets\I18nRegistry'    => EE_Dependency_Map::load_from_cache,
610
+			),
611
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
612
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
613
+			),
614
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
615
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
616
+			),
617
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
618
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
619
+			),
620
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
621
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
622
+			),
623
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
624
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
625
+			),
626
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
627
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
628
+			),
629
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
630
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
631
+			),
632
+			'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
633
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
634
+			),
635
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
636
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
637
+			),
638
+			'EventEspresso\core\domain\services\validation\email\EmailValidationService'                                  => array(
639
+				'EE_Registration_Config'                     => EE_Dependency_Map::load_from_cache,
640
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
641
+			),
642
+			'EventEspresso\core\domain\values\EmailAddress'                                                               => array(
643
+				null,
644
+				'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
645
+			),
646
+			'EventEspresso\core\services\orm\ModelFieldFactory'                                                           => array(
647
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
648
+			),
649
+			'LEGACY_MODELS'                                                                                               => array(
650
+				null,
651
+				'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
652
+			),
653
+			'EE_Module_Request_Router'                                                                                    => array(
654
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
655
+			),
656
+			'EE_Registration_Processor'                                                                                   => array(
657
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
658
+			),
659
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'                                      => array(
660
+				null,
661
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
662
+				'EventEspresso\core\services\request\Request'                         => EE_Dependency_Map::load_from_cache,
663
+			),
664
+			'EventEspresso\core\services\licensing\LicenseService'                                                        => array(
665
+				'EventEspresso\core\domain\services\pue\Stats'  => EE_Dependency_Map::load_from_cache,
666
+				'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
667
+			),
668
+			'EE_Admin_Transactions_List_Table'                                                                            => array(
669
+				null,
670
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
671
+			),
672
+			'EventEspresso\core\domain\services\pue\Stats'                                                                => array(
673
+				'EventEspresso\core\domain\services\pue\Config'        => EE_Dependency_Map::load_from_cache,
674
+				'EE_Maintenance_Mode'                                  => EE_Dependency_Map::load_from_cache,
675
+				'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache,
676
+			),
677
+			'EventEspresso\core\domain\services\pue\Config'                                                               => array(
678
+				'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
679
+				'EE_Config'         => EE_Dependency_Map::load_from_cache,
680
+			),
681
+			'EventEspresso\core\domain\services\pue\StatsGatherer'                                                        => array(
682
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
683
+				'EEM_Event'          => EE_Dependency_Map::load_from_cache,
684
+				'EEM_Datetime'       => EE_Dependency_Map::load_from_cache,
685
+				'EEM_Ticket'         => EE_Dependency_Map::load_from_cache,
686
+				'EEM_Registration'   => EE_Dependency_Map::load_from_cache,
687
+				'EEM_Transaction'    => EE_Dependency_Map::load_from_cache,
688
+				'EE_Config'          => EE_Dependency_Map::load_from_cache,
689
+			),
690
+			'EventEspresso\core\domain\services\admin\ExitModal'                                                          => array(
691
+				'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache,
692
+			),
693
+			'EventEspresso\core\domain\services\admin\PluginUpsells'                                                      => array(
694
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
695
+			),
696
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha'                                    => array(
697
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
698
+				'EE_Session'             => EE_Dependency_Map::load_from_cache,
699
+			),
700
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings'                                => array(
701
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
702
+			),
703
+			'EventEspresso\modules\ticket_selector\ProcessTicketSelector'                                                 => array(
704
+				'EE_Core_Config'                                                          => EE_Dependency_Map::load_from_cache,
705
+				'EventEspresso\core\services\request\Request'                             => EE_Dependency_Map::load_from_cache,
706
+				'EE_Session'                                                              => EE_Dependency_Map::load_from_cache,
707
+				'EEM_Ticket'                                                              => EE_Dependency_Map::load_from_cache,
708
+				'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
709
+			),
710
+			'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'                                     => array(
711
+				'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
712
+			),
713
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'                              => array(
714
+				'EE_Core_Config'                             => EE_Dependency_Map::load_from_cache,
715
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
716
+			),
717
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'                                => array(
718
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
719
+			),
720
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'                               => array(
721
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
722
+			),
723
+			'EE_CPT_Strategy'                                                                                             => array(
724
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
725
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
726
+			),
727
+			'EventEspresso\core\services\loaders\ObjectIdentifier'                                                        => array(
728
+				'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache,
729
+			),
730
+			'EventEspresso\core\domain\services\assets\CoreAssetManager'                                                  => array(
731
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
732
+				'EE_Currency_Config'                                 => EE_Dependency_Map::load_from_cache,
733
+				'EE_Template_Config'                                 => EE_Dependency_Map::load_from_cache,
734
+				'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
735
+				'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
736
+			),
737
+			'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array(
738
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
739
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache
740
+			),
741
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array(
742
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
743
+			),
744
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array(
745
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
746
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache
747
+			),
748
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array(
749
+				'EEM_Checkin' => EE_Dependency_Map::load_from_cache,
750
+			),
751
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array(
752
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache,
753
+			),
754
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array(
755
+				'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
756
+			),
757
+			'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array(
758
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
759
+			),
760
+			'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array(
761
+				'EEM_Answer' => EE_Dependency_Map::load_from_cache,
762
+				'EEM_Question' => EE_Dependency_Map::load_from_cache,
763
+			),
764
+			'EventEspresso\core\CPTs\CptQueryModifier' => array(
765
+				null,
766
+				null,
767
+				null,
768
+				'EE_Request_Handler'                          => EE_Dependency_Map::load_from_cache,
769
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
770
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
771
+			),
772
+			'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array(
773
+				'EE_Registry' => EE_Dependency_Map::load_from_cache,
774
+				'EE_Config' => EE_Dependency_Map::load_from_cache
775
+			),
776
+			'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => array(
777
+				'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache
778
+			),
779
+			'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => array(
780
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
781
+			),
782
+			'EventEspresso\core\libraries\rest_api\controllers\model\Read' => array(
783
+				'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache
784
+			),
785
+			'EventEspresso\core\libraries\rest_api\calculations\Datetime' => array(
786
+				'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
787
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache
788
+			),
789
+			'EventEspresso\core\libraries\rest_api\calculations\Event' => array(
790
+				'EEM_Event' => EE_Dependency_Map::load_from_cache,
791
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache
792
+			),
793
+			'EventEspresso\core\libraries\rest_api\calculations\Registration' => array(
794
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache
795
+			),
796
+			'EventEspresso\core\services\session\SessionStartHandler' => array(
797
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
798
+			),
799
+		);
800
+	}
801
+
802
+
803
+	/**
804
+	 * Registers how core classes are loaded.
805
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
806
+	 *        'EE_Request_Handler' => 'load_core'
807
+	 *        'EE_Messages_Queue'  => 'load_lib'
808
+	 *        'EEH_Debug_Tools'    => 'load_helper'
809
+	 * or, if greater control is required, by providing a custom closure. For example:
810
+	 *        'Some_Class' => function () {
811
+	 *            return new Some_Class();
812
+	 *        },
813
+	 * This is required for instantiating dependencies
814
+	 * where an interface has been type hinted in a class constructor. For example:
815
+	 *        'Required_Interface' => function () {
816
+	 *            return new A_Class_That_Implements_Required_Interface();
817
+	 *        },
818
+	 */
819
+	protected function _register_core_class_loaders()
820
+	{
821
+		// for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
822
+		// be used in a closure.
823
+		$request = &$this->request;
824
+		$response = &$this->response;
825
+		$legacy_request = &$this->legacy_request;
826
+		// $loader = &$this->loader;
827
+		$this->_class_loaders = array(
828
+			// load_core
829
+			'EE_Capabilities'                              => 'load_core',
830
+			'EE_Encryption'                                => 'load_core',
831
+			'EE_Front_Controller'                          => 'load_core',
832
+			'EE_Module_Request_Router'                     => 'load_core',
833
+			'EE_Registry'                                  => 'load_core',
834
+			'EE_Request'                                   => function () use (&$legacy_request) {
835
+				return $legacy_request;
836
+			},
837
+			'EventEspresso\core\services\request\Request'  => function () use (&$request) {
838
+				return $request;
839
+			},
840
+			'EventEspresso\core\services\request\Response' => function () use (&$response) {
841
+				return $response;
842
+			},
843
+			'EE_Base'                                      => 'load_core',
844
+			'EE_Request_Handler'                           => 'load_core',
845
+			'EE_Session'                                   => 'load_core',
846
+			'EE_Cron_Tasks'                                => 'load_core',
847
+			'EE_System'                                    => 'load_core',
848
+			'EE_Maintenance_Mode'                          => 'load_core',
849
+			'EE_Register_CPTs'                             => 'load_core',
850
+			'EE_Admin'                                     => 'load_core',
851
+			'EE_CPT_Strategy'                              => 'load_core',
852
+			// load_lib
853
+			'EE_Message_Resource_Manager'                  => 'load_lib',
854
+			'EE_Message_Type_Collection'                   => 'load_lib',
855
+			'EE_Message_Type_Collection_Loader'            => 'load_lib',
856
+			'EE_Messenger_Collection'                      => 'load_lib',
857
+			'EE_Messenger_Collection_Loader'               => 'load_lib',
858
+			'EE_Messages_Processor'                        => 'load_lib',
859
+			'EE_Message_Repository'                        => 'load_lib',
860
+			'EE_Messages_Queue'                            => 'load_lib',
861
+			'EE_Messages_Data_Handler_Collection'          => 'load_lib',
862
+			'EE_Message_Template_Group_Collection'         => 'load_lib',
863
+			'EE_Payment_Method_Manager'                    => 'load_lib',
864
+			'EE_Messages_Generator'                        => function () {
865
+				return EE_Registry::instance()->load_lib(
866
+					'Messages_Generator',
867
+					array(),
868
+					false,
869
+					false
870
+				);
871
+			},
872
+			'EE_Messages_Template_Defaults'                => function ($arguments = array()) {
873
+				return EE_Registry::instance()->load_lib(
874
+					'Messages_Template_Defaults',
875
+					$arguments,
876
+					false,
877
+					false
878
+				);
879
+			},
880
+			// load_helper
881
+			'EEH_Parse_Shortcodes'                         => function () {
882
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
883
+					return new EEH_Parse_Shortcodes();
884
+				}
885
+				return null;
886
+			},
887
+			'EE_Template_Config'                           => function () {
888
+				return EE_Config::instance()->template_settings;
889
+			},
890
+			'EE_Currency_Config'                           => function () {
891
+				return EE_Config::instance()->currency;
892
+			},
893
+			'EE_Registration_Config'                       => function () {
894
+				return EE_Config::instance()->registration;
895
+			},
896
+			'EE_Core_Config'                               => function () {
897
+				return EE_Config::instance()->core;
898
+			},
899
+			'EventEspresso\core\services\loaders\Loader'   => function () {
900
+				return LoaderFactory::getLoader();
901
+			},
902
+			'EE_Network_Config'                            => function () {
903
+				return EE_Network_Config::instance();
904
+			},
905
+			'EE_Config'                                    => function () {
906
+				return EE_Config::instance();
907
+			},
908
+			'EventEspresso\core\domain\Domain'             => function () {
909
+				return DomainFactory::getEventEspressoCoreDomain();
910
+			},
911
+			'EE_Admin_Config'                              => function () {
912
+				return EE_Config::instance()->admin;
913
+			},
914
+		);
915
+	}
916
+
917
+
918
+	/**
919
+	 * can be used for supplying alternate names for classes,
920
+	 * or for connecting interface names to instantiable classes
921
+	 */
922
+	protected function _register_core_aliases()
923
+	{
924
+		$aliases = array(
925
+			'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
926
+			'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
927
+			'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
928
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
929
+			'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
930
+			'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
931
+			'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
932
+			'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
933
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
934
+			'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
935
+			'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
936
+			'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
937
+			'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
938
+			'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
939
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
940
+			'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
941
+			'CreateTransactionCommandHandler'                                              => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
942
+			'CreateAttendeeCommandHandler'                                                 => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
943
+			'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
944
+			'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
945
+			'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
946
+			'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
947
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
948
+			'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
949
+			'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
950
+			'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
951
+			'CommandFactoryInterface'                                                      => 'EventEspresso\core\services\commands\CommandFactoryInterface',
952
+			'EventEspresso\core\services\commands\CommandFactoryInterface'                 => 'EventEspresso\core\services\commands\CommandFactory',
953
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface'        => 'EE_Session',
954
+			'EmailValidatorInterface'                                                      => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
955
+			'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface'  => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
956
+			'NoticeConverterInterface'                                                     => 'EventEspresso\core\services\notices\NoticeConverterInterface',
957
+			'EventEspresso\core\services\notices\NoticeConverterInterface'                 => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
958
+			'NoticesContainerInterface'                                                    => 'EventEspresso\core\services\notices\NoticesContainerInterface',
959
+			'EventEspresso\core\services\notices\NoticesContainerInterface'                => 'EventEspresso\core\services\notices\NoticesContainer',
960
+			'EventEspresso\core\services\request\RequestInterface'                         => 'EventEspresso\core\services\request\Request',
961
+			'EventEspresso\core\services\request\ResponseInterface'                        => 'EventEspresso\core\services\request\Response',
962
+			'EventEspresso\core\domain\DomainInterface'                                    => 'EventEspresso\core\domain\Domain',
963
+		);
964
+		foreach ($aliases as $alias => $fqn) {
965
+			if (is_array($fqn)) {
966
+				foreach ($fqn as $class => $for_class) {
967
+					$this->class_cache->addAlias($class, $alias, $for_class);
968
+				}
969
+				continue;
970
+			}
971
+			$this->class_cache->addAlias($fqn, $alias);
972
+		}
973
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
974
+			$this->class_cache->addAlias(
975
+				'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
976
+				'EventEspresso\core\services\notices\NoticeConverterInterface'
977
+			);
978
+		}
979
+	}
980
+
981
+
982
+	/**
983
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
984
+	 * request Primarily used by unit tests.
985
+	 */
986
+	public function reset()
987
+	{
988
+		$this->_register_core_class_loaders();
989
+		$this->_register_core_dependencies();
990
+	}
991
+
992
+
993
+	/**
994
+	 * PLZ NOTE: a better name for this method would be is_alias()
995
+	 * because it returns TRUE if the provided fully qualified name IS an alias
996
+	 * WHY?
997
+	 * Because if a class is type hinting for a concretion,
998
+	 * then why would we need to find another class to supply it?
999
+	 * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
1000
+	 * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
1001
+	 * Don't go looking for some substitute.
1002
+	 * Whereas if a class is type hinting for an interface...
1003
+	 * then we need to find an actual class to use.
1004
+	 * So the interface IS the alias for some other FQN,
1005
+	 * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
1006
+	 * represents some other class.
1007
+	 *
1008
+	 * @deprecated 4.9.62.p
1009
+	 * @param string $fqn
1010
+	 * @param string $for_class
1011
+	 * @return bool
1012
+	 */
1013
+	public function has_alias($fqn = '', $for_class = '')
1014
+	{
1015
+		return $this->isAlias($fqn, $for_class);
1016
+	}
1017
+
1018
+
1019
+	/**
1020
+	 * PLZ NOTE: a better name for this method would be get_fqn_for_alias()
1021
+	 * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias
1022
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
1023
+	 *  for example:
1024
+	 *      if the following two entries were added to the _aliases array:
1025
+	 *          array(
1026
+	 *              'interface_alias'           => 'some\namespace\interface'
1027
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
1028
+	 *          )
1029
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
1030
+	 *      to load an instance of 'some\namespace\classname'
1031
+	 *
1032
+	 * @deprecated 4.9.62.p
1033
+	 * @param string $alias
1034
+	 * @param string $for_class
1035
+	 * @return string
1036
+	 */
1037
+	public function get_alias($alias = '', $for_class = '')
1038
+	{
1039
+		return $this->getFqnForAlias($alias, $for_class);
1040
+	}
1041 1041
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.68.rc.010');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.68.rc.010');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.