/** * * Gets all the related entities (or if its a belongs-to relation just the one) * to the item with the given id * * @param \WP_REST_Request $request * @return \WP_REST_Response|\WP_Error */ public static function handle_request_get_related(\WP_REST_Request $request) { $controller = new Read(); try { $matches = $controller->parse_route($request->get_route(), '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', array('version', 'model', 'id', 'related_model')); $controller->set_requested_version($matches['version']); $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); if (!$controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { return $controller->send_response(new \WP_Error('endpoint_parsing_error', sprintf(__('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), $main_model_name_singular))); } $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); //assume the related model name is plural and try to find the model's name $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); if (!$controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { //so the word didn't singularize well. Maybe that's just because it's a singular word? $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']); } if (!$controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { return $controller->send_response(new \WP_Error('endpoint_parsing_error', sprintf(__('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), $related_model_name_singular))); } return $controller->send_response($controller->get_entities_from_relation($request->get_param('id'), $main_model->related_settings_for($related_model_name_singular), $request)); } catch (\Exception $e) { return $controller->send_response($e); } }
public function test_singuralize_and_upper__funny_plural() { $this->assertEquals('Term_Taxonomy', EEH_Inflector::singularize_and_upper('term_taxonomies')); }