@@ -780,7 +780,7 @@ |
||
780 | 780 | /** |
781 | 781 | * @param EEM_Base $source_model |
782 | 782 | * @param EEM_Base $related_model |
783 | - * @param $version |
|
783 | + * @param string $version |
|
784 | 784 | * @return array |
785 | 785 | * @throws EE_Error |
786 | 786 | * @since $VID:$ |
@@ -22,1355 +22,1355 @@ |
||
22 | 22 | class EED_Core_Rest_Api extends EED_Module |
23 | 23 | { |
24 | 24 | |
25 | - const ee_api_namespace = Domain::API_NAMESPACE; |
|
26 | - |
|
27 | - const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
28 | - |
|
29 | - const saved_routes_option_names = 'ee_core_routes'; |
|
30 | - |
|
31 | - /** |
|
32 | - * string used in _links response bodies to make them globally unique. |
|
33 | - * |
|
34 | - * @see http://v2.wp-api.org/extending/linking/ |
|
35 | - */ |
|
36 | - const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var CalculatedModelFields |
|
40 | - */ |
|
41 | - protected static $_field_calculator; |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @return EED_Core_Rest_Api|EED_Module |
|
46 | - */ |
|
47 | - public static function instance() |
|
48 | - { |
|
49 | - return parent::get_instance(EED_Core_Rest_Api::class); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
55 | - * |
|
56 | - * @access public |
|
57 | - * @return void |
|
58 | - */ |
|
59 | - public static function set_hooks() |
|
60 | - { |
|
61 | - EED_Core_Rest_Api::set_hooks_both(); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
67 | - * |
|
68 | - * @access public |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - public static function set_hooks_admin() |
|
72 | - { |
|
73 | - EED_Core_Rest_Api::set_hooks_both(); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - public static function set_hooks_both() |
|
78 | - { |
|
79 | - /** @var EventEspresso\core\services\request\Request $request */ |
|
80 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
81 | - if (! $request->isWordPressApi()) { |
|
82 | - return; |
|
83 | - } |
|
84 | - add_action('rest_api_init', ['EED_Core_Rest_Api', 'register_routes'], 10); |
|
85 | - add_action('rest_api_init', ['EED_Core_Rest_Api', 'set_hooks_rest_api'], 5); |
|
86 | - add_filter('rest_route_data', ['EED_Core_Rest_Api', 'hide_old_endpoints'], 10, 2); |
|
87 | - add_filter( |
|
88 | - 'rest_index', |
|
89 | - ['EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex'] |
|
90 | - ); |
|
91 | - EED_Core_Rest_Api::$_field_calculator = LoaderFactory::getLoader()->load( |
|
92 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' |
|
93 | - ); |
|
94 | - EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * sets up hooks which only need to be included as part of REST API requests; |
|
100 | - * other requests like to the frontend or admin etc don't need them |
|
101 | - * |
|
102 | - * @throws EE_Error |
|
103 | - */ |
|
104 | - public static function set_hooks_rest_api() |
|
105 | - { |
|
106 | - // set hooks which account for changes made to the API |
|
107 | - EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * public wrapper of _set_hooks_for_changes. |
|
113 | - * Loads all the hooks which make requests to old versions of the API |
|
114 | - * appear the same as they always did |
|
115 | - * |
|
116 | - * @throws EE_Error |
|
117 | - */ |
|
118 | - public static function set_hooks_for_changes() |
|
119 | - { |
|
120 | - EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * Loads all the hooks which make requests to old versions of the API |
|
126 | - * appear the same as they always did |
|
127 | - * |
|
128 | - * @throws EE_Error |
|
129 | - */ |
|
130 | - protected static function _set_hooks_for_changes() |
|
131 | - { |
|
132 | - $folder_contents = EEH_File::get_contents_of_folders([EE_LIBRARIES . 'rest_api/changes'], false); |
|
133 | - foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
134 | - // ignore the base parent class |
|
135 | - // and legacy named classes |
|
136 | - if ($classname_in_namespace === 'ChangesInBase' |
|
137 | - || strpos($classname_in_namespace, 'Changes_In_') === 0 |
|
138 | - ) { |
|
139 | - continue; |
|
140 | - } |
|
141 | - $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
142 | - if (class_exists($full_classname)) { |
|
143 | - $instance_of_class = new $full_classname; |
|
144 | - if ($instance_of_class instanceof ChangesInBase) { |
|
145 | - $instance_of_class->setHooks(); |
|
146 | - } |
|
147 | - } |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
154 | - * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
155 | - * |
|
156 | - * @throws EE_Error |
|
157 | - * @throws ReflectionException |
|
158 | - */ |
|
159 | - public static function register_routes() |
|
160 | - { |
|
161 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) { |
|
162 | - foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) { |
|
163 | - /** |
|
164 | - * @var array $data_for_multiple_endpoints numerically indexed array |
|
165 | - * but can also contain route options like { |
|
166 | - * @type array $schema { |
|
167 | - * @type callable $schema_callback |
|
168 | - * @type array $callback_args arguments that will be passed to the callback, after the |
|
169 | - * WP_REST_Request of course |
|
170 | - * } |
|
171 | - * } |
|
172 | - */ |
|
173 | - // when registering routes, register all the endpoints' data at the same time |
|
174 | - $multiple_endpoint_args = []; |
|
175 | - foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) { |
|
176 | - /** |
|
177 | - * @var array $data_for_single_endpoint { |
|
178 | - * @type callable $callback |
|
179 | - * @type string methods |
|
180 | - * @type array args |
|
181 | - * @type array _links |
|
182 | - * @type array $callback_args arguments that will be passed to the callback, after the |
|
183 | - * WP_REST_Request of course |
|
184 | - * } |
|
185 | - */ |
|
186 | - // skip route options |
|
187 | - if (! is_numeric($endpoint_key)) { |
|
188 | - continue; |
|
189 | - } |
|
190 | - if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
191 | - throw new EE_Error( |
|
192 | - esc_html__( |
|
193 | - // @codingStandardsIgnoreStart |
|
194 | - 'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).', |
|
195 | - // @codingStandardsIgnoreEnd |
|
196 | - 'event_espresso' |
|
197 | - ) |
|
198 | - ); |
|
199 | - } |
|
200 | - $callback = $data_for_single_endpoint['callback']; |
|
201 | - $single_endpoint_args = [ |
|
202 | - 'methods' => $data_for_single_endpoint['methods'], |
|
203 | - 'args' => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args'] |
|
204 | - : [], |
|
205 | - ]; |
|
206 | - if (isset($data_for_single_endpoint['_links'])) { |
|
207 | - $single_endpoint_args['_links'] = $data_for_single_endpoint['_links']; |
|
208 | - } |
|
209 | - if (isset($data_for_single_endpoint['callback_args'])) { |
|
210 | - $callback_args = $data_for_single_endpoint['callback_args']; |
|
211 | - $single_endpoint_args['callback'] = static function (WP_REST_Request $request) use ( |
|
212 | - $callback, |
|
213 | - $callback_args |
|
214 | - ) { |
|
215 | - array_unshift($callback_args, $request); |
|
216 | - return call_user_func_array( |
|
217 | - $callback, |
|
218 | - $callback_args |
|
219 | - ); |
|
220 | - }; |
|
221 | - } else { |
|
222 | - $single_endpoint_args['callback'] = $data_for_single_endpoint['callback']; |
|
223 | - } |
|
224 | - $multiple_endpoint_args[] = $single_endpoint_args; |
|
225 | - } |
|
226 | - if (isset($data_for_multiple_endpoints['schema'])) { |
|
227 | - $schema_route_data = $data_for_multiple_endpoints['schema']; |
|
228 | - $schema_callback = $schema_route_data['schema_callback']; |
|
229 | - $callback_args = $schema_route_data['callback_args']; |
|
230 | - $multiple_endpoint_args['schema'] = static function () use ($schema_callback, $callback_args) { |
|
231 | - return call_user_func_array( |
|
232 | - $schema_callback, |
|
233 | - $callback_args |
|
234 | - ); |
|
235 | - }; |
|
236 | - } |
|
237 | - register_rest_route( |
|
238 | - $namespace, |
|
239 | - $relative_route, |
|
240 | - $multiple_endpoint_args |
|
241 | - ); |
|
242 | - } |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Checks if there was a version change or something that merits invalidating the cached |
|
249 | - * route data. If so, invalidates the cached route data so that it gets refreshed |
|
250 | - * next time the WP API is used |
|
251 | - */ |
|
252 | - public static function invalidate_cached_route_data_on_version_change() |
|
253 | - { |
|
254 | - if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) { |
|
255 | - EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
256 | - } |
|
257 | - foreach (EE_Registry::instance()->addons as $addon) { |
|
258 | - if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) { |
|
259 | - EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
260 | - } |
|
261 | - } |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * Removes the cached route data so it will get refreshed next time the WP API is used |
|
267 | - */ |
|
268 | - public static function invalidate_cached_route_data() |
|
269 | - { |
|
270 | - // delete the saved EE REST API routes |
|
271 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
|
272 | - delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * Gets the EE route data |
|
279 | - * |
|
280 | - * @return array top-level key is the namespace, next-level key is the route and its value is array{ |
|
281 | - * @throws EE_Error |
|
282 | - * @throws ReflectionException |
|
283 | - * @type string|array $callback |
|
284 | - * @type string $methods |
|
285 | - * @type boolean $hidden_endpoint |
|
286 | - * } |
|
287 | - */ |
|
288 | - public static function get_ee_route_data() |
|
289 | - { |
|
290 | - $ee_routes = []; |
|
291 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoints) { |
|
292 | - $ee_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = EED_Core_Rest_Api::_get_ee_route_data_for_version( |
|
293 | - $version, |
|
294 | - $hidden_endpoints |
|
295 | - ); |
|
296 | - } |
|
297 | - return $ee_routes; |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Gets the EE route data from the wp options if it exists already, |
|
303 | - * otherwise re-generates it and saves it to the option |
|
304 | - * |
|
305 | - * @param string $version |
|
306 | - * @param boolean $hidden_endpoints |
|
307 | - * @return array |
|
308 | - * @throws EE_Error |
|
309 | - * @throws ReflectionException |
|
310 | - */ |
|
311 | - protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
312 | - { |
|
313 | - $ee_routes = get_option(EED_Core_Rest_Api::saved_routes_option_names . $version, null); |
|
314 | - if (! $ee_routes || EED_Core_Rest_Api::debugMode()) { |
|
315 | - $ee_routes = EED_Core_Rest_Api::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
316 | - } |
|
317 | - return $ee_routes; |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * Saves the EE REST API route data to a wp option and returns it |
|
323 | - * |
|
324 | - * @param string $version |
|
325 | - * @param boolean $hidden_endpoints |
|
326 | - * @return mixed|null |
|
327 | - * @throws EE_Error |
|
328 | - * @throws ReflectionException |
|
329 | - */ |
|
330 | - protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
331 | - { |
|
332 | - $instance = EED_Core_Rest_Api::instance(); |
|
333 | - $routes = apply_filters( |
|
334 | - 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
335 | - array_replace_recursive( |
|
336 | - $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
337 | - $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
338 | - $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
339 | - $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
340 | - ) |
|
341 | - ); |
|
342 | - $option_name = EED_Core_Rest_Api::saved_routes_option_names . $version; |
|
343 | - if (get_option($option_name)) { |
|
344 | - update_option($option_name, $routes, true); |
|
345 | - } else { |
|
346 | - add_option($option_name, $routes, null, 'no'); |
|
347 | - } |
|
348 | - return $routes; |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * Calculates all the EE routes and saves it to a WordPress option so we don't |
|
354 | - * need to calculate it on every request |
|
355 | - * |
|
356 | - * @return void |
|
357 | - * @deprecated since version 4.9.1 |
|
358 | - */ |
|
359 | - public static function save_ee_routes() |
|
360 | - { |
|
361 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
362 | - $instance = EED_Core_Rest_Api::instance(); |
|
363 | - $routes = apply_filters( |
|
364 | - 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
365 | - array_replace_recursive( |
|
366 | - $instance->_register_config_routes(), |
|
367 | - $instance->_register_meta_routes(), |
|
368 | - $instance->_register_model_routes(), |
|
369 | - $instance->_register_rpc_routes() |
|
370 | - ) |
|
371 | - ); |
|
372 | - update_option(EED_Core_Rest_Api::saved_routes_option_names, $routes, true); |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Gets all the route information relating to EE models |
|
379 | - * |
|
380 | - * @return array @see get_ee_route_data |
|
381 | - * @deprecated since version 4.9.1 |
|
382 | - */ |
|
383 | - protected function _register_model_routes() |
|
384 | - { |
|
385 | - $model_routes = []; |
|
386 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
|
387 | - $model_routes[ EED_Core_Rest_Api::ee_api_namespace |
|
388 | - . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
389 | - } |
|
390 | - return $model_routes; |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * Decides whether or not to add write endpoints for this model. |
|
396 | - * Currently, this defaults to exclude all global tables and models |
|
397 | - * which would allow inserting WP core data (we don't want to duplicate |
|
398 | - * what WP API does, as it's unnecessary, extra work, and potentially extra bugs) |
|
399 | - * |
|
400 | - * @param EEM_Base $model |
|
401 | - * @return bool |
|
402 | - */ |
|
403 | - public static function should_have_write_endpoints(EEM_Base $model) |
|
404 | - { |
|
405 | - if ($model->is_wp_core_model()) { |
|
406 | - return false; |
|
407 | - } |
|
408 | - foreach ($model->get_tables() as $table) { |
|
409 | - if ($table->is_global()) { |
|
410 | - return false; |
|
411 | - } |
|
412 | - } |
|
413 | - return true; |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`) |
|
419 | - * in this versioned namespace of EE4 |
|
420 | - * |
|
421 | - * @param $version |
|
422 | - * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event') |
|
423 | - */ |
|
424 | - public static function model_names_with_plural_routes($version) |
|
425 | - { |
|
426 | - $model_version_info = new ModelVersionInfo($version); |
|
427 | - $models_to_register = $model_version_info->modelsForRequestedVersion(); |
|
428 | - // let's not bother having endpoints for extra metas |
|
429 | - unset( |
|
430 | - $models_to_register['Extra_Meta'], |
|
431 | - $models_to_register['Extra_Join'], |
|
432 | - $models_to_register['Post_Meta'] |
|
433 | - ); |
|
434 | - return apply_filters( |
|
435 | - 'FHEE__EED_Core_REST_API___register_model_routes', |
|
436 | - $models_to_register |
|
437 | - ); |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * Gets the route data for EE models in the specified version |
|
443 | - * |
|
444 | - * @param string $version |
|
445 | - * @param boolean $hidden_endpoint |
|
446 | - * @return array |
|
447 | - * @throws EE_Error |
|
448 | - * @throws ReflectionException |
|
449 | - */ |
|
450 | - protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
451 | - { |
|
452 | - $model_routes = []; |
|
453 | - $model_version_info = new ModelVersionInfo($version); |
|
454 | - foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
|
455 | - $model = EE_Registry::instance()->load_model($model_name); |
|
456 | - // if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
457 | - if (! $model instanceof EEM_Base) { |
|
458 | - continue; |
|
459 | - } |
|
460 | - // yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
461 | - $plural_model_route = EED_Core_Rest_Api::get_collection_route($model); |
|
462 | - $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)'); |
|
463 | - $model_routes[ $plural_model_route ] = [ |
|
464 | - [ |
|
465 | - 'callback' => [ |
|
466 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
467 | - 'handleRequestGetAll', |
|
468 | - ], |
|
469 | - 'callback_args' => [$version, $model_name], |
|
470 | - 'methods' => WP_REST_Server::READABLE, |
|
471 | - 'hidden_endpoint' => $hidden_endpoint, |
|
472 | - 'args' => $this->_get_read_query_params($model, $version), |
|
473 | - '_links' => [ |
|
474 | - 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
475 | - ], |
|
476 | - ], |
|
477 | - 'schema' => [ |
|
478 | - 'schema_callback' => [ |
|
479 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
480 | - 'handleSchemaRequest', |
|
481 | - ], |
|
482 | - 'callback_args' => [$version, $model_name], |
|
483 | - ], |
|
484 | - ]; |
|
485 | - $model_routes[ $singular_model_route ] = [ |
|
486 | - [ |
|
487 | - 'callback' => [ |
|
488 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
489 | - 'handleRequestGetOne', |
|
490 | - ], |
|
491 | - 'callback_args' => [$version, $model_name], |
|
492 | - 'methods' => WP_REST_Server::READABLE, |
|
493 | - 'hidden_endpoint' => $hidden_endpoint, |
|
494 | - 'args' => $this->_get_response_selection_query_params($model, $version, true), |
|
495 | - ], |
|
496 | - ]; |
|
497 | - if (apply_filters( |
|
498 | - 'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints', |
|
499 | - EED_Core_Rest_Api::should_have_write_endpoints($model), |
|
500 | - $model |
|
501 | - )) { |
|
502 | - $model_routes[ $plural_model_route ][] = [ |
|
503 | - 'callback' => [ |
|
504 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
505 | - 'handleRequestInsert', |
|
506 | - ], |
|
507 | - 'callback_args' => [$version, $model_name], |
|
508 | - 'methods' => WP_REST_Server::CREATABLE, |
|
509 | - 'hidden_endpoint' => $hidden_endpoint, |
|
510 | - 'args' => $this->_get_write_params($model_name, $model_version_info, true), |
|
511 | - ]; |
|
512 | - $model_routes[ $singular_model_route ] = array_merge( |
|
513 | - $model_routes[ $singular_model_route ], |
|
514 | - [ |
|
515 | - [ |
|
516 | - 'callback' => [ |
|
517 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
518 | - 'handleRequestUpdate', |
|
519 | - ], |
|
520 | - 'callback_args' => [$version, $model_name], |
|
521 | - 'methods' => WP_REST_Server::EDITABLE, |
|
522 | - 'hidden_endpoint' => $hidden_endpoint, |
|
523 | - 'args' => $this->_get_write_params($model_name, $model_version_info), |
|
524 | - ], |
|
525 | - [ |
|
526 | - 'callback' => [ |
|
527 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
528 | - 'handleRequestDelete', |
|
529 | - ], |
|
530 | - 'callback_args' => [$version, $model_name], |
|
531 | - 'methods' => WP_REST_Server::DELETABLE, |
|
532 | - 'hidden_endpoint' => $hidden_endpoint, |
|
533 | - 'args' => $this->_get_delete_query_params($model, $version), |
|
534 | - ], |
|
535 | - ] |
|
536 | - ); |
|
537 | - } |
|
538 | - foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
539 | - $related_route = EED_Core_Rest_Api::get_relation_route_via( |
|
540 | - $model, |
|
541 | - '(?P<id>[^\/]+)', |
|
542 | - $relation_obj |
|
543 | - ); |
|
544 | - $model_routes[ $related_route ] = [ |
|
545 | - [ |
|
546 | - 'callback' => [ |
|
547 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
548 | - 'handleRequestGetRelated', |
|
549 | - ], |
|
550 | - 'callback_args' => [$version, $model_name, $relation_name], |
|
551 | - 'methods' => WP_REST_Server::READABLE, |
|
552 | - 'hidden_endpoint' => $hidden_endpoint, |
|
553 | - 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
554 | - ], |
|
555 | - ]; |
|
556 | - |
|
557 | - $related_write_route = $related_route . '/' . '(?P<related_id>[^\/]+)'; |
|
558 | - $model_routes[ $related_write_route ] = [ |
|
559 | - [ |
|
560 | - 'callback' => [ |
|
561 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
562 | - 'handleRequestAddRelation', |
|
563 | - ], |
|
564 | - 'callback_args' => [$version, $model_name, $relation_name], |
|
565 | - 'methods' => WP_REST_Server::EDITABLE, |
|
566 | - 'hidden_endpoint' => $hidden_endpoint, |
|
567 | - 'args' => $this->_get_add_relation_query_params($model, |
|
568 | - $relation_obj->get_other_model(), $version), |
|
569 | - ], |
|
570 | - [ |
|
571 | - 'callback' => [ |
|
572 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
573 | - 'handleRequestRemoveRelation', |
|
574 | - ], |
|
575 | - 'callback_args' => [$version, $model_name, $relation_name], |
|
576 | - 'methods' => WP_REST_Server::DELETABLE, |
|
577 | - 'hidden_endpoint' => $hidden_endpoint, |
|
578 | - 'args' => [], |
|
579 | - ], |
|
580 | - ]; |
|
581 | - } |
|
582 | - } |
|
583 | - return $model_routes; |
|
584 | - } |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace, |
|
589 | - * excluding the preceding slash. |
|
590 | - * Eg you pass get_plural_route_to('Event') = 'events' |
|
591 | - * |
|
592 | - * @param EEM_Base $model |
|
593 | - * @return string |
|
594 | - */ |
|
595 | - public static function get_collection_route(EEM_Base $model) |
|
596 | - { |
|
597 | - return EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - /** |
|
602 | - * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
603 | - * excluding the preceding slash. |
|
604 | - * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
605 | - * |
|
606 | - * @param EEM_Base $model eg Event or Venue |
|
607 | - * @param string $id |
|
608 | - * @return string |
|
609 | - */ |
|
610 | - public static function get_entity_route($model, $id) |
|
611 | - { |
|
612 | - return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id; |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
618 | - * excluding the preceding slash. |
|
619 | - * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
620 | - * |
|
621 | - * @param EEM_Base $model eg Event or Venue |
|
622 | - * @param string $id |
|
623 | - * @param EE_Model_Relation_Base $relation_obj |
|
624 | - * @return string |
|
625 | - */ |
|
626 | - public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj) |
|
627 | - { |
|
628 | - $related_model_name_endpoint_part = ModelRead::getRelatedEntityName( |
|
629 | - $relation_obj->get_other_model()->get_this_model_name(), |
|
630 | - $relation_obj |
|
631 | - ); |
|
632 | - return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
633 | - } |
|
634 | - |
|
635 | - |
|
636 | - /** |
|
637 | - * Adds onto the $relative_route the EE4 REST API versioned namespace. |
|
638 | - * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events' |
|
639 | - * |
|
640 | - * @param string $relative_route |
|
641 | - * @param string $version |
|
642 | - * @return string |
|
643 | - */ |
|
644 | - public static function get_versioned_route_to($relative_route, $version = '4.8.36') |
|
645 | - { |
|
646 | - return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
647 | - } |
|
648 | - |
|
649 | - |
|
650 | - /** |
|
651 | - * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
652 | - * routes that don't conform to the traditional REST CRUD-style). |
|
653 | - * |
|
654 | - * @deprecated since 4.9.1 |
|
655 | - */ |
|
656 | - protected function _register_rpc_routes() |
|
657 | - { |
|
658 | - $routes = []; |
|
659 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
|
660 | - $routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version( |
|
661 | - $version, |
|
662 | - $hidden_endpoint |
|
663 | - ); |
|
664 | - } |
|
665 | - return $routes; |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - /** |
|
670 | - * @param string $version |
|
671 | - * @param boolean $hidden_endpoint |
|
672 | - * @return array |
|
673 | - */ |
|
674 | - protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
675 | - { |
|
676 | - $this_versions_routes = []; |
|
677 | - // checkin endpoint |
|
678 | - $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = [ |
|
679 | - [ |
|
680 | - 'callback' => [ |
|
681 | - 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
682 | - 'handleRequestToggleCheckin', |
|
683 | - ], |
|
684 | - 'methods' => WP_REST_Server::CREATABLE, |
|
685 | - 'hidden_endpoint' => $hidden_endpoint, |
|
686 | - 'args' => [ |
|
687 | - 'force' => [ |
|
688 | - 'required' => false, |
|
689 | - 'default' => false, |
|
690 | - 'description' => __( |
|
691 | - // @codingStandardsIgnoreStart |
|
692 | - 'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
693 | - // @codingStandardsIgnoreEnd |
|
694 | - 'event_espresso' |
|
695 | - ), |
|
696 | - ], |
|
697 | - ], |
|
698 | - 'callback_args' => [$version], |
|
699 | - ], |
|
700 | - ]; |
|
701 | - return apply_filters( |
|
702 | - 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
703 | - $this_versions_routes, |
|
704 | - $version, |
|
705 | - $hidden_endpoint |
|
706 | - ); |
|
707 | - } |
|
708 | - |
|
709 | - |
|
710 | - /** |
|
711 | - * Gets the query params that can be used when request one or many |
|
712 | - * |
|
713 | - * @param EEM_Base $model |
|
714 | - * @param string $version |
|
715 | - * @return array |
|
716 | - */ |
|
717 | - protected function _get_response_selection_query_params(EEM_Base $model, $version, $single_only = false) |
|
718 | - { |
|
719 | - $query_params = [ |
|
720 | - 'include' => [ |
|
721 | - 'required' => false, |
|
722 | - 'default' => '*', |
|
723 | - 'type' => 'string', |
|
724 | - ], |
|
725 | - 'calculate' => [ |
|
726 | - 'required' => false, |
|
727 | - 'default' => '', |
|
728 | - 'enum' => EED_Core_Rest_Api::$_field_calculator->retrieveCalculatedFieldsForModel($model), |
|
729 | - 'type' => 'string', |
|
730 | - // because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization |
|
731 | - // freaks out. We'll just validate this argument while handling the request |
|
732 | - 'validate_callback' => null, |
|
733 | - 'sanitize_callback' => null, |
|
734 | - ], |
|
735 | - 'password' => [ |
|
736 | - 'required' => false, |
|
737 | - 'default' => '', |
|
738 | - 'type' => 'string', |
|
739 | - ], |
|
740 | - ]; |
|
741 | - return apply_filters( |
|
742 | - 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
743 | - $query_params, |
|
744 | - $model, |
|
745 | - $version |
|
746 | - ); |
|
747 | - } |
|
748 | - |
|
749 | - |
|
750 | - /** |
|
751 | - * Gets the parameters acceptable for delete requests |
|
752 | - * |
|
753 | - * @param EEM_Base $model |
|
754 | - * @param string $version |
|
755 | - * @return array |
|
756 | - */ |
|
757 | - protected function _get_delete_query_params(EEM_Base $model, $version) |
|
758 | - { |
|
759 | - $params_for_delete = [ |
|
760 | - 'allow_blocking' => [ |
|
761 | - 'required' => false, |
|
762 | - 'default' => true, |
|
763 | - 'type' => 'boolean', |
|
764 | - ], |
|
765 | - ]; |
|
766 | - $params_for_delete['force'] = [ |
|
767 | - 'required' => false, |
|
768 | - 'default' => false, |
|
769 | - 'type' => 'boolean', |
|
770 | - ]; |
|
771 | - return apply_filters( |
|
772 | - 'FHEE__EED_Core_Rest_Api___get_delete_query_params', |
|
773 | - $params_for_delete, |
|
774 | - $model, |
|
775 | - $version |
|
776 | - ); |
|
777 | - } |
|
778 | - |
|
779 | - |
|
780 | - /** |
|
781 | - * @param EEM_Base $source_model |
|
782 | - * @param EEM_Base $related_model |
|
783 | - * @param $version |
|
784 | - * @return array |
|
785 | - * @throws EE_Error |
|
786 | - * @since $VID:$ |
|
787 | - */ |
|
788 | - protected function _get_add_relation_query_params(EEM_Base $source_model, EEM_Base $related_model, $version) |
|
789 | - { |
|
790 | - // if they're related through a HABTM relation, check for any non-FKs |
|
791 | - $all_relation_settings = $source_model->relation_settings(); |
|
792 | - $relation_settings = $all_relation_settings[ $related_model->get_this_model_name() ]; |
|
793 | - $params = []; |
|
794 | - if ($relation_settings instanceof EE_HABTM_Relation && $relation_settings->hasNonKeyFields()) { |
|
795 | - foreach ($relation_settings->getNonKeyFields() as $field) { |
|
796 | - /* @var $field EE_Model_Field_Base */ |
|
797 | - $params[ $field->get_name() ] = [ |
|
798 | - 'required' => ! $field->is_nullable(), |
|
799 | - 'default' => ModelDataTranslator::prepareFieldValueForJson($field, |
|
800 | - $field->get_default_value(), $version), |
|
801 | - 'type' => $field->getSchemaType(), |
|
802 | - 'validate_callback' => null, |
|
803 | - 'sanitize_callback' => null, |
|
804 | - ]; |
|
805 | - } |
|
806 | - } |
|
807 | - return $params; |
|
808 | - } |
|
809 | - |
|
810 | - |
|
811 | - /** |
|
812 | - * Gets info about reading query params that are acceptable |
|
813 | - * |
|
814 | - * @param EEM_Base $model eg 'Event' or 'Venue' |
|
815 | - * @param string $version |
|
816 | - * @return array describing the args acceptable when querying this model |
|
817 | - * @throws EE_Error |
|
818 | - */ |
|
819 | - protected function _get_read_query_params(EEM_Base $model, $version) |
|
820 | - { |
|
821 | - $default_orderby = []; |
|
822 | - foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
823 | - $default_orderby[ $key_field->get_name() ] = 'ASC'; |
|
824 | - } |
|
825 | - return array_merge( |
|
826 | - $this->_get_response_selection_query_params($model, $version), |
|
827 | - [ |
|
828 | - 'where' => [ |
|
829 | - 'required' => false, |
|
830 | - 'default' => [], |
|
831 | - 'type' => 'object', |
|
832 | - // because we accept an almost infinite list of possible where conditions, WP |
|
833 | - // core validation and sanitization freaks out. We'll just validate this argument |
|
834 | - // while handling the request |
|
835 | - 'validate_callback' => null, |
|
836 | - 'sanitize_callback' => null, |
|
837 | - ], |
|
838 | - 'limit' => [ |
|
839 | - 'required' => false, |
|
840 | - 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
841 | - 'type' => [ |
|
842 | - 'array', |
|
843 | - 'string', |
|
844 | - 'integer', |
|
845 | - ], |
|
846 | - // because we accept a variety of types, WP core validation and sanitization |
|
847 | - // freaks out. We'll just validate this argument while handling the request |
|
848 | - 'validate_callback' => null, |
|
849 | - 'sanitize_callback' => null, |
|
850 | - ], |
|
851 | - 'order_by' => [ |
|
852 | - 'required' => false, |
|
853 | - 'default' => $default_orderby, |
|
854 | - 'type' => [ |
|
855 | - 'object', |
|
856 | - 'string', |
|
857 | - ],// because we accept a variety of types, WP core validation and sanitization |
|
858 | - // freaks out. We'll just validate this argument while handling the request |
|
859 | - 'validate_callback' => null, |
|
860 | - 'sanitize_callback' => null, |
|
861 | - ], |
|
862 | - 'group_by' => [ |
|
863 | - 'required' => false, |
|
864 | - 'default' => null, |
|
865 | - 'type' => [ |
|
866 | - 'object', |
|
867 | - 'string', |
|
868 | - ], |
|
869 | - // because we accept an almost infinite list of possible groupings, |
|
870 | - // WP core validation and sanitization |
|
871 | - // freaks out. We'll just validate this argument while handling the request |
|
872 | - 'validate_callback' => null, |
|
873 | - 'sanitize_callback' => null, |
|
874 | - ], |
|
875 | - 'having' => [ |
|
876 | - 'required' => false, |
|
877 | - 'default' => null, |
|
878 | - 'type' => 'object', |
|
879 | - // because we accept an almost infinite list of possible where conditions, WP |
|
880 | - // core validation and sanitization freaks out. We'll just validate this argument |
|
881 | - // while handling the request |
|
882 | - 'validate_callback' => null, |
|
883 | - 'sanitize_callback' => null, |
|
884 | - ], |
|
885 | - 'caps' => [ |
|
886 | - 'required' => false, |
|
887 | - 'default' => EEM_Base::caps_read, |
|
888 | - 'type' => 'string', |
|
889 | - 'enum' => [ |
|
890 | - EEM_Base::caps_read, |
|
891 | - EEM_Base::caps_read_admin, |
|
892 | - EEM_Base::caps_edit, |
|
893 | - EEM_Base::caps_delete, |
|
894 | - ], |
|
895 | - ], |
|
896 | - ] |
|
897 | - ); |
|
898 | - } |
|
899 | - |
|
900 | - |
|
901 | - /** |
|
902 | - * Gets parameter information for a model regarding writing data |
|
903 | - * |
|
904 | - * @param string $model_name |
|
905 | - * @param ModelVersionInfo $model_version_info |
|
906 | - * @param boolean $create whether this is for request to create (in |
|
907 | - * which case we need all required params) or |
|
908 | - * just to update (in which case we don't |
|
909 | - * need those on every request) |
|
910 | - * @return array |
|
911 | - * @throws EE_Error |
|
912 | - * @throws ReflectionException |
|
913 | - */ |
|
914 | - protected function _get_write_params( |
|
915 | - $model_name, |
|
916 | - ModelVersionInfo $model_version_info, |
|
917 | - $create = false |
|
918 | - ) { |
|
919 | - $model = EE_Registry::instance()->load_model($model_name); |
|
920 | - $fields = $model_version_info->fieldsOnModelInThisVersion($model); |
|
921 | - |
|
922 | - // we do our own validation and sanitization within the controller |
|
923 | - $sanitize_callback = function_exists('rest_validate_value_from_schema') |
|
924 | - ? ['EED_Core_Rest_Api', 'default_sanitize_callback'] |
|
925 | - : null; |
|
926 | - $args_info = []; |
|
927 | - foreach ($fields as $field_name => $field_obj) { |
|
928 | - if ($field_obj->is_auto_increment()) { |
|
929 | - // totally ignore auto increment IDs |
|
930 | - continue; |
|
931 | - } |
|
932 | - $arg_info = $field_obj->getSchema(); |
|
933 | - $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null; |
|
934 | - $arg_info['required'] = $required; |
|
935 | - // remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right? |
|
936 | - unset($arg_info['readonly']); |
|
937 | - $schema_properties = $field_obj->getSchemaProperties(); |
|
938 | - if (isset($schema_properties['raw']) |
|
939 | - && $field_obj->getSchemaType() === 'object' |
|
940 | - ) { |
|
941 | - // if there's a "raw" form of this argument, use those properties instead |
|
942 | - $arg_info = array_replace( |
|
943 | - $arg_info, |
|
944 | - $schema_properties['raw'] |
|
945 | - ); |
|
946 | - } |
|
947 | - $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson( |
|
948 | - $field_obj, |
|
949 | - $field_obj->get_default_value(), |
|
950 | - $model_version_info->requestedVersion() |
|
951 | - ); |
|
952 | - $arg_info['sanitize_callback'] = $sanitize_callback; |
|
953 | - $args_info[ $field_name ] = $arg_info; |
|
954 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
955 | - $gmt_arg_info = $arg_info; |
|
956 | - $gmt_arg_info['description'] = sprintf( |
|
957 | - esc_html__( |
|
958 | - '%1$s - the value for this field in UTC. Ignored if %2$s is provided.', |
|
959 | - 'event_espresso' |
|
960 | - ), |
|
961 | - $field_obj->get_nicename(), |
|
962 | - $field_name |
|
963 | - ); |
|
964 | - $args_info[ $field_name . '_gmt' ] = $gmt_arg_info; |
|
965 | - } |
|
966 | - } |
|
967 | - return $args_info; |
|
968 | - } |
|
969 | - |
|
970 | - |
|
971 | - /** |
|
972 | - * Replacement for WP API's 'rest_parse_request_arg'. |
|
973 | - * If the value is blank but not required, don't bother validating it. |
|
974 | - * Also, it uses our email validation instead of WP API's default. |
|
975 | - * |
|
976 | - * @param $value |
|
977 | - * @param WP_REST_Request $request |
|
978 | - * @param $param |
|
979 | - * @return bool|true|WP_Error |
|
980 | - * @throws InvalidArgumentException |
|
981 | - * @throws InvalidInterfaceException |
|
982 | - * @throws InvalidDataTypeException |
|
983 | - */ |
|
984 | - public static function default_sanitize_callback($value, WP_REST_Request $request, $param) |
|
985 | - { |
|
986 | - $attributes = $request->get_attributes(); |
|
987 | - if (! isset($attributes['args'][ $param ]) |
|
988 | - || ! is_array($attributes['args'][ $param ])) { |
|
989 | - $validation_result = true; |
|
990 | - } else { |
|
991 | - $args = $attributes['args'][ $param ]; |
|
992 | - if (( |
|
993 | - $value === '' |
|
994 | - || $value === null |
|
995 | - ) |
|
996 | - && (! isset($args['required']) |
|
997 | - || $args['required'] === false |
|
998 | - ) |
|
999 | - ) { |
|
1000 | - // not required and not provided? that's cool |
|
1001 | - $validation_result = true; |
|
1002 | - } elseif (isset($args['format']) |
|
1003 | - && $args['format'] === 'email' |
|
1004 | - ) { |
|
1005 | - $validation_result = true; |
|
1006 | - if (! EED_Core_Rest_Api::_validate_email($value)) { |
|
1007 | - $validation_result = new WP_Error( |
|
1008 | - 'rest_invalid_param', |
|
1009 | - esc_html__( |
|
1010 | - 'The email address is not valid or does not exist.', |
|
1011 | - 'event_espresso' |
|
1012 | - ) |
|
1013 | - ); |
|
1014 | - } |
|
1015 | - } else { |
|
1016 | - $validation_result = rest_validate_value_from_schema($value, $args, $param); |
|
1017 | - } |
|
1018 | - } |
|
1019 | - if (is_wp_error($validation_result)) { |
|
1020 | - return $validation_result; |
|
1021 | - } |
|
1022 | - return rest_sanitize_request_arg($value, $request, $param); |
|
1023 | - } |
|
1024 | - |
|
1025 | - |
|
1026 | - /** |
|
1027 | - * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email() |
|
1028 | - * |
|
1029 | - * @param $email |
|
1030 | - * @return bool |
|
1031 | - * @throws InvalidArgumentException |
|
1032 | - * @throws InvalidInterfaceException |
|
1033 | - * @throws InvalidDataTypeException |
|
1034 | - */ |
|
1035 | - protected static function _validate_email($email) |
|
1036 | - { |
|
1037 | - try { |
|
1038 | - EmailAddressFactory::create($email); |
|
1039 | - return true; |
|
1040 | - } catch (EmailValidationException $e) { |
|
1041 | - return false; |
|
1042 | - } |
|
1043 | - } |
|
1044 | - |
|
1045 | - |
|
1046 | - /** |
|
1047 | - * Gets routes for the config |
|
1048 | - * |
|
1049 | - * @return array @see _register_model_routes |
|
1050 | - * @deprecated since version 4.9.1 |
|
1051 | - */ |
|
1052 | - protected function _register_config_routes() |
|
1053 | - { |
|
1054 | - $config_routes = []; |
|
1055 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
|
1056 | - $config_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version( |
|
1057 | - $version, |
|
1058 | - $hidden_endpoint |
|
1059 | - ); |
|
1060 | - } |
|
1061 | - return $config_routes; |
|
1062 | - } |
|
1063 | - |
|
1064 | - |
|
1065 | - /** |
|
1066 | - * Gets routes for the config for the specified version |
|
1067 | - * |
|
1068 | - * @param string $version |
|
1069 | - * @param boolean $hidden_endpoint |
|
1070 | - * @return array |
|
1071 | - */ |
|
1072 | - protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
1073 | - { |
|
1074 | - return [ |
|
1075 | - 'config' => [ |
|
1076 | - [ |
|
1077 | - 'callback' => [ |
|
1078 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
1079 | - 'handleRequest', |
|
1080 | - ], |
|
1081 | - 'methods' => WP_REST_Server::READABLE, |
|
1082 | - 'hidden_endpoint' => $hidden_endpoint, |
|
1083 | - 'callback_args' => [$version], |
|
1084 | - ], |
|
1085 | - ], |
|
1086 | - 'site_info' => [ |
|
1087 | - [ |
|
1088 | - 'callback' => [ |
|
1089 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
1090 | - 'handleRequestSiteInfo', |
|
1091 | - ], |
|
1092 | - 'methods' => WP_REST_Server::READABLE, |
|
1093 | - 'hidden_endpoint' => $hidden_endpoint, |
|
1094 | - 'callback_args' => [$version], |
|
1095 | - ], |
|
1096 | - ], |
|
1097 | - ]; |
|
1098 | - } |
|
1099 | - |
|
1100 | - |
|
1101 | - /** |
|
1102 | - * Gets the meta info routes |
|
1103 | - * |
|
1104 | - * @return array @see _register_model_routes |
|
1105 | - * @deprecated since version 4.9.1 |
|
1106 | - */ |
|
1107 | - protected function _register_meta_routes() |
|
1108 | - { |
|
1109 | - $meta_routes = []; |
|
1110 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
|
1111 | - $meta_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version( |
|
1112 | - $version, |
|
1113 | - $hidden_endpoint |
|
1114 | - ); |
|
1115 | - } |
|
1116 | - return $meta_routes; |
|
1117 | - } |
|
1118 | - |
|
1119 | - |
|
1120 | - /** |
|
1121 | - * @param string $version |
|
1122 | - * @param boolean $hidden_endpoint |
|
1123 | - * @return array |
|
1124 | - */ |
|
1125 | - protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
1126 | - { |
|
1127 | - return [ |
|
1128 | - 'resources' => [ |
|
1129 | - [ |
|
1130 | - 'callback' => [ |
|
1131 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
1132 | - 'handleRequestModelsMeta', |
|
1133 | - ], |
|
1134 | - 'methods' => WP_REST_Server::READABLE, |
|
1135 | - 'hidden_endpoint' => $hidden_endpoint, |
|
1136 | - 'callback_args' => [$version], |
|
1137 | - ], |
|
1138 | - ], |
|
1139 | - ]; |
|
1140 | - } |
|
1141 | - |
|
1142 | - |
|
1143 | - /** |
|
1144 | - * Tries to hide old 4.6 endpoints from the |
|
1145 | - * |
|
1146 | - * @param array $route_data |
|
1147 | - * @return array |
|
1148 | - * @throws EE_Error |
|
1149 | - * @throws ReflectionException |
|
1150 | - */ |
|
1151 | - public static function hide_old_endpoints($route_data) |
|
1152 | - { |
|
1153 | - // allow API clients to override which endpoints get hidden, in case |
|
1154 | - // they want to discover particular endpoints |
|
1155 | - // also, we don't have access to the request so we have to just grab it from the superglobal |
|
1156 | - $force_show_ee_namespace = ltrim( |
|
1157 | - EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''), |
|
1158 | - '/' |
|
1159 | - ); |
|
1160 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
1161 | - foreach ($relative_urls as $resource_name => $endpoints) { |
|
1162 | - foreach ($endpoints as $key => $endpoint) { |
|
1163 | - // skip schema and other route options |
|
1164 | - if (! is_numeric($key)) { |
|
1165 | - continue; |
|
1166 | - } |
|
1167 | - // by default, hide "hidden_endpoint"s, unless the request indicates |
|
1168 | - // to $force_show_ee_namespace, in which case only show that one |
|
1169 | - // namespace's endpoints (and hide all others) |
|
1170 | - if (($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
1171 | - || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
1172 | - ) { |
|
1173 | - $full_route = '/' . ltrim($namespace, '/'); |
|
1174 | - $full_route .= '/' . ltrim($resource_name, '/'); |
|
1175 | - unset($route_data[ $full_route ]); |
|
1176 | - } |
|
1177 | - } |
|
1178 | - } |
|
1179 | - } |
|
1180 | - return $route_data; |
|
1181 | - } |
|
1182 | - |
|
1183 | - |
|
1184 | - /** |
|
1185 | - * Returns an array describing which versions of core support serving requests for. |
|
1186 | - * Keys are core versions' major and minor version, and values are the |
|
1187 | - * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
1188 | - * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
1189 | - * the answers table entirely, in which case it would be very difficult for |
|
1190 | - * it to serve 4.6-style responses. |
|
1191 | - * Versions of core that are missing from this array are unknowns. |
|
1192 | - * previous ver |
|
1193 | - * |
|
1194 | - * @return array |
|
1195 | - */ |
|
1196 | - public static function version_compatibilities() |
|
1197 | - { |
|
1198 | - return apply_filters( |
|
1199 | - 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
1200 | - [ |
|
1201 | - '4.8.29' => '4.8.29', |
|
1202 | - '4.8.33' => '4.8.29', |
|
1203 | - '4.8.34' => '4.8.29', |
|
1204 | - '4.8.36' => '4.8.29', |
|
1205 | - ] |
|
1206 | - ); |
|
1207 | - } |
|
1208 | - |
|
1209 | - |
|
1210 | - /** |
|
1211 | - * Gets the latest API version served. Eg if there |
|
1212 | - * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
1213 | - * we are on core version 4.8.34, it will return the string "4.8.32" |
|
1214 | - * |
|
1215 | - * @return string |
|
1216 | - */ |
|
1217 | - public static function latest_rest_api_version() |
|
1218 | - { |
|
1219 | - $versions_served = EED_Core_Rest_Api::versions_served(); |
|
1220 | - $versions_served_keys = array_keys($versions_served); |
|
1221 | - return end($versions_served_keys); |
|
1222 | - } |
|
1223 | - |
|
1224 | - |
|
1225 | - /** |
|
1226 | - * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
1227 | - * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
1228 | - * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
1229 | - * We also indicate whether or not this version should be put in the index or not |
|
1230 | - * |
|
1231 | - * @return array keys are API version numbers (just major and minor numbers), and values |
|
1232 | - * are whether or not they should be hidden |
|
1233 | - */ |
|
1234 | - public static function versions_served() |
|
1235 | - { |
|
1236 | - $versions_served = []; |
|
1237 | - $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
1238 | - $lowest_compatible_version = end($possibly_served_versions); |
|
1239 | - reset($possibly_served_versions); |
|
1240 | - $versions_served_historically = array_keys($possibly_served_versions); |
|
1241 | - $latest_version = end($versions_served_historically); |
|
1242 | - reset($versions_served_historically); |
|
1243 | - // for each version of core we have ever served: |
|
1244 | - foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
1245 | - // if it's not above the current core version, and it's compatible with the current version of core |
|
1246 | - |
|
1247 | - if ($key_versioned_endpoint === $latest_version) { |
|
1248 | - // don't hide the latest version in the index |
|
1249 | - $versions_served[ $key_versioned_endpoint ] = false; |
|
1250 | - } elseif (version_compare($key_versioned_endpoint, $lowest_compatible_version, '>=') |
|
1251 | - && version_compare($key_versioned_endpoint, EED_Core_Rest_Api::core_version(), '<') |
|
1252 | - ) { |
|
1253 | - // include, but hide, previous versions which are still supported |
|
1254 | - $versions_served[ $key_versioned_endpoint ] = true; |
|
1255 | - } elseif (apply_filters( |
|
1256 | - 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
1257 | - false, |
|
1258 | - $possibly_served_versions |
|
1259 | - )) { |
|
1260 | - // if a version is no longer supported, don't include it in index or list of versions served |
|
1261 | - $versions_served[ $key_versioned_endpoint ] = true; |
|
1262 | - } |
|
1263 | - } |
|
1264 | - return $versions_served; |
|
1265 | - } |
|
1266 | - |
|
1267 | - |
|
1268 | - /** |
|
1269 | - * Gets the major and minor version of EE core's version string |
|
1270 | - * |
|
1271 | - * @return string |
|
1272 | - */ |
|
1273 | - public static function core_version() |
|
1274 | - { |
|
1275 | - return apply_filters( |
|
1276 | - 'FHEE__EED_Core_REST_API__core_version', |
|
1277 | - implode( |
|
1278 | - '.', |
|
1279 | - array_slice( |
|
1280 | - explode( |
|
1281 | - '.', |
|
1282 | - espresso_version() |
|
1283 | - ), |
|
1284 | - 0, |
|
1285 | - 3 |
|
1286 | - ) |
|
1287 | - ) |
|
1288 | - ); |
|
1289 | - } |
|
1290 | - |
|
1291 | - |
|
1292 | - /** |
|
1293 | - * Gets the default limit that should be used when querying for resources |
|
1294 | - * |
|
1295 | - * @return int |
|
1296 | - */ |
|
1297 | - public static function get_default_query_limit() |
|
1298 | - { |
|
1299 | - // we actually don't use a const because we want folks to always use |
|
1300 | - // this method, not the const directly |
|
1301 | - return apply_filters( |
|
1302 | - 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
1303 | - 50 |
|
1304 | - ); |
|
1305 | - } |
|
1306 | - |
|
1307 | - |
|
1308 | - /** |
|
1309 | - * @param string $version api version string (i.e. '4.8.36') |
|
1310 | - * @return array |
|
1311 | - */ |
|
1312 | - public static function getCollectionRoutesIndexedByModelName($version = '') |
|
1313 | - { |
|
1314 | - $version = empty($version) ? EED_Core_Rest_Api::latest_rest_api_version() : $version; |
|
1315 | - $model_names = EED_Core_Rest_Api::model_names_with_plural_routes($version); |
|
1316 | - $collection_routes = []; |
|
1317 | - foreach ($model_names as $model_name => $model_class_name) { |
|
1318 | - $collection_routes[ strtolower($model_name) ] = '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' |
|
1319 | - . EEH_Inflector::pluralize_and_lower($model_name); |
|
1320 | - } |
|
1321 | - return $collection_routes; |
|
1322 | - } |
|
1323 | - |
|
1324 | - |
|
1325 | - /** |
|
1326 | - * Returns an array of primary key names indexed by model names. |
|
1327 | - * |
|
1328 | - * @param string $version |
|
1329 | - * @return array |
|
1330 | - */ |
|
1331 | - public static function getPrimaryKeyNamesIndexedByModelName($version = '') |
|
1332 | - { |
|
1333 | - $version = empty($version) ? EED_Core_Rest_Api::latest_rest_api_version() : $version; |
|
1334 | - $model_names = EED_Core_Rest_Api::model_names_with_plural_routes($version); |
|
1335 | - $primary_key_items = []; |
|
1336 | - foreach ($model_names as $model_name => $model_class_name) { |
|
1337 | - $primary_keys = $model_class_name::instance()->get_combined_primary_key_fields(); |
|
1338 | - foreach ($primary_keys as $primary_key_name => $primary_key_field) { |
|
1339 | - if (count($primary_keys) > 1) { |
|
1340 | - $primary_key_items[ strtolower($model_name) ][] = $primary_key_name; |
|
1341 | - } else { |
|
1342 | - $primary_key_items[ strtolower($model_name) ] = $primary_key_name; |
|
1343 | - } |
|
1344 | - } |
|
1345 | - } |
|
1346 | - return $primary_key_items; |
|
1347 | - } |
|
1348 | - |
|
1349 | - |
|
1350 | - /** |
|
1351 | - * Determines the EE REST API debug mode is activated, or not. |
|
1352 | - * |
|
1353 | - * @return bool |
|
1354 | - * @since 4.9.76.p |
|
1355 | - */ |
|
1356 | - public static function debugMode() |
|
1357 | - { |
|
1358 | - static $debug_mode = null; // could be class prop |
|
1359 | - if ($debug_mode === null) { |
|
1360 | - $debug_mode = defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE; |
|
1361 | - } |
|
1362 | - return $debug_mode; |
|
1363 | - } |
|
1364 | - |
|
1365 | - |
|
1366 | - /** |
|
1367 | - * run - initial module setup |
|
1368 | - * |
|
1369 | - * @access public |
|
1370 | - * @param WP $WP |
|
1371 | - * @return void |
|
1372 | - */ |
|
1373 | - public function run($WP) |
|
1374 | - { |
|
1375 | - } |
|
25 | + const ee_api_namespace = Domain::API_NAMESPACE; |
|
26 | + |
|
27 | + const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
28 | + |
|
29 | + const saved_routes_option_names = 'ee_core_routes'; |
|
30 | + |
|
31 | + /** |
|
32 | + * string used in _links response bodies to make them globally unique. |
|
33 | + * |
|
34 | + * @see http://v2.wp-api.org/extending/linking/ |
|
35 | + */ |
|
36 | + const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var CalculatedModelFields |
|
40 | + */ |
|
41 | + protected static $_field_calculator; |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @return EED_Core_Rest_Api|EED_Module |
|
46 | + */ |
|
47 | + public static function instance() |
|
48 | + { |
|
49 | + return parent::get_instance(EED_Core_Rest_Api::class); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
55 | + * |
|
56 | + * @access public |
|
57 | + * @return void |
|
58 | + */ |
|
59 | + public static function set_hooks() |
|
60 | + { |
|
61 | + EED_Core_Rest_Api::set_hooks_both(); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
67 | + * |
|
68 | + * @access public |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + public static function set_hooks_admin() |
|
72 | + { |
|
73 | + EED_Core_Rest_Api::set_hooks_both(); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + public static function set_hooks_both() |
|
78 | + { |
|
79 | + /** @var EventEspresso\core\services\request\Request $request */ |
|
80 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
81 | + if (! $request->isWordPressApi()) { |
|
82 | + return; |
|
83 | + } |
|
84 | + add_action('rest_api_init', ['EED_Core_Rest_Api', 'register_routes'], 10); |
|
85 | + add_action('rest_api_init', ['EED_Core_Rest_Api', 'set_hooks_rest_api'], 5); |
|
86 | + add_filter('rest_route_data', ['EED_Core_Rest_Api', 'hide_old_endpoints'], 10, 2); |
|
87 | + add_filter( |
|
88 | + 'rest_index', |
|
89 | + ['EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex'] |
|
90 | + ); |
|
91 | + EED_Core_Rest_Api::$_field_calculator = LoaderFactory::getLoader()->load( |
|
92 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' |
|
93 | + ); |
|
94 | + EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * sets up hooks which only need to be included as part of REST API requests; |
|
100 | + * other requests like to the frontend or admin etc don't need them |
|
101 | + * |
|
102 | + * @throws EE_Error |
|
103 | + */ |
|
104 | + public static function set_hooks_rest_api() |
|
105 | + { |
|
106 | + // set hooks which account for changes made to the API |
|
107 | + EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * public wrapper of _set_hooks_for_changes. |
|
113 | + * Loads all the hooks which make requests to old versions of the API |
|
114 | + * appear the same as they always did |
|
115 | + * |
|
116 | + * @throws EE_Error |
|
117 | + */ |
|
118 | + public static function set_hooks_for_changes() |
|
119 | + { |
|
120 | + EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * Loads all the hooks which make requests to old versions of the API |
|
126 | + * appear the same as they always did |
|
127 | + * |
|
128 | + * @throws EE_Error |
|
129 | + */ |
|
130 | + protected static function _set_hooks_for_changes() |
|
131 | + { |
|
132 | + $folder_contents = EEH_File::get_contents_of_folders([EE_LIBRARIES . 'rest_api/changes'], false); |
|
133 | + foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
134 | + // ignore the base parent class |
|
135 | + // and legacy named classes |
|
136 | + if ($classname_in_namespace === 'ChangesInBase' |
|
137 | + || strpos($classname_in_namespace, 'Changes_In_') === 0 |
|
138 | + ) { |
|
139 | + continue; |
|
140 | + } |
|
141 | + $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
142 | + if (class_exists($full_classname)) { |
|
143 | + $instance_of_class = new $full_classname; |
|
144 | + if ($instance_of_class instanceof ChangesInBase) { |
|
145 | + $instance_of_class->setHooks(); |
|
146 | + } |
|
147 | + } |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
154 | + * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
155 | + * |
|
156 | + * @throws EE_Error |
|
157 | + * @throws ReflectionException |
|
158 | + */ |
|
159 | + public static function register_routes() |
|
160 | + { |
|
161 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) { |
|
162 | + foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) { |
|
163 | + /** |
|
164 | + * @var array $data_for_multiple_endpoints numerically indexed array |
|
165 | + * but can also contain route options like { |
|
166 | + * @type array $schema { |
|
167 | + * @type callable $schema_callback |
|
168 | + * @type array $callback_args arguments that will be passed to the callback, after the |
|
169 | + * WP_REST_Request of course |
|
170 | + * } |
|
171 | + * } |
|
172 | + */ |
|
173 | + // when registering routes, register all the endpoints' data at the same time |
|
174 | + $multiple_endpoint_args = []; |
|
175 | + foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) { |
|
176 | + /** |
|
177 | + * @var array $data_for_single_endpoint { |
|
178 | + * @type callable $callback |
|
179 | + * @type string methods |
|
180 | + * @type array args |
|
181 | + * @type array _links |
|
182 | + * @type array $callback_args arguments that will be passed to the callback, after the |
|
183 | + * WP_REST_Request of course |
|
184 | + * } |
|
185 | + */ |
|
186 | + // skip route options |
|
187 | + if (! is_numeric($endpoint_key)) { |
|
188 | + continue; |
|
189 | + } |
|
190 | + if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
191 | + throw new EE_Error( |
|
192 | + esc_html__( |
|
193 | + // @codingStandardsIgnoreStart |
|
194 | + 'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).', |
|
195 | + // @codingStandardsIgnoreEnd |
|
196 | + 'event_espresso' |
|
197 | + ) |
|
198 | + ); |
|
199 | + } |
|
200 | + $callback = $data_for_single_endpoint['callback']; |
|
201 | + $single_endpoint_args = [ |
|
202 | + 'methods' => $data_for_single_endpoint['methods'], |
|
203 | + 'args' => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args'] |
|
204 | + : [], |
|
205 | + ]; |
|
206 | + if (isset($data_for_single_endpoint['_links'])) { |
|
207 | + $single_endpoint_args['_links'] = $data_for_single_endpoint['_links']; |
|
208 | + } |
|
209 | + if (isset($data_for_single_endpoint['callback_args'])) { |
|
210 | + $callback_args = $data_for_single_endpoint['callback_args']; |
|
211 | + $single_endpoint_args['callback'] = static function (WP_REST_Request $request) use ( |
|
212 | + $callback, |
|
213 | + $callback_args |
|
214 | + ) { |
|
215 | + array_unshift($callback_args, $request); |
|
216 | + return call_user_func_array( |
|
217 | + $callback, |
|
218 | + $callback_args |
|
219 | + ); |
|
220 | + }; |
|
221 | + } else { |
|
222 | + $single_endpoint_args['callback'] = $data_for_single_endpoint['callback']; |
|
223 | + } |
|
224 | + $multiple_endpoint_args[] = $single_endpoint_args; |
|
225 | + } |
|
226 | + if (isset($data_for_multiple_endpoints['schema'])) { |
|
227 | + $schema_route_data = $data_for_multiple_endpoints['schema']; |
|
228 | + $schema_callback = $schema_route_data['schema_callback']; |
|
229 | + $callback_args = $schema_route_data['callback_args']; |
|
230 | + $multiple_endpoint_args['schema'] = static function () use ($schema_callback, $callback_args) { |
|
231 | + return call_user_func_array( |
|
232 | + $schema_callback, |
|
233 | + $callback_args |
|
234 | + ); |
|
235 | + }; |
|
236 | + } |
|
237 | + register_rest_route( |
|
238 | + $namespace, |
|
239 | + $relative_route, |
|
240 | + $multiple_endpoint_args |
|
241 | + ); |
|
242 | + } |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Checks if there was a version change or something that merits invalidating the cached |
|
249 | + * route data. If so, invalidates the cached route data so that it gets refreshed |
|
250 | + * next time the WP API is used |
|
251 | + */ |
|
252 | + public static function invalidate_cached_route_data_on_version_change() |
|
253 | + { |
|
254 | + if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) { |
|
255 | + EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
256 | + } |
|
257 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
258 | + if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) { |
|
259 | + EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
260 | + } |
|
261 | + } |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * Removes the cached route data so it will get refreshed next time the WP API is used |
|
267 | + */ |
|
268 | + public static function invalidate_cached_route_data() |
|
269 | + { |
|
270 | + // delete the saved EE REST API routes |
|
271 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
|
272 | + delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * Gets the EE route data |
|
279 | + * |
|
280 | + * @return array top-level key is the namespace, next-level key is the route and its value is array{ |
|
281 | + * @throws EE_Error |
|
282 | + * @throws ReflectionException |
|
283 | + * @type string|array $callback |
|
284 | + * @type string $methods |
|
285 | + * @type boolean $hidden_endpoint |
|
286 | + * } |
|
287 | + */ |
|
288 | + public static function get_ee_route_data() |
|
289 | + { |
|
290 | + $ee_routes = []; |
|
291 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoints) { |
|
292 | + $ee_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = EED_Core_Rest_Api::_get_ee_route_data_for_version( |
|
293 | + $version, |
|
294 | + $hidden_endpoints |
|
295 | + ); |
|
296 | + } |
|
297 | + return $ee_routes; |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Gets the EE route data from the wp options if it exists already, |
|
303 | + * otherwise re-generates it and saves it to the option |
|
304 | + * |
|
305 | + * @param string $version |
|
306 | + * @param boolean $hidden_endpoints |
|
307 | + * @return array |
|
308 | + * @throws EE_Error |
|
309 | + * @throws ReflectionException |
|
310 | + */ |
|
311 | + protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
312 | + { |
|
313 | + $ee_routes = get_option(EED_Core_Rest_Api::saved_routes_option_names . $version, null); |
|
314 | + if (! $ee_routes || EED_Core_Rest_Api::debugMode()) { |
|
315 | + $ee_routes = EED_Core_Rest_Api::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
316 | + } |
|
317 | + return $ee_routes; |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * Saves the EE REST API route data to a wp option and returns it |
|
323 | + * |
|
324 | + * @param string $version |
|
325 | + * @param boolean $hidden_endpoints |
|
326 | + * @return mixed|null |
|
327 | + * @throws EE_Error |
|
328 | + * @throws ReflectionException |
|
329 | + */ |
|
330 | + protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
331 | + { |
|
332 | + $instance = EED_Core_Rest_Api::instance(); |
|
333 | + $routes = apply_filters( |
|
334 | + 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
335 | + array_replace_recursive( |
|
336 | + $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
337 | + $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
338 | + $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
339 | + $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
340 | + ) |
|
341 | + ); |
|
342 | + $option_name = EED_Core_Rest_Api::saved_routes_option_names . $version; |
|
343 | + if (get_option($option_name)) { |
|
344 | + update_option($option_name, $routes, true); |
|
345 | + } else { |
|
346 | + add_option($option_name, $routes, null, 'no'); |
|
347 | + } |
|
348 | + return $routes; |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * Calculates all the EE routes and saves it to a WordPress option so we don't |
|
354 | + * need to calculate it on every request |
|
355 | + * |
|
356 | + * @return void |
|
357 | + * @deprecated since version 4.9.1 |
|
358 | + */ |
|
359 | + public static function save_ee_routes() |
|
360 | + { |
|
361 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
362 | + $instance = EED_Core_Rest_Api::instance(); |
|
363 | + $routes = apply_filters( |
|
364 | + 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
365 | + array_replace_recursive( |
|
366 | + $instance->_register_config_routes(), |
|
367 | + $instance->_register_meta_routes(), |
|
368 | + $instance->_register_model_routes(), |
|
369 | + $instance->_register_rpc_routes() |
|
370 | + ) |
|
371 | + ); |
|
372 | + update_option(EED_Core_Rest_Api::saved_routes_option_names, $routes, true); |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Gets all the route information relating to EE models |
|
379 | + * |
|
380 | + * @return array @see get_ee_route_data |
|
381 | + * @deprecated since version 4.9.1 |
|
382 | + */ |
|
383 | + protected function _register_model_routes() |
|
384 | + { |
|
385 | + $model_routes = []; |
|
386 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
|
387 | + $model_routes[ EED_Core_Rest_Api::ee_api_namespace |
|
388 | + . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
389 | + } |
|
390 | + return $model_routes; |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * Decides whether or not to add write endpoints for this model. |
|
396 | + * Currently, this defaults to exclude all global tables and models |
|
397 | + * which would allow inserting WP core data (we don't want to duplicate |
|
398 | + * what WP API does, as it's unnecessary, extra work, and potentially extra bugs) |
|
399 | + * |
|
400 | + * @param EEM_Base $model |
|
401 | + * @return bool |
|
402 | + */ |
|
403 | + public static function should_have_write_endpoints(EEM_Base $model) |
|
404 | + { |
|
405 | + if ($model->is_wp_core_model()) { |
|
406 | + return false; |
|
407 | + } |
|
408 | + foreach ($model->get_tables() as $table) { |
|
409 | + if ($table->is_global()) { |
|
410 | + return false; |
|
411 | + } |
|
412 | + } |
|
413 | + return true; |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`) |
|
419 | + * in this versioned namespace of EE4 |
|
420 | + * |
|
421 | + * @param $version |
|
422 | + * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event') |
|
423 | + */ |
|
424 | + public static function model_names_with_plural_routes($version) |
|
425 | + { |
|
426 | + $model_version_info = new ModelVersionInfo($version); |
|
427 | + $models_to_register = $model_version_info->modelsForRequestedVersion(); |
|
428 | + // let's not bother having endpoints for extra metas |
|
429 | + unset( |
|
430 | + $models_to_register['Extra_Meta'], |
|
431 | + $models_to_register['Extra_Join'], |
|
432 | + $models_to_register['Post_Meta'] |
|
433 | + ); |
|
434 | + return apply_filters( |
|
435 | + 'FHEE__EED_Core_REST_API___register_model_routes', |
|
436 | + $models_to_register |
|
437 | + ); |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * Gets the route data for EE models in the specified version |
|
443 | + * |
|
444 | + * @param string $version |
|
445 | + * @param boolean $hidden_endpoint |
|
446 | + * @return array |
|
447 | + * @throws EE_Error |
|
448 | + * @throws ReflectionException |
|
449 | + */ |
|
450 | + protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
451 | + { |
|
452 | + $model_routes = []; |
|
453 | + $model_version_info = new ModelVersionInfo($version); |
|
454 | + foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
|
455 | + $model = EE_Registry::instance()->load_model($model_name); |
|
456 | + // if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
457 | + if (! $model instanceof EEM_Base) { |
|
458 | + continue; |
|
459 | + } |
|
460 | + // yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
461 | + $plural_model_route = EED_Core_Rest_Api::get_collection_route($model); |
|
462 | + $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)'); |
|
463 | + $model_routes[ $plural_model_route ] = [ |
|
464 | + [ |
|
465 | + 'callback' => [ |
|
466 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
467 | + 'handleRequestGetAll', |
|
468 | + ], |
|
469 | + 'callback_args' => [$version, $model_name], |
|
470 | + 'methods' => WP_REST_Server::READABLE, |
|
471 | + 'hidden_endpoint' => $hidden_endpoint, |
|
472 | + 'args' => $this->_get_read_query_params($model, $version), |
|
473 | + '_links' => [ |
|
474 | + 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
475 | + ], |
|
476 | + ], |
|
477 | + 'schema' => [ |
|
478 | + 'schema_callback' => [ |
|
479 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
480 | + 'handleSchemaRequest', |
|
481 | + ], |
|
482 | + 'callback_args' => [$version, $model_name], |
|
483 | + ], |
|
484 | + ]; |
|
485 | + $model_routes[ $singular_model_route ] = [ |
|
486 | + [ |
|
487 | + 'callback' => [ |
|
488 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
489 | + 'handleRequestGetOne', |
|
490 | + ], |
|
491 | + 'callback_args' => [$version, $model_name], |
|
492 | + 'methods' => WP_REST_Server::READABLE, |
|
493 | + 'hidden_endpoint' => $hidden_endpoint, |
|
494 | + 'args' => $this->_get_response_selection_query_params($model, $version, true), |
|
495 | + ], |
|
496 | + ]; |
|
497 | + if (apply_filters( |
|
498 | + 'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints', |
|
499 | + EED_Core_Rest_Api::should_have_write_endpoints($model), |
|
500 | + $model |
|
501 | + )) { |
|
502 | + $model_routes[ $plural_model_route ][] = [ |
|
503 | + 'callback' => [ |
|
504 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
505 | + 'handleRequestInsert', |
|
506 | + ], |
|
507 | + 'callback_args' => [$version, $model_name], |
|
508 | + 'methods' => WP_REST_Server::CREATABLE, |
|
509 | + 'hidden_endpoint' => $hidden_endpoint, |
|
510 | + 'args' => $this->_get_write_params($model_name, $model_version_info, true), |
|
511 | + ]; |
|
512 | + $model_routes[ $singular_model_route ] = array_merge( |
|
513 | + $model_routes[ $singular_model_route ], |
|
514 | + [ |
|
515 | + [ |
|
516 | + 'callback' => [ |
|
517 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
518 | + 'handleRequestUpdate', |
|
519 | + ], |
|
520 | + 'callback_args' => [$version, $model_name], |
|
521 | + 'methods' => WP_REST_Server::EDITABLE, |
|
522 | + 'hidden_endpoint' => $hidden_endpoint, |
|
523 | + 'args' => $this->_get_write_params($model_name, $model_version_info), |
|
524 | + ], |
|
525 | + [ |
|
526 | + 'callback' => [ |
|
527 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
528 | + 'handleRequestDelete', |
|
529 | + ], |
|
530 | + 'callback_args' => [$version, $model_name], |
|
531 | + 'methods' => WP_REST_Server::DELETABLE, |
|
532 | + 'hidden_endpoint' => $hidden_endpoint, |
|
533 | + 'args' => $this->_get_delete_query_params($model, $version), |
|
534 | + ], |
|
535 | + ] |
|
536 | + ); |
|
537 | + } |
|
538 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
539 | + $related_route = EED_Core_Rest_Api::get_relation_route_via( |
|
540 | + $model, |
|
541 | + '(?P<id>[^\/]+)', |
|
542 | + $relation_obj |
|
543 | + ); |
|
544 | + $model_routes[ $related_route ] = [ |
|
545 | + [ |
|
546 | + 'callback' => [ |
|
547 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
548 | + 'handleRequestGetRelated', |
|
549 | + ], |
|
550 | + 'callback_args' => [$version, $model_name, $relation_name], |
|
551 | + 'methods' => WP_REST_Server::READABLE, |
|
552 | + 'hidden_endpoint' => $hidden_endpoint, |
|
553 | + 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
554 | + ], |
|
555 | + ]; |
|
556 | + |
|
557 | + $related_write_route = $related_route . '/' . '(?P<related_id>[^\/]+)'; |
|
558 | + $model_routes[ $related_write_route ] = [ |
|
559 | + [ |
|
560 | + 'callback' => [ |
|
561 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
562 | + 'handleRequestAddRelation', |
|
563 | + ], |
|
564 | + 'callback_args' => [$version, $model_name, $relation_name], |
|
565 | + 'methods' => WP_REST_Server::EDITABLE, |
|
566 | + 'hidden_endpoint' => $hidden_endpoint, |
|
567 | + 'args' => $this->_get_add_relation_query_params($model, |
|
568 | + $relation_obj->get_other_model(), $version), |
|
569 | + ], |
|
570 | + [ |
|
571 | + 'callback' => [ |
|
572 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
573 | + 'handleRequestRemoveRelation', |
|
574 | + ], |
|
575 | + 'callback_args' => [$version, $model_name, $relation_name], |
|
576 | + 'methods' => WP_REST_Server::DELETABLE, |
|
577 | + 'hidden_endpoint' => $hidden_endpoint, |
|
578 | + 'args' => [], |
|
579 | + ], |
|
580 | + ]; |
|
581 | + } |
|
582 | + } |
|
583 | + return $model_routes; |
|
584 | + } |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace, |
|
589 | + * excluding the preceding slash. |
|
590 | + * Eg you pass get_plural_route_to('Event') = 'events' |
|
591 | + * |
|
592 | + * @param EEM_Base $model |
|
593 | + * @return string |
|
594 | + */ |
|
595 | + public static function get_collection_route(EEM_Base $model) |
|
596 | + { |
|
597 | + return EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + /** |
|
602 | + * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
603 | + * excluding the preceding slash. |
|
604 | + * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
605 | + * |
|
606 | + * @param EEM_Base $model eg Event or Venue |
|
607 | + * @param string $id |
|
608 | + * @return string |
|
609 | + */ |
|
610 | + public static function get_entity_route($model, $id) |
|
611 | + { |
|
612 | + return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id; |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
618 | + * excluding the preceding slash. |
|
619 | + * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
620 | + * |
|
621 | + * @param EEM_Base $model eg Event or Venue |
|
622 | + * @param string $id |
|
623 | + * @param EE_Model_Relation_Base $relation_obj |
|
624 | + * @return string |
|
625 | + */ |
|
626 | + public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj) |
|
627 | + { |
|
628 | + $related_model_name_endpoint_part = ModelRead::getRelatedEntityName( |
|
629 | + $relation_obj->get_other_model()->get_this_model_name(), |
|
630 | + $relation_obj |
|
631 | + ); |
|
632 | + return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
633 | + } |
|
634 | + |
|
635 | + |
|
636 | + /** |
|
637 | + * Adds onto the $relative_route the EE4 REST API versioned namespace. |
|
638 | + * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events' |
|
639 | + * |
|
640 | + * @param string $relative_route |
|
641 | + * @param string $version |
|
642 | + * @return string |
|
643 | + */ |
|
644 | + public static function get_versioned_route_to($relative_route, $version = '4.8.36') |
|
645 | + { |
|
646 | + return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
647 | + } |
|
648 | + |
|
649 | + |
|
650 | + /** |
|
651 | + * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
652 | + * routes that don't conform to the traditional REST CRUD-style). |
|
653 | + * |
|
654 | + * @deprecated since 4.9.1 |
|
655 | + */ |
|
656 | + protected function _register_rpc_routes() |
|
657 | + { |
|
658 | + $routes = []; |
|
659 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
|
660 | + $routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version( |
|
661 | + $version, |
|
662 | + $hidden_endpoint |
|
663 | + ); |
|
664 | + } |
|
665 | + return $routes; |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + /** |
|
670 | + * @param string $version |
|
671 | + * @param boolean $hidden_endpoint |
|
672 | + * @return array |
|
673 | + */ |
|
674 | + protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
675 | + { |
|
676 | + $this_versions_routes = []; |
|
677 | + // checkin endpoint |
|
678 | + $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = [ |
|
679 | + [ |
|
680 | + 'callback' => [ |
|
681 | + 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
682 | + 'handleRequestToggleCheckin', |
|
683 | + ], |
|
684 | + 'methods' => WP_REST_Server::CREATABLE, |
|
685 | + 'hidden_endpoint' => $hidden_endpoint, |
|
686 | + 'args' => [ |
|
687 | + 'force' => [ |
|
688 | + 'required' => false, |
|
689 | + 'default' => false, |
|
690 | + 'description' => __( |
|
691 | + // @codingStandardsIgnoreStart |
|
692 | + 'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
693 | + // @codingStandardsIgnoreEnd |
|
694 | + 'event_espresso' |
|
695 | + ), |
|
696 | + ], |
|
697 | + ], |
|
698 | + 'callback_args' => [$version], |
|
699 | + ], |
|
700 | + ]; |
|
701 | + return apply_filters( |
|
702 | + 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
703 | + $this_versions_routes, |
|
704 | + $version, |
|
705 | + $hidden_endpoint |
|
706 | + ); |
|
707 | + } |
|
708 | + |
|
709 | + |
|
710 | + /** |
|
711 | + * Gets the query params that can be used when request one or many |
|
712 | + * |
|
713 | + * @param EEM_Base $model |
|
714 | + * @param string $version |
|
715 | + * @return array |
|
716 | + */ |
|
717 | + protected function _get_response_selection_query_params(EEM_Base $model, $version, $single_only = false) |
|
718 | + { |
|
719 | + $query_params = [ |
|
720 | + 'include' => [ |
|
721 | + 'required' => false, |
|
722 | + 'default' => '*', |
|
723 | + 'type' => 'string', |
|
724 | + ], |
|
725 | + 'calculate' => [ |
|
726 | + 'required' => false, |
|
727 | + 'default' => '', |
|
728 | + 'enum' => EED_Core_Rest_Api::$_field_calculator->retrieveCalculatedFieldsForModel($model), |
|
729 | + 'type' => 'string', |
|
730 | + // because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization |
|
731 | + // freaks out. We'll just validate this argument while handling the request |
|
732 | + 'validate_callback' => null, |
|
733 | + 'sanitize_callback' => null, |
|
734 | + ], |
|
735 | + 'password' => [ |
|
736 | + 'required' => false, |
|
737 | + 'default' => '', |
|
738 | + 'type' => 'string', |
|
739 | + ], |
|
740 | + ]; |
|
741 | + return apply_filters( |
|
742 | + 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
743 | + $query_params, |
|
744 | + $model, |
|
745 | + $version |
|
746 | + ); |
|
747 | + } |
|
748 | + |
|
749 | + |
|
750 | + /** |
|
751 | + * Gets the parameters acceptable for delete requests |
|
752 | + * |
|
753 | + * @param EEM_Base $model |
|
754 | + * @param string $version |
|
755 | + * @return array |
|
756 | + */ |
|
757 | + protected function _get_delete_query_params(EEM_Base $model, $version) |
|
758 | + { |
|
759 | + $params_for_delete = [ |
|
760 | + 'allow_blocking' => [ |
|
761 | + 'required' => false, |
|
762 | + 'default' => true, |
|
763 | + 'type' => 'boolean', |
|
764 | + ], |
|
765 | + ]; |
|
766 | + $params_for_delete['force'] = [ |
|
767 | + 'required' => false, |
|
768 | + 'default' => false, |
|
769 | + 'type' => 'boolean', |
|
770 | + ]; |
|
771 | + return apply_filters( |
|
772 | + 'FHEE__EED_Core_Rest_Api___get_delete_query_params', |
|
773 | + $params_for_delete, |
|
774 | + $model, |
|
775 | + $version |
|
776 | + ); |
|
777 | + } |
|
778 | + |
|
779 | + |
|
780 | + /** |
|
781 | + * @param EEM_Base $source_model |
|
782 | + * @param EEM_Base $related_model |
|
783 | + * @param $version |
|
784 | + * @return array |
|
785 | + * @throws EE_Error |
|
786 | + * @since $VID:$ |
|
787 | + */ |
|
788 | + protected function _get_add_relation_query_params(EEM_Base $source_model, EEM_Base $related_model, $version) |
|
789 | + { |
|
790 | + // if they're related through a HABTM relation, check for any non-FKs |
|
791 | + $all_relation_settings = $source_model->relation_settings(); |
|
792 | + $relation_settings = $all_relation_settings[ $related_model->get_this_model_name() ]; |
|
793 | + $params = []; |
|
794 | + if ($relation_settings instanceof EE_HABTM_Relation && $relation_settings->hasNonKeyFields()) { |
|
795 | + foreach ($relation_settings->getNonKeyFields() as $field) { |
|
796 | + /* @var $field EE_Model_Field_Base */ |
|
797 | + $params[ $field->get_name() ] = [ |
|
798 | + 'required' => ! $field->is_nullable(), |
|
799 | + 'default' => ModelDataTranslator::prepareFieldValueForJson($field, |
|
800 | + $field->get_default_value(), $version), |
|
801 | + 'type' => $field->getSchemaType(), |
|
802 | + 'validate_callback' => null, |
|
803 | + 'sanitize_callback' => null, |
|
804 | + ]; |
|
805 | + } |
|
806 | + } |
|
807 | + return $params; |
|
808 | + } |
|
809 | + |
|
810 | + |
|
811 | + /** |
|
812 | + * Gets info about reading query params that are acceptable |
|
813 | + * |
|
814 | + * @param EEM_Base $model eg 'Event' or 'Venue' |
|
815 | + * @param string $version |
|
816 | + * @return array describing the args acceptable when querying this model |
|
817 | + * @throws EE_Error |
|
818 | + */ |
|
819 | + protected function _get_read_query_params(EEM_Base $model, $version) |
|
820 | + { |
|
821 | + $default_orderby = []; |
|
822 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
823 | + $default_orderby[ $key_field->get_name() ] = 'ASC'; |
|
824 | + } |
|
825 | + return array_merge( |
|
826 | + $this->_get_response_selection_query_params($model, $version), |
|
827 | + [ |
|
828 | + 'where' => [ |
|
829 | + 'required' => false, |
|
830 | + 'default' => [], |
|
831 | + 'type' => 'object', |
|
832 | + // because we accept an almost infinite list of possible where conditions, WP |
|
833 | + // core validation and sanitization freaks out. We'll just validate this argument |
|
834 | + // while handling the request |
|
835 | + 'validate_callback' => null, |
|
836 | + 'sanitize_callback' => null, |
|
837 | + ], |
|
838 | + 'limit' => [ |
|
839 | + 'required' => false, |
|
840 | + 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
841 | + 'type' => [ |
|
842 | + 'array', |
|
843 | + 'string', |
|
844 | + 'integer', |
|
845 | + ], |
|
846 | + // because we accept a variety of types, WP core validation and sanitization |
|
847 | + // freaks out. We'll just validate this argument while handling the request |
|
848 | + 'validate_callback' => null, |
|
849 | + 'sanitize_callback' => null, |
|
850 | + ], |
|
851 | + 'order_by' => [ |
|
852 | + 'required' => false, |
|
853 | + 'default' => $default_orderby, |
|
854 | + 'type' => [ |
|
855 | + 'object', |
|
856 | + 'string', |
|
857 | + ],// because we accept a variety of types, WP core validation and sanitization |
|
858 | + // freaks out. We'll just validate this argument while handling the request |
|
859 | + 'validate_callback' => null, |
|
860 | + 'sanitize_callback' => null, |
|
861 | + ], |
|
862 | + 'group_by' => [ |
|
863 | + 'required' => false, |
|
864 | + 'default' => null, |
|
865 | + 'type' => [ |
|
866 | + 'object', |
|
867 | + 'string', |
|
868 | + ], |
|
869 | + // because we accept an almost infinite list of possible groupings, |
|
870 | + // WP core validation and sanitization |
|
871 | + // freaks out. We'll just validate this argument while handling the request |
|
872 | + 'validate_callback' => null, |
|
873 | + 'sanitize_callback' => null, |
|
874 | + ], |
|
875 | + 'having' => [ |
|
876 | + 'required' => false, |
|
877 | + 'default' => null, |
|
878 | + 'type' => 'object', |
|
879 | + // because we accept an almost infinite list of possible where conditions, WP |
|
880 | + // core validation and sanitization freaks out. We'll just validate this argument |
|
881 | + // while handling the request |
|
882 | + 'validate_callback' => null, |
|
883 | + 'sanitize_callback' => null, |
|
884 | + ], |
|
885 | + 'caps' => [ |
|
886 | + 'required' => false, |
|
887 | + 'default' => EEM_Base::caps_read, |
|
888 | + 'type' => 'string', |
|
889 | + 'enum' => [ |
|
890 | + EEM_Base::caps_read, |
|
891 | + EEM_Base::caps_read_admin, |
|
892 | + EEM_Base::caps_edit, |
|
893 | + EEM_Base::caps_delete, |
|
894 | + ], |
|
895 | + ], |
|
896 | + ] |
|
897 | + ); |
|
898 | + } |
|
899 | + |
|
900 | + |
|
901 | + /** |
|
902 | + * Gets parameter information for a model regarding writing data |
|
903 | + * |
|
904 | + * @param string $model_name |
|
905 | + * @param ModelVersionInfo $model_version_info |
|
906 | + * @param boolean $create whether this is for request to create (in |
|
907 | + * which case we need all required params) or |
|
908 | + * just to update (in which case we don't |
|
909 | + * need those on every request) |
|
910 | + * @return array |
|
911 | + * @throws EE_Error |
|
912 | + * @throws ReflectionException |
|
913 | + */ |
|
914 | + protected function _get_write_params( |
|
915 | + $model_name, |
|
916 | + ModelVersionInfo $model_version_info, |
|
917 | + $create = false |
|
918 | + ) { |
|
919 | + $model = EE_Registry::instance()->load_model($model_name); |
|
920 | + $fields = $model_version_info->fieldsOnModelInThisVersion($model); |
|
921 | + |
|
922 | + // we do our own validation and sanitization within the controller |
|
923 | + $sanitize_callback = function_exists('rest_validate_value_from_schema') |
|
924 | + ? ['EED_Core_Rest_Api', 'default_sanitize_callback'] |
|
925 | + : null; |
|
926 | + $args_info = []; |
|
927 | + foreach ($fields as $field_name => $field_obj) { |
|
928 | + if ($field_obj->is_auto_increment()) { |
|
929 | + // totally ignore auto increment IDs |
|
930 | + continue; |
|
931 | + } |
|
932 | + $arg_info = $field_obj->getSchema(); |
|
933 | + $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null; |
|
934 | + $arg_info['required'] = $required; |
|
935 | + // remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right? |
|
936 | + unset($arg_info['readonly']); |
|
937 | + $schema_properties = $field_obj->getSchemaProperties(); |
|
938 | + if (isset($schema_properties['raw']) |
|
939 | + && $field_obj->getSchemaType() === 'object' |
|
940 | + ) { |
|
941 | + // if there's a "raw" form of this argument, use those properties instead |
|
942 | + $arg_info = array_replace( |
|
943 | + $arg_info, |
|
944 | + $schema_properties['raw'] |
|
945 | + ); |
|
946 | + } |
|
947 | + $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson( |
|
948 | + $field_obj, |
|
949 | + $field_obj->get_default_value(), |
|
950 | + $model_version_info->requestedVersion() |
|
951 | + ); |
|
952 | + $arg_info['sanitize_callback'] = $sanitize_callback; |
|
953 | + $args_info[ $field_name ] = $arg_info; |
|
954 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
955 | + $gmt_arg_info = $arg_info; |
|
956 | + $gmt_arg_info['description'] = sprintf( |
|
957 | + esc_html__( |
|
958 | + '%1$s - the value for this field in UTC. Ignored if %2$s is provided.', |
|
959 | + 'event_espresso' |
|
960 | + ), |
|
961 | + $field_obj->get_nicename(), |
|
962 | + $field_name |
|
963 | + ); |
|
964 | + $args_info[ $field_name . '_gmt' ] = $gmt_arg_info; |
|
965 | + } |
|
966 | + } |
|
967 | + return $args_info; |
|
968 | + } |
|
969 | + |
|
970 | + |
|
971 | + /** |
|
972 | + * Replacement for WP API's 'rest_parse_request_arg'. |
|
973 | + * If the value is blank but not required, don't bother validating it. |
|
974 | + * Also, it uses our email validation instead of WP API's default. |
|
975 | + * |
|
976 | + * @param $value |
|
977 | + * @param WP_REST_Request $request |
|
978 | + * @param $param |
|
979 | + * @return bool|true|WP_Error |
|
980 | + * @throws InvalidArgumentException |
|
981 | + * @throws InvalidInterfaceException |
|
982 | + * @throws InvalidDataTypeException |
|
983 | + */ |
|
984 | + public static function default_sanitize_callback($value, WP_REST_Request $request, $param) |
|
985 | + { |
|
986 | + $attributes = $request->get_attributes(); |
|
987 | + if (! isset($attributes['args'][ $param ]) |
|
988 | + || ! is_array($attributes['args'][ $param ])) { |
|
989 | + $validation_result = true; |
|
990 | + } else { |
|
991 | + $args = $attributes['args'][ $param ]; |
|
992 | + if (( |
|
993 | + $value === '' |
|
994 | + || $value === null |
|
995 | + ) |
|
996 | + && (! isset($args['required']) |
|
997 | + || $args['required'] === false |
|
998 | + ) |
|
999 | + ) { |
|
1000 | + // not required and not provided? that's cool |
|
1001 | + $validation_result = true; |
|
1002 | + } elseif (isset($args['format']) |
|
1003 | + && $args['format'] === 'email' |
|
1004 | + ) { |
|
1005 | + $validation_result = true; |
|
1006 | + if (! EED_Core_Rest_Api::_validate_email($value)) { |
|
1007 | + $validation_result = new WP_Error( |
|
1008 | + 'rest_invalid_param', |
|
1009 | + esc_html__( |
|
1010 | + 'The email address is not valid or does not exist.', |
|
1011 | + 'event_espresso' |
|
1012 | + ) |
|
1013 | + ); |
|
1014 | + } |
|
1015 | + } else { |
|
1016 | + $validation_result = rest_validate_value_from_schema($value, $args, $param); |
|
1017 | + } |
|
1018 | + } |
|
1019 | + if (is_wp_error($validation_result)) { |
|
1020 | + return $validation_result; |
|
1021 | + } |
|
1022 | + return rest_sanitize_request_arg($value, $request, $param); |
|
1023 | + } |
|
1024 | + |
|
1025 | + |
|
1026 | + /** |
|
1027 | + * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email() |
|
1028 | + * |
|
1029 | + * @param $email |
|
1030 | + * @return bool |
|
1031 | + * @throws InvalidArgumentException |
|
1032 | + * @throws InvalidInterfaceException |
|
1033 | + * @throws InvalidDataTypeException |
|
1034 | + */ |
|
1035 | + protected static function _validate_email($email) |
|
1036 | + { |
|
1037 | + try { |
|
1038 | + EmailAddressFactory::create($email); |
|
1039 | + return true; |
|
1040 | + } catch (EmailValidationException $e) { |
|
1041 | + return false; |
|
1042 | + } |
|
1043 | + } |
|
1044 | + |
|
1045 | + |
|
1046 | + /** |
|
1047 | + * Gets routes for the config |
|
1048 | + * |
|
1049 | + * @return array @see _register_model_routes |
|
1050 | + * @deprecated since version 4.9.1 |
|
1051 | + */ |
|
1052 | + protected function _register_config_routes() |
|
1053 | + { |
|
1054 | + $config_routes = []; |
|
1055 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
|
1056 | + $config_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version( |
|
1057 | + $version, |
|
1058 | + $hidden_endpoint |
|
1059 | + ); |
|
1060 | + } |
|
1061 | + return $config_routes; |
|
1062 | + } |
|
1063 | + |
|
1064 | + |
|
1065 | + /** |
|
1066 | + * Gets routes for the config for the specified version |
|
1067 | + * |
|
1068 | + * @param string $version |
|
1069 | + * @param boolean $hidden_endpoint |
|
1070 | + * @return array |
|
1071 | + */ |
|
1072 | + protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
1073 | + { |
|
1074 | + return [ |
|
1075 | + 'config' => [ |
|
1076 | + [ |
|
1077 | + 'callback' => [ |
|
1078 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
1079 | + 'handleRequest', |
|
1080 | + ], |
|
1081 | + 'methods' => WP_REST_Server::READABLE, |
|
1082 | + 'hidden_endpoint' => $hidden_endpoint, |
|
1083 | + 'callback_args' => [$version], |
|
1084 | + ], |
|
1085 | + ], |
|
1086 | + 'site_info' => [ |
|
1087 | + [ |
|
1088 | + 'callback' => [ |
|
1089 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
1090 | + 'handleRequestSiteInfo', |
|
1091 | + ], |
|
1092 | + 'methods' => WP_REST_Server::READABLE, |
|
1093 | + 'hidden_endpoint' => $hidden_endpoint, |
|
1094 | + 'callback_args' => [$version], |
|
1095 | + ], |
|
1096 | + ], |
|
1097 | + ]; |
|
1098 | + } |
|
1099 | + |
|
1100 | + |
|
1101 | + /** |
|
1102 | + * Gets the meta info routes |
|
1103 | + * |
|
1104 | + * @return array @see _register_model_routes |
|
1105 | + * @deprecated since version 4.9.1 |
|
1106 | + */ |
|
1107 | + protected function _register_meta_routes() |
|
1108 | + { |
|
1109 | + $meta_routes = []; |
|
1110 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
|
1111 | + $meta_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version( |
|
1112 | + $version, |
|
1113 | + $hidden_endpoint |
|
1114 | + ); |
|
1115 | + } |
|
1116 | + return $meta_routes; |
|
1117 | + } |
|
1118 | + |
|
1119 | + |
|
1120 | + /** |
|
1121 | + * @param string $version |
|
1122 | + * @param boolean $hidden_endpoint |
|
1123 | + * @return array |
|
1124 | + */ |
|
1125 | + protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
1126 | + { |
|
1127 | + return [ |
|
1128 | + 'resources' => [ |
|
1129 | + [ |
|
1130 | + 'callback' => [ |
|
1131 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
1132 | + 'handleRequestModelsMeta', |
|
1133 | + ], |
|
1134 | + 'methods' => WP_REST_Server::READABLE, |
|
1135 | + 'hidden_endpoint' => $hidden_endpoint, |
|
1136 | + 'callback_args' => [$version], |
|
1137 | + ], |
|
1138 | + ], |
|
1139 | + ]; |
|
1140 | + } |
|
1141 | + |
|
1142 | + |
|
1143 | + /** |
|
1144 | + * Tries to hide old 4.6 endpoints from the |
|
1145 | + * |
|
1146 | + * @param array $route_data |
|
1147 | + * @return array |
|
1148 | + * @throws EE_Error |
|
1149 | + * @throws ReflectionException |
|
1150 | + */ |
|
1151 | + public static function hide_old_endpoints($route_data) |
|
1152 | + { |
|
1153 | + // allow API clients to override which endpoints get hidden, in case |
|
1154 | + // they want to discover particular endpoints |
|
1155 | + // also, we don't have access to the request so we have to just grab it from the superglobal |
|
1156 | + $force_show_ee_namespace = ltrim( |
|
1157 | + EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''), |
|
1158 | + '/' |
|
1159 | + ); |
|
1160 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
1161 | + foreach ($relative_urls as $resource_name => $endpoints) { |
|
1162 | + foreach ($endpoints as $key => $endpoint) { |
|
1163 | + // skip schema and other route options |
|
1164 | + if (! is_numeric($key)) { |
|
1165 | + continue; |
|
1166 | + } |
|
1167 | + // by default, hide "hidden_endpoint"s, unless the request indicates |
|
1168 | + // to $force_show_ee_namespace, in which case only show that one |
|
1169 | + // namespace's endpoints (and hide all others) |
|
1170 | + if (($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
1171 | + || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
1172 | + ) { |
|
1173 | + $full_route = '/' . ltrim($namespace, '/'); |
|
1174 | + $full_route .= '/' . ltrim($resource_name, '/'); |
|
1175 | + unset($route_data[ $full_route ]); |
|
1176 | + } |
|
1177 | + } |
|
1178 | + } |
|
1179 | + } |
|
1180 | + return $route_data; |
|
1181 | + } |
|
1182 | + |
|
1183 | + |
|
1184 | + /** |
|
1185 | + * Returns an array describing which versions of core support serving requests for. |
|
1186 | + * Keys are core versions' major and minor version, and values are the |
|
1187 | + * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
1188 | + * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
1189 | + * the answers table entirely, in which case it would be very difficult for |
|
1190 | + * it to serve 4.6-style responses. |
|
1191 | + * Versions of core that are missing from this array are unknowns. |
|
1192 | + * previous ver |
|
1193 | + * |
|
1194 | + * @return array |
|
1195 | + */ |
|
1196 | + public static function version_compatibilities() |
|
1197 | + { |
|
1198 | + return apply_filters( |
|
1199 | + 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
1200 | + [ |
|
1201 | + '4.8.29' => '4.8.29', |
|
1202 | + '4.8.33' => '4.8.29', |
|
1203 | + '4.8.34' => '4.8.29', |
|
1204 | + '4.8.36' => '4.8.29', |
|
1205 | + ] |
|
1206 | + ); |
|
1207 | + } |
|
1208 | + |
|
1209 | + |
|
1210 | + /** |
|
1211 | + * Gets the latest API version served. Eg if there |
|
1212 | + * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
1213 | + * we are on core version 4.8.34, it will return the string "4.8.32" |
|
1214 | + * |
|
1215 | + * @return string |
|
1216 | + */ |
|
1217 | + public static function latest_rest_api_version() |
|
1218 | + { |
|
1219 | + $versions_served = EED_Core_Rest_Api::versions_served(); |
|
1220 | + $versions_served_keys = array_keys($versions_served); |
|
1221 | + return end($versions_served_keys); |
|
1222 | + } |
|
1223 | + |
|
1224 | + |
|
1225 | + /** |
|
1226 | + * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
1227 | + * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
1228 | + * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
1229 | + * We also indicate whether or not this version should be put in the index or not |
|
1230 | + * |
|
1231 | + * @return array keys are API version numbers (just major and minor numbers), and values |
|
1232 | + * are whether or not they should be hidden |
|
1233 | + */ |
|
1234 | + public static function versions_served() |
|
1235 | + { |
|
1236 | + $versions_served = []; |
|
1237 | + $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
1238 | + $lowest_compatible_version = end($possibly_served_versions); |
|
1239 | + reset($possibly_served_versions); |
|
1240 | + $versions_served_historically = array_keys($possibly_served_versions); |
|
1241 | + $latest_version = end($versions_served_historically); |
|
1242 | + reset($versions_served_historically); |
|
1243 | + // for each version of core we have ever served: |
|
1244 | + foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
1245 | + // if it's not above the current core version, and it's compatible with the current version of core |
|
1246 | + |
|
1247 | + if ($key_versioned_endpoint === $latest_version) { |
|
1248 | + // don't hide the latest version in the index |
|
1249 | + $versions_served[ $key_versioned_endpoint ] = false; |
|
1250 | + } elseif (version_compare($key_versioned_endpoint, $lowest_compatible_version, '>=') |
|
1251 | + && version_compare($key_versioned_endpoint, EED_Core_Rest_Api::core_version(), '<') |
|
1252 | + ) { |
|
1253 | + // include, but hide, previous versions which are still supported |
|
1254 | + $versions_served[ $key_versioned_endpoint ] = true; |
|
1255 | + } elseif (apply_filters( |
|
1256 | + 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
1257 | + false, |
|
1258 | + $possibly_served_versions |
|
1259 | + )) { |
|
1260 | + // if a version is no longer supported, don't include it in index or list of versions served |
|
1261 | + $versions_served[ $key_versioned_endpoint ] = true; |
|
1262 | + } |
|
1263 | + } |
|
1264 | + return $versions_served; |
|
1265 | + } |
|
1266 | + |
|
1267 | + |
|
1268 | + /** |
|
1269 | + * Gets the major and minor version of EE core's version string |
|
1270 | + * |
|
1271 | + * @return string |
|
1272 | + */ |
|
1273 | + public static function core_version() |
|
1274 | + { |
|
1275 | + return apply_filters( |
|
1276 | + 'FHEE__EED_Core_REST_API__core_version', |
|
1277 | + implode( |
|
1278 | + '.', |
|
1279 | + array_slice( |
|
1280 | + explode( |
|
1281 | + '.', |
|
1282 | + espresso_version() |
|
1283 | + ), |
|
1284 | + 0, |
|
1285 | + 3 |
|
1286 | + ) |
|
1287 | + ) |
|
1288 | + ); |
|
1289 | + } |
|
1290 | + |
|
1291 | + |
|
1292 | + /** |
|
1293 | + * Gets the default limit that should be used when querying for resources |
|
1294 | + * |
|
1295 | + * @return int |
|
1296 | + */ |
|
1297 | + public static function get_default_query_limit() |
|
1298 | + { |
|
1299 | + // we actually don't use a const because we want folks to always use |
|
1300 | + // this method, not the const directly |
|
1301 | + return apply_filters( |
|
1302 | + 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
1303 | + 50 |
|
1304 | + ); |
|
1305 | + } |
|
1306 | + |
|
1307 | + |
|
1308 | + /** |
|
1309 | + * @param string $version api version string (i.e. '4.8.36') |
|
1310 | + * @return array |
|
1311 | + */ |
|
1312 | + public static function getCollectionRoutesIndexedByModelName($version = '') |
|
1313 | + { |
|
1314 | + $version = empty($version) ? EED_Core_Rest_Api::latest_rest_api_version() : $version; |
|
1315 | + $model_names = EED_Core_Rest_Api::model_names_with_plural_routes($version); |
|
1316 | + $collection_routes = []; |
|
1317 | + foreach ($model_names as $model_name => $model_class_name) { |
|
1318 | + $collection_routes[ strtolower($model_name) ] = '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' |
|
1319 | + . EEH_Inflector::pluralize_and_lower($model_name); |
|
1320 | + } |
|
1321 | + return $collection_routes; |
|
1322 | + } |
|
1323 | + |
|
1324 | + |
|
1325 | + /** |
|
1326 | + * Returns an array of primary key names indexed by model names. |
|
1327 | + * |
|
1328 | + * @param string $version |
|
1329 | + * @return array |
|
1330 | + */ |
|
1331 | + public static function getPrimaryKeyNamesIndexedByModelName($version = '') |
|
1332 | + { |
|
1333 | + $version = empty($version) ? EED_Core_Rest_Api::latest_rest_api_version() : $version; |
|
1334 | + $model_names = EED_Core_Rest_Api::model_names_with_plural_routes($version); |
|
1335 | + $primary_key_items = []; |
|
1336 | + foreach ($model_names as $model_name => $model_class_name) { |
|
1337 | + $primary_keys = $model_class_name::instance()->get_combined_primary_key_fields(); |
|
1338 | + foreach ($primary_keys as $primary_key_name => $primary_key_field) { |
|
1339 | + if (count($primary_keys) > 1) { |
|
1340 | + $primary_key_items[ strtolower($model_name) ][] = $primary_key_name; |
|
1341 | + } else { |
|
1342 | + $primary_key_items[ strtolower($model_name) ] = $primary_key_name; |
|
1343 | + } |
|
1344 | + } |
|
1345 | + } |
|
1346 | + return $primary_key_items; |
|
1347 | + } |
|
1348 | + |
|
1349 | + |
|
1350 | + /** |
|
1351 | + * Determines the EE REST API debug mode is activated, or not. |
|
1352 | + * |
|
1353 | + * @return bool |
|
1354 | + * @since 4.9.76.p |
|
1355 | + */ |
|
1356 | + public static function debugMode() |
|
1357 | + { |
|
1358 | + static $debug_mode = null; // could be class prop |
|
1359 | + if ($debug_mode === null) { |
|
1360 | + $debug_mode = defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE; |
|
1361 | + } |
|
1362 | + return $debug_mode; |
|
1363 | + } |
|
1364 | + |
|
1365 | + |
|
1366 | + /** |
|
1367 | + * run - initial module setup |
|
1368 | + * |
|
1369 | + * @access public |
|
1370 | + * @param WP $WP |
|
1371 | + * @return void |
|
1372 | + */ |
|
1373 | + public function run($WP) |
|
1374 | + { |
|
1375 | + } |
|
1376 | 1376 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | { |
79 | 79 | /** @var EventEspresso\core\services\request\Request $request */ |
80 | 80 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
81 | - if (! $request->isWordPressApi()) { |
|
81 | + if ( ! $request->isWordPressApi()) { |
|
82 | 82 | return; |
83 | 83 | } |
84 | 84 | add_action('rest_api_init', ['EED_Core_Rest_Api', 'register_routes'], 10); |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | */ |
130 | 130 | protected static function _set_hooks_for_changes() |
131 | 131 | { |
132 | - $folder_contents = EEH_File::get_contents_of_folders([EE_LIBRARIES . 'rest_api/changes'], false); |
|
132 | + $folder_contents = EEH_File::get_contents_of_folders([EE_LIBRARIES.'rest_api/changes'], false); |
|
133 | 133 | foreach ($folder_contents as $classname_in_namespace => $filepath) { |
134 | 134 | // ignore the base parent class |
135 | 135 | // and legacy named classes |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | ) { |
139 | 139 | continue; |
140 | 140 | } |
141 | - $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
141 | + $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\'.$classname_in_namespace; |
|
142 | 142 | if (class_exists($full_classname)) { |
143 | 143 | $instance_of_class = new $full_classname; |
144 | 144 | if ($instance_of_class instanceof ChangesInBase) { |
@@ -184,10 +184,10 @@ discard block |
||
184 | 184 | * } |
185 | 185 | */ |
186 | 186 | // skip route options |
187 | - if (! is_numeric($endpoint_key)) { |
|
187 | + if ( ! is_numeric($endpoint_key)) { |
|
188 | 188 | continue; |
189 | 189 | } |
190 | - if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
190 | + if ( ! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
191 | 191 | throw new EE_Error( |
192 | 192 | esc_html__( |
193 | 193 | // @codingStandardsIgnoreStart |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | } |
209 | 209 | if (isset($data_for_single_endpoint['callback_args'])) { |
210 | 210 | $callback_args = $data_for_single_endpoint['callback_args']; |
211 | - $single_endpoint_args['callback'] = static function (WP_REST_Request $request) use ( |
|
211 | + $single_endpoint_args['callback'] = static function(WP_REST_Request $request) use ( |
|
212 | 212 | $callback, |
213 | 213 | $callback_args |
214 | 214 | ) { |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | $schema_route_data = $data_for_multiple_endpoints['schema']; |
228 | 228 | $schema_callback = $schema_route_data['schema_callback']; |
229 | 229 | $callback_args = $schema_route_data['callback_args']; |
230 | - $multiple_endpoint_args['schema'] = static function () use ($schema_callback, $callback_args) { |
|
230 | + $multiple_endpoint_args['schema'] = static function() use ($schema_callback, $callback_args) { |
|
231 | 231 | return call_user_func_array( |
232 | 232 | $schema_callback, |
233 | 233 | $callback_args |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | { |
270 | 270 | // delete the saved EE REST API routes |
271 | 271 | foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
272 | - delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
272 | + delete_option(EED_Core_Rest_Api::saved_routes_option_names.$version); |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | { |
290 | 290 | $ee_routes = []; |
291 | 291 | foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoints) { |
292 | - $ee_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = EED_Core_Rest_Api::_get_ee_route_data_for_version( |
|
292 | + $ee_routes[EED_Core_Rest_Api::ee_api_namespace.$version] = EED_Core_Rest_Api::_get_ee_route_data_for_version( |
|
293 | 293 | $version, |
294 | 294 | $hidden_endpoints |
295 | 295 | ); |
@@ -310,8 +310,8 @@ discard block |
||
310 | 310 | */ |
311 | 311 | protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
312 | 312 | { |
313 | - $ee_routes = get_option(EED_Core_Rest_Api::saved_routes_option_names . $version, null); |
|
314 | - if (! $ee_routes || EED_Core_Rest_Api::debugMode()) { |
|
313 | + $ee_routes = get_option(EED_Core_Rest_Api::saved_routes_option_names.$version, null); |
|
314 | + if ( ! $ee_routes || EED_Core_Rest_Api::debugMode()) { |
|
315 | 315 | $ee_routes = EED_Core_Rest_Api::_save_ee_route_data_for_version($version, $hidden_endpoints); |
316 | 316 | } |
317 | 317 | return $ee_routes; |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
340 | 340 | ) |
341 | 341 | ); |
342 | - $option_name = EED_Core_Rest_Api::saved_routes_option_names . $version; |
|
342 | + $option_name = EED_Core_Rest_Api::saved_routes_option_names.$version; |
|
343 | 343 | if (get_option($option_name)) { |
344 | 344 | update_option($option_name, $routes, true); |
345 | 345 | } else { |
@@ -384,8 +384,8 @@ discard block |
||
384 | 384 | { |
385 | 385 | $model_routes = []; |
386 | 386 | foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
387 | - $model_routes[ EED_Core_Rest_Api::ee_api_namespace |
|
388 | - . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
387 | + $model_routes[EED_Core_Rest_Api::ee_api_namespace |
|
388 | + . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
389 | 389 | } |
390 | 390 | return $model_routes; |
391 | 391 | } |
@@ -454,13 +454,13 @@ discard block |
||
454 | 454 | foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
455 | 455 | $model = EE_Registry::instance()->load_model($model_name); |
456 | 456 | // if this isn't a valid model then let's skip iterate to the next item in the loop. |
457 | - if (! $model instanceof EEM_Base) { |
|
457 | + if ( ! $model instanceof EEM_Base) { |
|
458 | 458 | continue; |
459 | 459 | } |
460 | 460 | // yes we could just register one route for ALL models, but then they wouldn't show up in the index |
461 | 461 | $plural_model_route = EED_Core_Rest_Api::get_collection_route($model); |
462 | 462 | $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)'); |
463 | - $model_routes[ $plural_model_route ] = [ |
|
463 | + $model_routes[$plural_model_route] = [ |
|
464 | 464 | [ |
465 | 465 | 'callback' => [ |
466 | 466 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | 'hidden_endpoint' => $hidden_endpoint, |
472 | 472 | 'args' => $this->_get_read_query_params($model, $version), |
473 | 473 | '_links' => [ |
474 | - 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
474 | + 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace.$version.$singular_model_route), |
|
475 | 475 | ], |
476 | 476 | ], |
477 | 477 | 'schema' => [ |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | 'callback_args' => [$version, $model_name], |
483 | 483 | ], |
484 | 484 | ]; |
485 | - $model_routes[ $singular_model_route ] = [ |
|
485 | + $model_routes[$singular_model_route] = [ |
|
486 | 486 | [ |
487 | 487 | 'callback' => [ |
488 | 488 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | EED_Core_Rest_Api::should_have_write_endpoints($model), |
500 | 500 | $model |
501 | 501 | )) { |
502 | - $model_routes[ $plural_model_route ][] = [ |
|
502 | + $model_routes[$plural_model_route][] = [ |
|
503 | 503 | 'callback' => [ |
504 | 504 | 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
505 | 505 | 'handleRequestInsert', |
@@ -509,8 +509,8 @@ discard block |
||
509 | 509 | 'hidden_endpoint' => $hidden_endpoint, |
510 | 510 | 'args' => $this->_get_write_params($model_name, $model_version_info, true), |
511 | 511 | ]; |
512 | - $model_routes[ $singular_model_route ] = array_merge( |
|
513 | - $model_routes[ $singular_model_route ], |
|
512 | + $model_routes[$singular_model_route] = array_merge( |
|
513 | + $model_routes[$singular_model_route], |
|
514 | 514 | [ |
515 | 515 | [ |
516 | 516 | 'callback' => [ |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | '(?P<id>[^\/]+)', |
542 | 542 | $relation_obj |
543 | 543 | ); |
544 | - $model_routes[ $related_route ] = [ |
|
544 | + $model_routes[$related_route] = [ |
|
545 | 545 | [ |
546 | 546 | 'callback' => [ |
547 | 547 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
@@ -554,8 +554,8 @@ discard block |
||
554 | 554 | ], |
555 | 555 | ]; |
556 | 556 | |
557 | - $related_write_route = $related_route . '/' . '(?P<related_id>[^\/]+)'; |
|
558 | - $model_routes[ $related_write_route ] = [ |
|
557 | + $related_write_route = $related_route.'/'.'(?P<related_id>[^\/]+)'; |
|
558 | + $model_routes[$related_write_route] = [ |
|
559 | 559 | [ |
560 | 560 | 'callback' => [ |
561 | 561 | 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
@@ -609,7 +609,7 @@ discard block |
||
609 | 609 | */ |
610 | 610 | public static function get_entity_route($model, $id) |
611 | 611 | { |
612 | - return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id; |
|
612 | + return EED_Core_Rest_Api::get_collection_route($model).'/'.$id; |
|
613 | 613 | } |
614 | 614 | |
615 | 615 | |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | $relation_obj->get_other_model()->get_this_model_name(), |
630 | 630 | $relation_obj |
631 | 631 | ); |
632 | - return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
632 | + return EED_Core_Rest_Api::get_entity_route($model, $id).'/'.$related_model_name_endpoint_part; |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | */ |
644 | 644 | public static function get_versioned_route_to($relative_route, $version = '4.8.36') |
645 | 645 | { |
646 | - return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
646 | + return '/'.EED_Core_Rest_Api::ee_api_namespace.$version.'/'.$relative_route; |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | { |
658 | 658 | $routes = []; |
659 | 659 | foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
660 | - $routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version( |
|
660 | + $routes[EED_Core_Rest_Api::ee_api_namespace.$version] = $this->_get_rpc_route_data_for_version( |
|
661 | 661 | $version, |
662 | 662 | $hidden_endpoint |
663 | 663 | ); |
@@ -789,12 +789,12 @@ discard block |
||
789 | 789 | { |
790 | 790 | // if they're related through a HABTM relation, check for any non-FKs |
791 | 791 | $all_relation_settings = $source_model->relation_settings(); |
792 | - $relation_settings = $all_relation_settings[ $related_model->get_this_model_name() ]; |
|
792 | + $relation_settings = $all_relation_settings[$related_model->get_this_model_name()]; |
|
793 | 793 | $params = []; |
794 | 794 | if ($relation_settings instanceof EE_HABTM_Relation && $relation_settings->hasNonKeyFields()) { |
795 | 795 | foreach ($relation_settings->getNonKeyFields() as $field) { |
796 | 796 | /* @var $field EE_Model_Field_Base */ |
797 | - $params[ $field->get_name() ] = [ |
|
797 | + $params[$field->get_name()] = [ |
|
798 | 798 | 'required' => ! $field->is_nullable(), |
799 | 799 | 'default' => ModelDataTranslator::prepareFieldValueForJson($field, |
800 | 800 | $field->get_default_value(), $version), |
@@ -820,7 +820,7 @@ discard block |
||
820 | 820 | { |
821 | 821 | $default_orderby = []; |
822 | 822 | foreach ($model->get_combined_primary_key_fields() as $key_field) { |
823 | - $default_orderby[ $key_field->get_name() ] = 'ASC'; |
|
823 | + $default_orderby[$key_field->get_name()] = 'ASC'; |
|
824 | 824 | } |
825 | 825 | return array_merge( |
826 | 826 | $this->_get_response_selection_query_params($model, $version), |
@@ -854,7 +854,7 @@ discard block |
||
854 | 854 | 'type' => [ |
855 | 855 | 'object', |
856 | 856 | 'string', |
857 | - ],// because we accept a variety of types, WP core validation and sanitization |
|
857 | + ], // because we accept a variety of types, WP core validation and sanitization |
|
858 | 858 | // freaks out. We'll just validate this argument while handling the request |
859 | 859 | 'validate_callback' => null, |
860 | 860 | 'sanitize_callback' => null, |
@@ -950,7 +950,7 @@ discard block |
||
950 | 950 | $model_version_info->requestedVersion() |
951 | 951 | ); |
952 | 952 | $arg_info['sanitize_callback'] = $sanitize_callback; |
953 | - $args_info[ $field_name ] = $arg_info; |
|
953 | + $args_info[$field_name] = $arg_info; |
|
954 | 954 | if ($field_obj instanceof EE_Datetime_Field) { |
955 | 955 | $gmt_arg_info = $arg_info; |
956 | 956 | $gmt_arg_info['description'] = sprintf( |
@@ -961,7 +961,7 @@ discard block |
||
961 | 961 | $field_obj->get_nicename(), |
962 | 962 | $field_name |
963 | 963 | ); |
964 | - $args_info[ $field_name . '_gmt' ] = $gmt_arg_info; |
|
964 | + $args_info[$field_name.'_gmt'] = $gmt_arg_info; |
|
965 | 965 | } |
966 | 966 | } |
967 | 967 | return $args_info; |
@@ -984,16 +984,16 @@ discard block |
||
984 | 984 | public static function default_sanitize_callback($value, WP_REST_Request $request, $param) |
985 | 985 | { |
986 | 986 | $attributes = $request->get_attributes(); |
987 | - if (! isset($attributes['args'][ $param ]) |
|
988 | - || ! is_array($attributes['args'][ $param ])) { |
|
987 | + if ( ! isset($attributes['args'][$param]) |
|
988 | + || ! is_array($attributes['args'][$param])) { |
|
989 | 989 | $validation_result = true; |
990 | 990 | } else { |
991 | - $args = $attributes['args'][ $param ]; |
|
991 | + $args = $attributes['args'][$param]; |
|
992 | 992 | if (( |
993 | 993 | $value === '' |
994 | 994 | || $value === null |
995 | 995 | ) |
996 | - && (! isset($args['required']) |
|
996 | + && ( ! isset($args['required']) |
|
997 | 997 | || $args['required'] === false |
998 | 998 | ) |
999 | 999 | ) { |
@@ -1003,7 +1003,7 @@ discard block |
||
1003 | 1003 | && $args['format'] === 'email' |
1004 | 1004 | ) { |
1005 | 1005 | $validation_result = true; |
1006 | - if (! EED_Core_Rest_Api::_validate_email($value)) { |
|
1006 | + if ( ! EED_Core_Rest_Api::_validate_email($value)) { |
|
1007 | 1007 | $validation_result = new WP_Error( |
1008 | 1008 | 'rest_invalid_param', |
1009 | 1009 | esc_html__( |
@@ -1053,7 +1053,7 @@ discard block |
||
1053 | 1053 | { |
1054 | 1054 | $config_routes = []; |
1055 | 1055 | foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
1056 | - $config_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version( |
|
1056 | + $config_routes[EED_Core_Rest_Api::ee_api_namespace.$version] = $this->_get_config_route_data_for_version( |
|
1057 | 1057 | $version, |
1058 | 1058 | $hidden_endpoint |
1059 | 1059 | ); |
@@ -1108,7 +1108,7 @@ discard block |
||
1108 | 1108 | { |
1109 | 1109 | $meta_routes = []; |
1110 | 1110 | foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
1111 | - $meta_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version( |
|
1111 | + $meta_routes[EED_Core_Rest_Api::ee_api_namespace.$version] = $this->_get_meta_route_data_for_version( |
|
1112 | 1112 | $version, |
1113 | 1113 | $hidden_endpoint |
1114 | 1114 | ); |
@@ -1161,7 +1161,7 @@ discard block |
||
1161 | 1161 | foreach ($relative_urls as $resource_name => $endpoints) { |
1162 | 1162 | foreach ($endpoints as $key => $endpoint) { |
1163 | 1163 | // skip schema and other route options |
1164 | - if (! is_numeric($key)) { |
|
1164 | + if ( ! is_numeric($key)) { |
|
1165 | 1165 | continue; |
1166 | 1166 | } |
1167 | 1167 | // by default, hide "hidden_endpoint"s, unless the request indicates |
@@ -1170,9 +1170,9 @@ discard block |
||
1170 | 1170 | if (($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
1171 | 1171 | || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
1172 | 1172 | ) { |
1173 | - $full_route = '/' . ltrim($namespace, '/'); |
|
1174 | - $full_route .= '/' . ltrim($resource_name, '/'); |
|
1175 | - unset($route_data[ $full_route ]); |
|
1173 | + $full_route = '/'.ltrim($namespace, '/'); |
|
1174 | + $full_route .= '/'.ltrim($resource_name, '/'); |
|
1175 | + unset($route_data[$full_route]); |
|
1176 | 1176 | } |
1177 | 1177 | } |
1178 | 1178 | } |
@@ -1246,19 +1246,19 @@ discard block |
||
1246 | 1246 | |
1247 | 1247 | if ($key_versioned_endpoint === $latest_version) { |
1248 | 1248 | // don't hide the latest version in the index |
1249 | - $versions_served[ $key_versioned_endpoint ] = false; |
|
1249 | + $versions_served[$key_versioned_endpoint] = false; |
|
1250 | 1250 | } elseif (version_compare($key_versioned_endpoint, $lowest_compatible_version, '>=') |
1251 | 1251 | && version_compare($key_versioned_endpoint, EED_Core_Rest_Api::core_version(), '<') |
1252 | 1252 | ) { |
1253 | 1253 | // include, but hide, previous versions which are still supported |
1254 | - $versions_served[ $key_versioned_endpoint ] = true; |
|
1254 | + $versions_served[$key_versioned_endpoint] = true; |
|
1255 | 1255 | } elseif (apply_filters( |
1256 | 1256 | 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
1257 | 1257 | false, |
1258 | 1258 | $possibly_served_versions |
1259 | 1259 | )) { |
1260 | 1260 | // if a version is no longer supported, don't include it in index or list of versions served |
1261 | - $versions_served[ $key_versioned_endpoint ] = true; |
|
1261 | + $versions_served[$key_versioned_endpoint] = true; |
|
1262 | 1262 | } |
1263 | 1263 | } |
1264 | 1264 | return $versions_served; |
@@ -1315,7 +1315,7 @@ discard block |
||
1315 | 1315 | $model_names = EED_Core_Rest_Api::model_names_with_plural_routes($version); |
1316 | 1316 | $collection_routes = []; |
1317 | 1317 | foreach ($model_names as $model_name => $model_class_name) { |
1318 | - $collection_routes[ strtolower($model_name) ] = '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' |
|
1318 | + $collection_routes[strtolower($model_name)] = '/'.EED_Core_Rest_Api::ee_api_namespace.$version.'/' |
|
1319 | 1319 | . EEH_Inflector::pluralize_and_lower($model_name); |
1320 | 1320 | } |
1321 | 1321 | return $collection_routes; |
@@ -1337,9 +1337,9 @@ discard block |
||
1337 | 1337 | $primary_keys = $model_class_name::instance()->get_combined_primary_key_fields(); |
1338 | 1338 | foreach ($primary_keys as $primary_key_name => $primary_key_field) { |
1339 | 1339 | if (count($primary_keys) > 1) { |
1340 | - $primary_key_items[ strtolower($model_name) ][] = $primary_key_name; |
|
1340 | + $primary_key_items[strtolower($model_name)][] = $primary_key_name; |
|
1341 | 1341 | } else { |
1342 | - $primary_key_items[ strtolower($model_name) ] = $primary_key_name; |
|
1342 | + $primary_key_items[strtolower($model_name)] = $primary_key_name; |
|
1343 | 1343 | } |
1344 | 1344 | } |
1345 | 1345 | } |
@@ -31,266 +31,266 @@ |
||
31 | 31 | class CoreAssetManager extends AssetManager |
32 | 32 | { |
33 | 33 | |
34 | - // WordPress core / Third party JS asset handles |
|
35 | - const JS_HANDLE_JQUERY = 'jquery'; |
|
36 | - |
|
37 | - const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
38 | - |
|
39 | - const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
40 | - |
|
41 | - const JS_HANDLE_JS_CORE = 'eejs-core'; |
|
42 | - |
|
43 | - const JS_HANDLE_CORE = 'espresso_core'; |
|
44 | - |
|
45 | - const JS_HANDLE_I18N = 'eei18n'; |
|
46 | - |
|
47 | - const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
48 | - |
|
49 | - // EE CSS assets handles |
|
50 | - const CSS_HANDLE_DEFAULT = 'espresso_default'; |
|
51 | - |
|
52 | - const CSS_HANDLE_CUSTOM = 'espresso_custom_css'; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var EE_Currency_Config $currency_config |
|
56 | - */ |
|
57 | - protected $currency_config; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var EE_Template_Config $template_config |
|
61 | - */ |
|
62 | - protected $template_config; |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * CoreAssetRegister constructor. |
|
67 | - * |
|
68 | - * @param AssetCollection $assets |
|
69 | - * @param EE_Currency_Config $currency_config |
|
70 | - * @param EE_Template_Config $template_config |
|
71 | - * @param DomainInterface $domain |
|
72 | - * @param Registry $registry |
|
73 | - */ |
|
74 | - public function __construct( |
|
75 | - AssetCollection $assets, |
|
76 | - EE_Currency_Config $currency_config, |
|
77 | - EE_Template_Config $template_config, |
|
78 | - DomainInterface $domain, |
|
79 | - Registry $registry |
|
80 | - ) { |
|
81 | - $this->currency_config = $currency_config; |
|
82 | - $this->template_config = $template_config; |
|
83 | - parent::__construct($domain, $assets, $registry); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @since 4.9.62.p |
|
89 | - * @throws DomainException |
|
90 | - * @throws DuplicateCollectionIdentifierException |
|
91 | - * @throws InvalidArgumentException |
|
92 | - * @throws InvalidDataTypeException |
|
93 | - * @throws InvalidEntityException |
|
94 | - * @throws InvalidInterfaceException |
|
95 | - */ |
|
96 | - public function addAssets() |
|
97 | - { |
|
98 | - $this->addJavascriptFiles(); |
|
99 | - $this->addStylesheetFiles(); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @since 4.9.62.p |
|
105 | - * @throws DomainException |
|
106 | - * @throws DuplicateCollectionIdentifierException |
|
107 | - * @throws InvalidArgumentException |
|
108 | - * @throws InvalidDataTypeException |
|
109 | - * @throws InvalidEntityException |
|
110 | - * @throws InvalidInterfaceException |
|
111 | - */ |
|
112 | - public function addJavascriptFiles() |
|
113 | - { |
|
114 | - $this->loadCoreJs(); |
|
115 | - $this->loadJqueryValidate(); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @throws DuplicateCollectionIdentifierException |
|
121 | - * @throws InvalidDataTypeException |
|
122 | - * @throws InvalidEntityException |
|
123 | - * @throws DomainException |
|
124 | - * @since 4.9.62.p |
|
125 | - */ |
|
126 | - public function addStylesheetFiles() |
|
127 | - { |
|
128 | - $this->loadCoreCss(); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * core default javascript |
|
134 | - * |
|
135 | - * @since 4.9.62.p |
|
136 | - * @throws DomainException |
|
137 | - * @throws DuplicateCollectionIdentifierException |
|
138 | - * @throws InvalidArgumentException |
|
139 | - * @throws InvalidDataTypeException |
|
140 | - * @throws InvalidEntityException |
|
141 | - * @throws InvalidInterfaceException |
|
142 | - */ |
|
143 | - private function loadCoreJs() |
|
144 | - { |
|
145 | - $this->addJs(CoreAssetManager::JS_HANDLE_VENDOR); |
|
146 | - $this->addJs(CoreAssetManager::JS_HANDLE_JS_CORE)->setHasInlineData(); |
|
147 | - $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
148 | - $this->registry->addData( |
|
149 | - 'paths', |
|
150 | - array( |
|
151 | - 'base_rest_route' => rest_url(), |
|
152 | - 'rest_route' => rest_url('ee/v4.8.36/'), |
|
153 | - 'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(), |
|
154 | - 'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(), |
|
155 | - 'site_url' => site_url('/'), |
|
156 | - 'admin_url' => admin_url('/'), |
|
157 | - ) |
|
158 | - ); |
|
159 | - // Event Espresso brand name |
|
160 | - $this->registry->addData('brandName', Domain::brandName()); |
|
161 | - /** site formatting values **/ |
|
162 | - $this->registry->addData( |
|
163 | - 'site_formats', |
|
164 | - array( |
|
165 | - 'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats() |
|
166 | - ) |
|
167 | - ); |
|
168 | - /** currency data **/ |
|
169 | - $this->registry->addData( |
|
170 | - 'currency_config', |
|
171 | - $this->getCurrencySettings() |
|
172 | - ); |
|
173 | - /** site timezone */ |
|
174 | - $this->registry->addData( |
|
175 | - 'default_timezone', |
|
176 | - array( |
|
177 | - 'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(), |
|
178 | - 'string' => get_option('timezone_string'), |
|
179 | - 'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(), |
|
180 | - ) |
|
181 | - ); |
|
182 | - /** site locale (user locale if user logged in) */ |
|
183 | - $this->registry->addData( |
|
184 | - 'locale', |
|
185 | - array( |
|
186 | - 'user' => get_user_locale(), |
|
187 | - 'site' => get_locale() |
|
188 | - ) |
|
189 | - ); |
|
190 | - |
|
191 | - $this->addJavascript( |
|
192 | - CoreAssetManager::JS_HANDLE_CORE, |
|
193 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
194 | - array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
195 | - ) |
|
196 | - ->setInlineDataCallback( |
|
197 | - static function () { |
|
198 | - wp_localize_script( |
|
199 | - CoreAssetManager::JS_HANDLE_CORE, |
|
200 | - CoreAssetManager::JS_HANDLE_I18N, |
|
201 | - EE_Registry::$i18n_js_strings |
|
202 | - ); |
|
203 | - } |
|
204 | - ); |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * Returns configuration data for the js Currency VO. |
|
211 | - * @since 4.9.71.p |
|
212 | - * @return array |
|
213 | - */ |
|
214 | - private function getCurrencySettings() |
|
215 | - { |
|
216 | - return array( |
|
217 | - 'code' => $this->currency_config->code, |
|
218 | - 'singularLabel' => $this->currency_config->name, |
|
219 | - 'pluralLabel' => $this->currency_config->plural, |
|
220 | - 'sign' => $this->currency_config->sign, |
|
221 | - 'signB4' => $this->currency_config->sign_b4, |
|
222 | - 'decimalPlaces' => $this->currency_config->dec_plc, |
|
223 | - 'decimalMark' => $this->currency_config->dec_mrk, |
|
224 | - 'thousandsSeparator' => $this->currency_config->thsnds, |
|
225 | - ); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * @throws DuplicateCollectionIdentifierException |
|
231 | - * @throws InvalidDataTypeException |
|
232 | - * @throws InvalidEntityException |
|
233 | - * @throws DomainException |
|
234 | - * @since 4.9.62.p |
|
235 | - */ |
|
236 | - private function loadCoreCss() |
|
237 | - { |
|
238 | - if ($this->template_config->enable_default_style && ! is_admin()) { |
|
239 | - $this->addStylesheet( |
|
240 | - CoreAssetManager::CSS_HANDLE_DEFAULT, |
|
241 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
242 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
243 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
244 | - array('dashicons') |
|
245 | - ); |
|
246 | - //Load custom style sheet if available |
|
247 | - if ($this->template_config->custom_style_sheet !== null) { |
|
248 | - $this->addStylesheet( |
|
249 | - CoreAssetManager::CSS_HANDLE_CUSTOM, |
|
250 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
251 | - array(CoreAssetManager::CSS_HANDLE_DEFAULT) |
|
252 | - ); |
|
253 | - } |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * jQuery Validate for form validation |
|
260 | - * |
|
261 | - * @since 4.9.62.p |
|
262 | - * @throws DomainException |
|
263 | - * @throws DuplicateCollectionIdentifierException |
|
264 | - * @throws InvalidDataTypeException |
|
265 | - * @throws InvalidEntityException |
|
266 | - */ |
|
267 | - private function loadJqueryValidate() |
|
268 | - { |
|
269 | - $this->addJavascript( |
|
270 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
271 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
272 | - array(CoreAssetManager::JS_HANDLE_JQUERY), |
|
273 | - true, |
|
274 | - '1.15.0' |
|
275 | - ); |
|
276 | - |
|
277 | - $this->addJavascript( |
|
278 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
279 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
280 | - array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE), |
|
281 | - true, |
|
282 | - '1.15.0' |
|
283 | - ); |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * @param JavascriptAsset $script |
|
289 | - * @deprecated $VID:$ |
|
290 | - */ |
|
291 | - public function loadQtipJs(JavascriptAsset $script) |
|
292 | - { |
|
293 | - // replacement: |
|
294 | - // \EventEspresso\core\domain\services\assets\EspressoLegacyAdminAssetManager::loadQtipJs |
|
295 | - } |
|
34 | + // WordPress core / Third party JS asset handles |
|
35 | + const JS_HANDLE_JQUERY = 'jquery'; |
|
36 | + |
|
37 | + const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
38 | + |
|
39 | + const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
40 | + |
|
41 | + const JS_HANDLE_JS_CORE = 'eejs-core'; |
|
42 | + |
|
43 | + const JS_HANDLE_CORE = 'espresso_core'; |
|
44 | + |
|
45 | + const JS_HANDLE_I18N = 'eei18n'; |
|
46 | + |
|
47 | + const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
48 | + |
|
49 | + // EE CSS assets handles |
|
50 | + const CSS_HANDLE_DEFAULT = 'espresso_default'; |
|
51 | + |
|
52 | + const CSS_HANDLE_CUSTOM = 'espresso_custom_css'; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var EE_Currency_Config $currency_config |
|
56 | + */ |
|
57 | + protected $currency_config; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var EE_Template_Config $template_config |
|
61 | + */ |
|
62 | + protected $template_config; |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * CoreAssetRegister constructor. |
|
67 | + * |
|
68 | + * @param AssetCollection $assets |
|
69 | + * @param EE_Currency_Config $currency_config |
|
70 | + * @param EE_Template_Config $template_config |
|
71 | + * @param DomainInterface $domain |
|
72 | + * @param Registry $registry |
|
73 | + */ |
|
74 | + public function __construct( |
|
75 | + AssetCollection $assets, |
|
76 | + EE_Currency_Config $currency_config, |
|
77 | + EE_Template_Config $template_config, |
|
78 | + DomainInterface $domain, |
|
79 | + Registry $registry |
|
80 | + ) { |
|
81 | + $this->currency_config = $currency_config; |
|
82 | + $this->template_config = $template_config; |
|
83 | + parent::__construct($domain, $assets, $registry); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @since 4.9.62.p |
|
89 | + * @throws DomainException |
|
90 | + * @throws DuplicateCollectionIdentifierException |
|
91 | + * @throws InvalidArgumentException |
|
92 | + * @throws InvalidDataTypeException |
|
93 | + * @throws InvalidEntityException |
|
94 | + * @throws InvalidInterfaceException |
|
95 | + */ |
|
96 | + public function addAssets() |
|
97 | + { |
|
98 | + $this->addJavascriptFiles(); |
|
99 | + $this->addStylesheetFiles(); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @since 4.9.62.p |
|
105 | + * @throws DomainException |
|
106 | + * @throws DuplicateCollectionIdentifierException |
|
107 | + * @throws InvalidArgumentException |
|
108 | + * @throws InvalidDataTypeException |
|
109 | + * @throws InvalidEntityException |
|
110 | + * @throws InvalidInterfaceException |
|
111 | + */ |
|
112 | + public function addJavascriptFiles() |
|
113 | + { |
|
114 | + $this->loadCoreJs(); |
|
115 | + $this->loadJqueryValidate(); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @throws DuplicateCollectionIdentifierException |
|
121 | + * @throws InvalidDataTypeException |
|
122 | + * @throws InvalidEntityException |
|
123 | + * @throws DomainException |
|
124 | + * @since 4.9.62.p |
|
125 | + */ |
|
126 | + public function addStylesheetFiles() |
|
127 | + { |
|
128 | + $this->loadCoreCss(); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * core default javascript |
|
134 | + * |
|
135 | + * @since 4.9.62.p |
|
136 | + * @throws DomainException |
|
137 | + * @throws DuplicateCollectionIdentifierException |
|
138 | + * @throws InvalidArgumentException |
|
139 | + * @throws InvalidDataTypeException |
|
140 | + * @throws InvalidEntityException |
|
141 | + * @throws InvalidInterfaceException |
|
142 | + */ |
|
143 | + private function loadCoreJs() |
|
144 | + { |
|
145 | + $this->addJs(CoreAssetManager::JS_HANDLE_VENDOR); |
|
146 | + $this->addJs(CoreAssetManager::JS_HANDLE_JS_CORE)->setHasInlineData(); |
|
147 | + $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
148 | + $this->registry->addData( |
|
149 | + 'paths', |
|
150 | + array( |
|
151 | + 'base_rest_route' => rest_url(), |
|
152 | + 'rest_route' => rest_url('ee/v4.8.36/'), |
|
153 | + 'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(), |
|
154 | + 'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(), |
|
155 | + 'site_url' => site_url('/'), |
|
156 | + 'admin_url' => admin_url('/'), |
|
157 | + ) |
|
158 | + ); |
|
159 | + // Event Espresso brand name |
|
160 | + $this->registry->addData('brandName', Domain::brandName()); |
|
161 | + /** site formatting values **/ |
|
162 | + $this->registry->addData( |
|
163 | + 'site_formats', |
|
164 | + array( |
|
165 | + 'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats() |
|
166 | + ) |
|
167 | + ); |
|
168 | + /** currency data **/ |
|
169 | + $this->registry->addData( |
|
170 | + 'currency_config', |
|
171 | + $this->getCurrencySettings() |
|
172 | + ); |
|
173 | + /** site timezone */ |
|
174 | + $this->registry->addData( |
|
175 | + 'default_timezone', |
|
176 | + array( |
|
177 | + 'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(), |
|
178 | + 'string' => get_option('timezone_string'), |
|
179 | + 'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(), |
|
180 | + ) |
|
181 | + ); |
|
182 | + /** site locale (user locale if user logged in) */ |
|
183 | + $this->registry->addData( |
|
184 | + 'locale', |
|
185 | + array( |
|
186 | + 'user' => get_user_locale(), |
|
187 | + 'site' => get_locale() |
|
188 | + ) |
|
189 | + ); |
|
190 | + |
|
191 | + $this->addJavascript( |
|
192 | + CoreAssetManager::JS_HANDLE_CORE, |
|
193 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
194 | + array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
195 | + ) |
|
196 | + ->setInlineDataCallback( |
|
197 | + static function () { |
|
198 | + wp_localize_script( |
|
199 | + CoreAssetManager::JS_HANDLE_CORE, |
|
200 | + CoreAssetManager::JS_HANDLE_I18N, |
|
201 | + EE_Registry::$i18n_js_strings |
|
202 | + ); |
|
203 | + } |
|
204 | + ); |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * Returns configuration data for the js Currency VO. |
|
211 | + * @since 4.9.71.p |
|
212 | + * @return array |
|
213 | + */ |
|
214 | + private function getCurrencySettings() |
|
215 | + { |
|
216 | + return array( |
|
217 | + 'code' => $this->currency_config->code, |
|
218 | + 'singularLabel' => $this->currency_config->name, |
|
219 | + 'pluralLabel' => $this->currency_config->plural, |
|
220 | + 'sign' => $this->currency_config->sign, |
|
221 | + 'signB4' => $this->currency_config->sign_b4, |
|
222 | + 'decimalPlaces' => $this->currency_config->dec_plc, |
|
223 | + 'decimalMark' => $this->currency_config->dec_mrk, |
|
224 | + 'thousandsSeparator' => $this->currency_config->thsnds, |
|
225 | + ); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * @throws DuplicateCollectionIdentifierException |
|
231 | + * @throws InvalidDataTypeException |
|
232 | + * @throws InvalidEntityException |
|
233 | + * @throws DomainException |
|
234 | + * @since 4.9.62.p |
|
235 | + */ |
|
236 | + private function loadCoreCss() |
|
237 | + { |
|
238 | + if ($this->template_config->enable_default_style && ! is_admin()) { |
|
239 | + $this->addStylesheet( |
|
240 | + CoreAssetManager::CSS_HANDLE_DEFAULT, |
|
241 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
242 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
243 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
244 | + array('dashicons') |
|
245 | + ); |
|
246 | + //Load custom style sheet if available |
|
247 | + if ($this->template_config->custom_style_sheet !== null) { |
|
248 | + $this->addStylesheet( |
|
249 | + CoreAssetManager::CSS_HANDLE_CUSTOM, |
|
250 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
251 | + array(CoreAssetManager::CSS_HANDLE_DEFAULT) |
|
252 | + ); |
|
253 | + } |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * jQuery Validate for form validation |
|
260 | + * |
|
261 | + * @since 4.9.62.p |
|
262 | + * @throws DomainException |
|
263 | + * @throws DuplicateCollectionIdentifierException |
|
264 | + * @throws InvalidDataTypeException |
|
265 | + * @throws InvalidEntityException |
|
266 | + */ |
|
267 | + private function loadJqueryValidate() |
|
268 | + { |
|
269 | + $this->addJavascript( |
|
270 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
271 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
272 | + array(CoreAssetManager::JS_HANDLE_JQUERY), |
|
273 | + true, |
|
274 | + '1.15.0' |
|
275 | + ); |
|
276 | + |
|
277 | + $this->addJavascript( |
|
278 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
279 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
280 | + array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE), |
|
281 | + true, |
|
282 | + '1.15.0' |
|
283 | + ); |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * @param JavascriptAsset $script |
|
289 | + * @deprecated $VID:$ |
|
290 | + */ |
|
291 | + public function loadQtipJs(JavascriptAsset $script) |
|
292 | + { |
|
293 | + // replacement: |
|
294 | + // \EventEspresso\core\domain\services\assets\EspressoLegacyAdminAssetManager::loadQtipJs |
|
295 | + } |
|
296 | 296 | } |
@@ -15,121 +15,121 @@ |
||
15 | 15 | class EspressoLegacyAdminAssetManager extends AssetManager |
16 | 16 | { |
17 | 17 | |
18 | - const JS_HANDLE_INJECT_WP = 'ee-inject-wp'; |
|
19 | - |
|
20 | - const JS_HANDLE_JQUERY_COOKIE = 'jquery-cookie'; |
|
21 | - |
|
22 | - const JS_HANDLE_JOYRIDE_MODERNIZR = 'joyride-modernizr'; |
|
23 | - |
|
24 | - const JS_HANDLE_JQUERY_JOYRIDE = 'jquery-joyride'; |
|
25 | - |
|
26 | - const CSS_HANDLE_EE_JOYRIDE = 'ee-joyride-css'; |
|
27 | - |
|
28 | - const CSS_HANDLE_JOYRIDE = 'joyride-css'; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * @inheritDoc |
|
33 | - */ |
|
34 | - public function addAssets() |
|
35 | - { |
|
36 | - $joyride = filter_var(apply_filters('FHEE_load_joyride', false), FILTER_VALIDATE_BOOLEAN); |
|
37 | - $this->registerJavascript($joyride); |
|
38 | - $this->registerStyleSheets($joyride); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * Register javascript assets |
|
44 | - * |
|
45 | - * @param bool $joyride |
|
46 | - */ |
|
47 | - private function registerJavascript($joyride = false) |
|
48 | - { |
|
49 | - // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
50 | - // Note: the intention of this script is to only do TARGETED injections. |
|
51 | - //ie: only injecting on certain script calls. |
|
52 | - $this->addJavascript( |
|
53 | - EspressoLegacyAdminAssetManager::JS_HANDLE_INJECT_WP, |
|
54 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
55 | - ['jquery'], |
|
56 | - true, |
|
57 | - EVENT_ESPRESSO_VERSION |
|
58 | - ); |
|
59 | - // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, |
|
60 | - // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
61 | - if (! $joyride) { |
|
62 | - return; |
|
63 | - } |
|
64 | - // register cookie script for future dependencies |
|
65 | - $this->addJavascript( |
|
66 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_COOKIE, |
|
67 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
68 | - ['jquery'], |
|
69 | - true, |
|
70 | - '2.1' |
|
71 | - ); |
|
72 | - $this->addJavascript( |
|
73 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
|
74 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
75 | - [], |
|
76 | - true, |
|
77 | - '2.1' |
|
78 | - ); |
|
79 | - // wanna go for a joyride? |
|
80 | - $this->addJavascript( |
|
81 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
|
82 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
83 | - [ |
|
84 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_COOKIE, |
|
85 | - EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR |
|
86 | - ], |
|
87 | - '2.1', |
|
88 | - true |
|
89 | - )->enqueueAsset(); |
|
90 | - $this->loadQtipJs(); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Register CSS assets. |
|
96 | - * |
|
97 | - * @param bool $joyride |
|
98 | - */ |
|
99 | - private function registerStyleSheets($joyride = false) |
|
100 | - { |
|
101 | - if (! $joyride) { |
|
102 | - return; |
|
103 | - } // joyride style |
|
104 | - $this->addStylesheet( |
|
105 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE, |
|
106 | - EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', |
|
107 | - [], |
|
108 | - 'all', |
|
109 | - '2.1' |
|
110 | - ); |
|
111 | - $this->addStylesheet( |
|
112 | - EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_JOYRIDE, |
|
113 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
114 | - ['joyride-css'], |
|
115 | - 'all', |
|
116 | - EVENT_ESPRESSO_VERSION |
|
117 | - )->enqueueAsset(); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * registers assets for cleaning your ears |
|
123 | - */ |
|
124 | - public function loadQtipJs() |
|
125 | - { |
|
126 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
127 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
128 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
129 | - $qtip_loader = EEH_Qtip_Loader::instance(); |
|
130 | - if ($qtip_loader instanceof EEH_Qtip_Loader) { |
|
131 | - $qtip_loader->register_and_enqueue(); |
|
132 | - } |
|
133 | - } |
|
134 | - } |
|
18 | + const JS_HANDLE_INJECT_WP = 'ee-inject-wp'; |
|
19 | + |
|
20 | + const JS_HANDLE_JQUERY_COOKIE = 'jquery-cookie'; |
|
21 | + |
|
22 | + const JS_HANDLE_JOYRIDE_MODERNIZR = 'joyride-modernizr'; |
|
23 | + |
|
24 | + const JS_HANDLE_JQUERY_JOYRIDE = 'jquery-joyride'; |
|
25 | + |
|
26 | + const CSS_HANDLE_EE_JOYRIDE = 'ee-joyride-css'; |
|
27 | + |
|
28 | + const CSS_HANDLE_JOYRIDE = 'joyride-css'; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * @inheritDoc |
|
33 | + */ |
|
34 | + public function addAssets() |
|
35 | + { |
|
36 | + $joyride = filter_var(apply_filters('FHEE_load_joyride', false), FILTER_VALIDATE_BOOLEAN); |
|
37 | + $this->registerJavascript($joyride); |
|
38 | + $this->registerStyleSheets($joyride); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * Register javascript assets |
|
44 | + * |
|
45 | + * @param bool $joyride |
|
46 | + */ |
|
47 | + private function registerJavascript($joyride = false) |
|
48 | + { |
|
49 | + // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
50 | + // Note: the intention of this script is to only do TARGETED injections. |
|
51 | + //ie: only injecting on certain script calls. |
|
52 | + $this->addJavascript( |
|
53 | + EspressoLegacyAdminAssetManager::JS_HANDLE_INJECT_WP, |
|
54 | + EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
55 | + ['jquery'], |
|
56 | + true, |
|
57 | + EVENT_ESPRESSO_VERSION |
|
58 | + ); |
|
59 | + // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, |
|
60 | + // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
61 | + if (! $joyride) { |
|
62 | + return; |
|
63 | + } |
|
64 | + // register cookie script for future dependencies |
|
65 | + $this->addJavascript( |
|
66 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_COOKIE, |
|
67 | + EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
68 | + ['jquery'], |
|
69 | + true, |
|
70 | + '2.1' |
|
71 | + ); |
|
72 | + $this->addJavascript( |
|
73 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
|
74 | + EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
75 | + [], |
|
76 | + true, |
|
77 | + '2.1' |
|
78 | + ); |
|
79 | + // wanna go for a joyride? |
|
80 | + $this->addJavascript( |
|
81 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
|
82 | + EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
83 | + [ |
|
84 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_COOKIE, |
|
85 | + EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR |
|
86 | + ], |
|
87 | + '2.1', |
|
88 | + true |
|
89 | + )->enqueueAsset(); |
|
90 | + $this->loadQtipJs(); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Register CSS assets. |
|
96 | + * |
|
97 | + * @param bool $joyride |
|
98 | + */ |
|
99 | + private function registerStyleSheets($joyride = false) |
|
100 | + { |
|
101 | + if (! $joyride) { |
|
102 | + return; |
|
103 | + } // joyride style |
|
104 | + $this->addStylesheet( |
|
105 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE, |
|
106 | + EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', |
|
107 | + [], |
|
108 | + 'all', |
|
109 | + '2.1' |
|
110 | + ); |
|
111 | + $this->addStylesheet( |
|
112 | + EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_JOYRIDE, |
|
113 | + EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
114 | + ['joyride-css'], |
|
115 | + 'all', |
|
116 | + EVENT_ESPRESSO_VERSION |
|
117 | + )->enqueueAsset(); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * registers assets for cleaning your ears |
|
123 | + */ |
|
124 | + public function loadQtipJs() |
|
125 | + { |
|
126 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
127 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
128 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
129 | + $qtip_loader = EEH_Qtip_Loader::instance(); |
|
130 | + if ($qtip_loader instanceof EEH_Qtip_Loader) { |
|
131 | + $qtip_loader->register_and_enqueue(); |
|
132 | + } |
|
133 | + } |
|
134 | + } |
|
135 | 135 | } |
@@ -51,27 +51,27 @@ discard block |
||
51 | 51 | //ie: only injecting on certain script calls. |
52 | 52 | $this->addJavascript( |
53 | 53 | EspressoLegacyAdminAssetManager::JS_HANDLE_INJECT_WP, |
54 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
54 | + EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', |
|
55 | 55 | ['jquery'], |
56 | 56 | true, |
57 | 57 | EVENT_ESPRESSO_VERSION |
58 | 58 | ); |
59 | 59 | // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, |
60 | 60 | // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' ); |
61 | - if (! $joyride) { |
|
61 | + if ( ! $joyride) { |
|
62 | 62 | return; |
63 | 63 | } |
64 | 64 | // register cookie script for future dependencies |
65 | 65 | $this->addJavascript( |
66 | 66 | EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_COOKIE, |
67 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
67 | + EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', |
|
68 | 68 | ['jquery'], |
69 | 69 | true, |
70 | 70 | '2.1' |
71 | 71 | ); |
72 | 72 | $this->addJavascript( |
73 | 73 | EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
74 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
74 | + EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', |
|
75 | 75 | [], |
76 | 76 | true, |
77 | 77 | '2.1' |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | // wanna go for a joyride? |
80 | 80 | $this->addJavascript( |
81 | 81 | EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
82 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
82 | + EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', |
|
83 | 83 | [ |
84 | 84 | EspressoLegacyAdminAssetManager::JS_HANDLE_JQUERY_COOKIE, |
85 | 85 | EspressoLegacyAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR |
@@ -98,19 +98,19 @@ discard block |
||
98 | 98 | */ |
99 | 99 | private function registerStyleSheets($joyride = false) |
100 | 100 | { |
101 | - if (! $joyride) { |
|
101 | + if ( ! $joyride) { |
|
102 | 102 | return; |
103 | 103 | } // joyride style |
104 | 104 | $this->addStylesheet( |
105 | 105 | EspressoLegacyAdminAssetManager::CSS_HANDLE_JOYRIDE, |
106 | - EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', |
|
106 | + EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', |
|
107 | 107 | [], |
108 | 108 | 'all', |
109 | 109 | '2.1' |
110 | 110 | ); |
111 | 111 | $this->addStylesheet( |
112 | 112 | EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_JOYRIDE, |
113 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
113 | + EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', |
|
114 | 114 | ['joyride-css'], |
115 | 115 | 'all', |
116 | 116 | EVENT_ESPRESSO_VERSION |
@@ -11,99 +11,99 @@ |
||
11 | 11 | class EE_Admin_File_Uploader_Display_Strategy extends EE_Display_Strategy_Base |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Its important this media only get enqueued AFTER init, but before the footer... where the |
|
16 | - * rest of our forms JS gets enqueued. Otherwise the JS gets enqueued fine, and loaded on the page fine, |
|
17 | - * but when you upload an image it gets uploaded fine to the server, but it doesn't display and reports an error |
|
18 | - * (also it doesn't show any of the currently existing media in the modal window that pops up when you click the button |
|
19 | - * to select media). |
|
20 | - * Besides that, no special consideration should be required to make the media uploader appear, besides having |
|
21 | - * this input displayed. |
|
22 | - * @deprecated. enqueue_js should be called automatically now |
|
23 | - */ |
|
24 | - public static function enqueue_scripts() |
|
25 | - { |
|
26 | - EE_Error::doing_it_wrong( |
|
27 | - __FUNCTION__, |
|
28 | - __( |
|
29 | - 'EE_Admin_File_Uploader_Display_Strategy::enqueue_scripts() no longer needs to be called in order to display the admin uploader input correctly. This is handled now by EE_Admin_File_Uploader_Display_Strategy::enqueue_js() which is called automatically when enqueueing JS and CSS for the form', |
|
30 | - 'event_espresso' |
|
31 | - ), |
|
32 | - '4.9.8.rc.015' |
|
33 | - ); |
|
34 | - wp_enqueue_media(); |
|
35 | - wp_enqueue_script('media-upload'); |
|
36 | - wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL.'scripts/ee-media-uploader.js'); |
|
37 | - } |
|
14 | + /** |
|
15 | + * Its important this media only get enqueued AFTER init, but before the footer... where the |
|
16 | + * rest of our forms JS gets enqueued. Otherwise the JS gets enqueued fine, and loaded on the page fine, |
|
17 | + * but when you upload an image it gets uploaded fine to the server, but it doesn't display and reports an error |
|
18 | + * (also it doesn't show any of the currently existing media in the modal window that pops up when you click the button |
|
19 | + * to select media). |
|
20 | + * Besides that, no special consideration should be required to make the media uploader appear, besides having |
|
21 | + * this input displayed. |
|
22 | + * @deprecated. enqueue_js should be called automatically now |
|
23 | + */ |
|
24 | + public static function enqueue_scripts() |
|
25 | + { |
|
26 | + EE_Error::doing_it_wrong( |
|
27 | + __FUNCTION__, |
|
28 | + __( |
|
29 | + 'EE_Admin_File_Uploader_Display_Strategy::enqueue_scripts() no longer needs to be called in order to display the admin uploader input correctly. This is handled now by EE_Admin_File_Uploader_Display_Strategy::enqueue_js() which is called automatically when enqueueing JS and CSS for the form', |
|
30 | + 'event_espresso' |
|
31 | + ), |
|
32 | + '4.9.8.rc.015' |
|
33 | + ); |
|
34 | + wp_enqueue_media(); |
|
35 | + wp_enqueue_script('media-upload'); |
|
36 | + wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL.'scripts/ee-media-uploader.js'); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Enqueues the JS and CSS needed to display this input |
|
42 | - */ |
|
43 | - public function enqueue_js() |
|
44 | - { |
|
45 | - wp_enqueue_media(); |
|
46 | - wp_enqueue_script('media-upload'); |
|
47 | - wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL.'scripts/ee-media-uploader.js'); |
|
48 | - parent::enqueue_js(); |
|
49 | - } |
|
40 | + /** |
|
41 | + * Enqueues the JS and CSS needed to display this input |
|
42 | + */ |
|
43 | + public function enqueue_js() |
|
44 | + { |
|
45 | + wp_enqueue_media(); |
|
46 | + wp_enqueue_script('media-upload'); |
|
47 | + wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL.'scripts/ee-media-uploader.js'); |
|
48 | + parent::enqueue_js(); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * |
|
55 | - * @return string of html to display the field |
|
56 | - */ |
|
53 | + /** |
|
54 | + * |
|
55 | + * @return string of html to display the field |
|
56 | + */ |
|
57 | 57 | |
58 | - public function display() |
|
59 | - { |
|
60 | - // the actual input |
|
61 | - $input = '<input type="text" size="34" '; |
|
62 | - $input .= 'name="' . $this->_input->html_name() . '" '; |
|
63 | - $input .= $this->_input->html_class() !== '' |
|
64 | - ? 'class="large-text ee_media_url ' . $this->_input->html_class() . '" ' |
|
65 | - : 'class="large-text ee_media_url" '; |
|
66 | - $input .= 'value="' . $this->_input->raw_value_in_form() . '" '; |
|
67 | - $input .= $this->_input->other_html_attributes() . '>'; |
|
68 | - // image uploader |
|
69 | - $uploader = EEH_HTML::link( |
|
70 | - '#', |
|
71 | - '<img src="' . admin_url('images/media-button-image.gif') . '" >', |
|
72 | - __('click to add an image', 'event_espresso'), |
|
73 | - '', |
|
74 | - 'ee_media_upload' |
|
75 | - ); |
|
76 | - // only attempt to show the image if it at least exists |
|
77 | - $image = $this->_input->raw_value() && $this->src_exists($this->_input->raw_value()) |
|
78 | - ? EEH_HTML::br(2) . EEH_HTML::img( |
|
79 | - $this->_input->raw_value(), |
|
80 | - __('logo', 'event_espresso'), |
|
81 | - '', |
|
82 | - 'ee_media_image' |
|
83 | - ) |
|
84 | - : ''; |
|
85 | - // html string |
|
86 | - return EEH_HTML::div( |
|
87 | - $input . EEH_HTML::nbsp() . $uploader . $image, |
|
88 | - '', |
|
89 | - 'ee_media_uploader_area' |
|
90 | - ); |
|
91 | - } |
|
58 | + public function display() |
|
59 | + { |
|
60 | + // the actual input |
|
61 | + $input = '<input type="text" size="34" '; |
|
62 | + $input .= 'name="' . $this->_input->html_name() . '" '; |
|
63 | + $input .= $this->_input->html_class() !== '' |
|
64 | + ? 'class="large-text ee_media_url ' . $this->_input->html_class() . '" ' |
|
65 | + : 'class="large-text ee_media_url" '; |
|
66 | + $input .= 'value="' . $this->_input->raw_value_in_form() . '" '; |
|
67 | + $input .= $this->_input->other_html_attributes() . '>'; |
|
68 | + // image uploader |
|
69 | + $uploader = EEH_HTML::link( |
|
70 | + '#', |
|
71 | + '<img src="' . admin_url('images/media-button-image.gif') . '" >', |
|
72 | + __('click to add an image', 'event_espresso'), |
|
73 | + '', |
|
74 | + 'ee_media_upload' |
|
75 | + ); |
|
76 | + // only attempt to show the image if it at least exists |
|
77 | + $image = $this->_input->raw_value() && $this->src_exists($this->_input->raw_value()) |
|
78 | + ? EEH_HTML::br(2) . EEH_HTML::img( |
|
79 | + $this->_input->raw_value(), |
|
80 | + __('logo', 'event_espresso'), |
|
81 | + '', |
|
82 | + 'ee_media_image' |
|
83 | + ) |
|
84 | + : ''; |
|
85 | + // html string |
|
86 | + return EEH_HTML::div( |
|
87 | + $input . EEH_HTML::nbsp() . $uploader . $image, |
|
88 | + '', |
|
89 | + 'ee_media_uploader_area' |
|
90 | + ); |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | 94 | |
95 | - /** |
|
96 | - * Asserts an image actually exists as quickly as possible by sending a HEAD |
|
97 | - * request |
|
98 | - * @param string $src |
|
99 | - * @return boolean |
|
100 | - */ |
|
101 | - protected function src_exists($src) |
|
102 | - { |
|
103 | - $results = wp_remote_head($src); |
|
104 | - if (is_array($results) && ! $results instanceof WP_Error) { |
|
105 | - return strpos($results['headers']['content-type'], "image") !== false; |
|
106 | - } |
|
107 | - return false; |
|
108 | - } |
|
95 | + /** |
|
96 | + * Asserts an image actually exists as quickly as possible by sending a HEAD |
|
97 | + * request |
|
98 | + * @param string $src |
|
99 | + * @return boolean |
|
100 | + */ |
|
101 | + protected function src_exists($src) |
|
102 | + { |
|
103 | + $results = wp_remote_head($src); |
|
104 | + if (is_array($results) && ! $results instanceof WP_Error) { |
|
105 | + return strpos($results['headers']['content-type'], "image") !== false; |
|
106 | + } |
|
107 | + return false; |
|
108 | + } |
|
109 | 109 | } |
@@ -59,23 +59,23 @@ discard block |
||
59 | 59 | { |
60 | 60 | // the actual input |
61 | 61 | $input = '<input type="text" size="34" '; |
62 | - $input .= 'name="' . $this->_input->html_name() . '" '; |
|
62 | + $input .= 'name="'.$this->_input->html_name().'" '; |
|
63 | 63 | $input .= $this->_input->html_class() !== '' |
64 | - ? 'class="large-text ee_media_url ' . $this->_input->html_class() . '" ' |
|
64 | + ? 'class="large-text ee_media_url '.$this->_input->html_class().'" ' |
|
65 | 65 | : 'class="large-text ee_media_url" '; |
66 | - $input .= 'value="' . $this->_input->raw_value_in_form() . '" '; |
|
67 | - $input .= $this->_input->other_html_attributes() . '>'; |
|
66 | + $input .= 'value="'.$this->_input->raw_value_in_form().'" '; |
|
67 | + $input .= $this->_input->other_html_attributes().'>'; |
|
68 | 68 | // image uploader |
69 | 69 | $uploader = EEH_HTML::link( |
70 | 70 | '#', |
71 | - '<img src="' . admin_url('images/media-button-image.gif') . '" >', |
|
71 | + '<img src="'.admin_url('images/media-button-image.gif').'" >', |
|
72 | 72 | __('click to add an image', 'event_espresso'), |
73 | 73 | '', |
74 | 74 | 'ee_media_upload' |
75 | 75 | ); |
76 | 76 | // only attempt to show the image if it at least exists |
77 | 77 | $image = $this->_input->raw_value() && $this->src_exists($this->_input->raw_value()) |
78 | - ? EEH_HTML::br(2) . EEH_HTML::img( |
|
78 | + ? EEH_HTML::br(2).EEH_HTML::img( |
|
79 | 79 | $this->_input->raw_value(), |
80 | 80 | __('logo', 'event_espresso'), |
81 | 81 | '', |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | : ''; |
85 | 85 | // html string |
86 | 86 | return EEH_HTML::div( |
87 | - $input . EEH_HTML::nbsp() . $uploader . $image, |
|
87 | + $input.EEH_HTML::nbsp().$uploader.$image, |
|
88 | 88 | '', |
89 | 89 | 'ee_media_uploader_area' |
90 | 90 | ); |
@@ -15,102 +15,102 @@ |
||
15 | 15 | abstract class DependencyMapRegistrar |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var EE_Dependency_Map $dependency_map |
|
20 | - */ |
|
21 | - protected $dependency_map; |
|
18 | + /** |
|
19 | + * @var EE_Dependency_Map $dependency_map |
|
20 | + */ |
|
21 | + protected $dependency_map; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var boolean $registered |
|
25 | - */ |
|
26 | - private $registered = false; |
|
23 | + /** |
|
24 | + * @var boolean $registered |
|
25 | + */ |
|
26 | + private $registered = false; |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * DependencyMap constructor. |
|
31 | - * |
|
32 | - * @param EE_Dependency_Map $dependency_map |
|
33 | - */ |
|
34 | - public function __construct(EE_Dependency_Map $dependency_map) |
|
35 | - { |
|
36 | - $this->dependency_map = $dependency_map; |
|
37 | - } |
|
29 | + /** |
|
30 | + * DependencyMap constructor. |
|
31 | + * |
|
32 | + * @param EE_Dependency_Map $dependency_map |
|
33 | + */ |
|
34 | + public function __construct(EE_Dependency_Map $dependency_map) |
|
35 | + { |
|
36 | + $this->dependency_map = $dependency_map; |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * registers concrete classes to be substituted for interfaces |
|
42 | - * ex: |
|
43 | - * $this->dependency_map->add_alias( |
|
44 | - * 'Namespace\path\to\ConcreteClassToInject', // the class name the alias is for |
|
45 | - * 'Namespace\path\to\InterfaceOrAlias', // the class name that would be type hinted for |
|
46 | - * 'Namespace\path\to\ClassWithDependencies' // the class that has the dependency |
|
47 | - * ); |
|
48 | - * |
|
49 | - * @return void |
|
50 | - * @see EE_Dependency_Map::add_alias() |
|
51 | - * @since $VID:$ |
|
52 | - */ |
|
53 | - public function registerClassAliases() |
|
54 | - { |
|
55 | - } |
|
40 | + /** |
|
41 | + * registers concrete classes to be substituted for interfaces |
|
42 | + * ex: |
|
43 | + * $this->dependency_map->add_alias( |
|
44 | + * 'Namespace\path\to\ConcreteClassToInject', // the class name the alias is for |
|
45 | + * 'Namespace\path\to\InterfaceOrAlias', // the class name that would be type hinted for |
|
46 | + * 'Namespace\path\to\ClassWithDependencies' // the class that has the dependency |
|
47 | + * ); |
|
48 | + * |
|
49 | + * @return void |
|
50 | + * @see EE_Dependency_Map::add_alias() |
|
51 | + * @since $VID:$ |
|
52 | + */ |
|
53 | + public function registerClassAliases() |
|
54 | + { |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * registers callbacks for classes that require special loading |
|
60 | - * ex: |
|
61 | - * $this->registerClassLoader( |
|
62 | - * 'Namespace\path\to\ConcreteClassToInject', // name of class that requires a custom loader |
|
63 | - * 'load_core' || static function () { ... } // name of "loader" method on EE_Registry or Closure |
|
64 | - * ); |
|
65 | - * |
|
66 | - * @return void |
|
67 | - * @see EE_Dependency_Map::register_class_loader() |
|
68 | - * @since $VID:$ |
|
69 | - */ |
|
70 | - public function registerClassLoaders() |
|
71 | - { |
|
72 | - } |
|
58 | + /** |
|
59 | + * registers callbacks for classes that require special loading |
|
60 | + * ex: |
|
61 | + * $this->registerClassLoader( |
|
62 | + * 'Namespace\path\to\ConcreteClassToInject', // name of class that requires a custom loader |
|
63 | + * 'load_core' || static function () { ... } // name of "loader" method on EE_Registry or Closure |
|
64 | + * ); |
|
65 | + * |
|
66 | + * @return void |
|
67 | + * @see EE_Dependency_Map::register_class_loader() |
|
68 | + * @since $VID:$ |
|
69 | + */ |
|
70 | + public function registerClassLoaders() |
|
71 | + { |
|
72 | + } |
|
73 | 73 | |
74 | 74 | |
75 | - /** |
|
76 | - * registers dependencies to be injected into a class upon construction |
|
77 | - * ex: |
|
78 | - * $this->registerDependencies($class, $dependencies, $overwrite); |
|
79 | - * 'Namespace\path\to\ConcreteClassToInject', // name of class that requires injected dependencies |
|
80 | - * [ |
|
81 | - * 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
82 | - * 'LoaderInterface' => EE_Dependency_Map::load_from_cache, |
|
83 | - * 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
84 | - * ], // array where keys are FQCNs and values are load sources (new or cached) |
|
85 | - * EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES || EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
86 | - * ); |
|
87 | - * IMPORTANT !!! |
|
88 | - * The order of elements in the incoming $dependencies array MUST match |
|
89 | - * the order of the constructor parameters for the class in question. |
|
90 | - * This is especially important when overriding any existing dependencies that are registered. |
|
91 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
92 | - * |
|
93 | - * @return bool |
|
94 | - * @see EE_Dependency_Map::registerDependencies() |
|
95 | - * @since $VID:$ |
|
96 | - */ |
|
97 | - public function registerDependencies() |
|
98 | - { |
|
99 | - return false; |
|
100 | - } |
|
75 | + /** |
|
76 | + * registers dependencies to be injected into a class upon construction |
|
77 | + * ex: |
|
78 | + * $this->registerDependencies($class, $dependencies, $overwrite); |
|
79 | + * 'Namespace\path\to\ConcreteClassToInject', // name of class that requires injected dependencies |
|
80 | + * [ |
|
81 | + * 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
82 | + * 'LoaderInterface' => EE_Dependency_Map::load_from_cache, |
|
83 | + * 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
84 | + * ], // array where keys are FQCNs and values are load sources (new or cached) |
|
85 | + * EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES || EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
86 | + * ); |
|
87 | + * IMPORTANT !!! |
|
88 | + * The order of elements in the incoming $dependencies array MUST match |
|
89 | + * the order of the constructor parameters for the class in question. |
|
90 | + * This is especially important when overriding any existing dependencies that are registered. |
|
91 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
92 | + * |
|
93 | + * @return bool |
|
94 | + * @see EE_Dependency_Map::registerDependencies() |
|
95 | + * @since $VID:$ |
|
96 | + */ |
|
97 | + public function registerDependencies() |
|
98 | + { |
|
99 | + return false; |
|
100 | + } |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * @since $VID:$ |
|
105 | - */ |
|
106 | - public function register() |
|
107 | - { |
|
108 | - if ($this->registered) { |
|
109 | - return; |
|
110 | - } |
|
111 | - // \EEH_Debug_Tools::printr(get_called_class(), __FUNCTION__, __FILE__, __LINE__); |
|
112 | - $this->registerClassAliases(); |
|
113 | - $this->registerClassLoaders(); |
|
114 | - $this->registered = $this->registerDependencies(); |
|
115 | - } |
|
103 | + /** |
|
104 | + * @since $VID:$ |
|
105 | + */ |
|
106 | + public function register() |
|
107 | + { |
|
108 | + if ($this->registered) { |
|
109 | + return; |
|
110 | + } |
|
111 | + // \EEH_Debug_Tools::printr(get_called_class(), __FUNCTION__, __FILE__, __LINE__); |
|
112 | + $this->registerClassAliases(); |
|
113 | + $this->registerClassLoaders(); |
|
114 | + $this->registered = $this->registerDependencies(); |
|
115 | + } |
|
116 | 116 | } |
@@ -23,42 +23,42 @@ |
||
23 | 23 | class LocalDependencyMapFactory extends FactoryWithDependencyResolver |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * RouteFactory constructor |
|
28 | - * |
|
29 | - * @param DependencyResolver $dependency_resolver |
|
30 | - * @param LoaderInterface $loader |
|
31 | - */ |
|
32 | - public function __construct(DependencyResolver $dependency_resolver, LoaderInterface $loader) |
|
33 | - { |
|
34 | - parent::__construct($dependency_resolver, $loader); |
|
35 | - } |
|
26 | + /** |
|
27 | + * RouteFactory constructor |
|
28 | + * |
|
29 | + * @param DependencyResolver $dependency_resolver |
|
30 | + * @param LoaderInterface $loader |
|
31 | + */ |
|
32 | + public function __construct(DependencyResolver $dependency_resolver, LoaderInterface $loader) |
|
33 | + { |
|
34 | + parent::__construct($dependency_resolver, $loader); |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * @param $fqcn |
|
40 | - * @return Route |
|
41 | - * @since 4.9.71.p |
|
42 | - */ |
|
43 | - public function createRoute($fqcn) |
|
44 | - { |
|
45 | - $this->dependencyResolver()->resolveDependenciesForClass($fqcn); |
|
46 | - return $this->loader()->getShared($fqcn); |
|
47 | - } |
|
38 | + /** |
|
39 | + * @param $fqcn |
|
40 | + * @return Route |
|
41 | + * @since 4.9.71.p |
|
42 | + */ |
|
43 | + public function createRoute($fqcn) |
|
44 | + { |
|
45 | + $this->dependencyResolver()->resolveDependenciesForClass($fqcn); |
|
46 | + return $this->loader()->getShared($fqcn); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @param $fqcn |
|
52 | - * @return Route |
|
53 | - * @throws InvalidArgumentException |
|
54 | - * @throws InvalidDataTypeException |
|
55 | - * @throws InvalidInterfaceException |
|
56 | - * @since 4.9.71.p |
|
57 | - */ |
|
58 | - public static function create($fqcn) |
|
59 | - { |
|
60 | - /** @var LocalDependencyMapFactory $local_dependency_map_factory */ |
|
61 | - $local_dependency_map_factory = LoaderFactory::getLoader()->getShared(LocalDependencyMapFactory::class); |
|
62 | - return $local_dependency_map_factory->createRoute($fqcn); |
|
63 | - } |
|
50 | + /** |
|
51 | + * @param $fqcn |
|
52 | + * @return Route |
|
53 | + * @throws InvalidArgumentException |
|
54 | + * @throws InvalidDataTypeException |
|
55 | + * @throws InvalidInterfaceException |
|
56 | + * @since 4.9.71.p |
|
57 | + */ |
|
58 | + public static function create($fqcn) |
|
59 | + { |
|
60 | + /** @var LocalDependencyMapFactory $local_dependency_map_factory */ |
|
61 | + $local_dependency_map_factory = LoaderFactory::getLoader()->getShared(LocalDependencyMapFactory::class); |
|
62 | + return $local_dependency_map_factory->createRoute($fqcn); |
|
63 | + } |
|
64 | 64 | } |
@@ -23,168 +23,168 @@ |
||
23 | 23 | class DependencyResolver implements DependencyResolverInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var Mirror $mirror |
|
28 | - */ |
|
29 | - private $mirror; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var ClassInterfaceCache $class_cache |
|
33 | - */ |
|
34 | - private $class_cache; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var EE_Dependency_Map $dependency_map |
|
38 | - */ |
|
39 | - private $dependency_map; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var ClassAlias[] $aliases |
|
43 | - */ |
|
44 | - protected $aliases = array(); |
|
45 | - |
|
46 | - /** |
|
47 | - * @var array $namespace_roots |
|
48 | - */ |
|
49 | - protected $namespace_roots = array(); |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * RouteMatchSpecificationDependencyResolver constructor. |
|
54 | - * |
|
55 | - * @param Mirror $mirror |
|
56 | - * @param ClassInterfaceCache $class_cache |
|
57 | - * @param EE_Dependency_Map $dependency_map |
|
58 | - */ |
|
59 | - public function __construct( |
|
60 | - Mirror $mirror, |
|
61 | - ClassInterfaceCache $class_cache, |
|
62 | - EE_Dependency_Map $dependency_map |
|
63 | - ) { |
|
64 | - $this->mirror = $mirror; |
|
65 | - $this->class_cache = $class_cache; |
|
66 | - $this->dependency_map = $dependency_map; |
|
67 | - $this->initialize(); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * Used to configure and/or setup any aliases or namespace roots required by the DependencyResolver |
|
73 | - * |
|
74 | - * @throws InvalidAliasException |
|
75 | - * @since 4.9.71.p |
|
76 | - */ |
|
77 | - public function initialize() |
|
78 | - { |
|
79 | - // nothing to do here for default resolver |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @return Mirror |
|
85 | - */ |
|
86 | - public function mirror() |
|
87 | - { |
|
88 | - return $this->mirror; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @return ClassInterfaceCache |
|
93 | - */ |
|
94 | - public function classCache() |
|
95 | - { |
|
96 | - return $this->class_cache; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @return EE_Dependency_Map |
|
101 | - */ |
|
102 | - public function dependencyMap() |
|
103 | - { |
|
104 | - return $this->dependency_map; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
109 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
110 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
111 | - * @throws InvalidAliasException |
|
112 | - */ |
|
113 | - public function addAlias($fqcn, $alias, $for_class = '') |
|
114 | - { |
|
115 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public function resolveAlias($param_fqcn) |
|
123 | - { |
|
124 | - return $this->class_cache->getFqnForAlias($param_fqcn); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Primarily used to indicate the namespace root for composite objects |
|
129 | - * so that dependencies requiring the same DependencyResolver can be acquired |
|
130 | - * for example: |
|
131 | - * Vendor\path\to\class\A, Vendor\path\to\class\B, and Vendor\path\to\class\C |
|
132 | - * may all implement Vendor\path\to\Interface, |
|
133 | - * but Vendor\path\to\class\C could be a composite object |
|
134 | - * that requires Vendor\path\to\class\A and Vendor\path\to\class\B, |
|
135 | - * and needs both of those dependencies resolved, which would therefore require |
|
136 | - * the use of the same DependencyResolver. |
|
137 | - * |
|
138 | - * By specifying a namespace root of "Vendor\path\to\", |
|
139 | - * then all classes that are descendants of that namespace |
|
140 | - * will use DependencyResolver to acquire the classes they need |
|
141 | - * |
|
142 | - * @param string $namespace_root Partial namespace used for detecting other classes |
|
143 | - * that should employ this same DependencyResolver |
|
144 | - */ |
|
145 | - public function addNamespaceRoot($namespace_root) |
|
146 | - { |
|
147 | - $this->namespace_roots[] = $namespace_root; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Returns true if the parameter FQCN belongs to one of |
|
152 | - * the namespaces that utilizes this DependencyResolver |
|
153 | - * |
|
154 | - * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
155 | - * @return boolean |
|
156 | - * @since 4.9.71.p |
|
157 | - */ |
|
158 | - public function dependencyRecursionExists($param_fqcn) |
|
159 | - { |
|
160 | - foreach ($this->namespace_roots as $namespace_root) { |
|
161 | - if (strpos($param_fqcn, $namespace_root) !== false) { |
|
162 | - return true; |
|
163 | - } |
|
164 | - } |
|
165 | - return false; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @param string $fqcn Fully Qualified Class Name |
|
171 | - * @throws InvalidDataTypeException |
|
172 | - * @throws ReflectionException |
|
173 | - * @since 4.9.71.p |
|
174 | - */ |
|
175 | - public function resolveDependenciesForClass($fqcn) |
|
176 | - { |
|
177 | - $dependencies = array(); |
|
178 | - $params = $this->mirror()->getParameters($fqcn); |
|
179 | - foreach ($params as $index => $param) { |
|
180 | - // is this a dependency for a specific class ? |
|
181 | - $param_class = $this->mirror()->getParameterClassName($param, $fqcn, $index); |
|
182 | - if ($this->dependencyRecursionExists($param_class)) { |
|
183 | - $this->resolveDependenciesForClass($param_class); |
|
184 | - } |
|
185 | - $param_class = $this->resolveAlias($param_class); |
|
186 | - $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache; |
|
187 | - } |
|
188 | - $this->dependencyMap()->registerDependencies($fqcn, $dependencies); |
|
189 | - } |
|
26 | + /** |
|
27 | + * @var Mirror $mirror |
|
28 | + */ |
|
29 | + private $mirror; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var ClassInterfaceCache $class_cache |
|
33 | + */ |
|
34 | + private $class_cache; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var EE_Dependency_Map $dependency_map |
|
38 | + */ |
|
39 | + private $dependency_map; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var ClassAlias[] $aliases |
|
43 | + */ |
|
44 | + protected $aliases = array(); |
|
45 | + |
|
46 | + /** |
|
47 | + * @var array $namespace_roots |
|
48 | + */ |
|
49 | + protected $namespace_roots = array(); |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * RouteMatchSpecificationDependencyResolver constructor. |
|
54 | + * |
|
55 | + * @param Mirror $mirror |
|
56 | + * @param ClassInterfaceCache $class_cache |
|
57 | + * @param EE_Dependency_Map $dependency_map |
|
58 | + */ |
|
59 | + public function __construct( |
|
60 | + Mirror $mirror, |
|
61 | + ClassInterfaceCache $class_cache, |
|
62 | + EE_Dependency_Map $dependency_map |
|
63 | + ) { |
|
64 | + $this->mirror = $mirror; |
|
65 | + $this->class_cache = $class_cache; |
|
66 | + $this->dependency_map = $dependency_map; |
|
67 | + $this->initialize(); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * Used to configure and/or setup any aliases or namespace roots required by the DependencyResolver |
|
73 | + * |
|
74 | + * @throws InvalidAliasException |
|
75 | + * @since 4.9.71.p |
|
76 | + */ |
|
77 | + public function initialize() |
|
78 | + { |
|
79 | + // nothing to do here for default resolver |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @return Mirror |
|
85 | + */ |
|
86 | + public function mirror() |
|
87 | + { |
|
88 | + return $this->mirror; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @return ClassInterfaceCache |
|
93 | + */ |
|
94 | + public function classCache() |
|
95 | + { |
|
96 | + return $this->class_cache; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @return EE_Dependency_Map |
|
101 | + */ |
|
102 | + public function dependencyMap() |
|
103 | + { |
|
104 | + return $this->dependency_map; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
109 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
110 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
111 | + * @throws InvalidAliasException |
|
112 | + */ |
|
113 | + public function addAlias($fqcn, $alias, $for_class = '') |
|
114 | + { |
|
115 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public function resolveAlias($param_fqcn) |
|
123 | + { |
|
124 | + return $this->class_cache->getFqnForAlias($param_fqcn); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Primarily used to indicate the namespace root for composite objects |
|
129 | + * so that dependencies requiring the same DependencyResolver can be acquired |
|
130 | + * for example: |
|
131 | + * Vendor\path\to\class\A, Vendor\path\to\class\B, and Vendor\path\to\class\C |
|
132 | + * may all implement Vendor\path\to\Interface, |
|
133 | + * but Vendor\path\to\class\C could be a composite object |
|
134 | + * that requires Vendor\path\to\class\A and Vendor\path\to\class\B, |
|
135 | + * and needs both of those dependencies resolved, which would therefore require |
|
136 | + * the use of the same DependencyResolver. |
|
137 | + * |
|
138 | + * By specifying a namespace root of "Vendor\path\to\", |
|
139 | + * then all classes that are descendants of that namespace |
|
140 | + * will use DependencyResolver to acquire the classes they need |
|
141 | + * |
|
142 | + * @param string $namespace_root Partial namespace used for detecting other classes |
|
143 | + * that should employ this same DependencyResolver |
|
144 | + */ |
|
145 | + public function addNamespaceRoot($namespace_root) |
|
146 | + { |
|
147 | + $this->namespace_roots[] = $namespace_root; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Returns true if the parameter FQCN belongs to one of |
|
152 | + * the namespaces that utilizes this DependencyResolver |
|
153 | + * |
|
154 | + * @param string $param_fqcn Fully Qualified Class Name for dependency parameter |
|
155 | + * @return boolean |
|
156 | + * @since 4.9.71.p |
|
157 | + */ |
|
158 | + public function dependencyRecursionExists($param_fqcn) |
|
159 | + { |
|
160 | + foreach ($this->namespace_roots as $namespace_root) { |
|
161 | + if (strpos($param_fqcn, $namespace_root) !== false) { |
|
162 | + return true; |
|
163 | + } |
|
164 | + } |
|
165 | + return false; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @param string $fqcn Fully Qualified Class Name |
|
171 | + * @throws InvalidDataTypeException |
|
172 | + * @throws ReflectionException |
|
173 | + * @since 4.9.71.p |
|
174 | + */ |
|
175 | + public function resolveDependenciesForClass($fqcn) |
|
176 | + { |
|
177 | + $dependencies = array(); |
|
178 | + $params = $this->mirror()->getParameters($fqcn); |
|
179 | + foreach ($params as $index => $param) { |
|
180 | + // is this a dependency for a specific class ? |
|
181 | + $param_class = $this->mirror()->getParameterClassName($param, $fqcn, $index); |
|
182 | + if ($this->dependencyRecursionExists($param_class)) { |
|
183 | + $this->resolveDependenciesForClass($param_class); |
|
184 | + } |
|
185 | + $param_class = $this->resolveAlias($param_class); |
|
186 | + $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache; |
|
187 | + } |
|
188 | + $this->dependencyMap()->registerDependencies($fqcn, $dependencies); |
|
189 | + } |
|
190 | 190 | } |
@@ -183,7 +183,7 @@ |
||
183 | 183 | $this->resolveDependenciesForClass($param_class); |
184 | 184 | } |
185 | 185 | $param_class = $this->resolveAlias($param_class); |
186 | - $dependencies[ $param_class ] = EE_Dependency_Map::load_from_cache; |
|
186 | + $dependencies[$param_class] = EE_Dependency_Map::load_from_cache; |
|
187 | 187 | } |
188 | 188 | $this->dependencyMap()->registerDependencies($fqcn, $dependencies); |
189 | 189 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | public static function instance(ClassInterfaceCache $class_cache = null) |
126 | 126 | { |
127 | 127 | // check if class object is instantiated, and instantiated properly |
128 | - if (! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map |
|
128 | + if ( ! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map |
|
129 | 129 | && $class_cache instanceof ClassInterfaceCache |
130 | 130 | ) { |
131 | 131 | EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache); |
@@ -206,18 +206,18 @@ discard block |
||
206 | 206 | ) { |
207 | 207 | $class = trim($class, '\\'); |
208 | 208 | $registered = false; |
209 | - if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) { |
|
210 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = array(); |
|
209 | + if (empty(EE_Dependency_Map::$_instance->_dependency_map[$class])) { |
|
210 | + EE_Dependency_Map::$_instance->_dependency_map[$class] = array(); |
|
211 | 211 | } |
212 | 212 | // we need to make sure that any aliases used when registering a dependency |
213 | 213 | // get resolved to the correct class name |
214 | 214 | foreach ($dependencies as $dependency => $load_source) { |
215 | 215 | $alias = EE_Dependency_Map::$_instance->getFqnForAlias($dependency); |
216 | 216 | if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
217 | - || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ]) |
|
217 | + || ! isset(EE_Dependency_Map::$_instance->_dependency_map[$class][$alias]) |
|
218 | 218 | ) { |
219 | - unset($dependencies[ $dependency ]); |
|
220 | - $dependencies[ $alias ] = $load_source; |
|
219 | + unset($dependencies[$dependency]); |
|
220 | + $dependencies[$alias] = $load_source; |
|
221 | 221 | $registered = true; |
222 | 222 | } |
223 | 223 | } |
@@ -227,13 +227,13 @@ discard block |
||
227 | 227 | // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
228 | 228 | // Union is way faster than array_merge() but should be used with caution... |
229 | 229 | // especially with numerically indexed arrays |
230 | - $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ]; |
|
230 | + $dependencies += EE_Dependency_Map::$_instance->_dependency_map[$class]; |
|
231 | 231 | // now we need to ensure that the resulting dependencies |
232 | 232 | // array only has the entries that are required for the class |
233 | 233 | // so first count how many dependencies were originally registered for the class |
234 | - $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]); |
|
234 | + $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[$class]); |
|
235 | 235 | // if that count is non-zero (meaning dependencies were already registered) |
236 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count |
|
236 | + EE_Dependency_Map::$_instance->_dependency_map[$class] = $dependency_count |
|
237 | 237 | // then truncate the final array to match that count |
238 | 238 | ? array_slice($dependencies, 0, $dependency_count) |
239 | 239 | // otherwise just take the incoming array because nothing previously existed |
@@ -262,13 +262,13 @@ discard block |
||
262 | 262 | */ |
263 | 263 | public function registerClassLoader($class_name, $loader = 'load_core') |
264 | 264 | { |
265 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
265 | + if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
266 | 266 | throw new DomainException( |
267 | 267 | esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
268 | 268 | ); |
269 | 269 | } |
270 | 270 | // check that loader is callable or method starts with "load_" and exists in EE_Registry |
271 | - if (! is_callable($loader) |
|
271 | + if ( ! is_callable($loader) |
|
272 | 272 | && ( |
273 | 273 | strpos($loader, 'load_') !== 0 |
274 | 274 | || ! method_exists('EE_Registry', $loader) |
@@ -285,8 +285,8 @@ discard block |
||
285 | 285 | ); |
286 | 286 | } |
287 | 287 | $class_name = EE_Dependency_Map::$_instance->getFqnForAlias($class_name); |
288 | - if (! isset(EE_Dependency_Map::$_instance->_class_loaders[ $class_name ])) { |
|
289 | - EE_Dependency_Map::$_instance->_class_loaders[ $class_name ] = $loader; |
|
288 | + if ( ! isset(EE_Dependency_Map::$_instance->_class_loaders[$class_name])) { |
|
289 | + EE_Dependency_Map::$_instance->_class_loaders[$class_name] = $loader; |
|
290 | 290 | return true; |
291 | 291 | } |
292 | 292 | return false; |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | if (strpos($class_name, 'EEM_') === 0) { |
315 | 315 | $class_name = 'LEGACY_MODELS'; |
316 | 316 | } |
317 | - return isset($this->_dependency_map[ $class_name ]); |
|
317 | + return isset($this->_dependency_map[$class_name]); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | $class_name = 'LEGACY_MODELS'; |
333 | 333 | } |
334 | 334 | $dependency = $this->getFqnForAlias($dependency, $class_name); |
335 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
335 | + return isset($this->_dependency_map[$class_name][$dependency]); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | } |
352 | 352 | $dependency = $this->getFqnForAlias($dependency); |
353 | 353 | return $this->has_dependency_for_class($class_name, $dependency) |
354 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
354 | + ? $this->_dependency_map[$class_name][$dependency] |
|
355 | 355 | : EE_Dependency_Map::not_registered; |
356 | 356 | } |
357 | 357 | |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | return 'load_core'; |
375 | 375 | } |
376 | 376 | $class_name = $this->getFqnForAlias($class_name); |
377 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
377 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | { |
756 | 756 | $this->_class_loaders = array( |
757 | 757 | // load_core |
758 | - 'EE_Dependency_Map' => function () { |
|
758 | + 'EE_Dependency_Map' => function() { |
|
759 | 759 | return $this; |
760 | 760 | }, |
761 | 761 | 'EE_Capabilities' => 'load_core', |
@@ -763,13 +763,13 @@ discard block |
||
763 | 763 | 'EE_Front_Controller' => 'load_core', |
764 | 764 | 'EE_Module_Request_Router' => 'load_core', |
765 | 765 | 'EE_Registry' => 'load_core', |
766 | - 'EE_Request' => function () { |
|
766 | + 'EE_Request' => function() { |
|
767 | 767 | return $this->legacy_request; |
768 | 768 | }, |
769 | - 'EventEspresso\core\services\request\Request' => function () { |
|
769 | + 'EventEspresso\core\services\request\Request' => function() { |
|
770 | 770 | return $this->request; |
771 | 771 | }, |
772 | - 'EventEspresso\core\services\request\Response' => function () { |
|
772 | + 'EventEspresso\core\services\request\Response' => function() { |
|
773 | 773 | return $this->response; |
774 | 774 | }, |
775 | 775 | 'EE_Base' => 'load_core', |
@@ -804,7 +804,7 @@ discard block |
||
804 | 804 | 'EE_DMS_Core_4_8_0' => 'load_dms', |
805 | 805 | 'EE_DMS_Core_4_9_0' => 'load_dms', |
806 | 806 | 'EE_DMS_Core_4_10_0' => 'load_dms', |
807 | - 'EE_Messages_Generator' => static function () { |
|
807 | + 'EE_Messages_Generator' => static function() { |
|
808 | 808 | return EE_Registry::instance()->load_lib( |
809 | 809 | 'Messages_Generator', |
810 | 810 | array(), |
@@ -812,7 +812,7 @@ discard block |
||
812 | 812 | false |
813 | 813 | ); |
814 | 814 | }, |
815 | - 'EE_Messages_Template_Defaults' => static function ($arguments = array()) { |
|
815 | + 'EE_Messages_Template_Defaults' => static function($arguments = array()) { |
|
816 | 816 | return EE_Registry::instance()->load_lib( |
817 | 817 | 'Messages_Template_Defaults', |
818 | 818 | $arguments, |
@@ -821,52 +821,52 @@ discard block |
||
821 | 821 | ); |
822 | 822 | }, |
823 | 823 | // load_helper |
824 | - 'EEH_Parse_Shortcodes' => static function () { |
|
824 | + 'EEH_Parse_Shortcodes' => static function() { |
|
825 | 825 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
826 | 826 | return new EEH_Parse_Shortcodes(); |
827 | 827 | } |
828 | 828 | return null; |
829 | 829 | }, |
830 | - 'EE_Template_Config' => static function () { |
|
830 | + 'EE_Template_Config' => static function() { |
|
831 | 831 | return EE_Config::instance()->template_settings; |
832 | 832 | }, |
833 | - 'EE_Currency_Config' => static function () { |
|
833 | + 'EE_Currency_Config' => static function() { |
|
834 | 834 | return EE_Config::instance()->currency; |
835 | 835 | }, |
836 | - 'EE_Registration_Config' => static function () { |
|
836 | + 'EE_Registration_Config' => static function() { |
|
837 | 837 | return EE_Config::instance()->registration; |
838 | 838 | }, |
839 | - 'EE_Core_Config' => static function () { |
|
839 | + 'EE_Core_Config' => static function() { |
|
840 | 840 | return EE_Config::instance()->core; |
841 | 841 | }, |
842 | - 'EventEspresso\core\services\loaders\Loader' => static function () { |
|
842 | + 'EventEspresso\core\services\loaders\Loader' => static function() { |
|
843 | 843 | return LoaderFactory::getLoader(); |
844 | 844 | }, |
845 | - 'EE_Network_Config' => static function () { |
|
845 | + 'EE_Network_Config' => static function() { |
|
846 | 846 | return EE_Network_Config::instance(); |
847 | 847 | }, |
848 | - 'EE_Config' => static function () { |
|
848 | + 'EE_Config' => static function() { |
|
849 | 849 | return EE_Config::instance(); |
850 | 850 | }, |
851 | - 'EventEspresso\core\domain\Domain' => static function () { |
|
851 | + 'EventEspresso\core\domain\Domain' => static function() { |
|
852 | 852 | return DomainFactory::getEventEspressoCoreDomain(); |
853 | 853 | }, |
854 | - 'EE_Admin_Config' => static function () { |
|
854 | + 'EE_Admin_Config' => static function() { |
|
855 | 855 | return EE_Config::instance()->admin; |
856 | 856 | }, |
857 | - 'EE_Organization_Config' => static function () { |
|
857 | + 'EE_Organization_Config' => static function() { |
|
858 | 858 | return EE_Config::instance()->organization; |
859 | 859 | }, |
860 | - 'EE_Network_Core_Config' => static function () { |
|
860 | + 'EE_Network_Core_Config' => static function() { |
|
861 | 861 | return EE_Network_Config::instance()->core; |
862 | 862 | }, |
863 | - 'EE_Environment_Config' => static function () { |
|
863 | + 'EE_Environment_Config' => static function() { |
|
864 | 864 | return EE_Config::instance()->environment; |
865 | 865 | }, |
866 | - 'EED_Core_Rest_Api' => static function () { |
|
866 | + 'EED_Core_Rest_Api' => static function() { |
|
867 | 867 | return EED_Core_Rest_Api::instance(); |
868 | 868 | }, |
869 | - 'WP_REST_Server' => static function () { |
|
869 | + 'WP_REST_Server' => static function() { |
|
870 | 870 | return rest_get_server(); |
871 | 871 | }, |
872 | 872 | ); |
@@ -930,7 +930,7 @@ discard block |
||
930 | 930 | } |
931 | 931 | $this->class_cache->addAlias($fqn, $alias); |
932 | 932 | } |
933 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
933 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
934 | 934 | $this->class_cache->addAlias( |
935 | 935 | 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
936 | 936 | 'EventEspresso\core\services\notices\NoticeConverterInterface' |
@@ -21,981 +21,981 @@ |
||
21 | 21 | class EE_Dependency_Map |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * This means that the requested class dependency is not present in the dependency map |
|
26 | - */ |
|
27 | - const not_registered = 0; |
|
28 | - |
|
29 | - /** |
|
30 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
31 | - */ |
|
32 | - const load_new_object = 1; |
|
33 | - |
|
34 | - /** |
|
35 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
36 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
37 | - */ |
|
38 | - const load_from_cache = 2; |
|
39 | - |
|
40 | - /** |
|
41 | - * When registering a dependency, |
|
42 | - * this indicates to keep any existing dependencies that already exist, |
|
43 | - * and simply discard any new dependencies declared in the incoming data |
|
44 | - */ |
|
45 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
46 | - |
|
47 | - /** |
|
48 | - * When registering a dependency, |
|
49 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
50 | - */ |
|
51 | - const OVERWRITE_DEPENDENCIES = 1; |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @type EE_Dependency_Map $_instance |
|
56 | - */ |
|
57 | - protected static $_instance; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var ClassInterfaceCache $class_cache |
|
61 | - */ |
|
62 | - private $class_cache; |
|
63 | - |
|
64 | - /** |
|
65 | - * @type RequestInterface $request |
|
66 | - */ |
|
67 | - protected $request; |
|
68 | - |
|
69 | - /** |
|
70 | - * @type LegacyRequestInterface $legacy_request |
|
71 | - */ |
|
72 | - protected $legacy_request; |
|
73 | - |
|
74 | - /** |
|
75 | - * @type ResponseInterface $response |
|
76 | - */ |
|
77 | - protected $response; |
|
78 | - |
|
79 | - /** |
|
80 | - * @type LoaderInterface $loader |
|
81 | - */ |
|
82 | - protected $loader; |
|
83 | - |
|
84 | - /** |
|
85 | - * @type array $_dependency_map |
|
86 | - */ |
|
87 | - protected $_dependency_map = array(); |
|
88 | - |
|
89 | - /** |
|
90 | - * @type array $_class_loaders |
|
91 | - */ |
|
92 | - protected $_class_loaders = array(); |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * EE_Dependency_Map constructor. |
|
97 | - * |
|
98 | - * @param ClassInterfaceCache $class_cache |
|
99 | - */ |
|
100 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
101 | - { |
|
102 | - $this->class_cache = $class_cache; |
|
103 | - do_action('EE_Dependency_Map____construct', $this); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @return void |
|
109 | - * @throws EE_Error |
|
110 | - * @throws InvalidAliasException |
|
111 | - */ |
|
112 | - public function initialize() |
|
113 | - { |
|
114 | - $this->_register_core_dependencies(); |
|
115 | - $this->_register_core_class_loaders(); |
|
116 | - $this->_register_core_aliases(); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * @singleton method used to instantiate class object |
|
122 | - * @param ClassInterfaceCache|null $class_cache |
|
123 | - * @return EE_Dependency_Map |
|
124 | - */ |
|
125 | - public static function instance(ClassInterfaceCache $class_cache = null) |
|
126 | - { |
|
127 | - // check if class object is instantiated, and instantiated properly |
|
128 | - if (! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map |
|
129 | - && $class_cache instanceof ClassInterfaceCache |
|
130 | - ) { |
|
131 | - EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache); |
|
132 | - } |
|
133 | - return EE_Dependency_Map::$_instance; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param RequestInterface $request |
|
139 | - */ |
|
140 | - public function setRequest(RequestInterface $request) |
|
141 | - { |
|
142 | - $this->request = $request; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @param LegacyRequestInterface $legacy_request |
|
148 | - */ |
|
149 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
150 | - { |
|
151 | - $this->legacy_request = $legacy_request; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @param ResponseInterface $response |
|
157 | - */ |
|
158 | - public function setResponse(ResponseInterface $response) |
|
159 | - { |
|
160 | - $this->response = $response; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * @param LoaderInterface $loader |
|
166 | - */ |
|
167 | - public function setLoader(LoaderInterface $loader) |
|
168 | - { |
|
169 | - $this->loader = $loader; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * @param string $class |
|
175 | - * @param array $dependencies |
|
176 | - * @param int $overwrite |
|
177 | - * @return bool |
|
178 | - */ |
|
179 | - public static function register_dependencies( |
|
180 | - $class, |
|
181 | - array $dependencies, |
|
182 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
183 | - ) { |
|
184 | - return EE_Dependency_Map::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
190 | - * to the class specified by the first parameter. |
|
191 | - * IMPORTANT !!! |
|
192 | - * The order of elements in the incoming $dependencies array MUST match |
|
193 | - * the order of the constructor parameters for the class in question. |
|
194 | - * This is especially important when overriding any existing dependencies that are registered. |
|
195 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
196 | - * |
|
197 | - * @param string $class |
|
198 | - * @param array $dependencies |
|
199 | - * @param int $overwrite |
|
200 | - * @return bool |
|
201 | - */ |
|
202 | - public function registerDependencies( |
|
203 | - $class, |
|
204 | - array $dependencies, |
|
205 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
206 | - ) { |
|
207 | - $class = trim($class, '\\'); |
|
208 | - $registered = false; |
|
209 | - if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) { |
|
210 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = array(); |
|
211 | - } |
|
212 | - // we need to make sure that any aliases used when registering a dependency |
|
213 | - // get resolved to the correct class name |
|
214 | - foreach ($dependencies as $dependency => $load_source) { |
|
215 | - $alias = EE_Dependency_Map::$_instance->getFqnForAlias($dependency); |
|
216 | - if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
217 | - || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ]) |
|
218 | - ) { |
|
219 | - unset($dependencies[ $dependency ]); |
|
220 | - $dependencies[ $alias ] = $load_source; |
|
221 | - $registered = true; |
|
222 | - } |
|
223 | - } |
|
224 | - // now add our two lists of dependencies together. |
|
225 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
226 | - // so $dependencies is NOT overwritten because it is listed first |
|
227 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
228 | - // Union is way faster than array_merge() but should be used with caution... |
|
229 | - // especially with numerically indexed arrays |
|
230 | - $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ]; |
|
231 | - // now we need to ensure that the resulting dependencies |
|
232 | - // array only has the entries that are required for the class |
|
233 | - // so first count how many dependencies were originally registered for the class |
|
234 | - $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]); |
|
235 | - // if that count is non-zero (meaning dependencies were already registered) |
|
236 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count |
|
237 | - // then truncate the final array to match that count |
|
238 | - ? array_slice($dependencies, 0, $dependency_count) |
|
239 | - // otherwise just take the incoming array because nothing previously existed |
|
240 | - : $dependencies; |
|
241 | - return $registered; |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * @param string $class_name |
|
247 | - * @param string $loader |
|
248 | - * @return bool |
|
249 | - * @throws DomainException |
|
250 | - */ |
|
251 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
252 | - { |
|
253 | - return EE_Dependency_Map::$_instance->registerClassLoader($class_name, $loader); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * @param string $class_name |
|
259 | - * @param string $loader |
|
260 | - * @return bool |
|
261 | - * @throws DomainException |
|
262 | - */ |
|
263 | - public function registerClassLoader($class_name, $loader = 'load_core') |
|
264 | - { |
|
265 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
266 | - throw new DomainException( |
|
267 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
268 | - ); |
|
269 | - } |
|
270 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
271 | - if (! is_callable($loader) |
|
272 | - && ( |
|
273 | - strpos($loader, 'load_') !== 0 |
|
274 | - || ! method_exists('EE_Registry', $loader) |
|
275 | - ) |
|
276 | - ) { |
|
277 | - throw new DomainException( |
|
278 | - sprintf( |
|
279 | - esc_html__( |
|
280 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
281 | - 'event_espresso' |
|
282 | - ), |
|
283 | - $loader |
|
284 | - ) |
|
285 | - ); |
|
286 | - } |
|
287 | - $class_name = EE_Dependency_Map::$_instance->getFqnForAlias($class_name); |
|
288 | - if (! isset(EE_Dependency_Map::$_instance->_class_loaders[ $class_name ])) { |
|
289 | - EE_Dependency_Map::$_instance->_class_loaders[ $class_name ] = $loader; |
|
290 | - return true; |
|
291 | - } |
|
292 | - return false; |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * @return array |
|
298 | - */ |
|
299 | - public function dependency_map() |
|
300 | - { |
|
301 | - return $this->_dependency_map; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
307 | - * |
|
308 | - * @param string $class_name |
|
309 | - * @return boolean |
|
310 | - */ |
|
311 | - public function has($class_name = '') |
|
312 | - { |
|
313 | - // all legacy models have the same dependencies |
|
314 | - if (strpos($class_name, 'EEM_') === 0) { |
|
315 | - $class_name = 'LEGACY_MODELS'; |
|
316 | - } |
|
317 | - return isset($this->_dependency_map[ $class_name ]); |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
323 | - * |
|
324 | - * @param string $class_name |
|
325 | - * @param string $dependency |
|
326 | - * @return bool |
|
327 | - */ |
|
328 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
329 | - { |
|
330 | - // all legacy models have the same dependencies |
|
331 | - if (strpos($class_name, 'EEM_') === 0) { |
|
332 | - $class_name = 'LEGACY_MODELS'; |
|
333 | - } |
|
334 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
335 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
341 | - * |
|
342 | - * @param string $class_name |
|
343 | - * @param string $dependency |
|
344 | - * @return int |
|
345 | - */ |
|
346 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
347 | - { |
|
348 | - // all legacy models have the same dependencies |
|
349 | - if (strpos($class_name, 'EEM_') === 0) { |
|
350 | - $class_name = 'LEGACY_MODELS'; |
|
351 | - } |
|
352 | - $dependency = $this->getFqnForAlias($dependency); |
|
353 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
354 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
355 | - : EE_Dependency_Map::not_registered; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * @param string $class_name |
|
361 | - * @return string | Closure |
|
362 | - */ |
|
363 | - public function class_loader($class_name) |
|
364 | - { |
|
365 | - // all legacy models use load_model() |
|
366 | - if (strpos($class_name, 'EEM_') === 0) { |
|
367 | - return 'load_model'; |
|
368 | - } |
|
369 | - // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
370 | - // perform strpos() first to avoid loading regex every time we load a class |
|
371 | - if (strpos($class_name, 'EE_CPT_') === 0 |
|
372 | - && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
373 | - ) { |
|
374 | - return 'load_core'; |
|
375 | - } |
|
376 | - $class_name = $this->getFqnForAlias($class_name); |
|
377 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * @return array |
|
383 | - */ |
|
384 | - public function class_loaders() |
|
385 | - { |
|
386 | - return $this->_class_loaders; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * adds an alias for a classname |
|
392 | - * |
|
393 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
394 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
395 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
396 | - * @return bool |
|
397 | - * @throws InvalidAliasException |
|
398 | - */ |
|
399 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
400 | - { |
|
401 | - return $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
407 | - * WHY? |
|
408 | - * Because if a class is type hinting for a concretion, |
|
409 | - * then why would we need to find another class to supply it? |
|
410 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
411 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
412 | - * Don't go looking for some substitute. |
|
413 | - * Whereas if a class is type hinting for an interface... |
|
414 | - * then we need to find an actual class to use. |
|
415 | - * So the interface IS the alias for some other FQN, |
|
416 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
417 | - * represents some other class. |
|
418 | - * |
|
419 | - * @param string $fqn |
|
420 | - * @param string $for_class |
|
421 | - * @return bool |
|
422 | - */ |
|
423 | - public function isAlias($fqn = '', $for_class = '') |
|
424 | - { |
|
425 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
431 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
432 | - * for example: |
|
433 | - * if the following two entries were added to the _aliases array: |
|
434 | - * array( |
|
435 | - * 'interface_alias' => 'some\namespace\interface' |
|
436 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
437 | - * ) |
|
438 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
439 | - * to load an instance of 'some\namespace\classname' |
|
440 | - * |
|
441 | - * @param string $alias |
|
442 | - * @param string $for_class |
|
443 | - * @return string |
|
444 | - */ |
|
445 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
446 | - { |
|
447 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
453 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
454 | - * This is done by using the following class constants: |
|
455 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
456 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
457 | - */ |
|
458 | - protected function _register_core_dependencies() |
|
459 | - { |
|
460 | - $this->_dependency_map = array( |
|
461 | - 'EE_Request_Handler' => array( |
|
462 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
463 | - ), |
|
464 | - 'EE_System' => array( |
|
465 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
466 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
467 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
468 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
469 | - ), |
|
470 | - 'EE_Cart' => array( |
|
471 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
472 | - ), |
|
473 | - 'EE_Messenger_Collection_Loader' => array( |
|
474 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
475 | - ), |
|
476 | - 'EE_Message_Type_Collection_Loader' => array( |
|
477 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
478 | - ), |
|
479 | - 'EE_Message_Resource_Manager' => array( |
|
480 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
481 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
482 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
483 | - ), |
|
484 | - 'EE_Message_Factory' => array( |
|
485 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
486 | - ), |
|
487 | - 'EE_messages' => array( |
|
488 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
489 | - ), |
|
490 | - 'EE_Messages_Generator' => array( |
|
491 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
492 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
493 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
494 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
495 | - ), |
|
496 | - 'EE_Messages_Processor' => array( |
|
497 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
498 | - ), |
|
499 | - 'EE_Messages_Queue' => array( |
|
500 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
501 | - ), |
|
502 | - 'EE_Messages_Template_Defaults' => array( |
|
503 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
504 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
505 | - ), |
|
506 | - 'EE_Message_To_Generate_From_Request' => array( |
|
507 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
508 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
509 | - ), |
|
510 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
511 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
512 | - ), |
|
513 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
514 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
515 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
516 | - ), |
|
517 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
518 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
519 | - ), |
|
520 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
521 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
522 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
523 | - ), |
|
524 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
525 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
526 | - ), |
|
527 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
528 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
529 | - ), |
|
530 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
531 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
532 | - ), |
|
533 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
534 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
535 | - ), |
|
536 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
537 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
538 | - ), |
|
539 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
540 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
541 | - ), |
|
542 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
543 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
544 | - ), |
|
545 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
546 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
547 | - ), |
|
548 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
549 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
550 | - ), |
|
551 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
552 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
553 | - ), |
|
554 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
555 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
556 | - ), |
|
557 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
558 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
559 | - ), |
|
560 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
561 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
562 | - ), |
|
563 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
564 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
565 | - ), |
|
566 | - 'EE_Data_Migration_Class_Base' => array( |
|
567 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
568 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
569 | - ), |
|
570 | - 'EE_DMS_Core_4_1_0' => array( |
|
571 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
572 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
573 | - ), |
|
574 | - 'EE_DMS_Core_4_2_0' => array( |
|
575 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
576 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
577 | - ), |
|
578 | - 'EE_DMS_Core_4_3_0' => array( |
|
579 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
580 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
581 | - ), |
|
582 | - 'EE_DMS_Core_4_4_0' => array( |
|
583 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
584 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
585 | - ), |
|
586 | - 'EE_DMS_Core_4_5_0' => array( |
|
587 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
588 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
589 | - ), |
|
590 | - 'EE_DMS_Core_4_6_0' => array( |
|
591 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
592 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
593 | - ), |
|
594 | - 'EE_DMS_Core_4_7_0' => array( |
|
595 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
596 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
597 | - ), |
|
598 | - 'EE_DMS_Core_4_8_0' => array( |
|
599 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
600 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
601 | - ), |
|
602 | - 'EE_DMS_Core_4_9_0' => array( |
|
603 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
604 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
605 | - ), |
|
606 | - 'EE_DMS_Core_4_10_0' => array( |
|
607 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
608 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
609 | - 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
610 | - ), |
|
611 | - 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
612 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
613 | - 'EventEspresso\core\services\assets\JedLocaleData' => EE_Dependency_Map::load_from_cache, |
|
614 | - array(), |
|
615 | - ), |
|
616 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
617 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
618 | - 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
619 | - ), |
|
620 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
621 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
622 | - ), |
|
623 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
624 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
625 | - ), |
|
626 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
627 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
628 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
629 | - ), |
|
630 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
631 | - null, |
|
632 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
633 | - ), |
|
634 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
635 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
636 | - ), |
|
637 | - 'LEGACY_MODELS' => array( |
|
638 | - null, |
|
639 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
640 | - ), |
|
641 | - 'EE_Module_Request_Router' => array( |
|
642 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
643 | - ), |
|
644 | - 'EE_Registration_Processor' => array( |
|
645 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
646 | - ), |
|
647 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => [ |
|
648 | - null, |
|
649 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
650 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
651 | - ], |
|
652 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
653 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
654 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
655 | - ), |
|
656 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
657 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
658 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
659 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
660 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
661 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
662 | - ), |
|
663 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
664 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
665 | - ), |
|
666 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
667 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
668 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
669 | - ), |
|
670 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
671 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
672 | - ), |
|
673 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
674 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
675 | - ), |
|
676 | - 'EE_CPT_Strategy' => array( |
|
677 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
678 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
679 | - ), |
|
680 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
681 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
682 | - ), |
|
683 | - 'EventEspresso\core\CPTs\CptQueryModifier' => array( |
|
684 | - null, |
|
685 | - null, |
|
686 | - null, |
|
687 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
688 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
689 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
690 | - ), |
|
691 | - 'EventEspresso\core\services\dependencies\DependencyResolver' => [ |
|
692 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
693 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
694 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
695 | - ], |
|
696 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => array( |
|
697 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
698 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
699 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
700 | - ), |
|
701 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => array( |
|
702 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
703 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
704 | - ), |
|
705 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationManager' => array( |
|
706 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
707 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
708 | - ), |
|
709 | - 'EE_URL_Validation_Strategy' => array( |
|
710 | - null, |
|
711 | - null, |
|
712 | - 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache |
|
713 | - ), |
|
714 | - 'EventEspresso\core\services\request\files\FilesDataHandler' => array( |
|
715 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
716 | - ), |
|
717 | - 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
718 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
719 | - ], |
|
720 | - 'EventEspresso\core\domain\services\converters\RestApiSpoofer' => [ |
|
721 | - 'WP_REST_Server' => EE_Dependency_Map::load_from_cache, |
|
722 | - 'EED_Core_Rest_Api' => EE_Dependency_Map::load_from_cache, |
|
723 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => EE_Dependency_Map::load_from_cache, |
|
724 | - null |
|
725 | - ], |
|
726 | - 'EventEspresso\core\services\routing\RouteHandler' => [ |
|
727 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
728 | - 'EventEspresso\core\services\routing\RouteCollection' => EE_Dependency_Map::load_from_cache, |
|
729 | - ], |
|
730 | - 'EventEspresso\core\services\dependencies\LocalDependencyMapFactory' => [ |
|
731 | - 'EventEspresso\core\services\dependencies\DependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
732 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
733 | - ], |
|
734 | - ); |
|
735 | - } |
|
736 | - |
|
737 | - |
|
738 | - /** |
|
739 | - * Registers how core classes are loaded. |
|
740 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
741 | - * 'EE_Request_Handler' => 'load_core' |
|
742 | - * 'EE_Messages_Queue' => 'load_lib' |
|
743 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
744 | - * or, if greater control is required, by providing a custom closure. For example: |
|
745 | - * 'Some_Class' => function () { |
|
746 | - * return new Some_Class(); |
|
747 | - * }, |
|
748 | - * This is required for instantiating dependencies |
|
749 | - * where an interface has been type hinted in a class constructor. For example: |
|
750 | - * 'Required_Interface' => function () { |
|
751 | - * return new A_Class_That_Implements_Required_Interface(); |
|
752 | - * }, |
|
753 | - */ |
|
754 | - protected function _register_core_class_loaders() |
|
755 | - { |
|
756 | - $this->_class_loaders = array( |
|
757 | - // load_core |
|
758 | - 'EE_Dependency_Map' => function () { |
|
759 | - return $this; |
|
760 | - }, |
|
761 | - 'EE_Capabilities' => 'load_core', |
|
762 | - 'EE_Encryption' => 'load_core', |
|
763 | - 'EE_Front_Controller' => 'load_core', |
|
764 | - 'EE_Module_Request_Router' => 'load_core', |
|
765 | - 'EE_Registry' => 'load_core', |
|
766 | - 'EE_Request' => function () { |
|
767 | - return $this->legacy_request; |
|
768 | - }, |
|
769 | - 'EventEspresso\core\services\request\Request' => function () { |
|
770 | - return $this->request; |
|
771 | - }, |
|
772 | - 'EventEspresso\core\services\request\Response' => function () { |
|
773 | - return $this->response; |
|
774 | - }, |
|
775 | - 'EE_Base' => 'load_core', |
|
776 | - 'EE_Request_Handler' => 'load_core', |
|
777 | - 'EE_Session' => 'load_core', |
|
778 | - 'EE_Cron_Tasks' => 'load_core', |
|
779 | - 'EE_System' => 'load_core', |
|
780 | - 'EE_Maintenance_Mode' => 'load_core', |
|
781 | - 'EE_Register_CPTs' => 'load_core', |
|
782 | - 'EE_Admin' => 'load_core', |
|
783 | - 'EE_CPT_Strategy' => 'load_core', |
|
784 | - // load_class |
|
785 | - 'EE_Registration_Processor' => 'load_class', |
|
786 | - // load_lib |
|
787 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
788 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
789 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
790 | - 'EE_Messenger_Collection' => 'load_lib', |
|
791 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
792 | - 'EE_Messages_Processor' => 'load_lib', |
|
793 | - 'EE_Message_Repository' => 'load_lib', |
|
794 | - 'EE_Messages_Queue' => 'load_lib', |
|
795 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
796 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
797 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
798 | - 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
799 | - 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
800 | - 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
801 | - 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
802 | - 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
803 | - 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
804 | - 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
805 | - 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
806 | - 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
807 | - 'EE_Messages_Generator' => static function () { |
|
808 | - return EE_Registry::instance()->load_lib( |
|
809 | - 'Messages_Generator', |
|
810 | - array(), |
|
811 | - false, |
|
812 | - false |
|
813 | - ); |
|
814 | - }, |
|
815 | - 'EE_Messages_Template_Defaults' => static function ($arguments = array()) { |
|
816 | - return EE_Registry::instance()->load_lib( |
|
817 | - 'Messages_Template_Defaults', |
|
818 | - $arguments, |
|
819 | - false, |
|
820 | - false |
|
821 | - ); |
|
822 | - }, |
|
823 | - // load_helper |
|
824 | - 'EEH_Parse_Shortcodes' => static function () { |
|
825 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
826 | - return new EEH_Parse_Shortcodes(); |
|
827 | - } |
|
828 | - return null; |
|
829 | - }, |
|
830 | - 'EE_Template_Config' => static function () { |
|
831 | - return EE_Config::instance()->template_settings; |
|
832 | - }, |
|
833 | - 'EE_Currency_Config' => static function () { |
|
834 | - return EE_Config::instance()->currency; |
|
835 | - }, |
|
836 | - 'EE_Registration_Config' => static function () { |
|
837 | - return EE_Config::instance()->registration; |
|
838 | - }, |
|
839 | - 'EE_Core_Config' => static function () { |
|
840 | - return EE_Config::instance()->core; |
|
841 | - }, |
|
842 | - 'EventEspresso\core\services\loaders\Loader' => static function () { |
|
843 | - return LoaderFactory::getLoader(); |
|
844 | - }, |
|
845 | - 'EE_Network_Config' => static function () { |
|
846 | - return EE_Network_Config::instance(); |
|
847 | - }, |
|
848 | - 'EE_Config' => static function () { |
|
849 | - return EE_Config::instance(); |
|
850 | - }, |
|
851 | - 'EventEspresso\core\domain\Domain' => static function () { |
|
852 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
853 | - }, |
|
854 | - 'EE_Admin_Config' => static function () { |
|
855 | - return EE_Config::instance()->admin; |
|
856 | - }, |
|
857 | - 'EE_Organization_Config' => static function () { |
|
858 | - return EE_Config::instance()->organization; |
|
859 | - }, |
|
860 | - 'EE_Network_Core_Config' => static function () { |
|
861 | - return EE_Network_Config::instance()->core; |
|
862 | - }, |
|
863 | - 'EE_Environment_Config' => static function () { |
|
864 | - return EE_Config::instance()->environment; |
|
865 | - }, |
|
866 | - 'EED_Core_Rest_Api' => static function () { |
|
867 | - return EED_Core_Rest_Api::instance(); |
|
868 | - }, |
|
869 | - 'WP_REST_Server' => static function () { |
|
870 | - return rest_get_server(); |
|
871 | - }, |
|
872 | - ); |
|
873 | - } |
|
874 | - |
|
875 | - |
|
876 | - /** |
|
877 | - * can be used for supplying alternate names for classes, |
|
878 | - * or for connecting interface names to instantiable classes |
|
879 | - * |
|
880 | - * @throws InvalidAliasException |
|
881 | - */ |
|
882 | - protected function _register_core_aliases() |
|
883 | - { |
|
884 | - $aliases = array( |
|
885 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
886 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
887 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
888 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
889 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
890 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
891 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
892 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
893 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
894 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
895 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
896 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
897 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
898 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
899 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
900 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
901 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
902 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
903 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
904 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
905 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
906 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
907 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
908 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
909 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
910 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
911 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
912 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
913 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
914 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
915 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
916 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
917 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
918 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
919 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
920 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
921 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
922 | - 'Registration_Processor' => 'EE_Registration_Processor', |
|
923 | - ); |
|
924 | - foreach ($aliases as $alias => $fqn) { |
|
925 | - if (is_array($fqn)) { |
|
926 | - foreach ($fqn as $class => $for_class) { |
|
927 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
928 | - } |
|
929 | - continue; |
|
930 | - } |
|
931 | - $this->class_cache->addAlias($fqn, $alias); |
|
932 | - } |
|
933 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
934 | - $this->class_cache->addAlias( |
|
935 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
936 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
937 | - ); |
|
938 | - } |
|
939 | - } |
|
940 | - |
|
941 | - |
|
942 | - /** |
|
943 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
944 | - * request Primarily used by unit tests. |
|
945 | - */ |
|
946 | - public function reset() |
|
947 | - { |
|
948 | - $this->_register_core_class_loaders(); |
|
949 | - $this->_register_core_dependencies(); |
|
950 | - } |
|
951 | - |
|
952 | - |
|
953 | - /** |
|
954 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
955 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
956 | - * WHY? |
|
957 | - * Because if a class is type hinting for a concretion, |
|
958 | - * then why would we need to find another class to supply it? |
|
959 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
960 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
961 | - * Don't go looking for some substitute. |
|
962 | - * Whereas if a class is type hinting for an interface... |
|
963 | - * then we need to find an actual class to use. |
|
964 | - * So the interface IS the alias for some other FQN, |
|
965 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
966 | - * represents some other class. |
|
967 | - * |
|
968 | - * @deprecated 4.9.62.p |
|
969 | - * @param string $fqn |
|
970 | - * @param string $for_class |
|
971 | - * @return bool |
|
972 | - */ |
|
973 | - public function has_alias($fqn = '', $for_class = '') |
|
974 | - { |
|
975 | - return $this->isAlias($fqn, $for_class); |
|
976 | - } |
|
977 | - |
|
978 | - |
|
979 | - /** |
|
980 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
981 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
982 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
983 | - * for example: |
|
984 | - * if the following two entries were added to the _aliases array: |
|
985 | - * array( |
|
986 | - * 'interface_alias' => 'some\namespace\interface' |
|
987 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
988 | - * ) |
|
989 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
990 | - * to load an instance of 'some\namespace\classname' |
|
991 | - * |
|
992 | - * @deprecated 4.9.62.p |
|
993 | - * @param string $alias |
|
994 | - * @param string $for_class |
|
995 | - * @return string |
|
996 | - */ |
|
997 | - public function get_alias($alias = '', $for_class = '') |
|
998 | - { |
|
999 | - return $this->getFqnForAlias($alias, $for_class); |
|
1000 | - } |
|
24 | + /** |
|
25 | + * This means that the requested class dependency is not present in the dependency map |
|
26 | + */ |
|
27 | + const not_registered = 0; |
|
28 | + |
|
29 | + /** |
|
30 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
31 | + */ |
|
32 | + const load_new_object = 1; |
|
33 | + |
|
34 | + /** |
|
35 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
36 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
37 | + */ |
|
38 | + const load_from_cache = 2; |
|
39 | + |
|
40 | + /** |
|
41 | + * When registering a dependency, |
|
42 | + * this indicates to keep any existing dependencies that already exist, |
|
43 | + * and simply discard any new dependencies declared in the incoming data |
|
44 | + */ |
|
45 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
46 | + |
|
47 | + /** |
|
48 | + * When registering a dependency, |
|
49 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
50 | + */ |
|
51 | + const OVERWRITE_DEPENDENCIES = 1; |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @type EE_Dependency_Map $_instance |
|
56 | + */ |
|
57 | + protected static $_instance; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var ClassInterfaceCache $class_cache |
|
61 | + */ |
|
62 | + private $class_cache; |
|
63 | + |
|
64 | + /** |
|
65 | + * @type RequestInterface $request |
|
66 | + */ |
|
67 | + protected $request; |
|
68 | + |
|
69 | + /** |
|
70 | + * @type LegacyRequestInterface $legacy_request |
|
71 | + */ |
|
72 | + protected $legacy_request; |
|
73 | + |
|
74 | + /** |
|
75 | + * @type ResponseInterface $response |
|
76 | + */ |
|
77 | + protected $response; |
|
78 | + |
|
79 | + /** |
|
80 | + * @type LoaderInterface $loader |
|
81 | + */ |
|
82 | + protected $loader; |
|
83 | + |
|
84 | + /** |
|
85 | + * @type array $_dependency_map |
|
86 | + */ |
|
87 | + protected $_dependency_map = array(); |
|
88 | + |
|
89 | + /** |
|
90 | + * @type array $_class_loaders |
|
91 | + */ |
|
92 | + protected $_class_loaders = array(); |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * EE_Dependency_Map constructor. |
|
97 | + * |
|
98 | + * @param ClassInterfaceCache $class_cache |
|
99 | + */ |
|
100 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
101 | + { |
|
102 | + $this->class_cache = $class_cache; |
|
103 | + do_action('EE_Dependency_Map____construct', $this); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @return void |
|
109 | + * @throws EE_Error |
|
110 | + * @throws InvalidAliasException |
|
111 | + */ |
|
112 | + public function initialize() |
|
113 | + { |
|
114 | + $this->_register_core_dependencies(); |
|
115 | + $this->_register_core_class_loaders(); |
|
116 | + $this->_register_core_aliases(); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * @singleton method used to instantiate class object |
|
122 | + * @param ClassInterfaceCache|null $class_cache |
|
123 | + * @return EE_Dependency_Map |
|
124 | + */ |
|
125 | + public static function instance(ClassInterfaceCache $class_cache = null) |
|
126 | + { |
|
127 | + // check if class object is instantiated, and instantiated properly |
|
128 | + if (! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map |
|
129 | + && $class_cache instanceof ClassInterfaceCache |
|
130 | + ) { |
|
131 | + EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache); |
|
132 | + } |
|
133 | + return EE_Dependency_Map::$_instance; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param RequestInterface $request |
|
139 | + */ |
|
140 | + public function setRequest(RequestInterface $request) |
|
141 | + { |
|
142 | + $this->request = $request; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @param LegacyRequestInterface $legacy_request |
|
148 | + */ |
|
149 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
150 | + { |
|
151 | + $this->legacy_request = $legacy_request; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @param ResponseInterface $response |
|
157 | + */ |
|
158 | + public function setResponse(ResponseInterface $response) |
|
159 | + { |
|
160 | + $this->response = $response; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * @param LoaderInterface $loader |
|
166 | + */ |
|
167 | + public function setLoader(LoaderInterface $loader) |
|
168 | + { |
|
169 | + $this->loader = $loader; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * @param string $class |
|
175 | + * @param array $dependencies |
|
176 | + * @param int $overwrite |
|
177 | + * @return bool |
|
178 | + */ |
|
179 | + public static function register_dependencies( |
|
180 | + $class, |
|
181 | + array $dependencies, |
|
182 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
183 | + ) { |
|
184 | + return EE_Dependency_Map::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
190 | + * to the class specified by the first parameter. |
|
191 | + * IMPORTANT !!! |
|
192 | + * The order of elements in the incoming $dependencies array MUST match |
|
193 | + * the order of the constructor parameters for the class in question. |
|
194 | + * This is especially important when overriding any existing dependencies that are registered. |
|
195 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
196 | + * |
|
197 | + * @param string $class |
|
198 | + * @param array $dependencies |
|
199 | + * @param int $overwrite |
|
200 | + * @return bool |
|
201 | + */ |
|
202 | + public function registerDependencies( |
|
203 | + $class, |
|
204 | + array $dependencies, |
|
205 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
206 | + ) { |
|
207 | + $class = trim($class, '\\'); |
|
208 | + $registered = false; |
|
209 | + if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) { |
|
210 | + EE_Dependency_Map::$_instance->_dependency_map[ $class ] = array(); |
|
211 | + } |
|
212 | + // we need to make sure that any aliases used when registering a dependency |
|
213 | + // get resolved to the correct class name |
|
214 | + foreach ($dependencies as $dependency => $load_source) { |
|
215 | + $alias = EE_Dependency_Map::$_instance->getFqnForAlias($dependency); |
|
216 | + if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
217 | + || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ]) |
|
218 | + ) { |
|
219 | + unset($dependencies[ $dependency ]); |
|
220 | + $dependencies[ $alias ] = $load_source; |
|
221 | + $registered = true; |
|
222 | + } |
|
223 | + } |
|
224 | + // now add our two lists of dependencies together. |
|
225 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
226 | + // so $dependencies is NOT overwritten because it is listed first |
|
227 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
228 | + // Union is way faster than array_merge() but should be used with caution... |
|
229 | + // especially with numerically indexed arrays |
|
230 | + $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ]; |
|
231 | + // now we need to ensure that the resulting dependencies |
|
232 | + // array only has the entries that are required for the class |
|
233 | + // so first count how many dependencies were originally registered for the class |
|
234 | + $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]); |
|
235 | + // if that count is non-zero (meaning dependencies were already registered) |
|
236 | + EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count |
|
237 | + // then truncate the final array to match that count |
|
238 | + ? array_slice($dependencies, 0, $dependency_count) |
|
239 | + // otherwise just take the incoming array because nothing previously existed |
|
240 | + : $dependencies; |
|
241 | + return $registered; |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * @param string $class_name |
|
247 | + * @param string $loader |
|
248 | + * @return bool |
|
249 | + * @throws DomainException |
|
250 | + */ |
|
251 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
252 | + { |
|
253 | + return EE_Dependency_Map::$_instance->registerClassLoader($class_name, $loader); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * @param string $class_name |
|
259 | + * @param string $loader |
|
260 | + * @return bool |
|
261 | + * @throws DomainException |
|
262 | + */ |
|
263 | + public function registerClassLoader($class_name, $loader = 'load_core') |
|
264 | + { |
|
265 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
266 | + throw new DomainException( |
|
267 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
268 | + ); |
|
269 | + } |
|
270 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
271 | + if (! is_callable($loader) |
|
272 | + && ( |
|
273 | + strpos($loader, 'load_') !== 0 |
|
274 | + || ! method_exists('EE_Registry', $loader) |
|
275 | + ) |
|
276 | + ) { |
|
277 | + throw new DomainException( |
|
278 | + sprintf( |
|
279 | + esc_html__( |
|
280 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
281 | + 'event_espresso' |
|
282 | + ), |
|
283 | + $loader |
|
284 | + ) |
|
285 | + ); |
|
286 | + } |
|
287 | + $class_name = EE_Dependency_Map::$_instance->getFqnForAlias($class_name); |
|
288 | + if (! isset(EE_Dependency_Map::$_instance->_class_loaders[ $class_name ])) { |
|
289 | + EE_Dependency_Map::$_instance->_class_loaders[ $class_name ] = $loader; |
|
290 | + return true; |
|
291 | + } |
|
292 | + return false; |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * @return array |
|
298 | + */ |
|
299 | + public function dependency_map() |
|
300 | + { |
|
301 | + return $this->_dependency_map; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
307 | + * |
|
308 | + * @param string $class_name |
|
309 | + * @return boolean |
|
310 | + */ |
|
311 | + public function has($class_name = '') |
|
312 | + { |
|
313 | + // all legacy models have the same dependencies |
|
314 | + if (strpos($class_name, 'EEM_') === 0) { |
|
315 | + $class_name = 'LEGACY_MODELS'; |
|
316 | + } |
|
317 | + return isset($this->_dependency_map[ $class_name ]); |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
323 | + * |
|
324 | + * @param string $class_name |
|
325 | + * @param string $dependency |
|
326 | + * @return bool |
|
327 | + */ |
|
328 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
329 | + { |
|
330 | + // all legacy models have the same dependencies |
|
331 | + if (strpos($class_name, 'EEM_') === 0) { |
|
332 | + $class_name = 'LEGACY_MODELS'; |
|
333 | + } |
|
334 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
335 | + return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
341 | + * |
|
342 | + * @param string $class_name |
|
343 | + * @param string $dependency |
|
344 | + * @return int |
|
345 | + */ |
|
346 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
347 | + { |
|
348 | + // all legacy models have the same dependencies |
|
349 | + if (strpos($class_name, 'EEM_') === 0) { |
|
350 | + $class_name = 'LEGACY_MODELS'; |
|
351 | + } |
|
352 | + $dependency = $this->getFqnForAlias($dependency); |
|
353 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
354 | + ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
355 | + : EE_Dependency_Map::not_registered; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * @param string $class_name |
|
361 | + * @return string | Closure |
|
362 | + */ |
|
363 | + public function class_loader($class_name) |
|
364 | + { |
|
365 | + // all legacy models use load_model() |
|
366 | + if (strpos($class_name, 'EEM_') === 0) { |
|
367 | + return 'load_model'; |
|
368 | + } |
|
369 | + // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
370 | + // perform strpos() first to avoid loading regex every time we load a class |
|
371 | + if (strpos($class_name, 'EE_CPT_') === 0 |
|
372 | + && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
373 | + ) { |
|
374 | + return 'load_core'; |
|
375 | + } |
|
376 | + $class_name = $this->getFqnForAlias($class_name); |
|
377 | + return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * @return array |
|
383 | + */ |
|
384 | + public function class_loaders() |
|
385 | + { |
|
386 | + return $this->_class_loaders; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * adds an alias for a classname |
|
392 | + * |
|
393 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
394 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
395 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
396 | + * @return bool |
|
397 | + * @throws InvalidAliasException |
|
398 | + */ |
|
399 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
400 | + { |
|
401 | + return $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
407 | + * WHY? |
|
408 | + * Because if a class is type hinting for a concretion, |
|
409 | + * then why would we need to find another class to supply it? |
|
410 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
411 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
412 | + * Don't go looking for some substitute. |
|
413 | + * Whereas if a class is type hinting for an interface... |
|
414 | + * then we need to find an actual class to use. |
|
415 | + * So the interface IS the alias for some other FQN, |
|
416 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
417 | + * represents some other class. |
|
418 | + * |
|
419 | + * @param string $fqn |
|
420 | + * @param string $for_class |
|
421 | + * @return bool |
|
422 | + */ |
|
423 | + public function isAlias($fqn = '', $for_class = '') |
|
424 | + { |
|
425 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
431 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
432 | + * for example: |
|
433 | + * if the following two entries were added to the _aliases array: |
|
434 | + * array( |
|
435 | + * 'interface_alias' => 'some\namespace\interface' |
|
436 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
437 | + * ) |
|
438 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
439 | + * to load an instance of 'some\namespace\classname' |
|
440 | + * |
|
441 | + * @param string $alias |
|
442 | + * @param string $for_class |
|
443 | + * @return string |
|
444 | + */ |
|
445 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
446 | + { |
|
447 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
453 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
454 | + * This is done by using the following class constants: |
|
455 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
456 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
457 | + */ |
|
458 | + protected function _register_core_dependencies() |
|
459 | + { |
|
460 | + $this->_dependency_map = array( |
|
461 | + 'EE_Request_Handler' => array( |
|
462 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
463 | + ), |
|
464 | + 'EE_System' => array( |
|
465 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
466 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
467 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
468 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
469 | + ), |
|
470 | + 'EE_Cart' => array( |
|
471 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
472 | + ), |
|
473 | + 'EE_Messenger_Collection_Loader' => array( |
|
474 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
475 | + ), |
|
476 | + 'EE_Message_Type_Collection_Loader' => array( |
|
477 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
478 | + ), |
|
479 | + 'EE_Message_Resource_Manager' => array( |
|
480 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
481 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
482 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
483 | + ), |
|
484 | + 'EE_Message_Factory' => array( |
|
485 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
486 | + ), |
|
487 | + 'EE_messages' => array( |
|
488 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
489 | + ), |
|
490 | + 'EE_Messages_Generator' => array( |
|
491 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
492 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
493 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
494 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
495 | + ), |
|
496 | + 'EE_Messages_Processor' => array( |
|
497 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
498 | + ), |
|
499 | + 'EE_Messages_Queue' => array( |
|
500 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
501 | + ), |
|
502 | + 'EE_Messages_Template_Defaults' => array( |
|
503 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
504 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
505 | + ), |
|
506 | + 'EE_Message_To_Generate_From_Request' => array( |
|
507 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
508 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
509 | + ), |
|
510 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
511 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
512 | + ), |
|
513 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
514 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
515 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
516 | + ), |
|
517 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
518 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
519 | + ), |
|
520 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
521 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
522 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
523 | + ), |
|
524 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
525 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
526 | + ), |
|
527 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
528 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
529 | + ), |
|
530 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
531 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
532 | + ), |
|
533 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
534 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
535 | + ), |
|
536 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
537 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
538 | + ), |
|
539 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
540 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
541 | + ), |
|
542 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
543 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
544 | + ), |
|
545 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
546 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
547 | + ), |
|
548 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
549 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
550 | + ), |
|
551 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
552 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
553 | + ), |
|
554 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
555 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
556 | + ), |
|
557 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
558 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
559 | + ), |
|
560 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
561 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
562 | + ), |
|
563 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
564 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
565 | + ), |
|
566 | + 'EE_Data_Migration_Class_Base' => array( |
|
567 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
568 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
569 | + ), |
|
570 | + 'EE_DMS_Core_4_1_0' => array( |
|
571 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
572 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
573 | + ), |
|
574 | + 'EE_DMS_Core_4_2_0' => array( |
|
575 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
576 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
577 | + ), |
|
578 | + 'EE_DMS_Core_4_3_0' => array( |
|
579 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
580 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
581 | + ), |
|
582 | + 'EE_DMS_Core_4_4_0' => array( |
|
583 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
584 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
585 | + ), |
|
586 | + 'EE_DMS_Core_4_5_0' => array( |
|
587 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
588 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
589 | + ), |
|
590 | + 'EE_DMS_Core_4_6_0' => array( |
|
591 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
592 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
593 | + ), |
|
594 | + 'EE_DMS_Core_4_7_0' => array( |
|
595 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
596 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
597 | + ), |
|
598 | + 'EE_DMS_Core_4_8_0' => array( |
|
599 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
600 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
601 | + ), |
|
602 | + 'EE_DMS_Core_4_9_0' => array( |
|
603 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
604 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
605 | + ), |
|
606 | + 'EE_DMS_Core_4_10_0' => array( |
|
607 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
608 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
609 | + 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
610 | + ), |
|
611 | + 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
612 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
613 | + 'EventEspresso\core\services\assets\JedLocaleData' => EE_Dependency_Map::load_from_cache, |
|
614 | + array(), |
|
615 | + ), |
|
616 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
617 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
618 | + 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
619 | + ), |
|
620 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
621 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
622 | + ), |
|
623 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
624 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
625 | + ), |
|
626 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
627 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
628 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
629 | + ), |
|
630 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
631 | + null, |
|
632 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
633 | + ), |
|
634 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
635 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
636 | + ), |
|
637 | + 'LEGACY_MODELS' => array( |
|
638 | + null, |
|
639 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
640 | + ), |
|
641 | + 'EE_Module_Request_Router' => array( |
|
642 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
643 | + ), |
|
644 | + 'EE_Registration_Processor' => array( |
|
645 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
646 | + ), |
|
647 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => [ |
|
648 | + null, |
|
649 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
650 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
651 | + ], |
|
652 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
653 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
654 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
655 | + ), |
|
656 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
657 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
658 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
659 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
660 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
661 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
662 | + ), |
|
663 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
664 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
665 | + ), |
|
666 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
667 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
668 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
669 | + ), |
|
670 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
671 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
672 | + ), |
|
673 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
674 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
675 | + ), |
|
676 | + 'EE_CPT_Strategy' => array( |
|
677 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
678 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
679 | + ), |
|
680 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
681 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
682 | + ), |
|
683 | + 'EventEspresso\core\CPTs\CptQueryModifier' => array( |
|
684 | + null, |
|
685 | + null, |
|
686 | + null, |
|
687 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
688 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
689 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
690 | + ), |
|
691 | + 'EventEspresso\core\services\dependencies\DependencyResolver' => [ |
|
692 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
693 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
694 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
695 | + ], |
|
696 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => array( |
|
697 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
698 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
699 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
700 | + ), |
|
701 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => array( |
|
702 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
703 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
704 | + ), |
|
705 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationManager' => array( |
|
706 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
707 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
708 | + ), |
|
709 | + 'EE_URL_Validation_Strategy' => array( |
|
710 | + null, |
|
711 | + null, |
|
712 | + 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache |
|
713 | + ), |
|
714 | + 'EventEspresso\core\services\request\files\FilesDataHandler' => array( |
|
715 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
716 | + ), |
|
717 | + 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
718 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
719 | + ], |
|
720 | + 'EventEspresso\core\domain\services\converters\RestApiSpoofer' => [ |
|
721 | + 'WP_REST_Server' => EE_Dependency_Map::load_from_cache, |
|
722 | + 'EED_Core_Rest_Api' => EE_Dependency_Map::load_from_cache, |
|
723 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => EE_Dependency_Map::load_from_cache, |
|
724 | + null |
|
725 | + ], |
|
726 | + 'EventEspresso\core\services\routing\RouteHandler' => [ |
|
727 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
728 | + 'EventEspresso\core\services\routing\RouteCollection' => EE_Dependency_Map::load_from_cache, |
|
729 | + ], |
|
730 | + 'EventEspresso\core\services\dependencies\LocalDependencyMapFactory' => [ |
|
731 | + 'EventEspresso\core\services\dependencies\DependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
732 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
733 | + ], |
|
734 | + ); |
|
735 | + } |
|
736 | + |
|
737 | + |
|
738 | + /** |
|
739 | + * Registers how core classes are loaded. |
|
740 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
741 | + * 'EE_Request_Handler' => 'load_core' |
|
742 | + * 'EE_Messages_Queue' => 'load_lib' |
|
743 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
744 | + * or, if greater control is required, by providing a custom closure. For example: |
|
745 | + * 'Some_Class' => function () { |
|
746 | + * return new Some_Class(); |
|
747 | + * }, |
|
748 | + * This is required for instantiating dependencies |
|
749 | + * where an interface has been type hinted in a class constructor. For example: |
|
750 | + * 'Required_Interface' => function () { |
|
751 | + * return new A_Class_That_Implements_Required_Interface(); |
|
752 | + * }, |
|
753 | + */ |
|
754 | + protected function _register_core_class_loaders() |
|
755 | + { |
|
756 | + $this->_class_loaders = array( |
|
757 | + // load_core |
|
758 | + 'EE_Dependency_Map' => function () { |
|
759 | + return $this; |
|
760 | + }, |
|
761 | + 'EE_Capabilities' => 'load_core', |
|
762 | + 'EE_Encryption' => 'load_core', |
|
763 | + 'EE_Front_Controller' => 'load_core', |
|
764 | + 'EE_Module_Request_Router' => 'load_core', |
|
765 | + 'EE_Registry' => 'load_core', |
|
766 | + 'EE_Request' => function () { |
|
767 | + return $this->legacy_request; |
|
768 | + }, |
|
769 | + 'EventEspresso\core\services\request\Request' => function () { |
|
770 | + return $this->request; |
|
771 | + }, |
|
772 | + 'EventEspresso\core\services\request\Response' => function () { |
|
773 | + return $this->response; |
|
774 | + }, |
|
775 | + 'EE_Base' => 'load_core', |
|
776 | + 'EE_Request_Handler' => 'load_core', |
|
777 | + 'EE_Session' => 'load_core', |
|
778 | + 'EE_Cron_Tasks' => 'load_core', |
|
779 | + 'EE_System' => 'load_core', |
|
780 | + 'EE_Maintenance_Mode' => 'load_core', |
|
781 | + 'EE_Register_CPTs' => 'load_core', |
|
782 | + 'EE_Admin' => 'load_core', |
|
783 | + 'EE_CPT_Strategy' => 'load_core', |
|
784 | + // load_class |
|
785 | + 'EE_Registration_Processor' => 'load_class', |
|
786 | + // load_lib |
|
787 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
788 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
789 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
790 | + 'EE_Messenger_Collection' => 'load_lib', |
|
791 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
792 | + 'EE_Messages_Processor' => 'load_lib', |
|
793 | + 'EE_Message_Repository' => 'load_lib', |
|
794 | + 'EE_Messages_Queue' => 'load_lib', |
|
795 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
796 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
797 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
798 | + 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
799 | + 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
800 | + 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
801 | + 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
802 | + 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
803 | + 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
804 | + 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
805 | + 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
806 | + 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
807 | + 'EE_Messages_Generator' => static function () { |
|
808 | + return EE_Registry::instance()->load_lib( |
|
809 | + 'Messages_Generator', |
|
810 | + array(), |
|
811 | + false, |
|
812 | + false |
|
813 | + ); |
|
814 | + }, |
|
815 | + 'EE_Messages_Template_Defaults' => static function ($arguments = array()) { |
|
816 | + return EE_Registry::instance()->load_lib( |
|
817 | + 'Messages_Template_Defaults', |
|
818 | + $arguments, |
|
819 | + false, |
|
820 | + false |
|
821 | + ); |
|
822 | + }, |
|
823 | + // load_helper |
|
824 | + 'EEH_Parse_Shortcodes' => static function () { |
|
825 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
826 | + return new EEH_Parse_Shortcodes(); |
|
827 | + } |
|
828 | + return null; |
|
829 | + }, |
|
830 | + 'EE_Template_Config' => static function () { |
|
831 | + return EE_Config::instance()->template_settings; |
|
832 | + }, |
|
833 | + 'EE_Currency_Config' => static function () { |
|
834 | + return EE_Config::instance()->currency; |
|
835 | + }, |
|
836 | + 'EE_Registration_Config' => static function () { |
|
837 | + return EE_Config::instance()->registration; |
|
838 | + }, |
|
839 | + 'EE_Core_Config' => static function () { |
|
840 | + return EE_Config::instance()->core; |
|
841 | + }, |
|
842 | + 'EventEspresso\core\services\loaders\Loader' => static function () { |
|
843 | + return LoaderFactory::getLoader(); |
|
844 | + }, |
|
845 | + 'EE_Network_Config' => static function () { |
|
846 | + return EE_Network_Config::instance(); |
|
847 | + }, |
|
848 | + 'EE_Config' => static function () { |
|
849 | + return EE_Config::instance(); |
|
850 | + }, |
|
851 | + 'EventEspresso\core\domain\Domain' => static function () { |
|
852 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
853 | + }, |
|
854 | + 'EE_Admin_Config' => static function () { |
|
855 | + return EE_Config::instance()->admin; |
|
856 | + }, |
|
857 | + 'EE_Organization_Config' => static function () { |
|
858 | + return EE_Config::instance()->organization; |
|
859 | + }, |
|
860 | + 'EE_Network_Core_Config' => static function () { |
|
861 | + return EE_Network_Config::instance()->core; |
|
862 | + }, |
|
863 | + 'EE_Environment_Config' => static function () { |
|
864 | + return EE_Config::instance()->environment; |
|
865 | + }, |
|
866 | + 'EED_Core_Rest_Api' => static function () { |
|
867 | + return EED_Core_Rest_Api::instance(); |
|
868 | + }, |
|
869 | + 'WP_REST_Server' => static function () { |
|
870 | + return rest_get_server(); |
|
871 | + }, |
|
872 | + ); |
|
873 | + } |
|
874 | + |
|
875 | + |
|
876 | + /** |
|
877 | + * can be used for supplying alternate names for classes, |
|
878 | + * or for connecting interface names to instantiable classes |
|
879 | + * |
|
880 | + * @throws InvalidAliasException |
|
881 | + */ |
|
882 | + protected function _register_core_aliases() |
|
883 | + { |
|
884 | + $aliases = array( |
|
885 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
886 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
887 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
888 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
889 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
890 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
891 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
892 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
893 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
894 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
895 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
896 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
897 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
898 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
899 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
900 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
901 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
902 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
903 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
904 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
905 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
906 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
907 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
908 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
909 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
910 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
911 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
912 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
913 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
914 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
915 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
916 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
917 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
918 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
919 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
920 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
921 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
922 | + 'Registration_Processor' => 'EE_Registration_Processor', |
|
923 | + ); |
|
924 | + foreach ($aliases as $alias => $fqn) { |
|
925 | + if (is_array($fqn)) { |
|
926 | + foreach ($fqn as $class => $for_class) { |
|
927 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
928 | + } |
|
929 | + continue; |
|
930 | + } |
|
931 | + $this->class_cache->addAlias($fqn, $alias); |
|
932 | + } |
|
933 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
934 | + $this->class_cache->addAlias( |
|
935 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
936 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
937 | + ); |
|
938 | + } |
|
939 | + } |
|
940 | + |
|
941 | + |
|
942 | + /** |
|
943 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
944 | + * request Primarily used by unit tests. |
|
945 | + */ |
|
946 | + public function reset() |
|
947 | + { |
|
948 | + $this->_register_core_class_loaders(); |
|
949 | + $this->_register_core_dependencies(); |
|
950 | + } |
|
951 | + |
|
952 | + |
|
953 | + /** |
|
954 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
955 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
956 | + * WHY? |
|
957 | + * Because if a class is type hinting for a concretion, |
|
958 | + * then why would we need to find another class to supply it? |
|
959 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
960 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
961 | + * Don't go looking for some substitute. |
|
962 | + * Whereas if a class is type hinting for an interface... |
|
963 | + * then we need to find an actual class to use. |
|
964 | + * So the interface IS the alias for some other FQN, |
|
965 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
966 | + * represents some other class. |
|
967 | + * |
|
968 | + * @deprecated 4.9.62.p |
|
969 | + * @param string $fqn |
|
970 | + * @param string $for_class |
|
971 | + * @return bool |
|
972 | + */ |
|
973 | + public function has_alias($fqn = '', $for_class = '') |
|
974 | + { |
|
975 | + return $this->isAlias($fqn, $for_class); |
|
976 | + } |
|
977 | + |
|
978 | + |
|
979 | + /** |
|
980 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
981 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
982 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
983 | + * for example: |
|
984 | + * if the following two entries were added to the _aliases array: |
|
985 | + * array( |
|
986 | + * 'interface_alias' => 'some\namespace\interface' |
|
987 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
988 | + * ) |
|
989 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
990 | + * to load an instance of 'some\namespace\classname' |
|
991 | + * |
|
992 | + * @deprecated 4.9.62.p |
|
993 | + * @param string $alias |
|
994 | + * @param string $for_class |
|
995 | + * @return string |
|
996 | + */ |
|
997 | + public function get_alias($alias = '', $for_class = '') |
|
998 | + { |
|
999 | + return $this->getFqnForAlias($alias, $for_class); |
|
1000 | + } |
|
1001 | 1001 | } |
@@ -15,71 +15,71 @@ |
||
15 | 15 | class PueRequests extends Route |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * returns true if the current request matches this route |
|
20 | - * |
|
21 | - * @return bool |
|
22 | - * @since $VID:$ |
|
23 | - */ |
|
24 | - public function matchesCurrentRequest() |
|
25 | - { |
|
26 | - return $this->request->isAdmin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true); |
|
27 | - } |
|
18 | + /** |
|
19 | + * returns true if the current request matches this route |
|
20 | + * |
|
21 | + * @return bool |
|
22 | + * @since $VID:$ |
|
23 | + */ |
|
24 | + public function matchesCurrentRequest() |
|
25 | + { |
|
26 | + return $this->request->isAdmin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true); |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * @since $VID:$ |
|
32 | - */ |
|
33 | - protected function registerDependencies() |
|
34 | - { |
|
35 | - $this->dependency_map->registerDependencies( |
|
36 | - 'EventEspresso\core\services\licensing\LicenseService', |
|
37 | - [ |
|
38 | - 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
39 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
40 | - ] |
|
41 | - ); |
|
42 | - $this->dependency_map->registerDependencies( |
|
43 | - 'EventEspresso\core\domain\services\pue\Stats', |
|
44 | - [ |
|
45 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
46 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
47 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
48 | - ] |
|
49 | - ); |
|
50 | - $this->dependency_map->registerDependencies( |
|
51 | - 'EventEspresso\core\domain\services\pue\Config', |
|
52 | - [ |
|
53 | - 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
54 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
55 | - ] |
|
56 | - ); |
|
57 | - $this->dependency_map->registerDependencies( |
|
58 | - 'EventEspresso\core\domain\services\pue\StatsGatherer', |
|
59 | - [ |
|
60 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
61 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
62 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
63 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
64 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
65 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
66 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
67 | - ] |
|
68 | - ); |
|
69 | - } |
|
30 | + /** |
|
31 | + * @since $VID:$ |
|
32 | + */ |
|
33 | + protected function registerDependencies() |
|
34 | + { |
|
35 | + $this->dependency_map->registerDependencies( |
|
36 | + 'EventEspresso\core\services\licensing\LicenseService', |
|
37 | + [ |
|
38 | + 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
39 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
40 | + ] |
|
41 | + ); |
|
42 | + $this->dependency_map->registerDependencies( |
|
43 | + 'EventEspresso\core\domain\services\pue\Stats', |
|
44 | + [ |
|
45 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
46 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
47 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
48 | + ] |
|
49 | + ); |
|
50 | + $this->dependency_map->registerDependencies( |
|
51 | + 'EventEspresso\core\domain\services\pue\Config', |
|
52 | + [ |
|
53 | + 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
54 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
55 | + ] |
|
56 | + ); |
|
57 | + $this->dependency_map->registerDependencies( |
|
58 | + 'EventEspresso\core\domain\services\pue\StatsGatherer', |
|
59 | + [ |
|
60 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
61 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
62 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
63 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
64 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
65 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
66 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
67 | + ] |
|
68 | + ); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * implements logic required to run during request |
|
74 | - * |
|
75 | - * @return bool |
|
76 | - * @since $VID:$ |
|
77 | - */ |
|
78 | - protected function requestHandler() |
|
79 | - { |
|
80 | - // pew pew pew |
|
81 | - $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService'); |
|
82 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
83 | - return true; |
|
84 | - } |
|
72 | + /** |
|
73 | + * implements logic required to run during request |
|
74 | + * |
|
75 | + * @return bool |
|
76 | + * @since $VID:$ |
|
77 | + */ |
|
78 | + protected function requestHandler() |
|
79 | + { |
|
80 | + // pew pew pew |
|
81 | + $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService'); |
|
82 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
83 | + return true; |
|
84 | + } |
|
85 | 85 | } |