@@ -51,7 +51,7 @@ |
||
| 51 | 51 | */ |
| 52 | 52 | public function wp_user_obj() |
| 53 | 53 | { |
| 54 | - if (! $this->_wp_user_obj) { |
|
| 54 | + if ( ! $this->_wp_user_obj) { |
|
| 55 | 55 | $this->_wp_user_obj = get_user_by('ID', $this->ID()); |
| 56 | 56 | } |
| 57 | 57 | return $this->_wp_user_obj; |
@@ -11,91 +11,91 @@ |
||
| 11 | 11 | class EE_WP_User extends EE_Base_Class implements EEI_Admin_Links |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var WP_User |
|
| 16 | - */ |
|
| 17 | - protected $_wp_user_obj; |
|
| 14 | + /** |
|
| 15 | + * @var WP_User |
|
| 16 | + */ |
|
| 17 | + protected $_wp_user_obj; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @param array $props_n_values |
|
| 21 | - * @return EE_WP_User|mixed |
|
| 22 | - */ |
|
| 23 | - public static function new_instance($props_n_values = array()) |
|
| 24 | - { |
|
| 25 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 26 | - return $has_object ? $has_object : new self($props_n_values); |
|
| 27 | - } |
|
| 19 | + /** |
|
| 20 | + * @param array $props_n_values |
|
| 21 | + * @return EE_WP_User|mixed |
|
| 22 | + */ |
|
| 23 | + public static function new_instance($props_n_values = array()) |
|
| 24 | + { |
|
| 25 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 26 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param array $props_n_values |
|
| 32 | - * @return EE_WP_User |
|
| 33 | - */ |
|
| 34 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 35 | - { |
|
| 36 | - return new self($props_n_values, true); |
|
| 37 | - } |
|
| 30 | + /** |
|
| 31 | + * @param array $props_n_values |
|
| 32 | + * @return EE_WP_User |
|
| 33 | + */ |
|
| 34 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 35 | + { |
|
| 36 | + return new self($props_n_values, true); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Return a normal WP_User object (caches the object for future calls) |
|
| 41 | - * |
|
| 42 | - * @return WP_User |
|
| 43 | - */ |
|
| 44 | - public function wp_user_obj() |
|
| 45 | - { |
|
| 46 | - if (! $this->_wp_user_obj) { |
|
| 47 | - $this->_wp_user_obj = get_user_by('ID', $this->ID()); |
|
| 48 | - } |
|
| 49 | - return $this->_wp_user_obj; |
|
| 50 | - } |
|
| 39 | + /** |
|
| 40 | + * Return a normal WP_User object (caches the object for future calls) |
|
| 41 | + * |
|
| 42 | + * @return WP_User |
|
| 43 | + */ |
|
| 44 | + public function wp_user_obj() |
|
| 45 | + { |
|
| 46 | + if (! $this->_wp_user_obj) { |
|
| 47 | + $this->_wp_user_obj = get_user_by('ID', $this->ID()); |
|
| 48 | + } |
|
| 49 | + return $this->_wp_user_obj; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Return the link to the admin details for the object. |
|
| 54 | - * |
|
| 55 | - * @return string |
|
| 56 | - */ |
|
| 57 | - public function get_admin_details_link() |
|
| 58 | - { |
|
| 59 | - return $this->get_admin_edit_link(); |
|
| 60 | - } |
|
| 52 | + /** |
|
| 53 | + * Return the link to the admin details for the object. |
|
| 54 | + * |
|
| 55 | + * @return string |
|
| 56 | + */ |
|
| 57 | + public function get_admin_details_link() |
|
| 58 | + { |
|
| 59 | + return $this->get_admin_edit_link(); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 64 | - * |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public function get_admin_edit_link() |
|
| 68 | - { |
|
| 69 | - return esc_url( |
|
| 70 | - add_query_arg( |
|
| 71 | - 'wp_http_referer', |
|
| 72 | - urlencode( |
|
| 73 | - wp_unslash( |
|
| 74 | - $_SERVER['REQUEST_URI'] |
|
| 75 | - ) |
|
| 76 | - ), |
|
| 77 | - get_edit_user_link($this->ID()) |
|
| 78 | - ) |
|
| 79 | - ); |
|
| 80 | - } |
|
| 62 | + /** |
|
| 63 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 64 | + * |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public function get_admin_edit_link() |
|
| 68 | + { |
|
| 69 | + return esc_url( |
|
| 70 | + add_query_arg( |
|
| 71 | + 'wp_http_referer', |
|
| 72 | + urlencode( |
|
| 73 | + wp_unslash( |
|
| 74 | + $_SERVER['REQUEST_URI'] |
|
| 75 | + ) |
|
| 76 | + ), |
|
| 77 | + get_edit_user_link($this->ID()) |
|
| 78 | + ) |
|
| 79 | + ); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Returns the link to a settings page for the object. |
|
| 84 | - * |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 87 | - public function get_admin_settings_link() |
|
| 88 | - { |
|
| 89 | - return $this->get_admin_edit_link(); |
|
| 90 | - } |
|
| 82 | + /** |
|
| 83 | + * Returns the link to a settings page for the object. |
|
| 84 | + * |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | + public function get_admin_settings_link() |
|
| 88 | + { |
|
| 89 | + return $this->get_admin_edit_link(); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 94 | - * |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - public function get_admin_overview_link() |
|
| 98 | - { |
|
| 99 | - return admin_url('users.php'); |
|
| 100 | - } |
|
| 92 | + /** |
|
| 93 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 94 | + * |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + public function get_admin_overview_link() |
|
| 98 | + { |
|
| 99 | + return admin_url('users.php'); |
|
| 100 | + } |
|
| 101 | 101 | } |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * this method instantiates modules and calls the method that was defined when the route was registered |
| 183 | 183 | * |
| 184 | 184 | * @param string $module_name |
| 185 | - * @return EED_Module|object|null |
|
| 185 | + * @return null|EED_Module |
|
| 186 | 186 | * @throws ReflectionException |
| 187 | 187 | */ |
| 188 | 188 | public static function module_factory($module_name) |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | |
| 254 | 254 | /** |
| 255 | - * @param $current_route |
|
| 255 | + * @param string $current_route |
|
| 256 | 256 | * @return string |
| 257 | 257 | */ |
| 258 | 258 | public function get_view($current_route) |
@@ -15,255 +15,255 @@ |
||
| 15 | 15 | final class EE_Module_Request_Router implements InterminableInterface |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @var EE_Request $request |
|
| 20 | - */ |
|
| 21 | - private $request; |
|
| 18 | + /** |
|
| 19 | + * @var EE_Request $request |
|
| 20 | + */ |
|
| 21 | + private $request; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @var array $_previous_routes |
|
| 25 | - */ |
|
| 26 | - private static $_previous_routes = array(); |
|
| 23 | + /** |
|
| 24 | + * @var array $_previous_routes |
|
| 25 | + */ |
|
| 26 | + private static $_previous_routes = array(); |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var WP_Query $WP_Query |
|
| 30 | - */ |
|
| 31 | - public $WP_Query; |
|
| 28 | + /** |
|
| 29 | + * @var WP_Query $WP_Query |
|
| 30 | + */ |
|
| 31 | + public $WP_Query; |
|
| 32 | 32 | |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * EE_Module_Request_Router constructor. |
|
| 36 | - * |
|
| 37 | - * @param EE_Request $request |
|
| 38 | - */ |
|
| 39 | - public function __construct(EE_Request $request) |
|
| 40 | - { |
|
| 41 | - $this->request = $request; |
|
| 42 | - } |
|
| 34 | + /** |
|
| 35 | + * EE_Module_Request_Router constructor. |
|
| 36 | + * |
|
| 37 | + * @param EE_Request $request |
|
| 38 | + */ |
|
| 39 | + public function __construct(EE_Request $request) |
|
| 40 | + { |
|
| 41 | + $this->request = $request; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
| 47 | - * on subsequent calls to this method, |
|
| 48 | - * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
| 49 | - * and checks if the last called route has any forwarding routes registered for it |
|
| 50 | - * |
|
| 51 | - * @param WP_Query $WP_Query |
|
| 52 | - * @return NULL|string |
|
| 53 | - * @throws EE_Error |
|
| 54 | - * @throws ReflectionException |
|
| 55 | - */ |
|
| 56 | - public function get_route(WP_Query $WP_Query) |
|
| 57 | - { |
|
| 58 | - $this->WP_Query = $WP_Query; |
|
| 59 | - // assume this if first route being called |
|
| 60 | - $previous_route = false; |
|
| 61 | - // but is it really ??? |
|
| 62 | - if (! empty(self::$_previous_routes)) { |
|
| 63 | - // get last run route |
|
| 64 | - $previous_routes = array_values(self::$_previous_routes); |
|
| 65 | - $previous_route = array_pop($previous_routes); |
|
| 66 | - } |
|
| 67 | - // has another route already been run ? |
|
| 68 | - if ($previous_route) { |
|
| 69 | - // check if forwarding has been set |
|
| 70 | - $current_route = $this->get_forward($previous_route); |
|
| 71 | - try { |
|
| 72 | - // check for recursive forwarding |
|
| 73 | - if (isset(self::$_previous_routes[ $current_route ])) { |
|
| 74 | - throw new EE_Error( |
|
| 75 | - sprintf( |
|
| 76 | - __( |
|
| 77 | - 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
| 78 | - 'event_espresso' |
|
| 79 | - ), |
|
| 80 | - $current_route |
|
| 81 | - ) |
|
| 82 | - ); |
|
| 83 | - } |
|
| 84 | - } catch (EE_Error $e) { |
|
| 85 | - $e->get_error(); |
|
| 86 | - return null; |
|
| 87 | - } |
|
| 88 | - } else { |
|
| 89 | - // first route called |
|
| 90 | - $current_route = null; |
|
| 91 | - // grab all routes |
|
| 92 | - $routes = EE_Config::get_routes(); |
|
| 93 | - foreach ($routes as $key => $route) { |
|
| 94 | - // first determine if route key uses w?ldc*rds |
|
| 95 | - $uses_wildcards = strpos($key, '?') !== false |
|
| 96 | - || strpos($key, '*') !== false; |
|
| 97 | - // check request for module route |
|
| 98 | - $route_found = $uses_wildcards |
|
| 99 | - ? $this->request->matches($key) |
|
| 100 | - : $this->request->is_set($key); |
|
| 101 | - if ($route_found) { |
|
| 102 | - $current_route = $uses_wildcards |
|
| 103 | - ? $this->request->getMatch($key) |
|
| 104 | - : $this->request->get($key); |
|
| 105 | - $current_route = sanitize_text_field($current_route); |
|
| 106 | - if ($current_route) { |
|
| 107 | - $current_route = array($key, $current_route); |
|
| 108 | - break; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - // sorry, but I can't read what you route ! |
|
| 114 | - if (empty($current_route)) { |
|
| 115 | - return null; |
|
| 116 | - } |
|
| 117 | - // add route to previous routes array |
|
| 118 | - self::$_previous_routes[] = $current_route; |
|
| 119 | - return $current_route; |
|
| 120 | - } |
|
| 45 | + /** |
|
| 46 | + * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
| 47 | + * on subsequent calls to this method, |
|
| 48 | + * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
| 49 | + * and checks if the last called route has any forwarding routes registered for it |
|
| 50 | + * |
|
| 51 | + * @param WP_Query $WP_Query |
|
| 52 | + * @return NULL|string |
|
| 53 | + * @throws EE_Error |
|
| 54 | + * @throws ReflectionException |
|
| 55 | + */ |
|
| 56 | + public function get_route(WP_Query $WP_Query) |
|
| 57 | + { |
|
| 58 | + $this->WP_Query = $WP_Query; |
|
| 59 | + // assume this if first route being called |
|
| 60 | + $previous_route = false; |
|
| 61 | + // but is it really ??? |
|
| 62 | + if (! empty(self::$_previous_routes)) { |
|
| 63 | + // get last run route |
|
| 64 | + $previous_routes = array_values(self::$_previous_routes); |
|
| 65 | + $previous_route = array_pop($previous_routes); |
|
| 66 | + } |
|
| 67 | + // has another route already been run ? |
|
| 68 | + if ($previous_route) { |
|
| 69 | + // check if forwarding has been set |
|
| 70 | + $current_route = $this->get_forward($previous_route); |
|
| 71 | + try { |
|
| 72 | + // check for recursive forwarding |
|
| 73 | + if (isset(self::$_previous_routes[ $current_route ])) { |
|
| 74 | + throw new EE_Error( |
|
| 75 | + sprintf( |
|
| 76 | + __( |
|
| 77 | + 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
| 78 | + 'event_espresso' |
|
| 79 | + ), |
|
| 80 | + $current_route |
|
| 81 | + ) |
|
| 82 | + ); |
|
| 83 | + } |
|
| 84 | + } catch (EE_Error $e) { |
|
| 85 | + $e->get_error(); |
|
| 86 | + return null; |
|
| 87 | + } |
|
| 88 | + } else { |
|
| 89 | + // first route called |
|
| 90 | + $current_route = null; |
|
| 91 | + // grab all routes |
|
| 92 | + $routes = EE_Config::get_routes(); |
|
| 93 | + foreach ($routes as $key => $route) { |
|
| 94 | + // first determine if route key uses w?ldc*rds |
|
| 95 | + $uses_wildcards = strpos($key, '?') !== false |
|
| 96 | + || strpos($key, '*') !== false; |
|
| 97 | + // check request for module route |
|
| 98 | + $route_found = $uses_wildcards |
|
| 99 | + ? $this->request->matches($key) |
|
| 100 | + : $this->request->is_set($key); |
|
| 101 | + if ($route_found) { |
|
| 102 | + $current_route = $uses_wildcards |
|
| 103 | + ? $this->request->getMatch($key) |
|
| 104 | + : $this->request->get($key); |
|
| 105 | + $current_route = sanitize_text_field($current_route); |
|
| 106 | + if ($current_route) { |
|
| 107 | + $current_route = array($key, $current_route); |
|
| 108 | + break; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + // sorry, but I can't read what you route ! |
|
| 114 | + if (empty($current_route)) { |
|
| 115 | + return null; |
|
| 116 | + } |
|
| 117 | + // add route to previous routes array |
|
| 118 | + self::$_previous_routes[] = $current_route; |
|
| 119 | + return $current_route; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * this method simply takes a valid route, and resolves what module class method the route points to |
|
| 125 | - * |
|
| 126 | - * @param string $key |
|
| 127 | - * @param string $current_route |
|
| 128 | - * @return mixed EED_Module | boolean |
|
| 129 | - * @throws EE_Error |
|
| 130 | - * @throws ReflectionException |
|
| 131 | - */ |
|
| 132 | - public function resolve_route($key, $current_route) |
|
| 133 | - { |
|
| 134 | - // get module method that route has been mapped to |
|
| 135 | - $module_method = EE_Config::get_route($current_route, $key); |
|
| 136 | - // verify result was returned |
|
| 137 | - if (empty($module_method)) { |
|
| 138 | - $msg = sprintf( |
|
| 139 | - __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
| 140 | - $current_route |
|
| 141 | - ); |
|
| 142 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 143 | - return false; |
|
| 144 | - } |
|
| 145 | - // verify that result is an array |
|
| 146 | - if (! is_array($module_method)) { |
|
| 147 | - $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
| 148 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 149 | - return false; |
|
| 150 | - } |
|
| 151 | - // grab module name |
|
| 152 | - $module_name = $module_method[0]; |
|
| 153 | - // verify that a class method was registered properly |
|
| 154 | - if (! isset($module_method[1])) { |
|
| 155 | - $msg = sprintf( |
|
| 156 | - __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
| 157 | - $current_route |
|
| 158 | - ); |
|
| 159 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 160 | - return false; |
|
| 161 | - } |
|
| 162 | - // grab method |
|
| 163 | - $method = $module_method[1]; |
|
| 164 | - // verify that class exists |
|
| 165 | - if (! class_exists($module_name)) { |
|
| 166 | - $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
| 167 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 168 | - return false; |
|
| 169 | - } |
|
| 170 | - // verify that method exists |
|
| 171 | - if (! method_exists($module_name, $method)) { |
|
| 172 | - $msg = sprintf( |
|
| 173 | - __('The class method %s for the %s route is in invalid.', 'event_espresso'), |
|
| 174 | - $method, |
|
| 175 | - $current_route |
|
| 176 | - ); |
|
| 177 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 178 | - return false; |
|
| 179 | - } |
|
| 180 | - // instantiate module and call route method |
|
| 181 | - return $this->_module_router($module_name, $method); |
|
| 182 | - } |
|
| 123 | + /** |
|
| 124 | + * this method simply takes a valid route, and resolves what module class method the route points to |
|
| 125 | + * |
|
| 126 | + * @param string $key |
|
| 127 | + * @param string $current_route |
|
| 128 | + * @return mixed EED_Module | boolean |
|
| 129 | + * @throws EE_Error |
|
| 130 | + * @throws ReflectionException |
|
| 131 | + */ |
|
| 132 | + public function resolve_route($key, $current_route) |
|
| 133 | + { |
|
| 134 | + // get module method that route has been mapped to |
|
| 135 | + $module_method = EE_Config::get_route($current_route, $key); |
|
| 136 | + // verify result was returned |
|
| 137 | + if (empty($module_method)) { |
|
| 138 | + $msg = sprintf( |
|
| 139 | + __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
| 140 | + $current_route |
|
| 141 | + ); |
|
| 142 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 143 | + return false; |
|
| 144 | + } |
|
| 145 | + // verify that result is an array |
|
| 146 | + if (! is_array($module_method)) { |
|
| 147 | + $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
| 148 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 149 | + return false; |
|
| 150 | + } |
|
| 151 | + // grab module name |
|
| 152 | + $module_name = $module_method[0]; |
|
| 153 | + // verify that a class method was registered properly |
|
| 154 | + if (! isset($module_method[1])) { |
|
| 155 | + $msg = sprintf( |
|
| 156 | + __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
| 157 | + $current_route |
|
| 158 | + ); |
|
| 159 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 160 | + return false; |
|
| 161 | + } |
|
| 162 | + // grab method |
|
| 163 | + $method = $module_method[1]; |
|
| 164 | + // verify that class exists |
|
| 165 | + if (! class_exists($module_name)) { |
|
| 166 | + $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
| 167 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 168 | + return false; |
|
| 169 | + } |
|
| 170 | + // verify that method exists |
|
| 171 | + if (! method_exists($module_name, $method)) { |
|
| 172 | + $msg = sprintf( |
|
| 173 | + __('The class method %s for the %s route is in invalid.', 'event_espresso'), |
|
| 174 | + $method, |
|
| 175 | + $current_route |
|
| 176 | + ); |
|
| 177 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 178 | + return false; |
|
| 179 | + } |
|
| 180 | + // instantiate module and call route method |
|
| 181 | + return $this->_module_router($module_name, $method); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | 184 | |
| 185 | - /** |
|
| 186 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
| 187 | - * |
|
| 188 | - * @param string $module_name |
|
| 189 | - * @return EED_Module|object|null |
|
| 190 | - * @throws ReflectionException |
|
| 191 | - */ |
|
| 192 | - public static function module_factory($module_name) |
|
| 193 | - { |
|
| 194 | - if ($module_name === 'EED_Module') { |
|
| 195 | - EE_Error::add_error( |
|
| 196 | - sprintf( |
|
| 197 | - __( |
|
| 198 | - 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
| 199 | - 'event_espresso' |
|
| 200 | - ), |
|
| 201 | - $module_name |
|
| 202 | - ), |
|
| 203 | - __FILE__, |
|
| 204 | - __FUNCTION__, |
|
| 205 | - __LINE__ |
|
| 206 | - ); |
|
| 207 | - return null; |
|
| 208 | - } |
|
| 209 | - // instantiate module class |
|
| 210 | - $module = new $module_name(); |
|
| 211 | - // ensure that class is actually a module |
|
| 212 | - if (! $module instanceof EED_Module) { |
|
| 213 | - EE_Error::add_error( |
|
| 214 | - sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
| 215 | - __FILE__, |
|
| 216 | - __FUNCTION__, |
|
| 217 | - __LINE__ |
|
| 218 | - ); |
|
| 219 | - return null; |
|
| 220 | - } |
|
| 221 | - return $module; |
|
| 222 | - } |
|
| 185 | + /** |
|
| 186 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
| 187 | + * |
|
| 188 | + * @param string $module_name |
|
| 189 | + * @return EED_Module|object|null |
|
| 190 | + * @throws ReflectionException |
|
| 191 | + */ |
|
| 192 | + public static function module_factory($module_name) |
|
| 193 | + { |
|
| 194 | + if ($module_name === 'EED_Module') { |
|
| 195 | + EE_Error::add_error( |
|
| 196 | + sprintf( |
|
| 197 | + __( |
|
| 198 | + 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
| 199 | + 'event_espresso' |
|
| 200 | + ), |
|
| 201 | + $module_name |
|
| 202 | + ), |
|
| 203 | + __FILE__, |
|
| 204 | + __FUNCTION__, |
|
| 205 | + __LINE__ |
|
| 206 | + ); |
|
| 207 | + return null; |
|
| 208 | + } |
|
| 209 | + // instantiate module class |
|
| 210 | + $module = new $module_name(); |
|
| 211 | + // ensure that class is actually a module |
|
| 212 | + if (! $module instanceof EED_Module) { |
|
| 213 | + EE_Error::add_error( |
|
| 214 | + sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
| 215 | + __FILE__, |
|
| 216 | + __FUNCTION__, |
|
| 217 | + __LINE__ |
|
| 218 | + ); |
|
| 219 | + return null; |
|
| 220 | + } |
|
| 221 | + return $module; |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
| 227 | - * |
|
| 228 | - * @param string $module_name |
|
| 229 | - * @param string $method |
|
| 230 | - * @return EED_Module|null |
|
| 231 | - * @throws EE_Error |
|
| 232 | - * @throws ReflectionException |
|
| 233 | - */ |
|
| 234 | - private function _module_router($module_name, $method) |
|
| 235 | - { |
|
| 236 | - // instantiate module class |
|
| 237 | - $module = EE_Module_Request_Router::module_factory($module_name); |
|
| 238 | - if ($module instanceof EED_Module) { |
|
| 239 | - // and call whatever action the route was for |
|
| 240 | - try { |
|
| 241 | - call_user_func(array($module, $method), $this->WP_Query); |
|
| 242 | - } catch (EE_Error $e) { |
|
| 243 | - $e->get_error(); |
|
| 244 | - return null; |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - return $module; |
|
| 248 | - } |
|
| 225 | + /** |
|
| 226 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
| 227 | + * |
|
| 228 | + * @param string $module_name |
|
| 229 | + * @param string $method |
|
| 230 | + * @return EED_Module|null |
|
| 231 | + * @throws EE_Error |
|
| 232 | + * @throws ReflectionException |
|
| 233 | + */ |
|
| 234 | + private function _module_router($module_name, $method) |
|
| 235 | + { |
|
| 236 | + // instantiate module class |
|
| 237 | + $module = EE_Module_Request_Router::module_factory($module_name); |
|
| 238 | + if ($module instanceof EED_Module) { |
|
| 239 | + // and call whatever action the route was for |
|
| 240 | + try { |
|
| 241 | + call_user_func(array($module, $method), $this->WP_Query); |
|
| 242 | + } catch (EE_Error $e) { |
|
| 243 | + $e->get_error(); |
|
| 244 | + return null; |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + return $module; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | 250 | |
| 251 | - /** |
|
| 252 | - * @param $current_route |
|
| 253 | - * @return string |
|
| 254 | - */ |
|
| 255 | - public function get_forward($current_route) |
|
| 256 | - { |
|
| 257 | - return EE_Config::get_forward($current_route); |
|
| 258 | - } |
|
| 251 | + /** |
|
| 252 | + * @param $current_route |
|
| 253 | + * @return string |
|
| 254 | + */ |
|
| 255 | + public function get_forward($current_route) |
|
| 256 | + { |
|
| 257 | + return EE_Config::get_forward($current_route); |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * @param $current_route |
|
| 263 | - * @return string |
|
| 264 | - */ |
|
| 265 | - public function get_view($current_route) |
|
| 266 | - { |
|
| 267 | - return EE_Config::get_view($current_route); |
|
| 268 | - } |
|
| 261 | + /** |
|
| 262 | + * @param $current_route |
|
| 263 | + * @return string |
|
| 264 | + */ |
|
| 265 | + public function get_view($current_route) |
|
| 266 | + { |
|
| 267 | + return EE_Config::get_view($current_route); |
|
| 268 | + } |
|
| 269 | 269 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | // assume this if first route being called |
| 60 | 60 | $previous_route = false; |
| 61 | 61 | // but is it really ??? |
| 62 | - if (! empty(self::$_previous_routes)) { |
|
| 62 | + if ( ! empty(self::$_previous_routes)) { |
|
| 63 | 63 | // get last run route |
| 64 | 64 | $previous_routes = array_values(self::$_previous_routes); |
| 65 | 65 | $previous_route = array_pop($previous_routes); |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $current_route = $this->get_forward($previous_route); |
| 71 | 71 | try { |
| 72 | 72 | // check for recursive forwarding |
| 73 | - if (isset(self::$_previous_routes[ $current_route ])) { |
|
| 73 | + if (isset(self::$_previous_routes[$current_route])) { |
|
| 74 | 74 | throw new EE_Error( |
| 75 | 75 | sprintf( |
| 76 | 76 | __( |
@@ -143,38 +143,38 @@ discard block |
||
| 143 | 143 | return false; |
| 144 | 144 | } |
| 145 | 145 | // verify that result is an array |
| 146 | - if (! is_array($module_method)) { |
|
| 146 | + if ( ! is_array($module_method)) { |
|
| 147 | 147 | $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
| 148 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 148 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 149 | 149 | return false; |
| 150 | 150 | } |
| 151 | 151 | // grab module name |
| 152 | 152 | $module_name = $module_method[0]; |
| 153 | 153 | // verify that a class method was registered properly |
| 154 | - if (! isset($module_method[1])) { |
|
| 154 | + if ( ! isset($module_method[1])) { |
|
| 155 | 155 | $msg = sprintf( |
| 156 | 156 | __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
| 157 | 157 | $current_route |
| 158 | 158 | ); |
| 159 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 159 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 160 | 160 | return false; |
| 161 | 161 | } |
| 162 | 162 | // grab method |
| 163 | 163 | $method = $module_method[1]; |
| 164 | 164 | // verify that class exists |
| 165 | - if (! class_exists($module_name)) { |
|
| 165 | + if ( ! class_exists($module_name)) { |
|
| 166 | 166 | $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
| 167 | 167 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
| 168 | 168 | return false; |
| 169 | 169 | } |
| 170 | 170 | // verify that method exists |
| 171 | - if (! method_exists($module_name, $method)) { |
|
| 171 | + if ( ! method_exists($module_name, $method)) { |
|
| 172 | 172 | $msg = sprintf( |
| 173 | 173 | __('The class method %s for the %s route is in invalid.', 'event_espresso'), |
| 174 | 174 | $method, |
| 175 | 175 | $current_route |
| 176 | 176 | ); |
| 177 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 177 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 178 | 178 | return false; |
| 179 | 179 | } |
| 180 | 180 | // instantiate module and call route method |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | // instantiate module class |
| 210 | 210 | $module = new $module_name(); |
| 211 | 211 | // ensure that class is actually a module |
| 212 | - if (! $module instanceof EED_Module) { |
|
| 212 | + if ( ! $module instanceof EED_Module) { |
|
| 213 | 213 | EE_Error::add_error( |
| 214 | 214 | sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
| 215 | 215 | __FILE__, |
@@ -9,24 +9,24 @@ |
||
| 9 | 9 | interface EEI_Request_Decorator |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * converts a Request to a Response |
|
| 14 | - * can perform their logic either before or after the core application has run like so: |
|
| 15 | - * public function handle_request( EE_Request $request, EE_Response $response ) { |
|
| 16 | - * $this->request = $request; |
|
| 17 | - * $this->response = $response; |
|
| 18 | - * // logic performed BEFORE core app has run |
|
| 19 | - * $this->process_request_stack( $this->request, $this->response ); |
|
| 20 | - * // logic performed AFTER core app has run |
|
| 21 | - * return $response; |
|
| 22 | - * } |
|
| 23 | - * |
|
| 24 | - * @deprecated 4.9.53 |
|
| 25 | - * @param EE_Request $request |
|
| 26 | - * @param EE_Response $response |
|
| 27 | - * @return EE_Response |
|
| 28 | - */ |
|
| 29 | - public function handle_request(EE_Request $request, EE_Response $response); |
|
| 12 | + /** |
|
| 13 | + * converts a Request to a Response |
|
| 14 | + * can perform their logic either before or after the core application has run like so: |
|
| 15 | + * public function handle_request( EE_Request $request, EE_Response $response ) { |
|
| 16 | + * $this->request = $request; |
|
| 17 | + * $this->response = $response; |
|
| 18 | + * // logic performed BEFORE core app has run |
|
| 19 | + * $this->process_request_stack( $this->request, $this->response ); |
|
| 20 | + * // logic performed AFTER core app has run |
|
| 21 | + * return $response; |
|
| 22 | + * } |
|
| 23 | + * |
|
| 24 | + * @deprecated 4.9.53 |
|
| 25 | + * @param EE_Request $request |
|
| 26 | + * @param EE_Response $response |
|
| 27 | + * @return EE_Response |
|
| 28 | + */ |
|
| 29 | + public function handle_request(EE_Request $request, EE_Response $response); |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | } |
@@ -15,125 +15,125 @@ |
||
| 15 | 15 | interface LegacyRequestInterface |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @return array |
|
| 20 | - */ |
|
| 21 | - public function get_params(); |
|
| 18 | + /** |
|
| 19 | + * @return array |
|
| 20 | + */ |
|
| 21 | + public function get_params(); |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @return array |
|
| 26 | - */ |
|
| 27 | - public function post_params(); |
|
| 24 | + /** |
|
| 25 | + * @return array |
|
| 26 | + */ |
|
| 27 | + public function post_params(); |
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @return array |
|
| 32 | - */ |
|
| 33 | - public function cookie_params(); |
|
| 30 | + /** |
|
| 31 | + * @return array |
|
| 32 | + */ |
|
| 33 | + public function cookie_params(); |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @return array |
|
| 38 | - */ |
|
| 39 | - public function server_params(); |
|
| 36 | + /** |
|
| 37 | + * @return array |
|
| 38 | + */ |
|
| 39 | + public function server_params(); |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * returns contents of $_REQUEST |
|
| 44 | - * |
|
| 45 | - * @return array |
|
| 46 | - */ |
|
| 47 | - public function params(); |
|
| 42 | + /** |
|
| 43 | + * returns contents of $_REQUEST |
|
| 44 | + * |
|
| 45 | + * @return array |
|
| 46 | + */ |
|
| 47 | + public function params(); |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param $key |
|
| 52 | - * @param $value |
|
| 53 | - * @param bool $override_ee |
|
| 54 | - * @return void |
|
| 55 | - */ |
|
| 56 | - public function set($key, $value, $override_ee = false); |
|
| 50 | + /** |
|
| 51 | + * @param $key |
|
| 52 | + * @param $value |
|
| 53 | + * @param bool $override_ee |
|
| 54 | + * @return void |
|
| 55 | + */ |
|
| 56 | + public function set($key, $value, $override_ee = false); |
|
| 57 | 57 | |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * returns the value for a request param if the given key exists |
|
| 61 | - * |
|
| 62 | - * @param $key |
|
| 63 | - * @param null $default |
|
| 64 | - * @return mixed |
|
| 65 | - */ |
|
| 66 | - public function get($key, $default = null); |
|
| 59 | + /** |
|
| 60 | + * returns the value for a request param if the given key exists |
|
| 61 | + * |
|
| 62 | + * @param $key |
|
| 63 | + * @param null $default |
|
| 64 | + * @return mixed |
|
| 65 | + */ |
|
| 66 | + public function get($key, $default = null); |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * check if param exists |
|
| 71 | - * |
|
| 72 | - * @param $key |
|
| 73 | - * @return bool |
|
| 74 | - */ |
|
| 75 | - public function is_set($key); |
|
| 69 | + /** |
|
| 70 | + * check if param exists |
|
| 71 | + * |
|
| 72 | + * @param $key |
|
| 73 | + * @return bool |
|
| 74 | + */ |
|
| 75 | + public function is_set($key); |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * remove param |
|
| 80 | - * |
|
| 81 | - * @param $key |
|
| 82 | - * @param bool $unset_from_global_too |
|
| 83 | - */ |
|
| 84 | - public function un_set($key, $unset_from_global_too = false); |
|
| 78 | + /** |
|
| 79 | + * remove param |
|
| 80 | + * |
|
| 81 | + * @param $key |
|
| 82 | + * @param bool $unset_from_global_too |
|
| 83 | + */ |
|
| 84 | + public function un_set($key, $unset_from_global_too = false); |
|
| 85 | 85 | |
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - public function ip_address(); |
|
| 87 | + /** |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + public function ip_address(); |
|
| 91 | 91 | |
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @return bool |
|
| 95 | - */ |
|
| 96 | - public function isAdmin(); |
|
| 93 | + /** |
|
| 94 | + * @return bool |
|
| 95 | + */ |
|
| 96 | + public function isAdmin(); |
|
| 97 | 97 | |
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @return mixed |
|
| 101 | - */ |
|
| 102 | - public function isAjax(); |
|
| 99 | + /** |
|
| 100 | + * @return mixed |
|
| 101 | + */ |
|
| 102 | + public function isAjax(); |
|
| 103 | 103 | |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * @return mixed |
|
| 107 | - */ |
|
| 108 | - public function isFrontAjax(); |
|
| 105 | + /** |
|
| 106 | + * @return mixed |
|
| 107 | + */ |
|
| 108 | + public function isFrontAjax(); |
|
| 109 | 109 | |
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * @return mixed|string |
|
| 113 | - */ |
|
| 114 | - public function requestUri(); |
|
| 111 | + /** |
|
| 112 | + * @return mixed|string |
|
| 113 | + */ |
|
| 114 | + public function requestUri(); |
|
| 115 | 115 | |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * @return string |
|
| 119 | - */ |
|
| 120 | - public function userAgent(); |
|
| 117 | + /** |
|
| 118 | + * @return string |
|
| 119 | + */ |
|
| 120 | + public function userAgent(); |
|
| 121 | 121 | |
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * @param string $user_agent |
|
| 125 | - */ |
|
| 126 | - public function setUserAgent($user_agent = ''); |
|
| 123 | + /** |
|
| 124 | + * @param string $user_agent |
|
| 125 | + */ |
|
| 126 | + public function setUserAgent($user_agent = ''); |
|
| 127 | 127 | |
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * @return bool |
|
| 131 | - */ |
|
| 132 | - public function isBot(); |
|
| 129 | + /** |
|
| 130 | + * @return bool |
|
| 131 | + */ |
|
| 132 | + public function isBot(); |
|
| 133 | 133 | |
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * @param bool $is_bot |
|
| 137 | - */ |
|
| 138 | - public function setIsBot($is_bot); |
|
| 135 | + /** |
|
| 136 | + * @param bool $is_bot |
|
| 137 | + */ |
|
| 138 | + public function setIsBot($is_bot); |
|
| 139 | 139 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | public function setNotice($key, $value) |
| 60 | 60 | { |
| 61 | - $this->notice[ $key ] = $value; |
|
| 61 | + $this->notice[$key] = $value; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public function getNotice($key) |
| 71 | 71 | { |
| 72 | - return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null; |
|
| 72 | + return isset($this->notice[$key]) ? $this->notice[$key] : null; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | public function addOutput($string, $append = true) |
| 92 | 92 | { |
| 93 | - $this->output = $append ? $this->output . $string : $string . $this->output; |
|
| 93 | + $this->output = $append ? $this->output.$string : $string.$this->output; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | |
@@ -16,119 +16,119 @@ |
||
| 16 | 16 | class Response implements ResponseInterface, ReservedInstanceInterface |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var array $notice |
|
| 21 | - */ |
|
| 22 | - protected $notice = array(); |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * rendered output to be returned to WP |
|
| 26 | - * |
|
| 27 | - * @var string $output |
|
| 28 | - */ |
|
| 29 | - protected $output = ''; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var bool |
|
| 33 | - */ |
|
| 34 | - protected $request_terminated = false; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var bool $deactivate_plugin |
|
| 38 | - */ |
|
| 39 | - protected $deactivate_plugin = false; |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * EE_Response constructor. |
|
| 44 | - */ |
|
| 45 | - public function __construct() |
|
| 46 | - { |
|
| 47 | - $this->terminateRequest(false); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @param $key |
|
| 53 | - * @param $value |
|
| 54 | - * @return void |
|
| 55 | - */ |
|
| 56 | - public function setNotice($key, $value) |
|
| 57 | - { |
|
| 58 | - $this->notice[ $key ] = $value; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param $key |
|
| 64 | - * @return mixed |
|
| 65 | - */ |
|
| 66 | - public function getNotice($key) |
|
| 67 | - { |
|
| 68 | - return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @return array |
|
| 74 | - */ |
|
| 75 | - public function getNotices() |
|
| 76 | - { |
|
| 77 | - return $this->notice; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @param string $string |
|
| 83 | - * @param bool $append |
|
| 84 | - */ |
|
| 85 | - public function addOutput($string, $append = true) |
|
| 86 | - { |
|
| 87 | - $this->output = $append ? $this->output . $string : $string . $this->output; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @return string |
|
| 93 | - */ |
|
| 94 | - public function getOutput() |
|
| 95 | - { |
|
| 96 | - return $this->output; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @return boolean |
|
| 102 | - */ |
|
| 103 | - public function requestTerminated() |
|
| 104 | - { |
|
| 105 | - return $this->request_terminated; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @param boolean $request_terminated |
|
| 111 | - */ |
|
| 112 | - public function terminateRequest($request_terminated = true) |
|
| 113 | - { |
|
| 114 | - $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @return boolean |
|
| 120 | - */ |
|
| 121 | - public function pluginDeactivated() |
|
| 122 | - { |
|
| 123 | - return $this->deactivate_plugin; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * sets $deactivate_plugin to true |
|
| 129 | - */ |
|
| 130 | - public function deactivatePlugin() |
|
| 131 | - { |
|
| 132 | - $this->deactivate_plugin = true; |
|
| 133 | - } |
|
| 19 | + /** |
|
| 20 | + * @var array $notice |
|
| 21 | + */ |
|
| 22 | + protected $notice = array(); |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * rendered output to be returned to WP |
|
| 26 | + * |
|
| 27 | + * @var string $output |
|
| 28 | + */ |
|
| 29 | + protected $output = ''; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var bool |
|
| 33 | + */ |
|
| 34 | + protected $request_terminated = false; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var bool $deactivate_plugin |
|
| 38 | + */ |
|
| 39 | + protected $deactivate_plugin = false; |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * EE_Response constructor. |
|
| 44 | + */ |
|
| 45 | + public function __construct() |
|
| 46 | + { |
|
| 47 | + $this->terminateRequest(false); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @param $key |
|
| 53 | + * @param $value |
|
| 54 | + * @return void |
|
| 55 | + */ |
|
| 56 | + public function setNotice($key, $value) |
|
| 57 | + { |
|
| 58 | + $this->notice[ $key ] = $value; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param $key |
|
| 64 | + * @return mixed |
|
| 65 | + */ |
|
| 66 | + public function getNotice($key) |
|
| 67 | + { |
|
| 68 | + return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @return array |
|
| 74 | + */ |
|
| 75 | + public function getNotices() |
|
| 76 | + { |
|
| 77 | + return $this->notice; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @param string $string |
|
| 83 | + * @param bool $append |
|
| 84 | + */ |
|
| 85 | + public function addOutput($string, $append = true) |
|
| 86 | + { |
|
| 87 | + $this->output = $append ? $this->output . $string : $string . $this->output; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @return string |
|
| 93 | + */ |
|
| 94 | + public function getOutput() |
|
| 95 | + { |
|
| 96 | + return $this->output; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @return boolean |
|
| 102 | + */ |
|
| 103 | + public function requestTerminated() |
|
| 104 | + { |
|
| 105 | + return $this->request_terminated; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @param boolean $request_terminated |
|
| 111 | + */ |
|
| 112 | + public function terminateRequest($request_terminated = true) |
|
| 113 | + { |
|
| 114 | + $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @return boolean |
|
| 120 | + */ |
|
| 121 | + public function pluginDeactivated() |
|
| 122 | + { |
|
| 123 | + return $this->deactivate_plugin; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * sets $deactivate_plugin to true |
|
| 129 | + */ |
|
| 130 | + public function deactivatePlugin() |
|
| 131 | + { |
|
| 132 | + $this->deactivate_plugin = true; |
|
| 133 | + } |
|
| 134 | 134 | } |
@@ -78,7 +78,7 @@ |
||
| 78 | 78 | public function preProductionVersionAdminNotice() |
| 79 | 79 | { |
| 80 | 80 | new PersistentAdminNotice( |
| 81 | - 'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION, |
|
| 81 | + 'preProductionVersionAdminNotice_'.EVENT_ESPRESSO_VERSION, |
|
| 82 | 82 | $this->warningNotice() |
| 83 | 83 | ); |
| 84 | 84 | } |
@@ -18,91 +18,91 @@ |
||
| 18 | 18 | class PreProductionVersionWarning extends Middleware |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * converts a Request to a Response |
|
| 23 | - * |
|
| 24 | - * @param RequestInterface $request |
|
| 25 | - * @param ResponseInterface $response |
|
| 26 | - * @return ResponseInterface |
|
| 27 | - */ |
|
| 28 | - public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 29 | - { |
|
| 30 | - $this->request = $request; |
|
| 31 | - $this->response = $response; |
|
| 32 | - $this->displayPreProductionVersionWarning(); |
|
| 33 | - $this->response = $this->processRequestStack($this->request, $this->response); |
|
| 34 | - return $this->response; |
|
| 35 | - } |
|
| 21 | + /** |
|
| 22 | + * converts a Request to a Response |
|
| 23 | + * |
|
| 24 | + * @param RequestInterface $request |
|
| 25 | + * @param ResponseInterface $response |
|
| 26 | + * @return ResponseInterface |
|
| 27 | + */ |
|
| 28 | + public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 29 | + { |
|
| 30 | + $this->request = $request; |
|
| 31 | + $this->response = $response; |
|
| 32 | + $this->displayPreProductionVersionWarning(); |
|
| 33 | + $this->response = $this->processRequestStack($this->request, $this->response); |
|
| 34 | + return $this->response; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
| 40 | - * |
|
| 41 | - * @return void |
|
| 42 | - */ |
|
| 43 | - public function displayPreProductionVersionWarning() |
|
| 44 | - { |
|
| 45 | - // skip AJAX requests |
|
| 46 | - if ($this->request->isAjax()) { |
|
| 47 | - return; |
|
| 48 | - } |
|
| 49 | - // skip stable releases |
|
| 50 | - if (substr(EVENT_ESPRESSO_VERSION, -5) !== '.beta') { |
|
| 51 | - return; |
|
| 52 | - } |
|
| 53 | - // site admin has authorized use of non-stable release candidate for production |
|
| 54 | - if (defined('ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE') && ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE) { |
|
| 55 | - return; |
|
| 56 | - } |
|
| 57 | - // post release candidate warning |
|
| 58 | - if ($this->request->isAdmin()) { |
|
| 59 | - add_action('admin_notices', array($this, 'preProductionVersionAdminNotice'), -999); |
|
| 60 | - } else { |
|
| 61 | - add_action('shutdown', array($this, 'preProductionVersionWarningNotice'), 10); |
|
| 62 | - } |
|
| 63 | - } |
|
| 38 | + /** |
|
| 39 | + * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
| 40 | + * |
|
| 41 | + * @return void |
|
| 42 | + */ |
|
| 43 | + public function displayPreProductionVersionWarning() |
|
| 44 | + { |
|
| 45 | + // skip AJAX requests |
|
| 46 | + if ($this->request->isAjax()) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 49 | + // skip stable releases |
|
| 50 | + if (substr(EVENT_ESPRESSO_VERSION, -5) !== '.beta') { |
|
| 51 | + return; |
|
| 52 | + } |
|
| 53 | + // site admin has authorized use of non-stable release candidate for production |
|
| 54 | + if (defined('ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE') && ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE) { |
|
| 55 | + return; |
|
| 56 | + } |
|
| 57 | + // post release candidate warning |
|
| 58 | + if ($this->request->isAdmin()) { |
|
| 59 | + add_action('admin_notices', array($this, 'preProductionVersionAdminNotice'), -999); |
|
| 60 | + } else { |
|
| 61 | + add_action('shutdown', array($this, 'preProductionVersionWarningNotice'), 10); |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * displays admin notice that current version of EE is not a stable release |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - * @throws InvalidDataTypeException |
|
| 71 | - */ |
|
| 72 | - public function preProductionVersionAdminNotice() |
|
| 73 | - { |
|
| 74 | - new PersistentAdminNotice( |
|
| 75 | - 'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION, |
|
| 76 | - $this->warningNotice() |
|
| 77 | - ); |
|
| 78 | - } |
|
| 66 | + /** |
|
| 67 | + * displays admin notice that current version of EE is not a stable release |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + * @throws InvalidDataTypeException |
|
| 71 | + */ |
|
| 72 | + public function preProductionVersionAdminNotice() |
|
| 73 | + { |
|
| 74 | + new PersistentAdminNotice( |
|
| 75 | + 'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION, |
|
| 76 | + $this->warningNotice() |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * displays message on frontend of site notifying admin that current version of EE is not a stable release |
|
| 83 | - * |
|
| 84 | - * @return void |
|
| 85 | - */ |
|
| 86 | - public function preProductionVersionWarningNotice() |
|
| 87 | - { |
|
| 88 | - echo '<div id="ee-release-candidate-notice-dv" class="ee-really-important-notice-dv"><p>'; |
|
| 89 | - echo $this->warningNotice(); |
|
| 90 | - echo '</p></div>'; |
|
| 91 | - } |
|
| 81 | + /** |
|
| 82 | + * displays message on frontend of site notifying admin that current version of EE is not a stable release |
|
| 83 | + * |
|
| 84 | + * @return void |
|
| 85 | + */ |
|
| 86 | + public function preProductionVersionWarningNotice() |
|
| 87 | + { |
|
| 88 | + echo '<div id="ee-release-candidate-notice-dv" class="ee-really-important-notice-dv"><p>'; |
|
| 89 | + echo $this->warningNotice(); |
|
| 90 | + echo '</p></div>'; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - private function warningNotice() |
|
| 98 | - { |
|
| 99 | - return sprintf( |
|
| 100 | - esc_html__( |
|
| 101 | - 'This version of Event Espresso is for testing and/or evaluation purposes only. It is %1$snot%2$s considered a stable release and should therefore %1$snot%2$s be activated on a live or production website.', |
|
| 102 | - 'event_espresso' |
|
| 103 | - ), |
|
| 104 | - '<strong>', |
|
| 105 | - '</strong>' |
|
| 106 | - ); |
|
| 107 | - } |
|
| 94 | + /** |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + private function warningNotice() |
|
| 98 | + { |
|
| 99 | + return sprintf( |
|
| 100 | + esc_html__( |
|
| 101 | + 'This version of Event Espresso is for testing and/or evaluation purposes only. It is %1$snot%2$s considered a stable release and should therefore %1$snot%2$s be activated on a live or production website.', |
|
| 102 | + 'event_espresso' |
|
| 103 | + ), |
|
| 104 | + '<strong>', |
|
| 105 | + '</strong>' |
|
| 106 | + ); |
|
| 107 | + } |
|
| 108 | 108 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * |
| 182 | 182 | * @deprecated 4.9.53 |
| 183 | 183 | * @param $key |
| 184 | - * @param null $default |
|
| 184 | + * @param null|string $default |
|
| 185 | 185 | * @return mixed |
| 186 | 186 | * @throws InvalidArgumentException |
| 187 | 187 | * @throws InvalidDataTypeException |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | /** |
| 258 | 258 | * @deprecated 4.9.53 |
| 259 | - * @return mixed |
|
| 259 | + * @return boolean |
|
| 260 | 260 | * @throws InvalidArgumentException |
| 261 | 261 | * @throws InvalidDataTypeException |
| 262 | 262 | * @throws InvalidInterfaceException |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | |
| 270 | 270 | /** |
| 271 | 271 | * @deprecated 4.9.53 |
| 272 | - * @return mixed |
|
| 272 | + * @return boolean |
|
| 273 | 273 | * @throws InvalidArgumentException |
| 274 | 274 | * @throws InvalidDataTypeException |
| 275 | 275 | * @throws InvalidInterfaceException |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | |
| 283 | 283 | /** |
| 284 | 284 | * @deprecated 4.9.53 |
| 285 | - * @return mixed|string |
|
| 285 | + * @return string |
|
| 286 | 286 | * @throws InvalidArgumentException |
| 287 | 287 | * @throws InvalidDataTypeException |
| 288 | 288 | * @throws InvalidInterfaceException |
@@ -18,359 +18,359 @@ |
||
| 18 | 18 | class EE_Request implements LegacyRequestInterface, InterminableInterface |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var RequestInterface $request |
|
| 23 | - */ |
|
| 24 | - private $request; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * whether current request is for the admin but NOT via AJAX |
|
| 28 | - * |
|
| 29 | - * @var boolean $admin |
|
| 30 | - */ |
|
| 31 | - public $admin = false; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * whether current request is via AJAX |
|
| 35 | - * |
|
| 36 | - * @var boolean $ajax |
|
| 37 | - */ |
|
| 38 | - public $ajax = false; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * whether current request is via AJAX from the frontend of the site |
|
| 42 | - * |
|
| 43 | - * @var boolean $front_ajax |
|
| 44 | - */ |
|
| 45 | - public $front_ajax = false; |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @deprecated 4.9.53 |
|
| 50 | - * @param array $get |
|
| 51 | - * @param array $post |
|
| 52 | - * @param array $cookie |
|
| 53 | - * @param array $server |
|
| 54 | - */ |
|
| 55 | - public function __construct( |
|
| 56 | - array $get = array(), |
|
| 57 | - array $post = array(), |
|
| 58 | - array $cookie = array(), |
|
| 59 | - array $server = array() |
|
| 60 | - ) { |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @return RequestInterface |
|
| 66 | - * @throws InvalidArgumentException |
|
| 67 | - * @throws InvalidInterfaceException |
|
| 68 | - * @throws InvalidDataTypeException |
|
| 69 | - */ |
|
| 70 | - private function request() |
|
| 71 | - { |
|
| 72 | - if ($this->request instanceof RequestInterface) { |
|
| 73 | - return $this->request; |
|
| 74 | - } |
|
| 75 | - $loader = LoaderFactory::getLoader(); |
|
| 76 | - $this->request = $loader->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
| 77 | - return $this->request; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @param RequestInterface $request |
|
| 83 | - */ |
|
| 84 | - public function setRequest(RequestInterface $request) |
|
| 85 | - { |
|
| 86 | - $this->request = $request; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @deprecated 4.9.53 |
|
| 92 | - * @return array |
|
| 93 | - * @throws InvalidArgumentException |
|
| 94 | - * @throws InvalidDataTypeException |
|
| 95 | - * @throws InvalidInterfaceException |
|
| 96 | - */ |
|
| 97 | - public function get_params() |
|
| 98 | - { |
|
| 99 | - return $this->request()->getParams(); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @deprecated 4.9.53 |
|
| 105 | - * @return array |
|
| 106 | - * @throws InvalidArgumentException |
|
| 107 | - * @throws InvalidDataTypeException |
|
| 108 | - * @throws InvalidInterfaceException |
|
| 109 | - */ |
|
| 110 | - public function post_params() |
|
| 111 | - { |
|
| 112 | - return $this->request()->postParams(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @deprecated 4.9.53 |
|
| 118 | - * @return array |
|
| 119 | - * @throws InvalidArgumentException |
|
| 120 | - * @throws InvalidDataTypeException |
|
| 121 | - * @throws InvalidInterfaceException |
|
| 122 | - */ |
|
| 123 | - public function cookie_params() |
|
| 124 | - { |
|
| 125 | - return $this->request()->cookieParams(); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @deprecated 4.9.53 |
|
| 131 | - * @return array |
|
| 132 | - * @throws InvalidArgumentException |
|
| 133 | - * @throws InvalidDataTypeException |
|
| 134 | - * @throws InvalidInterfaceException |
|
| 135 | - */ |
|
| 136 | - public function server_params() |
|
| 137 | - { |
|
| 138 | - return $this->request()->serverParams(); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * returns contents of $_REQUEST |
|
| 144 | - * |
|
| 145 | - * @deprecated 4.9.53 |
|
| 146 | - * @return array |
|
| 147 | - * @throws InvalidArgumentException |
|
| 148 | - * @throws InvalidDataTypeException |
|
| 149 | - * @throws InvalidInterfaceException |
|
| 150 | - */ |
|
| 151 | - public function params() |
|
| 152 | - { |
|
| 153 | - return $this->request()->requestParams(); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @deprecated 4.9.53 |
|
| 159 | - * @param $key |
|
| 160 | - * @param $value |
|
| 161 | - * @param bool $override_ee |
|
| 162 | - * @return void |
|
| 163 | - * @throws InvalidArgumentException |
|
| 164 | - * @throws InvalidDataTypeException |
|
| 165 | - * @throws InvalidInterfaceException |
|
| 166 | - */ |
|
| 167 | - public function set($key, $value, $override_ee = false) |
|
| 168 | - { |
|
| 169 | - $this->request()->setRequestParam($key, $value, $override_ee); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * returns the value for a request param if the given key exists |
|
| 175 | - * |
|
| 176 | - * @deprecated 4.9.53 |
|
| 177 | - * @param $key |
|
| 178 | - * @param null $default |
|
| 179 | - * @return mixed |
|
| 180 | - * @throws InvalidArgumentException |
|
| 181 | - * @throws InvalidDataTypeException |
|
| 182 | - * @throws InvalidInterfaceException |
|
| 183 | - */ |
|
| 184 | - public function get($key, $default = null) |
|
| 185 | - { |
|
| 186 | - return $this->request()->getRequestParam($key, $default); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * check if param exists |
|
| 192 | - * |
|
| 193 | - * @deprecated 4.9.53 |
|
| 194 | - * @param $key |
|
| 195 | - * @return bool |
|
| 196 | - * @throws InvalidArgumentException |
|
| 197 | - * @throws InvalidDataTypeException |
|
| 198 | - * @throws InvalidInterfaceException |
|
| 199 | - */ |
|
| 200 | - public function is_set($key) |
|
| 201 | - { |
|
| 202 | - return $this->request()->requestParamIsSet($key); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * remove param |
|
| 208 | - * |
|
| 209 | - * @deprecated 4.9.53 |
|
| 210 | - * @param $key |
|
| 211 | - * @param bool $unset_from_global_too |
|
| 212 | - * @throws InvalidArgumentException |
|
| 213 | - * @throws InvalidDataTypeException |
|
| 214 | - * @throws InvalidInterfaceException |
|
| 215 | - */ |
|
| 216 | - public function un_set($key, $unset_from_global_too = false) |
|
| 217 | - { |
|
| 218 | - $this->request()->unSetRequestParam($key, $unset_from_global_too); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * @deprecated 4.9.53 |
|
| 224 | - * @return string |
|
| 225 | - * @throws InvalidArgumentException |
|
| 226 | - * @throws InvalidDataTypeException |
|
| 227 | - * @throws InvalidInterfaceException |
|
| 228 | - */ |
|
| 229 | - public function ip_address() |
|
| 230 | - { |
|
| 231 | - return $this->request()->ipAddress(); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * @deprecated 4.9.53 |
|
| 237 | - * @return bool |
|
| 238 | - * @throws InvalidArgumentException |
|
| 239 | - * @throws InvalidDataTypeException |
|
| 240 | - * @throws InvalidInterfaceException |
|
| 241 | - */ |
|
| 242 | - public function isAdmin() |
|
| 243 | - { |
|
| 244 | - return $this->request()->isAdmin(); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @deprecated 4.9.53 |
|
| 250 | - * @return mixed |
|
| 251 | - * @throws InvalidArgumentException |
|
| 252 | - * @throws InvalidDataTypeException |
|
| 253 | - * @throws InvalidInterfaceException |
|
| 254 | - */ |
|
| 255 | - public function isAjax() |
|
| 256 | - { |
|
| 257 | - return $this->request()->isAjax(); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * @deprecated 4.9.53 |
|
| 263 | - * @return mixed |
|
| 264 | - * @throws InvalidArgumentException |
|
| 265 | - * @throws InvalidDataTypeException |
|
| 266 | - * @throws InvalidInterfaceException |
|
| 267 | - */ |
|
| 268 | - public function isFrontAjax() |
|
| 269 | - { |
|
| 270 | - return $this->request()->isFrontAjax(); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * @deprecated 4.9.53 |
|
| 276 | - * @return mixed|string |
|
| 277 | - * @throws InvalidArgumentException |
|
| 278 | - * @throws InvalidDataTypeException |
|
| 279 | - * @throws InvalidInterfaceException |
|
| 280 | - */ |
|
| 281 | - public function requestUri() |
|
| 282 | - { |
|
| 283 | - return $this->request()->requestUri(); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * @deprecated 4.9.53 |
|
| 289 | - * @return string |
|
| 290 | - * @throws InvalidArgumentException |
|
| 291 | - * @throws InvalidDataTypeException |
|
| 292 | - * @throws InvalidInterfaceException |
|
| 293 | - */ |
|
| 294 | - public function userAgent() |
|
| 295 | - { |
|
| 296 | - return $this->request()->userAgent(); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @deprecated 4.9.53 |
|
| 302 | - * @param string $user_agent |
|
| 303 | - * @throws InvalidArgumentException |
|
| 304 | - * @throws InvalidDataTypeException |
|
| 305 | - * @throws InvalidInterfaceException |
|
| 306 | - */ |
|
| 307 | - public function setUserAgent($user_agent = '') |
|
| 308 | - { |
|
| 309 | - $this->request()->setUserAgent($user_agent); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * @deprecated 4.9.53 |
|
| 315 | - * @return bool |
|
| 316 | - * @throws InvalidArgumentException |
|
| 317 | - * @throws InvalidDataTypeException |
|
| 318 | - * @throws InvalidInterfaceException |
|
| 319 | - */ |
|
| 320 | - public function isBot() |
|
| 321 | - { |
|
| 322 | - return $this->request()->isBot(); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * @deprecated 4.9.53 |
|
| 328 | - * @param bool $is_bot |
|
| 329 | - * @throws InvalidArgumentException |
|
| 330 | - * @throws InvalidDataTypeException |
|
| 331 | - * @throws InvalidInterfaceException |
|
| 332 | - */ |
|
| 333 | - public function setIsBot($is_bot) |
|
| 334 | - { |
|
| 335 | - $this->request()->setIsBot($is_bot); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 341 | - * and return the value for the first match found |
|
| 342 | - * wildcards can be either of the following: |
|
| 343 | - * ? to represent a single character of any type |
|
| 344 | - * * to represent one or more characters of any type |
|
| 345 | - * |
|
| 346 | - * @param string $pattern |
|
| 347 | - * @param null|mixed $default |
|
| 348 | - * @return false|int |
|
| 349 | - * @throws InvalidArgumentException |
|
| 350 | - * @throws InvalidInterfaceException |
|
| 351 | - * @throws InvalidDataTypeException |
|
| 352 | - */ |
|
| 353 | - public function getMatch($pattern, $default = null) |
|
| 354 | - { |
|
| 355 | - return $this->request()->getMatch($pattern, $default); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 361 | - * wildcards can be either of the following: |
|
| 362 | - * ? to represent a single character of any type |
|
| 363 | - * * to represent one or more characters of any type |
|
| 364 | - * returns true if a match is found or false if not |
|
| 365 | - * |
|
| 366 | - * @param string $pattern |
|
| 367 | - * @return false|int |
|
| 368 | - * @throws InvalidArgumentException |
|
| 369 | - * @throws InvalidInterfaceException |
|
| 370 | - * @throws InvalidDataTypeException |
|
| 371 | - */ |
|
| 372 | - public function matches($pattern) |
|
| 373 | - { |
|
| 374 | - return $this->request()->matches($pattern); |
|
| 375 | - } |
|
| 21 | + /** |
|
| 22 | + * @var RequestInterface $request |
|
| 23 | + */ |
|
| 24 | + private $request; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * whether current request is for the admin but NOT via AJAX |
|
| 28 | + * |
|
| 29 | + * @var boolean $admin |
|
| 30 | + */ |
|
| 31 | + public $admin = false; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * whether current request is via AJAX |
|
| 35 | + * |
|
| 36 | + * @var boolean $ajax |
|
| 37 | + */ |
|
| 38 | + public $ajax = false; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * whether current request is via AJAX from the frontend of the site |
|
| 42 | + * |
|
| 43 | + * @var boolean $front_ajax |
|
| 44 | + */ |
|
| 45 | + public $front_ajax = false; |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @deprecated 4.9.53 |
|
| 50 | + * @param array $get |
|
| 51 | + * @param array $post |
|
| 52 | + * @param array $cookie |
|
| 53 | + * @param array $server |
|
| 54 | + */ |
|
| 55 | + public function __construct( |
|
| 56 | + array $get = array(), |
|
| 57 | + array $post = array(), |
|
| 58 | + array $cookie = array(), |
|
| 59 | + array $server = array() |
|
| 60 | + ) { |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @return RequestInterface |
|
| 66 | + * @throws InvalidArgumentException |
|
| 67 | + * @throws InvalidInterfaceException |
|
| 68 | + * @throws InvalidDataTypeException |
|
| 69 | + */ |
|
| 70 | + private function request() |
|
| 71 | + { |
|
| 72 | + if ($this->request instanceof RequestInterface) { |
|
| 73 | + return $this->request; |
|
| 74 | + } |
|
| 75 | + $loader = LoaderFactory::getLoader(); |
|
| 76 | + $this->request = $loader->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
| 77 | + return $this->request; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @param RequestInterface $request |
|
| 83 | + */ |
|
| 84 | + public function setRequest(RequestInterface $request) |
|
| 85 | + { |
|
| 86 | + $this->request = $request; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @deprecated 4.9.53 |
|
| 92 | + * @return array |
|
| 93 | + * @throws InvalidArgumentException |
|
| 94 | + * @throws InvalidDataTypeException |
|
| 95 | + * @throws InvalidInterfaceException |
|
| 96 | + */ |
|
| 97 | + public function get_params() |
|
| 98 | + { |
|
| 99 | + return $this->request()->getParams(); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @deprecated 4.9.53 |
|
| 105 | + * @return array |
|
| 106 | + * @throws InvalidArgumentException |
|
| 107 | + * @throws InvalidDataTypeException |
|
| 108 | + * @throws InvalidInterfaceException |
|
| 109 | + */ |
|
| 110 | + public function post_params() |
|
| 111 | + { |
|
| 112 | + return $this->request()->postParams(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @deprecated 4.9.53 |
|
| 118 | + * @return array |
|
| 119 | + * @throws InvalidArgumentException |
|
| 120 | + * @throws InvalidDataTypeException |
|
| 121 | + * @throws InvalidInterfaceException |
|
| 122 | + */ |
|
| 123 | + public function cookie_params() |
|
| 124 | + { |
|
| 125 | + return $this->request()->cookieParams(); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @deprecated 4.9.53 |
|
| 131 | + * @return array |
|
| 132 | + * @throws InvalidArgumentException |
|
| 133 | + * @throws InvalidDataTypeException |
|
| 134 | + * @throws InvalidInterfaceException |
|
| 135 | + */ |
|
| 136 | + public function server_params() |
|
| 137 | + { |
|
| 138 | + return $this->request()->serverParams(); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * returns contents of $_REQUEST |
|
| 144 | + * |
|
| 145 | + * @deprecated 4.9.53 |
|
| 146 | + * @return array |
|
| 147 | + * @throws InvalidArgumentException |
|
| 148 | + * @throws InvalidDataTypeException |
|
| 149 | + * @throws InvalidInterfaceException |
|
| 150 | + */ |
|
| 151 | + public function params() |
|
| 152 | + { |
|
| 153 | + return $this->request()->requestParams(); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @deprecated 4.9.53 |
|
| 159 | + * @param $key |
|
| 160 | + * @param $value |
|
| 161 | + * @param bool $override_ee |
|
| 162 | + * @return void |
|
| 163 | + * @throws InvalidArgumentException |
|
| 164 | + * @throws InvalidDataTypeException |
|
| 165 | + * @throws InvalidInterfaceException |
|
| 166 | + */ |
|
| 167 | + public function set($key, $value, $override_ee = false) |
|
| 168 | + { |
|
| 169 | + $this->request()->setRequestParam($key, $value, $override_ee); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * returns the value for a request param if the given key exists |
|
| 175 | + * |
|
| 176 | + * @deprecated 4.9.53 |
|
| 177 | + * @param $key |
|
| 178 | + * @param null $default |
|
| 179 | + * @return mixed |
|
| 180 | + * @throws InvalidArgumentException |
|
| 181 | + * @throws InvalidDataTypeException |
|
| 182 | + * @throws InvalidInterfaceException |
|
| 183 | + */ |
|
| 184 | + public function get($key, $default = null) |
|
| 185 | + { |
|
| 186 | + return $this->request()->getRequestParam($key, $default); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * check if param exists |
|
| 192 | + * |
|
| 193 | + * @deprecated 4.9.53 |
|
| 194 | + * @param $key |
|
| 195 | + * @return bool |
|
| 196 | + * @throws InvalidArgumentException |
|
| 197 | + * @throws InvalidDataTypeException |
|
| 198 | + * @throws InvalidInterfaceException |
|
| 199 | + */ |
|
| 200 | + public function is_set($key) |
|
| 201 | + { |
|
| 202 | + return $this->request()->requestParamIsSet($key); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * remove param |
|
| 208 | + * |
|
| 209 | + * @deprecated 4.9.53 |
|
| 210 | + * @param $key |
|
| 211 | + * @param bool $unset_from_global_too |
|
| 212 | + * @throws InvalidArgumentException |
|
| 213 | + * @throws InvalidDataTypeException |
|
| 214 | + * @throws InvalidInterfaceException |
|
| 215 | + */ |
|
| 216 | + public function un_set($key, $unset_from_global_too = false) |
|
| 217 | + { |
|
| 218 | + $this->request()->unSetRequestParam($key, $unset_from_global_too); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * @deprecated 4.9.53 |
|
| 224 | + * @return string |
|
| 225 | + * @throws InvalidArgumentException |
|
| 226 | + * @throws InvalidDataTypeException |
|
| 227 | + * @throws InvalidInterfaceException |
|
| 228 | + */ |
|
| 229 | + public function ip_address() |
|
| 230 | + { |
|
| 231 | + return $this->request()->ipAddress(); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * @deprecated 4.9.53 |
|
| 237 | + * @return bool |
|
| 238 | + * @throws InvalidArgumentException |
|
| 239 | + * @throws InvalidDataTypeException |
|
| 240 | + * @throws InvalidInterfaceException |
|
| 241 | + */ |
|
| 242 | + public function isAdmin() |
|
| 243 | + { |
|
| 244 | + return $this->request()->isAdmin(); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @deprecated 4.9.53 |
|
| 250 | + * @return mixed |
|
| 251 | + * @throws InvalidArgumentException |
|
| 252 | + * @throws InvalidDataTypeException |
|
| 253 | + * @throws InvalidInterfaceException |
|
| 254 | + */ |
|
| 255 | + public function isAjax() |
|
| 256 | + { |
|
| 257 | + return $this->request()->isAjax(); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * @deprecated 4.9.53 |
|
| 263 | + * @return mixed |
|
| 264 | + * @throws InvalidArgumentException |
|
| 265 | + * @throws InvalidDataTypeException |
|
| 266 | + * @throws InvalidInterfaceException |
|
| 267 | + */ |
|
| 268 | + public function isFrontAjax() |
|
| 269 | + { |
|
| 270 | + return $this->request()->isFrontAjax(); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * @deprecated 4.9.53 |
|
| 276 | + * @return mixed|string |
|
| 277 | + * @throws InvalidArgumentException |
|
| 278 | + * @throws InvalidDataTypeException |
|
| 279 | + * @throws InvalidInterfaceException |
|
| 280 | + */ |
|
| 281 | + public function requestUri() |
|
| 282 | + { |
|
| 283 | + return $this->request()->requestUri(); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * @deprecated 4.9.53 |
|
| 289 | + * @return string |
|
| 290 | + * @throws InvalidArgumentException |
|
| 291 | + * @throws InvalidDataTypeException |
|
| 292 | + * @throws InvalidInterfaceException |
|
| 293 | + */ |
|
| 294 | + public function userAgent() |
|
| 295 | + { |
|
| 296 | + return $this->request()->userAgent(); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @deprecated 4.9.53 |
|
| 302 | + * @param string $user_agent |
|
| 303 | + * @throws InvalidArgumentException |
|
| 304 | + * @throws InvalidDataTypeException |
|
| 305 | + * @throws InvalidInterfaceException |
|
| 306 | + */ |
|
| 307 | + public function setUserAgent($user_agent = '') |
|
| 308 | + { |
|
| 309 | + $this->request()->setUserAgent($user_agent); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * @deprecated 4.9.53 |
|
| 315 | + * @return bool |
|
| 316 | + * @throws InvalidArgumentException |
|
| 317 | + * @throws InvalidDataTypeException |
|
| 318 | + * @throws InvalidInterfaceException |
|
| 319 | + */ |
|
| 320 | + public function isBot() |
|
| 321 | + { |
|
| 322 | + return $this->request()->isBot(); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * @deprecated 4.9.53 |
|
| 328 | + * @param bool $is_bot |
|
| 329 | + * @throws InvalidArgumentException |
|
| 330 | + * @throws InvalidDataTypeException |
|
| 331 | + * @throws InvalidInterfaceException |
|
| 332 | + */ |
|
| 333 | + public function setIsBot($is_bot) |
|
| 334 | + { |
|
| 335 | + $this->request()->setIsBot($is_bot); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 341 | + * and return the value for the first match found |
|
| 342 | + * wildcards can be either of the following: |
|
| 343 | + * ? to represent a single character of any type |
|
| 344 | + * * to represent one or more characters of any type |
|
| 345 | + * |
|
| 346 | + * @param string $pattern |
|
| 347 | + * @param null|mixed $default |
|
| 348 | + * @return false|int |
|
| 349 | + * @throws InvalidArgumentException |
|
| 350 | + * @throws InvalidInterfaceException |
|
| 351 | + * @throws InvalidDataTypeException |
|
| 352 | + */ |
|
| 353 | + public function getMatch($pattern, $default = null) |
|
| 354 | + { |
|
| 355 | + return $this->request()->getMatch($pattern, $default); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 361 | + * wildcards can be either of the following: |
|
| 362 | + * ? to represent a single character of any type |
|
| 363 | + * * to represent one or more characters of any type |
|
| 364 | + * returns true if a match is found or false if not |
|
| 365 | + * |
|
| 366 | + * @param string $pattern |
|
| 367 | + * @return false|int |
|
| 368 | + * @throws InvalidArgumentException |
|
| 369 | + * @throws InvalidInterfaceException |
|
| 370 | + * @throws InvalidDataTypeException |
|
| 371 | + */ |
|
| 372 | + public function matches($pattern) |
|
| 373 | + { |
|
| 374 | + return $this->request()->matches($pattern); |
|
| 375 | + } |
|
| 376 | 376 | } |
@@ -19,59 +19,59 @@ |
||
| 19 | 19 | class RequestStack |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var RequestDecoratorInterface $request_stack_app |
|
| 24 | - */ |
|
| 25 | - protected $request_stack_app; |
|
| 22 | + /** |
|
| 23 | + * @var RequestDecoratorInterface $request_stack_app |
|
| 24 | + */ |
|
| 25 | + protected $request_stack_app; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var RequestStackCoreAppInterface $core_app |
|
| 29 | - */ |
|
| 30 | - protected $core_app; |
|
| 27 | + /** |
|
| 28 | + * @var RequestStackCoreAppInterface $core_app |
|
| 29 | + */ |
|
| 30 | + protected $core_app; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var RequestInterface $request |
|
| 34 | - */ |
|
| 35 | - protected $request; |
|
| 32 | + /** |
|
| 33 | + * @var RequestInterface $request |
|
| 34 | + */ |
|
| 35 | + protected $request; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var ResponseInterface $response |
|
| 39 | - */ |
|
| 40 | - protected $response; |
|
| 37 | + /** |
|
| 38 | + * @var ResponseInterface $response |
|
| 39 | + */ |
|
| 40 | + protected $response; |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param RequestDecoratorInterface $request_stack_app |
|
| 45 | - * @param RequestStackCoreAppInterface $core_app |
|
| 46 | - */ |
|
| 47 | - public function __construct(RequestDecoratorInterface $request_stack_app, RequestStackCoreAppInterface $core_app) |
|
| 48 | - { |
|
| 49 | - $this->request_stack_app = $request_stack_app; |
|
| 50 | - $this->core_app = $core_app; |
|
| 51 | - } |
|
| 43 | + /** |
|
| 44 | + * @param RequestDecoratorInterface $request_stack_app |
|
| 45 | + * @param RequestStackCoreAppInterface $core_app |
|
| 46 | + */ |
|
| 47 | + public function __construct(RequestDecoratorInterface $request_stack_app, RequestStackCoreAppInterface $core_app) |
|
| 48 | + { |
|
| 49 | + $this->request_stack_app = $request_stack_app; |
|
| 50 | + $this->core_app = $core_app; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @param RequestInterface $request |
|
| 56 | - * @param ResponseInterface $response |
|
| 57 | - * @return ResponseInterface |
|
| 58 | - */ |
|
| 59 | - public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 60 | - { |
|
| 61 | - $this->request = $request; |
|
| 62 | - $this->response = $response; |
|
| 63 | - return $this->request_stack_app->handleRequest($request, $response); |
|
| 64 | - } |
|
| 54 | + /** |
|
| 55 | + * @param RequestInterface $request |
|
| 56 | + * @param ResponseInterface $response |
|
| 57 | + * @return ResponseInterface |
|
| 58 | + */ |
|
| 59 | + public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 60 | + { |
|
| 61 | + $this->request = $request; |
|
| 62 | + $this->response = $response; |
|
| 63 | + return $this->request_stack_app->handleRequest($request, $response); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * handle_response |
|
| 69 | - * executes the handle_response() method on the RequestStackCoreAppInterface object |
|
| 70 | - * after the request stack has been fully processed |
|
| 71 | - */ |
|
| 72 | - public function handleResponse() |
|
| 73 | - { |
|
| 74 | - $this->core_app->handleResponse($this->request, $this->response); |
|
| 75 | - } |
|
| 67 | + /** |
|
| 68 | + * handle_response |
|
| 69 | + * executes the handle_response() method on the RequestStackCoreAppInterface object |
|
| 70 | + * after the request stack has been fully processed |
|
| 71 | + */ |
|
| 72 | + public function handleResponse() |
|
| 73 | + { |
|
| 74 | + $this->core_app->handleResponse($this->request, $this->response); |
|
| 75 | + } |
|
| 76 | 76 | } |
| 77 | 77 | // Location: RequestStack.php |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | public function __construct(RequestDecoratorInterface $request_stack_app, RequestStackCoreAppInterface $core_app) |
| 48 | 48 | { |
| 49 | 49 | $this->request_stack_app = $request_stack_app; |
| 50 | - $this->core_app = $core_app; |
|
| 50 | + $this->core_app = $core_app; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -1,7 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | use EventEspresso\core\domain\Domain; |
| 4 | -use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice; |
|
| 5 | 4 | use EventEspresso\core\domain\services\factories\EmailAddressFactory; |
| 6 | 5 | use EventEspresso\core\domain\services\validation\email\EmailValidationException; |
| 7 | 6 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
@@ -765,6 +765,9 @@ |
||
| 765 | 765 | ); |
| 766 | 766 | } |
| 767 | 767 | |
| 768 | + /** |
|
| 769 | + * @param string $version |
|
| 770 | + */ |
|
| 768 | 771 | protected function _get_add_relation_query_params(\EEM_Base $source_model, \EEM_Base $related_model, $version) |
| 769 | 772 | { |
| 770 | 773 | // if they're related through a HABTM relation, check for any non-FKs |
@@ -23,1340 +23,1340 @@ |
||
| 23 | 23 | class EED_Core_Rest_Api extends \EED_Module |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - const ee_api_namespace = Domain::API_NAMESPACE; |
|
| 27 | - |
|
| 28 | - const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
| 29 | - |
|
| 30 | - const saved_routes_option_names = 'ee_core_routes'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * string used in _links response bodies to make them globally unique. |
|
| 34 | - * |
|
| 35 | - * @see http://v2.wp-api.org/extending/linking/ |
|
| 36 | - */ |
|
| 37 | - const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var CalculatedModelFields |
|
| 41 | - */ |
|
| 42 | - protected static $_field_calculator; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @return EED_Core_Rest_Api|EED_Module |
|
| 47 | - */ |
|
| 48 | - public static function instance() |
|
| 49 | - { |
|
| 50 | - self::$_field_calculator = LoaderFactory::getLoader()->load('EventEspresso\core\libraries\rest_api\CalculatedModelFields'); |
|
| 51 | - return parent::get_instance(__CLASS__); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 57 | - * |
|
| 58 | - * @access public |
|
| 59 | - * @return void |
|
| 60 | - */ |
|
| 61 | - public static function set_hooks() |
|
| 62 | - { |
|
| 63 | - self::set_hooks_both(); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 69 | - * |
|
| 70 | - * @access public |
|
| 71 | - * @return void |
|
| 72 | - */ |
|
| 73 | - public static function set_hooks_admin() |
|
| 74 | - { |
|
| 75 | - self::set_hooks_both(); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - public static function set_hooks_both() |
|
| 80 | - { |
|
| 81 | - add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5); |
|
| 82 | - add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10); |
|
| 83 | - add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2); |
|
| 84 | - add_filter( |
|
| 85 | - 'rest_index', |
|
| 86 | - array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex') |
|
| 87 | - ); |
|
| 88 | - EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * sets up hooks which only need to be included as part of REST API requests; |
|
| 94 | - * other requests like to the frontend or admin etc don't need them |
|
| 95 | - * |
|
| 96 | - * @throws \EE_Error |
|
| 97 | - */ |
|
| 98 | - public static function set_hooks_rest_api() |
|
| 99 | - { |
|
| 100 | - // set hooks which account for changes made to the API |
|
| 101 | - EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * public wrapper of _set_hooks_for_changes. |
|
| 107 | - * Loads all the hooks which make requests to old versions of the API |
|
| 108 | - * appear the same as they always did |
|
| 109 | - * |
|
| 110 | - * @throws EE_Error |
|
| 111 | - */ |
|
| 112 | - public static function set_hooks_for_changes() |
|
| 113 | - { |
|
| 114 | - self::_set_hooks_for_changes(); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Loads all the hooks which make requests to old versions of the API |
|
| 120 | - * appear the same as they always did |
|
| 121 | - * |
|
| 122 | - * @throws EE_Error |
|
| 123 | - */ |
|
| 124 | - protected static function _set_hooks_for_changes() |
|
| 125 | - { |
|
| 126 | - $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api/changes'), false); |
|
| 127 | - foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
| 128 | - // ignore the base parent class |
|
| 129 | - // and legacy named classes |
|
| 130 | - if ($classname_in_namespace === 'ChangesInBase' |
|
| 131 | - || strpos($classname_in_namespace, 'Changes_In_') === 0 |
|
| 132 | - ) { |
|
| 133 | - continue; |
|
| 134 | - } |
|
| 135 | - $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
| 136 | - if (class_exists($full_classname)) { |
|
| 137 | - $instance_of_class = new $full_classname; |
|
| 138 | - if ($instance_of_class instanceof ChangesInBase) { |
|
| 139 | - $instance_of_class->setHooks(); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
| 148 | - * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
| 149 | - * |
|
| 150 | - * @throws \EE_Error |
|
| 151 | - */ |
|
| 152 | - public static function register_routes() |
|
| 153 | - { |
|
| 154 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) { |
|
| 155 | - foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) { |
|
| 156 | - /** |
|
| 157 | - * @var array $data_for_multiple_endpoints numerically indexed array |
|
| 158 | - * but can also contain route options like { |
|
| 159 | - * @type array $schema { |
|
| 160 | - * @type callable $schema_callback |
|
| 161 | - * @type array $callback_args arguments that will be passed to the callback, after the |
|
| 162 | - * WP_REST_Request of course |
|
| 163 | - * } |
|
| 164 | - * } |
|
| 165 | - */ |
|
| 166 | - // when registering routes, register all the endpoints' data at the same time |
|
| 167 | - $multiple_endpoint_args = array(); |
|
| 168 | - foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) { |
|
| 169 | - /** |
|
| 170 | - * @var array $data_for_single_endpoint { |
|
| 171 | - * @type callable $callback |
|
| 172 | - * @type string methods |
|
| 173 | - * @type array args |
|
| 174 | - * @type array _links |
|
| 175 | - * @type array $callback_args arguments that will be passed to the callback, after the |
|
| 176 | - * WP_REST_Request of course |
|
| 177 | - * } |
|
| 178 | - */ |
|
| 179 | - // skip route options |
|
| 180 | - if (! is_numeric($endpoint_key)) { |
|
| 181 | - continue; |
|
| 182 | - } |
|
| 183 | - if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
| 184 | - throw new EE_Error( |
|
| 185 | - esc_html__( |
|
| 186 | - // @codingStandardsIgnoreStart |
|
| 187 | - 'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).', |
|
| 188 | - // @codingStandardsIgnoreEnd |
|
| 189 | - 'event_espresso' |
|
| 190 | - ) |
|
| 191 | - ); |
|
| 192 | - } |
|
| 193 | - $callback = $data_for_single_endpoint['callback']; |
|
| 194 | - $single_endpoint_args = array( |
|
| 195 | - 'methods' => $data_for_single_endpoint['methods'], |
|
| 196 | - 'args' => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args'] |
|
| 197 | - : array(), |
|
| 198 | - ); |
|
| 199 | - if (isset($data_for_single_endpoint['_links'])) { |
|
| 200 | - $single_endpoint_args['_links'] = $data_for_single_endpoint['_links']; |
|
| 201 | - } |
|
| 202 | - if (isset($data_for_single_endpoint['callback_args'])) { |
|
| 203 | - $callback_args = $data_for_single_endpoint['callback_args']; |
|
| 204 | - $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use ( |
|
| 205 | - $callback, |
|
| 206 | - $callback_args |
|
| 207 | - ) { |
|
| 208 | - array_unshift($callback_args, $request); |
|
| 209 | - return call_user_func_array( |
|
| 210 | - $callback, |
|
| 211 | - $callback_args |
|
| 212 | - ); |
|
| 213 | - }; |
|
| 214 | - } else { |
|
| 215 | - $single_endpoint_args['callback'] = $data_for_single_endpoint['callback']; |
|
| 216 | - } |
|
| 217 | - // As of WordPress 5.5, if a permission_callback is not provided, |
|
| 218 | - // the REST API will issue a _doing_it_wrong notice. |
|
| 219 | - // Since the EE REST API defers capabilities to the db model system, |
|
| 220 | - // we will just use the generic WP callback for public endpoints |
|
| 221 | - if (! isset($single_endpoint_args['permission_callback'])) { |
|
| 222 | - $single_endpoint_args['permission_callback'] = '__return_true'; |
|
| 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'] = 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 | - * @type string|array $callback |
|
| 283 | - * @type string $methods |
|
| 284 | - * @type boolean $hidden_endpoint |
|
| 285 | - * } |
|
| 286 | - */ |
|
| 287 | - public static function get_ee_route_data() |
|
| 288 | - { |
|
| 289 | - $ee_routes = array(); |
|
| 290 | - foreach (self::versions_served() as $version => $hidden_endpoints) { |
|
| 291 | - $ee_routes[ self::ee_api_namespace . $version ] = self::_get_ee_route_data_for_version( |
|
| 292 | - $version, |
|
| 293 | - $hidden_endpoints |
|
| 294 | - ); |
|
| 295 | - } |
|
| 296 | - return $ee_routes; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * Gets the EE route data from the wp options if it exists already, |
|
| 302 | - * otherwise re-generates it and saves it to the option |
|
| 303 | - * |
|
| 304 | - * @param string $version |
|
| 305 | - * @param boolean $hidden_endpoints |
|
| 306 | - * @return array |
|
| 307 | - * @throws \EE_Error |
|
| 308 | - */ |
|
| 309 | - protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
| 310 | - { |
|
| 311 | - $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
| 312 | - if (! $ee_routes || EED_Core_Rest_Api::debugMode()) { |
|
| 313 | - $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
| 314 | - } |
|
| 315 | - return $ee_routes; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Saves the EE REST API route data to a wp option and returns it |
|
| 321 | - * |
|
| 322 | - * @param string $version |
|
| 323 | - * @param boolean $hidden_endpoints |
|
| 324 | - * @return mixed|null |
|
| 325 | - * @throws \EE_Error |
|
| 326 | - */ |
|
| 327 | - protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
| 328 | - { |
|
| 329 | - $instance = self::instance(); |
|
| 330 | - $routes = apply_filters( |
|
| 331 | - 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
| 332 | - array_replace_recursive( |
|
| 333 | - $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
| 334 | - $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
| 335 | - $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
| 336 | - $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
| 337 | - ) |
|
| 338 | - ); |
|
| 339 | - $option_name = self::saved_routes_option_names . $version; |
|
| 340 | - if (get_option($option_name)) { |
|
| 341 | - update_option($option_name, $routes, true); |
|
| 342 | - } else { |
|
| 343 | - add_option($option_name, $routes, null, 'no'); |
|
| 344 | - } |
|
| 345 | - return $routes; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Calculates all the EE routes and saves it to a WordPress option so we don't |
|
| 351 | - * need to calculate it on every request |
|
| 352 | - * |
|
| 353 | - * @deprecated since version 4.9.1 |
|
| 354 | - * @return void |
|
| 355 | - */ |
|
| 356 | - public static function save_ee_routes() |
|
| 357 | - { |
|
| 358 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 359 | - $instance = self::instance(); |
|
| 360 | - $routes = apply_filters( |
|
| 361 | - 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
| 362 | - array_replace_recursive( |
|
| 363 | - $instance->_register_config_routes(), |
|
| 364 | - $instance->_register_meta_routes(), |
|
| 365 | - $instance->_register_model_routes(), |
|
| 366 | - $instance->_register_rpc_routes() |
|
| 367 | - ) |
|
| 368 | - ); |
|
| 369 | - update_option(self::saved_routes_option_names, $routes, true); |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Gets all the route information relating to EE models |
|
| 376 | - * |
|
| 377 | - * @return array @see get_ee_route_data |
|
| 378 | - * @deprecated since version 4.9.1 |
|
| 379 | - */ |
|
| 380 | - protected function _register_model_routes() |
|
| 381 | - { |
|
| 382 | - $model_routes = array(); |
|
| 383 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 384 | - $model_routes[ EED_Core_Rest_Api::ee_api_namespace |
|
| 385 | - . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
| 386 | - } |
|
| 387 | - return $model_routes; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * Decides whether or not to add write endpoints for this model. |
|
| 393 | - * |
|
| 394 | - * Currently, this defaults to exclude all global tables and models |
|
| 395 | - * which would allow inserting WP core data (we don't want to duplicate |
|
| 396 | - * what WP API does, as it's unnecessary, extra work, and potentially extra bugs) |
|
| 397 | - * |
|
| 398 | - * @param EEM_Base $model |
|
| 399 | - * @return bool |
|
| 400 | - */ |
|
| 401 | - public static function should_have_write_endpoints(EEM_Base $model) |
|
| 402 | - { |
|
| 403 | - if ($model->is_wp_core_model()) { |
|
| 404 | - return false; |
|
| 405 | - } |
|
| 406 | - foreach ($model->get_tables() as $table) { |
|
| 407 | - if ($table->is_global()) { |
|
| 408 | - return false; |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - return true; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`) |
|
| 417 | - * in this versioned namespace of EE4 |
|
| 418 | - * |
|
| 419 | - * @param $version |
|
| 420 | - * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event') |
|
| 421 | - */ |
|
| 422 | - public static function model_names_with_plural_routes($version) |
|
| 423 | - { |
|
| 424 | - $model_version_info = new ModelVersionInfo($version); |
|
| 425 | - $models_to_register = $model_version_info->modelsForRequestedVersion(); |
|
| 426 | - // let's not bother having endpoints for extra metas |
|
| 427 | - unset( |
|
| 428 | - $models_to_register['Extra_Meta'], |
|
| 429 | - $models_to_register['Extra_Join'], |
|
| 430 | - $models_to_register['Post_Meta'] |
|
| 431 | - ); |
|
| 432 | - return apply_filters( |
|
| 433 | - 'FHEE__EED_Core_REST_API___register_model_routes', |
|
| 434 | - $models_to_register |
|
| 435 | - ); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * Gets the route data for EE models in the specified version |
|
| 441 | - * |
|
| 442 | - * @param string $version |
|
| 443 | - * @param boolean $hidden_endpoint |
|
| 444 | - * @return array |
|
| 445 | - * @throws EE_Error |
|
| 446 | - */ |
|
| 447 | - protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
| 448 | - { |
|
| 449 | - $model_routes = array(); |
|
| 450 | - $model_version_info = new ModelVersionInfo($version); |
|
| 451 | - foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
|
| 452 | - $model = \EE_Registry::instance()->load_model($model_name); |
|
| 453 | - // if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
| 454 | - if (! $model instanceof EEM_Base) { |
|
| 455 | - continue; |
|
| 456 | - } |
|
| 457 | - // yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
| 458 | - $plural_model_route = EED_Core_Rest_Api::get_collection_route($model); |
|
| 459 | - $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)'); |
|
| 460 | - $model_routes[ $plural_model_route ] = array( |
|
| 461 | - array( |
|
| 462 | - 'callback' => array( |
|
| 463 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 464 | - 'handleRequestGetAll', |
|
| 465 | - ), |
|
| 466 | - 'callback_args' => array($version, $model_name), |
|
| 467 | - 'methods' => WP_REST_Server::READABLE, |
|
| 468 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 469 | - 'args' => $this->_get_read_query_params($model, $version), |
|
| 470 | - '_links' => array( |
|
| 471 | - 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
| 472 | - ), |
|
| 473 | - ), |
|
| 474 | - 'schema' => array( |
|
| 475 | - 'schema_callback' => array( |
|
| 476 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 477 | - 'handleSchemaRequest', |
|
| 478 | - ), |
|
| 479 | - 'callback_args' => array($version, $model_name), |
|
| 480 | - ), |
|
| 481 | - ); |
|
| 482 | - $model_routes[ $singular_model_route ] = array( |
|
| 483 | - array( |
|
| 484 | - 'callback' => array( |
|
| 485 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 486 | - 'handleRequestGetOne', |
|
| 487 | - ), |
|
| 488 | - 'callback_args' => array($version, $model_name), |
|
| 489 | - 'methods' => WP_REST_Server::READABLE, |
|
| 490 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 491 | - 'args' => $this->_get_response_selection_query_params($model, $version, true), |
|
| 492 | - ), |
|
| 493 | - ); |
|
| 494 | - if (apply_filters( |
|
| 495 | - 'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints', |
|
| 496 | - EED_Core_Rest_Api::should_have_write_endpoints($model), |
|
| 497 | - $model |
|
| 498 | - )) { |
|
| 499 | - $model_routes[ $plural_model_route ][] = array( |
|
| 500 | - 'callback' => array( |
|
| 501 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 502 | - 'handleRequestInsert', |
|
| 503 | - ), |
|
| 504 | - 'callback_args' => array($version, $model_name), |
|
| 505 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 506 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 507 | - 'args' => $this->_get_write_params($model_name, $model_version_info, true), |
|
| 508 | - ); |
|
| 509 | - $model_routes[ $singular_model_route ] = array_merge( |
|
| 510 | - $model_routes[ $singular_model_route ], |
|
| 511 | - array( |
|
| 512 | - array( |
|
| 513 | - 'callback' => array( |
|
| 514 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 515 | - 'handleRequestUpdate', |
|
| 516 | - ), |
|
| 517 | - 'callback_args' => array($version, $model_name), |
|
| 518 | - 'methods' => WP_REST_Server::EDITABLE, |
|
| 519 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 520 | - 'args' => $this->_get_write_params($model_name, $model_version_info), |
|
| 521 | - ), |
|
| 522 | - array( |
|
| 523 | - 'callback' => array( |
|
| 524 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 525 | - 'handleRequestDelete', |
|
| 526 | - ), |
|
| 527 | - 'callback_args' => array($version, $model_name), |
|
| 528 | - 'methods' => WP_REST_Server::DELETABLE, |
|
| 529 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 530 | - 'args' => $this->_get_delete_query_params($model, $version), |
|
| 531 | - ), |
|
| 532 | - ) |
|
| 533 | - ); |
|
| 534 | - } |
|
| 535 | - foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
| 536 | - $related_route = EED_Core_Rest_Api::get_relation_route_via( |
|
| 537 | - $model, |
|
| 538 | - '(?P<id>[^\/]+)', |
|
| 539 | - $relation_obj |
|
| 540 | - ); |
|
| 541 | - $model_routes[ $related_route ] = array( |
|
| 542 | - array( |
|
| 543 | - 'callback' => array( |
|
| 544 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 545 | - 'handleRequestGetRelated', |
|
| 546 | - ), |
|
| 547 | - 'callback_args' => array($version, $model_name, $relation_name), |
|
| 548 | - 'methods' => WP_REST_Server::READABLE, |
|
| 549 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 550 | - 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
| 551 | - ), |
|
| 552 | - ); |
|
| 553 | - |
|
| 554 | - $related_write_route = $related_route . '/' . '(?P<related_id>[^\/]+)'; |
|
| 555 | - $model_routes[ $related_write_route ] = array( |
|
| 556 | - array( |
|
| 557 | - 'callback' => array( |
|
| 558 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 559 | - 'handleRequestAddRelation', |
|
| 560 | - ), |
|
| 561 | - 'callback_args' => array($version, $model_name, $relation_name), |
|
| 562 | - 'methods' => WP_REST_Server::EDITABLE, |
|
| 563 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 564 | - 'args' => $this->_get_add_relation_query_params($model, $relation_obj->get_other_model(), $version) |
|
| 565 | - ), |
|
| 566 | - array( |
|
| 567 | - 'callback' => array( |
|
| 568 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 569 | - 'handleRequestRemoveRelation', |
|
| 570 | - ), |
|
| 571 | - 'callback_args' => array($version, $model_name, $relation_name), |
|
| 572 | - 'methods' => WP_REST_Server::DELETABLE, |
|
| 573 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 574 | - 'args' => array() |
|
| 575 | - ), |
|
| 576 | - ); |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - return $model_routes; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace, |
|
| 585 | - * excluding the preceding slash. |
|
| 586 | - * Eg you pass get_plural_route_to('Event') = 'events' |
|
| 587 | - * |
|
| 588 | - * @param EEM_Base $model |
|
| 589 | - * @return string |
|
| 590 | - */ |
|
| 591 | - public static function get_collection_route(EEM_Base $model) |
|
| 592 | - { |
|
| 593 | - return EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
| 599 | - * excluding the preceding slash. |
|
| 600 | - * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
| 601 | - * |
|
| 602 | - * @param EEM_Base $model eg Event or Venue |
|
| 603 | - * @param string $id |
|
| 604 | - * @return string |
|
| 605 | - */ |
|
| 606 | - public static function get_entity_route($model, $id) |
|
| 607 | - { |
|
| 608 | - return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id; |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - |
|
| 612 | - /** |
|
| 613 | - * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
| 614 | - * excluding the preceding slash. |
|
| 615 | - * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
| 616 | - * |
|
| 617 | - * @param EEM_Base $model eg Event or Venue |
|
| 618 | - * @param string $id |
|
| 619 | - * @param EE_Model_Relation_Base $relation_obj |
|
| 620 | - * @return string |
|
| 621 | - */ |
|
| 622 | - public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj) |
|
| 623 | - { |
|
| 624 | - $related_model_name_endpoint_part = ModelRead::getRelatedEntityName( |
|
| 625 | - $relation_obj->get_other_model()->get_this_model_name(), |
|
| 626 | - $relation_obj |
|
| 627 | - ); |
|
| 628 | - return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * Adds onto the $relative_route the EE4 REST API versioned namespace. |
|
| 634 | - * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events' |
|
| 635 | - * |
|
| 636 | - * @param string $relative_route |
|
| 637 | - * @param string $version |
|
| 638 | - * @return string |
|
| 639 | - */ |
|
| 640 | - public static function get_versioned_route_to($relative_route, $version = '4.8.36') |
|
| 641 | - { |
|
| 642 | - return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - /** |
|
| 647 | - * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
| 648 | - * routes that don't conform to the traditional REST CRUD-style). |
|
| 649 | - * |
|
| 650 | - * @deprecated since 4.9.1 |
|
| 651 | - */ |
|
| 652 | - protected function _register_rpc_routes() |
|
| 653 | - { |
|
| 654 | - $routes = array(); |
|
| 655 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 656 | - $routes[ self::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version( |
|
| 657 | - $version, |
|
| 658 | - $hidden_endpoint |
|
| 659 | - ); |
|
| 660 | - } |
|
| 661 | - return $routes; |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - |
|
| 665 | - /** |
|
| 666 | - * @param string $version |
|
| 667 | - * @param boolean $hidden_endpoint |
|
| 668 | - * @return array |
|
| 669 | - */ |
|
| 670 | - protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
| 671 | - { |
|
| 672 | - $this_versions_routes = array(); |
|
| 673 | - // checkin endpoint |
|
| 674 | - $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array( |
|
| 675 | - array( |
|
| 676 | - 'callback' => array( |
|
| 677 | - 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
| 678 | - 'handleRequestToggleCheckin', |
|
| 679 | - ), |
|
| 680 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 681 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 682 | - 'args' => array( |
|
| 683 | - 'force' => array( |
|
| 684 | - 'required' => false, |
|
| 685 | - 'default' => false, |
|
| 686 | - 'description' => __( |
|
| 687 | - // @codingStandardsIgnoreStart |
|
| 688 | - 'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
| 689 | - // @codingStandardsIgnoreEnd |
|
| 690 | - 'event_espresso' |
|
| 691 | - ), |
|
| 692 | - ), |
|
| 693 | - ), |
|
| 694 | - 'callback_args' => array($version), |
|
| 695 | - ), |
|
| 696 | - ); |
|
| 697 | - return apply_filters( |
|
| 698 | - 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
| 699 | - $this_versions_routes, |
|
| 700 | - $version, |
|
| 701 | - $hidden_endpoint |
|
| 702 | - ); |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * Gets the query params that can be used when request one or many |
|
| 708 | - * |
|
| 709 | - * @param EEM_Base $model |
|
| 710 | - * @param string $version |
|
| 711 | - * @return array |
|
| 712 | - */ |
|
| 713 | - protected function _get_response_selection_query_params(\EEM_Base $model, $version, $single_only = false) |
|
| 714 | - { |
|
| 715 | - $query_params = array( |
|
| 716 | - 'include' => array( |
|
| 717 | - 'required' => false, |
|
| 718 | - 'default' => '*', |
|
| 719 | - 'type' => 'string', |
|
| 720 | - ), |
|
| 721 | - 'calculate' => array( |
|
| 722 | - 'required' => false, |
|
| 723 | - 'default' => '', |
|
| 724 | - 'enum' => self::$_field_calculator->retrieveCalculatedFieldsForModel($model), |
|
| 725 | - 'type' => 'string', |
|
| 726 | - // because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization |
|
| 727 | - // freaks out. We'll just validate this argument while handling the request |
|
| 728 | - 'validate_callback' => null, |
|
| 729 | - 'sanitize_callback' => null, |
|
| 730 | - ), |
|
| 731 | - 'password' => array( |
|
| 732 | - 'required' => false, |
|
| 733 | - 'default' => '', |
|
| 734 | - 'type' => 'string' |
|
| 735 | - ) |
|
| 736 | - ); |
|
| 737 | - return apply_filters( |
|
| 738 | - 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
| 739 | - $query_params, |
|
| 740 | - $model, |
|
| 741 | - $version |
|
| 742 | - ); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * Gets the parameters acceptable for delete requests |
|
| 748 | - * |
|
| 749 | - * @param \EEM_Base $model |
|
| 750 | - * @param string $version |
|
| 751 | - * @return array |
|
| 752 | - */ |
|
| 753 | - protected function _get_delete_query_params(\EEM_Base $model, $version) |
|
| 754 | - { |
|
| 755 | - $params_for_delete = array( |
|
| 756 | - 'allow_blocking' => array( |
|
| 757 | - 'required' => false, |
|
| 758 | - 'default' => true, |
|
| 759 | - 'type' => 'boolean', |
|
| 760 | - ), |
|
| 761 | - ); |
|
| 762 | - $params_for_delete['force'] = array( |
|
| 763 | - 'required' => false, |
|
| 764 | - 'default' => false, |
|
| 765 | - 'type' => 'boolean', |
|
| 766 | - ); |
|
| 767 | - return apply_filters( |
|
| 768 | - 'FHEE__EED_Core_Rest_Api___get_delete_query_params', |
|
| 769 | - $params_for_delete, |
|
| 770 | - $model, |
|
| 771 | - $version |
|
| 772 | - ); |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - protected function _get_add_relation_query_params(\EEM_Base $source_model, \EEM_Base $related_model, $version) |
|
| 776 | - { |
|
| 777 | - // if they're related through a HABTM relation, check for any non-FKs |
|
| 778 | - $all_relation_settings = $source_model->relation_settings(); |
|
| 779 | - $relation_settings = $all_relation_settings[ $related_model->get_this_model_name() ]; |
|
| 780 | - $params = array(); |
|
| 781 | - if ($relation_settings instanceof EE_HABTM_Relation && $relation_settings->hasNonKeyFields()) { |
|
| 782 | - foreach ($relation_settings->getNonKeyFields() as $field) { |
|
| 783 | - /* @var $field EE_Model_Field_Base */ |
|
| 784 | - $params[ $field->get_name() ] = array( |
|
| 785 | - 'required' => ! $field->is_nullable(), |
|
| 786 | - 'default' => ModelDataTranslator::prepareFieldValueForJson($field, $field->get_default_value(), $version), |
|
| 787 | - 'type' => $field->getSchemaType(), |
|
| 788 | - 'validate_callbaack' => null, |
|
| 789 | - 'sanitize_callback' => null |
|
| 790 | - ); |
|
| 791 | - } |
|
| 792 | - } |
|
| 793 | - return $params; |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - |
|
| 797 | - /** |
|
| 798 | - * Gets info about reading query params that are acceptable |
|
| 799 | - * |
|
| 800 | - * @param \EEM_Base $model eg 'Event' or 'Venue' |
|
| 801 | - * @param string $version |
|
| 802 | - * @return array describing the args acceptable when querying this model |
|
| 803 | - * @throws EE_Error |
|
| 804 | - */ |
|
| 805 | - protected function _get_read_query_params(\EEM_Base $model, $version) |
|
| 806 | - { |
|
| 807 | - $default_orderby = array(); |
|
| 808 | - foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
| 809 | - $default_orderby[ $key_field->get_name() ] = 'ASC'; |
|
| 810 | - } |
|
| 811 | - return array_merge( |
|
| 812 | - $this->_get_response_selection_query_params($model, $version), |
|
| 813 | - array( |
|
| 814 | - 'where' => array( |
|
| 815 | - 'required' => false, |
|
| 816 | - 'default' => array(), |
|
| 817 | - 'type' => 'object', |
|
| 818 | - // because we accept an almost infinite list of possible where conditions, WP |
|
| 819 | - // core validation and sanitization freaks out. We'll just validate this argument |
|
| 820 | - // while handling the request |
|
| 821 | - 'validate_callback' => null, |
|
| 822 | - 'sanitize_callback' => null, |
|
| 823 | - ), |
|
| 824 | - 'limit' => array( |
|
| 825 | - 'required' => false, |
|
| 826 | - 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
| 827 | - 'type' => array( |
|
| 828 | - 'array', |
|
| 829 | - 'string', |
|
| 830 | - 'integer', |
|
| 831 | - ), |
|
| 832 | - // because we accept a variety of types, WP core validation and sanitization |
|
| 833 | - // freaks out. We'll just validate this argument while handling the request |
|
| 834 | - 'validate_callback' => null, |
|
| 835 | - 'sanitize_callback' => null, |
|
| 836 | - ), |
|
| 837 | - 'order_by' => array( |
|
| 838 | - 'required' => false, |
|
| 839 | - 'default' => $default_orderby, |
|
| 840 | - 'type' => array( |
|
| 841 | - 'object', |
|
| 842 | - 'string', |
|
| 843 | - ),// because we accept a variety of types, WP core validation and sanitization |
|
| 844 | - // freaks out. We'll just validate this argument while handling the request |
|
| 845 | - 'validate_callback' => null, |
|
| 846 | - 'sanitize_callback' => null, |
|
| 847 | - ), |
|
| 848 | - 'group_by' => array( |
|
| 849 | - 'required' => false, |
|
| 850 | - 'default' => null, |
|
| 851 | - 'type' => array( |
|
| 852 | - 'object', |
|
| 853 | - 'string', |
|
| 854 | - ), |
|
| 855 | - // because we accept an almost infinite list of possible groupings, |
|
| 856 | - // WP core validation and sanitization |
|
| 857 | - // freaks out. We'll just validate this argument while handling the request |
|
| 858 | - 'validate_callback' => null, |
|
| 859 | - 'sanitize_callback' => null, |
|
| 860 | - ), |
|
| 861 | - 'having' => array( |
|
| 862 | - 'required' => false, |
|
| 863 | - 'default' => null, |
|
| 864 | - 'type' => 'object', |
|
| 865 | - // because we accept an almost infinite list of possible where conditions, WP |
|
| 866 | - // core validation and sanitization freaks out. We'll just validate this argument |
|
| 867 | - // while handling the request |
|
| 868 | - 'validate_callback' => null, |
|
| 869 | - 'sanitize_callback' => null, |
|
| 870 | - ), |
|
| 871 | - 'caps' => array( |
|
| 872 | - 'required' => false, |
|
| 873 | - 'default' => EEM_Base::caps_read, |
|
| 874 | - 'type' => 'string', |
|
| 875 | - 'enum' => array( |
|
| 876 | - EEM_Base::caps_read, |
|
| 877 | - EEM_Base::caps_read_admin, |
|
| 878 | - EEM_Base::caps_edit, |
|
| 879 | - EEM_Base::caps_delete, |
|
| 880 | - ), |
|
| 881 | - ), |
|
| 882 | - ) |
|
| 883 | - ); |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - |
|
| 887 | - /** |
|
| 888 | - * Gets parameter information for a model regarding writing data |
|
| 889 | - * |
|
| 890 | - * @param string $model_name |
|
| 891 | - * @param ModelVersionInfo $model_version_info |
|
| 892 | - * @param boolean $create whether this is for request to create (in |
|
| 893 | - * which case we need all required params) or |
|
| 894 | - * just to update (in which case we don't |
|
| 895 | - * need those on every request) |
|
| 896 | - * @return array |
|
| 897 | - */ |
|
| 898 | - protected function _get_write_params( |
|
| 899 | - $model_name, |
|
| 900 | - ModelVersionInfo $model_version_info, |
|
| 901 | - $create = false |
|
| 902 | - ) { |
|
| 903 | - $model = EE_Registry::instance()->load_model($model_name); |
|
| 904 | - $fields = $model_version_info->fieldsOnModelInThisVersion($model); |
|
| 905 | - $args_info = array(); |
|
| 906 | - foreach ($fields as $field_name => $field_obj) { |
|
| 907 | - if ($field_obj->is_auto_increment()) { |
|
| 908 | - // totally ignore auto increment IDs |
|
| 909 | - continue; |
|
| 910 | - } |
|
| 911 | - $arg_info = $field_obj->getSchema(); |
|
| 912 | - $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null; |
|
| 913 | - $arg_info['required'] = $required; |
|
| 914 | - // remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right? |
|
| 915 | - unset($arg_info['readonly']); |
|
| 916 | - $schema_properties = $field_obj->getSchemaProperties(); |
|
| 917 | - if (isset($schema_properties['raw']) |
|
| 918 | - && $field_obj->getSchemaType() === 'object' |
|
| 919 | - ) { |
|
| 920 | - // if there's a "raw" form of this argument, use those properties instead |
|
| 921 | - $arg_info = array_replace( |
|
| 922 | - $arg_info, |
|
| 923 | - $schema_properties['raw'] |
|
| 924 | - ); |
|
| 925 | - } |
|
| 926 | - $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson( |
|
| 927 | - $field_obj, |
|
| 928 | - $field_obj->get_default_value(), |
|
| 929 | - $model_version_info->requestedVersion() |
|
| 930 | - ); |
|
| 931 | - // we do our own validation and sanitization within the controller |
|
| 932 | - if (function_exists('rest_validate_value_from_schema')) { |
|
| 933 | - $sanitize_callback = array( |
|
| 934 | - 'EED_Core_Rest_Api', |
|
| 935 | - 'default_sanitize_callback', |
|
| 936 | - ); |
|
| 937 | - } else { |
|
| 938 | - $sanitize_callback = null; |
|
| 939 | - } |
|
| 940 | - $arg_info['sanitize_callback'] = $sanitize_callback; |
|
| 941 | - $args_info[ $field_name ] = $arg_info; |
|
| 942 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
| 943 | - $gmt_arg_info = $arg_info; |
|
| 944 | - $gmt_arg_info['description'] = sprintf( |
|
| 945 | - esc_html__( |
|
| 946 | - '%1$s - the value for this field in UTC. Ignored if %2$s is provided.', |
|
| 947 | - 'event_espresso' |
|
| 948 | - ), |
|
| 949 | - $field_obj->get_nicename(), |
|
| 950 | - $field_name |
|
| 951 | - ); |
|
| 952 | - $args_info[ $field_name . '_gmt' ] = $gmt_arg_info; |
|
| 953 | - } |
|
| 954 | - } |
|
| 955 | - return $args_info; |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - |
|
| 959 | - /** |
|
| 960 | - * Replacement for WP API's 'rest_parse_request_arg'. |
|
| 961 | - * If the value is blank but not required, don't bother validating it. |
|
| 962 | - * Also, it uses our email validation instead of WP API's default. |
|
| 963 | - * |
|
| 964 | - * @param $value |
|
| 965 | - * @param WP_REST_Request $request |
|
| 966 | - * @param $param |
|
| 967 | - * @return bool|true|WP_Error |
|
| 968 | - * @throws InvalidArgumentException |
|
| 969 | - * @throws InvalidInterfaceException |
|
| 970 | - * @throws InvalidDataTypeException |
|
| 971 | - */ |
|
| 972 | - public static function default_sanitize_callback($value, WP_REST_Request $request, $param) |
|
| 973 | - { |
|
| 974 | - $attributes = $request->get_attributes(); |
|
| 975 | - if (! isset($attributes['args'][ $param ]) |
|
| 976 | - || ! is_array($attributes['args'][ $param ])) { |
|
| 977 | - $validation_result = true; |
|
| 978 | - } else { |
|
| 979 | - $args = $attributes['args'][ $param ]; |
|
| 980 | - if (( |
|
| 981 | - $value === '' |
|
| 982 | - || $value === null |
|
| 983 | - ) |
|
| 984 | - && (! isset($args['required']) |
|
| 985 | - || $args['required'] === false |
|
| 986 | - ) |
|
| 987 | - ) { |
|
| 988 | - // not required and not provided? that's cool |
|
| 989 | - $validation_result = true; |
|
| 990 | - } elseif (isset($args['format']) |
|
| 991 | - && $args['format'] === 'email' |
|
| 992 | - ) { |
|
| 993 | - $validation_result = true; |
|
| 994 | - if (! self::_validate_email($value)) { |
|
| 995 | - $validation_result = new WP_Error( |
|
| 996 | - 'rest_invalid_param', |
|
| 997 | - esc_html__( |
|
| 998 | - 'The email address is not valid or does not exist.', |
|
| 999 | - 'event_espresso' |
|
| 1000 | - ) |
|
| 1001 | - ); |
|
| 1002 | - } |
|
| 1003 | - } else { |
|
| 1004 | - $validation_result = rest_validate_value_from_schema($value, $args, $param); |
|
| 1005 | - } |
|
| 1006 | - } |
|
| 1007 | - if (is_wp_error($validation_result)) { |
|
| 1008 | - return $validation_result; |
|
| 1009 | - } |
|
| 1010 | - return rest_sanitize_request_arg($value, $request, $param); |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - |
|
| 1014 | - /** |
|
| 1015 | - * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email() |
|
| 1016 | - * |
|
| 1017 | - * @param $email |
|
| 1018 | - * @return bool |
|
| 1019 | - * @throws InvalidArgumentException |
|
| 1020 | - * @throws InvalidInterfaceException |
|
| 1021 | - * @throws InvalidDataTypeException |
|
| 1022 | - */ |
|
| 1023 | - protected static function _validate_email($email) |
|
| 1024 | - { |
|
| 1025 | - try { |
|
| 1026 | - EmailAddressFactory::create($email); |
|
| 1027 | - return true; |
|
| 1028 | - } catch (EmailValidationException $e) { |
|
| 1029 | - return false; |
|
| 1030 | - } |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - |
|
| 1034 | - /** |
|
| 1035 | - * Gets routes for the config |
|
| 1036 | - * |
|
| 1037 | - * @return array @see _register_model_routes |
|
| 1038 | - * @deprecated since version 4.9.1 |
|
| 1039 | - */ |
|
| 1040 | - protected function _register_config_routes() |
|
| 1041 | - { |
|
| 1042 | - $config_routes = array(); |
|
| 1043 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 1044 | - $config_routes[ self::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version( |
|
| 1045 | - $version, |
|
| 1046 | - $hidden_endpoint |
|
| 1047 | - ); |
|
| 1048 | - } |
|
| 1049 | - return $config_routes; |
|
| 1050 | - } |
|
| 1051 | - |
|
| 1052 | - |
|
| 1053 | - /** |
|
| 1054 | - * Gets routes for the config for the specified version |
|
| 1055 | - * |
|
| 1056 | - * @param string $version |
|
| 1057 | - * @param boolean $hidden_endpoint |
|
| 1058 | - * @return array |
|
| 1059 | - */ |
|
| 1060 | - protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
| 1061 | - { |
|
| 1062 | - return array( |
|
| 1063 | - 'config' => array( |
|
| 1064 | - array( |
|
| 1065 | - 'callback' => array( |
|
| 1066 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
| 1067 | - 'handleRequest', |
|
| 1068 | - ), |
|
| 1069 | - 'methods' => WP_REST_Server::READABLE, |
|
| 1070 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 1071 | - 'callback_args' => array($version), |
|
| 1072 | - ), |
|
| 1073 | - ), |
|
| 1074 | - 'site_info' => array( |
|
| 1075 | - array( |
|
| 1076 | - 'callback' => array( |
|
| 1077 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
| 1078 | - 'handleRequestSiteInfo', |
|
| 1079 | - ), |
|
| 1080 | - 'methods' => WP_REST_Server::READABLE, |
|
| 1081 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 1082 | - 'callback_args' => array($version), |
|
| 1083 | - ), |
|
| 1084 | - ), |
|
| 1085 | - ); |
|
| 1086 | - } |
|
| 1087 | - |
|
| 1088 | - |
|
| 1089 | - /** |
|
| 1090 | - * Gets the meta info routes |
|
| 1091 | - * |
|
| 1092 | - * @return array @see _register_model_routes |
|
| 1093 | - * @deprecated since version 4.9.1 |
|
| 1094 | - */ |
|
| 1095 | - protected function _register_meta_routes() |
|
| 1096 | - { |
|
| 1097 | - $meta_routes = array(); |
|
| 1098 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 1099 | - $meta_routes[ self::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version( |
|
| 1100 | - $version, |
|
| 1101 | - $hidden_endpoint |
|
| 1102 | - ); |
|
| 1103 | - } |
|
| 1104 | - return $meta_routes; |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - |
|
| 1108 | - /** |
|
| 1109 | - * @param string $version |
|
| 1110 | - * @param boolean $hidden_endpoint |
|
| 1111 | - * @return array |
|
| 1112 | - */ |
|
| 1113 | - protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
| 1114 | - { |
|
| 1115 | - return array( |
|
| 1116 | - 'resources' => array( |
|
| 1117 | - array( |
|
| 1118 | - 'callback' => array( |
|
| 1119 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
| 1120 | - 'handleRequestModelsMeta', |
|
| 1121 | - ), |
|
| 1122 | - 'methods' => WP_REST_Server::READABLE, |
|
| 1123 | - 'hidden_endpoint' => $hidden_endpoint, |
|
| 1124 | - 'callback_args' => array($version), |
|
| 1125 | - ), |
|
| 1126 | - ), |
|
| 1127 | - ); |
|
| 1128 | - } |
|
| 1129 | - |
|
| 1130 | - |
|
| 1131 | - /** |
|
| 1132 | - * Tries to hide old 4.6 endpoints from the |
|
| 1133 | - * |
|
| 1134 | - * @param array $route_data |
|
| 1135 | - * @return array |
|
| 1136 | - * @throws \EE_Error |
|
| 1137 | - */ |
|
| 1138 | - public static function hide_old_endpoints($route_data) |
|
| 1139 | - { |
|
| 1140 | - // allow API clients to override which endpoints get hidden, in case |
|
| 1141 | - // they want to discover particular endpoints |
|
| 1142 | - // also, we don't have access to the request so we have to just grab it from the superglobal |
|
| 1143 | - $force_show_ee_namespace = ltrim( |
|
| 1144 | - EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''), |
|
| 1145 | - '/' |
|
| 1146 | - ); |
|
| 1147 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
| 1148 | - foreach ($relative_urls as $resource_name => $endpoints) { |
|
| 1149 | - foreach ($endpoints as $key => $endpoint) { |
|
| 1150 | - // skip schema and other route options |
|
| 1151 | - if (! is_numeric($key)) { |
|
| 1152 | - continue; |
|
| 1153 | - } |
|
| 1154 | - // by default, hide "hidden_endpoint"s, unless the request indicates |
|
| 1155 | - // to $force_show_ee_namespace, in which case only show that one |
|
| 1156 | - // namespace's endpoints (and hide all others) |
|
| 1157 | - if (($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
| 1158 | - || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
| 1159 | - ) { |
|
| 1160 | - $full_route = '/' . ltrim($namespace, '/'); |
|
| 1161 | - $full_route .= '/' . ltrim($resource_name, '/'); |
|
| 1162 | - unset($route_data[ $full_route ]); |
|
| 1163 | - } |
|
| 1164 | - } |
|
| 1165 | - } |
|
| 1166 | - } |
|
| 1167 | - return $route_data; |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - |
|
| 1171 | - /** |
|
| 1172 | - * Returns an array describing which versions of core support serving requests for. |
|
| 1173 | - * Keys are core versions' major and minor version, and values are the |
|
| 1174 | - * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
| 1175 | - * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
| 1176 | - * the answers table entirely, in which case it would be very difficult for |
|
| 1177 | - * it to serve 4.6-style responses. |
|
| 1178 | - * Versions of core that are missing from this array are unknowns. |
|
| 1179 | - * previous ver |
|
| 1180 | - * |
|
| 1181 | - * @return array |
|
| 1182 | - */ |
|
| 1183 | - public static function version_compatibilities() |
|
| 1184 | - { |
|
| 1185 | - return apply_filters( |
|
| 1186 | - 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
| 1187 | - array( |
|
| 1188 | - '4.8.29' => '4.8.29', |
|
| 1189 | - '4.8.33' => '4.8.29', |
|
| 1190 | - '4.8.34' => '4.8.29', |
|
| 1191 | - '4.8.36' => '4.8.29', |
|
| 1192 | - ) |
|
| 1193 | - ); |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - |
|
| 1197 | - /** |
|
| 1198 | - * Gets the latest API version served. Eg if there |
|
| 1199 | - * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
| 1200 | - * we are on core version 4.8.34, it will return the string "4.8.32" |
|
| 1201 | - * |
|
| 1202 | - * @return string |
|
| 1203 | - */ |
|
| 1204 | - public static function latest_rest_api_version() |
|
| 1205 | - { |
|
| 1206 | - $versions_served = \EED_Core_Rest_Api::versions_served(); |
|
| 1207 | - $versions_served_keys = array_keys($versions_served); |
|
| 1208 | - return end($versions_served_keys); |
|
| 1209 | - } |
|
| 1210 | - |
|
| 1211 | - |
|
| 1212 | - /** |
|
| 1213 | - * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
| 1214 | - * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
| 1215 | - * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
| 1216 | - * We also indicate whether or not this version should be put in the index or not |
|
| 1217 | - * |
|
| 1218 | - * @return array keys are API version numbers (just major and minor numbers), and values |
|
| 1219 | - * are whether or not they should be hidden |
|
| 1220 | - */ |
|
| 1221 | - public static function versions_served() |
|
| 1222 | - { |
|
| 1223 | - $versions_served = array(); |
|
| 1224 | - $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
| 1225 | - $lowest_compatible_version = end($possibly_served_versions); |
|
| 1226 | - reset($possibly_served_versions); |
|
| 1227 | - $versions_served_historically = array_keys($possibly_served_versions); |
|
| 1228 | - $latest_version = end($versions_served_historically); |
|
| 1229 | - reset($versions_served_historically); |
|
| 1230 | - // for each version of core we have ever served: |
|
| 1231 | - foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
| 1232 | - // if it's not above the current core version, and it's compatible with the current version of core |
|
| 1233 | - |
|
| 1234 | - if ($key_versioned_endpoint === $latest_version) { |
|
| 1235 | - // don't hide the latest version in the index |
|
| 1236 | - $versions_served[ $key_versioned_endpoint ] = false; |
|
| 1237 | - } elseif (version_compare($key_versioned_endpoint, $lowest_compatible_version, '>=') |
|
| 1238 | - && version_compare($key_versioned_endpoint, EED_Core_Rest_Api::core_version(), '<') |
|
| 1239 | - ) { |
|
| 1240 | - // include, but hide, previous versions which are still supported |
|
| 1241 | - $versions_served[ $key_versioned_endpoint ] = true; |
|
| 1242 | - } elseif (apply_filters( |
|
| 1243 | - 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
| 1244 | - false, |
|
| 1245 | - $possibly_served_versions |
|
| 1246 | - )) { |
|
| 1247 | - // if a version is no longer supported, don't include it in index or list of versions served |
|
| 1248 | - $versions_served[ $key_versioned_endpoint ] = true; |
|
| 1249 | - } |
|
| 1250 | - } |
|
| 1251 | - return $versions_served; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - |
|
| 1255 | - /** |
|
| 1256 | - * Gets the major and minor version of EE core's version string |
|
| 1257 | - * |
|
| 1258 | - * @return string |
|
| 1259 | - */ |
|
| 1260 | - public static function core_version() |
|
| 1261 | - { |
|
| 1262 | - return apply_filters( |
|
| 1263 | - 'FHEE__EED_Core_REST_API__core_version', |
|
| 1264 | - implode( |
|
| 1265 | - '.', |
|
| 1266 | - array_slice( |
|
| 1267 | - explode( |
|
| 1268 | - '.', |
|
| 1269 | - espresso_version() |
|
| 1270 | - ), |
|
| 1271 | - 0, |
|
| 1272 | - 3 |
|
| 1273 | - ) |
|
| 1274 | - ) |
|
| 1275 | - ); |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - |
|
| 1279 | - /** |
|
| 1280 | - * Gets the default limit that should be used when querying for resources |
|
| 1281 | - * |
|
| 1282 | - * @return int |
|
| 1283 | - */ |
|
| 1284 | - public static function get_default_query_limit() |
|
| 1285 | - { |
|
| 1286 | - // we actually don't use a const because we want folks to always use |
|
| 1287 | - // this method, not the const directly |
|
| 1288 | - return apply_filters( |
|
| 1289 | - 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
| 1290 | - 50 |
|
| 1291 | - ); |
|
| 1292 | - } |
|
| 1293 | - |
|
| 1294 | - |
|
| 1295 | - /** |
|
| 1296 | - * |
|
| 1297 | - * @param string $version api version string (i.e. '4.8.36') |
|
| 1298 | - * @return array |
|
| 1299 | - */ |
|
| 1300 | - public static function getCollectionRoutesIndexedByModelName($version = '') |
|
| 1301 | - { |
|
| 1302 | - $version = empty($version) ? self::latest_rest_api_version() : $version; |
|
| 1303 | - $model_names = self::model_names_with_plural_routes($version); |
|
| 1304 | - $collection_routes = array(); |
|
| 1305 | - foreach ($model_names as $model_name => $model_class_name) { |
|
| 1306 | - $collection_routes[ strtolower($model_name) ] = '/' . self::ee_api_namespace . $version . '/' |
|
| 1307 | - . EEH_Inflector::pluralize_and_lower($model_name); |
|
| 1308 | - } |
|
| 1309 | - return $collection_routes; |
|
| 1310 | - } |
|
| 1311 | - |
|
| 1312 | - |
|
| 1313 | - /** |
|
| 1314 | - * Returns an array of primary key names indexed by model names. |
|
| 1315 | - * @param string $version |
|
| 1316 | - * @return array |
|
| 1317 | - */ |
|
| 1318 | - public static function getPrimaryKeyNamesIndexedByModelName($version = '') |
|
| 1319 | - { |
|
| 1320 | - $version = empty($version) ? self::latest_rest_api_version() : $version; |
|
| 1321 | - $model_names = self::model_names_with_plural_routes($version); |
|
| 1322 | - $primary_key_items = array(); |
|
| 1323 | - foreach ($model_names as $model_name => $model_class_name) { |
|
| 1324 | - $primary_keys = $model_class_name::instance()->get_combined_primary_key_fields(); |
|
| 1325 | - foreach ($primary_keys as $primary_key_name => $primary_key_field) { |
|
| 1326 | - if (count($primary_keys) > 1) { |
|
| 1327 | - $primary_key_items[ strtolower($model_name) ][] = $primary_key_name; |
|
| 1328 | - } else { |
|
| 1329 | - $primary_key_items[ strtolower($model_name) ] = $primary_key_name; |
|
| 1330 | - } |
|
| 1331 | - } |
|
| 1332 | - } |
|
| 1333 | - return $primary_key_items; |
|
| 1334 | - } |
|
| 1335 | - |
|
| 1336 | - /** |
|
| 1337 | - * Determines the EE REST API debug mode is activated, or not. |
|
| 1338 | - * @since 4.9.76.p |
|
| 1339 | - * @return bool |
|
| 1340 | - */ |
|
| 1341 | - public static function debugMode() |
|
| 1342 | - { |
|
| 1343 | - static $debug_mode = null; // could be class prop |
|
| 1344 | - if ($debug_mode === null) { |
|
| 1345 | - $debug_mode = defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE; |
|
| 1346 | - } |
|
| 1347 | - return $debug_mode; |
|
| 1348 | - } |
|
| 1349 | - |
|
| 1350 | - |
|
| 1351 | - |
|
| 1352 | - /** |
|
| 1353 | - * run - initial module setup |
|
| 1354 | - * |
|
| 1355 | - * @access public |
|
| 1356 | - * @param WP $WP |
|
| 1357 | - * @return void |
|
| 1358 | - */ |
|
| 1359 | - public function run($WP) |
|
| 1360 | - { |
|
| 1361 | - } |
|
| 26 | + const ee_api_namespace = Domain::API_NAMESPACE; |
|
| 27 | + |
|
| 28 | + const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
| 29 | + |
|
| 30 | + const saved_routes_option_names = 'ee_core_routes'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * string used in _links response bodies to make them globally unique. |
|
| 34 | + * |
|
| 35 | + * @see http://v2.wp-api.org/extending/linking/ |
|
| 36 | + */ |
|
| 37 | + const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var CalculatedModelFields |
|
| 41 | + */ |
|
| 42 | + protected static $_field_calculator; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @return EED_Core_Rest_Api|EED_Module |
|
| 47 | + */ |
|
| 48 | + public static function instance() |
|
| 49 | + { |
|
| 50 | + self::$_field_calculator = LoaderFactory::getLoader()->load('EventEspresso\core\libraries\rest_api\CalculatedModelFields'); |
|
| 51 | + return parent::get_instance(__CLASS__); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 57 | + * |
|
| 58 | + * @access public |
|
| 59 | + * @return void |
|
| 60 | + */ |
|
| 61 | + public static function set_hooks() |
|
| 62 | + { |
|
| 63 | + self::set_hooks_both(); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 69 | + * |
|
| 70 | + * @access public |
|
| 71 | + * @return void |
|
| 72 | + */ |
|
| 73 | + public static function set_hooks_admin() |
|
| 74 | + { |
|
| 75 | + self::set_hooks_both(); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + public static function set_hooks_both() |
|
| 80 | + { |
|
| 81 | + add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5); |
|
| 82 | + add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10); |
|
| 83 | + add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2); |
|
| 84 | + add_filter( |
|
| 85 | + 'rest_index', |
|
| 86 | + array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex') |
|
| 87 | + ); |
|
| 88 | + EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * sets up hooks which only need to be included as part of REST API requests; |
|
| 94 | + * other requests like to the frontend or admin etc don't need them |
|
| 95 | + * |
|
| 96 | + * @throws \EE_Error |
|
| 97 | + */ |
|
| 98 | + public static function set_hooks_rest_api() |
|
| 99 | + { |
|
| 100 | + // set hooks which account for changes made to the API |
|
| 101 | + EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * public wrapper of _set_hooks_for_changes. |
|
| 107 | + * Loads all the hooks which make requests to old versions of the API |
|
| 108 | + * appear the same as they always did |
|
| 109 | + * |
|
| 110 | + * @throws EE_Error |
|
| 111 | + */ |
|
| 112 | + public static function set_hooks_for_changes() |
|
| 113 | + { |
|
| 114 | + self::_set_hooks_for_changes(); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Loads all the hooks which make requests to old versions of the API |
|
| 120 | + * appear the same as they always did |
|
| 121 | + * |
|
| 122 | + * @throws EE_Error |
|
| 123 | + */ |
|
| 124 | + protected static function _set_hooks_for_changes() |
|
| 125 | + { |
|
| 126 | + $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api/changes'), false); |
|
| 127 | + foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
| 128 | + // ignore the base parent class |
|
| 129 | + // and legacy named classes |
|
| 130 | + if ($classname_in_namespace === 'ChangesInBase' |
|
| 131 | + || strpos($classname_in_namespace, 'Changes_In_') === 0 |
|
| 132 | + ) { |
|
| 133 | + continue; |
|
| 134 | + } |
|
| 135 | + $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
| 136 | + if (class_exists($full_classname)) { |
|
| 137 | + $instance_of_class = new $full_classname; |
|
| 138 | + if ($instance_of_class instanceof ChangesInBase) { |
|
| 139 | + $instance_of_class->setHooks(); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
| 148 | + * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
| 149 | + * |
|
| 150 | + * @throws \EE_Error |
|
| 151 | + */ |
|
| 152 | + public static function register_routes() |
|
| 153 | + { |
|
| 154 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) { |
|
| 155 | + foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) { |
|
| 156 | + /** |
|
| 157 | + * @var array $data_for_multiple_endpoints numerically indexed array |
|
| 158 | + * but can also contain route options like { |
|
| 159 | + * @type array $schema { |
|
| 160 | + * @type callable $schema_callback |
|
| 161 | + * @type array $callback_args arguments that will be passed to the callback, after the |
|
| 162 | + * WP_REST_Request of course |
|
| 163 | + * } |
|
| 164 | + * } |
|
| 165 | + */ |
|
| 166 | + // when registering routes, register all the endpoints' data at the same time |
|
| 167 | + $multiple_endpoint_args = array(); |
|
| 168 | + foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) { |
|
| 169 | + /** |
|
| 170 | + * @var array $data_for_single_endpoint { |
|
| 171 | + * @type callable $callback |
|
| 172 | + * @type string methods |
|
| 173 | + * @type array args |
|
| 174 | + * @type array _links |
|
| 175 | + * @type array $callback_args arguments that will be passed to the callback, after the |
|
| 176 | + * WP_REST_Request of course |
|
| 177 | + * } |
|
| 178 | + */ |
|
| 179 | + // skip route options |
|
| 180 | + if (! is_numeric($endpoint_key)) { |
|
| 181 | + continue; |
|
| 182 | + } |
|
| 183 | + if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
| 184 | + throw new EE_Error( |
|
| 185 | + esc_html__( |
|
| 186 | + // @codingStandardsIgnoreStart |
|
| 187 | + 'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).', |
|
| 188 | + // @codingStandardsIgnoreEnd |
|
| 189 | + 'event_espresso' |
|
| 190 | + ) |
|
| 191 | + ); |
|
| 192 | + } |
|
| 193 | + $callback = $data_for_single_endpoint['callback']; |
|
| 194 | + $single_endpoint_args = array( |
|
| 195 | + 'methods' => $data_for_single_endpoint['methods'], |
|
| 196 | + 'args' => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args'] |
|
| 197 | + : array(), |
|
| 198 | + ); |
|
| 199 | + if (isset($data_for_single_endpoint['_links'])) { |
|
| 200 | + $single_endpoint_args['_links'] = $data_for_single_endpoint['_links']; |
|
| 201 | + } |
|
| 202 | + if (isset($data_for_single_endpoint['callback_args'])) { |
|
| 203 | + $callback_args = $data_for_single_endpoint['callback_args']; |
|
| 204 | + $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use ( |
|
| 205 | + $callback, |
|
| 206 | + $callback_args |
|
| 207 | + ) { |
|
| 208 | + array_unshift($callback_args, $request); |
|
| 209 | + return call_user_func_array( |
|
| 210 | + $callback, |
|
| 211 | + $callback_args |
|
| 212 | + ); |
|
| 213 | + }; |
|
| 214 | + } else { |
|
| 215 | + $single_endpoint_args['callback'] = $data_for_single_endpoint['callback']; |
|
| 216 | + } |
|
| 217 | + // As of WordPress 5.5, if a permission_callback is not provided, |
|
| 218 | + // the REST API will issue a _doing_it_wrong notice. |
|
| 219 | + // Since the EE REST API defers capabilities to the db model system, |
|
| 220 | + // we will just use the generic WP callback for public endpoints |
|
| 221 | + if (! isset($single_endpoint_args['permission_callback'])) { |
|
| 222 | + $single_endpoint_args['permission_callback'] = '__return_true'; |
|
| 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'] = 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 | + * @type string|array $callback |
|
| 283 | + * @type string $methods |
|
| 284 | + * @type boolean $hidden_endpoint |
|
| 285 | + * } |
|
| 286 | + */ |
|
| 287 | + public static function get_ee_route_data() |
|
| 288 | + { |
|
| 289 | + $ee_routes = array(); |
|
| 290 | + foreach (self::versions_served() as $version => $hidden_endpoints) { |
|
| 291 | + $ee_routes[ self::ee_api_namespace . $version ] = self::_get_ee_route_data_for_version( |
|
| 292 | + $version, |
|
| 293 | + $hidden_endpoints |
|
| 294 | + ); |
|
| 295 | + } |
|
| 296 | + return $ee_routes; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Gets the EE route data from the wp options if it exists already, |
|
| 302 | + * otherwise re-generates it and saves it to the option |
|
| 303 | + * |
|
| 304 | + * @param string $version |
|
| 305 | + * @param boolean $hidden_endpoints |
|
| 306 | + * @return array |
|
| 307 | + * @throws \EE_Error |
|
| 308 | + */ |
|
| 309 | + protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
| 310 | + { |
|
| 311 | + $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
| 312 | + if (! $ee_routes || EED_Core_Rest_Api::debugMode()) { |
|
| 313 | + $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
| 314 | + } |
|
| 315 | + return $ee_routes; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Saves the EE REST API route data to a wp option and returns it |
|
| 321 | + * |
|
| 322 | + * @param string $version |
|
| 323 | + * @param boolean $hidden_endpoints |
|
| 324 | + * @return mixed|null |
|
| 325 | + * @throws \EE_Error |
|
| 326 | + */ |
|
| 327 | + protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
| 328 | + { |
|
| 329 | + $instance = self::instance(); |
|
| 330 | + $routes = apply_filters( |
|
| 331 | + 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
| 332 | + array_replace_recursive( |
|
| 333 | + $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
| 334 | + $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
| 335 | + $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
| 336 | + $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
| 337 | + ) |
|
| 338 | + ); |
|
| 339 | + $option_name = self::saved_routes_option_names . $version; |
|
| 340 | + if (get_option($option_name)) { |
|
| 341 | + update_option($option_name, $routes, true); |
|
| 342 | + } else { |
|
| 343 | + add_option($option_name, $routes, null, 'no'); |
|
| 344 | + } |
|
| 345 | + return $routes; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Calculates all the EE routes and saves it to a WordPress option so we don't |
|
| 351 | + * need to calculate it on every request |
|
| 352 | + * |
|
| 353 | + * @deprecated since version 4.9.1 |
|
| 354 | + * @return void |
|
| 355 | + */ |
|
| 356 | + public static function save_ee_routes() |
|
| 357 | + { |
|
| 358 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 359 | + $instance = self::instance(); |
|
| 360 | + $routes = apply_filters( |
|
| 361 | + 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
| 362 | + array_replace_recursive( |
|
| 363 | + $instance->_register_config_routes(), |
|
| 364 | + $instance->_register_meta_routes(), |
|
| 365 | + $instance->_register_model_routes(), |
|
| 366 | + $instance->_register_rpc_routes() |
|
| 367 | + ) |
|
| 368 | + ); |
|
| 369 | + update_option(self::saved_routes_option_names, $routes, true); |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Gets all the route information relating to EE models |
|
| 376 | + * |
|
| 377 | + * @return array @see get_ee_route_data |
|
| 378 | + * @deprecated since version 4.9.1 |
|
| 379 | + */ |
|
| 380 | + protected function _register_model_routes() |
|
| 381 | + { |
|
| 382 | + $model_routes = array(); |
|
| 383 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 384 | + $model_routes[ EED_Core_Rest_Api::ee_api_namespace |
|
| 385 | + . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
| 386 | + } |
|
| 387 | + return $model_routes; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * Decides whether or not to add write endpoints for this model. |
|
| 393 | + * |
|
| 394 | + * Currently, this defaults to exclude all global tables and models |
|
| 395 | + * which would allow inserting WP core data (we don't want to duplicate |
|
| 396 | + * what WP API does, as it's unnecessary, extra work, and potentially extra bugs) |
|
| 397 | + * |
|
| 398 | + * @param EEM_Base $model |
|
| 399 | + * @return bool |
|
| 400 | + */ |
|
| 401 | + public static function should_have_write_endpoints(EEM_Base $model) |
|
| 402 | + { |
|
| 403 | + if ($model->is_wp_core_model()) { |
|
| 404 | + return false; |
|
| 405 | + } |
|
| 406 | + foreach ($model->get_tables() as $table) { |
|
| 407 | + if ($table->is_global()) { |
|
| 408 | + return false; |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + return true; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`) |
|
| 417 | + * in this versioned namespace of EE4 |
|
| 418 | + * |
|
| 419 | + * @param $version |
|
| 420 | + * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event') |
|
| 421 | + */ |
|
| 422 | + public static function model_names_with_plural_routes($version) |
|
| 423 | + { |
|
| 424 | + $model_version_info = new ModelVersionInfo($version); |
|
| 425 | + $models_to_register = $model_version_info->modelsForRequestedVersion(); |
|
| 426 | + // let's not bother having endpoints for extra metas |
|
| 427 | + unset( |
|
| 428 | + $models_to_register['Extra_Meta'], |
|
| 429 | + $models_to_register['Extra_Join'], |
|
| 430 | + $models_to_register['Post_Meta'] |
|
| 431 | + ); |
|
| 432 | + return apply_filters( |
|
| 433 | + 'FHEE__EED_Core_REST_API___register_model_routes', |
|
| 434 | + $models_to_register |
|
| 435 | + ); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * Gets the route data for EE models in the specified version |
|
| 441 | + * |
|
| 442 | + * @param string $version |
|
| 443 | + * @param boolean $hidden_endpoint |
|
| 444 | + * @return array |
|
| 445 | + * @throws EE_Error |
|
| 446 | + */ |
|
| 447 | + protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
| 448 | + { |
|
| 449 | + $model_routes = array(); |
|
| 450 | + $model_version_info = new ModelVersionInfo($version); |
|
| 451 | + foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
|
| 452 | + $model = \EE_Registry::instance()->load_model($model_name); |
|
| 453 | + // if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
| 454 | + if (! $model instanceof EEM_Base) { |
|
| 455 | + continue; |
|
| 456 | + } |
|
| 457 | + // yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
| 458 | + $plural_model_route = EED_Core_Rest_Api::get_collection_route($model); |
|
| 459 | + $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)'); |
|
| 460 | + $model_routes[ $plural_model_route ] = array( |
|
| 461 | + array( |
|
| 462 | + 'callback' => array( |
|
| 463 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 464 | + 'handleRequestGetAll', |
|
| 465 | + ), |
|
| 466 | + 'callback_args' => array($version, $model_name), |
|
| 467 | + 'methods' => WP_REST_Server::READABLE, |
|
| 468 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 469 | + 'args' => $this->_get_read_query_params($model, $version), |
|
| 470 | + '_links' => array( |
|
| 471 | + 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
| 472 | + ), |
|
| 473 | + ), |
|
| 474 | + 'schema' => array( |
|
| 475 | + 'schema_callback' => array( |
|
| 476 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 477 | + 'handleSchemaRequest', |
|
| 478 | + ), |
|
| 479 | + 'callback_args' => array($version, $model_name), |
|
| 480 | + ), |
|
| 481 | + ); |
|
| 482 | + $model_routes[ $singular_model_route ] = array( |
|
| 483 | + array( |
|
| 484 | + 'callback' => array( |
|
| 485 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 486 | + 'handleRequestGetOne', |
|
| 487 | + ), |
|
| 488 | + 'callback_args' => array($version, $model_name), |
|
| 489 | + 'methods' => WP_REST_Server::READABLE, |
|
| 490 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 491 | + 'args' => $this->_get_response_selection_query_params($model, $version, true), |
|
| 492 | + ), |
|
| 493 | + ); |
|
| 494 | + if (apply_filters( |
|
| 495 | + 'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints', |
|
| 496 | + EED_Core_Rest_Api::should_have_write_endpoints($model), |
|
| 497 | + $model |
|
| 498 | + )) { |
|
| 499 | + $model_routes[ $plural_model_route ][] = array( |
|
| 500 | + 'callback' => array( |
|
| 501 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 502 | + 'handleRequestInsert', |
|
| 503 | + ), |
|
| 504 | + 'callback_args' => array($version, $model_name), |
|
| 505 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 506 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 507 | + 'args' => $this->_get_write_params($model_name, $model_version_info, true), |
|
| 508 | + ); |
|
| 509 | + $model_routes[ $singular_model_route ] = array_merge( |
|
| 510 | + $model_routes[ $singular_model_route ], |
|
| 511 | + array( |
|
| 512 | + array( |
|
| 513 | + 'callback' => array( |
|
| 514 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 515 | + 'handleRequestUpdate', |
|
| 516 | + ), |
|
| 517 | + 'callback_args' => array($version, $model_name), |
|
| 518 | + 'methods' => WP_REST_Server::EDITABLE, |
|
| 519 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 520 | + 'args' => $this->_get_write_params($model_name, $model_version_info), |
|
| 521 | + ), |
|
| 522 | + array( |
|
| 523 | + 'callback' => array( |
|
| 524 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 525 | + 'handleRequestDelete', |
|
| 526 | + ), |
|
| 527 | + 'callback_args' => array($version, $model_name), |
|
| 528 | + 'methods' => WP_REST_Server::DELETABLE, |
|
| 529 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 530 | + 'args' => $this->_get_delete_query_params($model, $version), |
|
| 531 | + ), |
|
| 532 | + ) |
|
| 533 | + ); |
|
| 534 | + } |
|
| 535 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
| 536 | + $related_route = EED_Core_Rest_Api::get_relation_route_via( |
|
| 537 | + $model, |
|
| 538 | + '(?P<id>[^\/]+)', |
|
| 539 | + $relation_obj |
|
| 540 | + ); |
|
| 541 | + $model_routes[ $related_route ] = array( |
|
| 542 | + array( |
|
| 543 | + 'callback' => array( |
|
| 544 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
| 545 | + 'handleRequestGetRelated', |
|
| 546 | + ), |
|
| 547 | + 'callback_args' => array($version, $model_name, $relation_name), |
|
| 548 | + 'methods' => WP_REST_Server::READABLE, |
|
| 549 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 550 | + 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
| 551 | + ), |
|
| 552 | + ); |
|
| 553 | + |
|
| 554 | + $related_write_route = $related_route . '/' . '(?P<related_id>[^\/]+)'; |
|
| 555 | + $model_routes[ $related_write_route ] = array( |
|
| 556 | + array( |
|
| 557 | + 'callback' => array( |
|
| 558 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 559 | + 'handleRequestAddRelation', |
|
| 560 | + ), |
|
| 561 | + 'callback_args' => array($version, $model_name, $relation_name), |
|
| 562 | + 'methods' => WP_REST_Server::EDITABLE, |
|
| 563 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 564 | + 'args' => $this->_get_add_relation_query_params($model, $relation_obj->get_other_model(), $version) |
|
| 565 | + ), |
|
| 566 | + array( |
|
| 567 | + 'callback' => array( |
|
| 568 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
| 569 | + 'handleRequestRemoveRelation', |
|
| 570 | + ), |
|
| 571 | + 'callback_args' => array($version, $model_name, $relation_name), |
|
| 572 | + 'methods' => WP_REST_Server::DELETABLE, |
|
| 573 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 574 | + 'args' => array() |
|
| 575 | + ), |
|
| 576 | + ); |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + return $model_routes; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace, |
|
| 585 | + * excluding the preceding slash. |
|
| 586 | + * Eg you pass get_plural_route_to('Event') = 'events' |
|
| 587 | + * |
|
| 588 | + * @param EEM_Base $model |
|
| 589 | + * @return string |
|
| 590 | + */ |
|
| 591 | + public static function get_collection_route(EEM_Base $model) |
|
| 592 | + { |
|
| 593 | + return EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
| 599 | + * excluding the preceding slash. |
|
| 600 | + * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
| 601 | + * |
|
| 602 | + * @param EEM_Base $model eg Event or Venue |
|
| 603 | + * @param string $id |
|
| 604 | + * @return string |
|
| 605 | + */ |
|
| 606 | + public static function get_entity_route($model, $id) |
|
| 607 | + { |
|
| 608 | + return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id; |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + |
|
| 612 | + /** |
|
| 613 | + * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
| 614 | + * excluding the preceding slash. |
|
| 615 | + * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
| 616 | + * |
|
| 617 | + * @param EEM_Base $model eg Event or Venue |
|
| 618 | + * @param string $id |
|
| 619 | + * @param EE_Model_Relation_Base $relation_obj |
|
| 620 | + * @return string |
|
| 621 | + */ |
|
| 622 | + public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj) |
|
| 623 | + { |
|
| 624 | + $related_model_name_endpoint_part = ModelRead::getRelatedEntityName( |
|
| 625 | + $relation_obj->get_other_model()->get_this_model_name(), |
|
| 626 | + $relation_obj |
|
| 627 | + ); |
|
| 628 | + return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * Adds onto the $relative_route the EE4 REST API versioned namespace. |
|
| 634 | + * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events' |
|
| 635 | + * |
|
| 636 | + * @param string $relative_route |
|
| 637 | + * @param string $version |
|
| 638 | + * @return string |
|
| 639 | + */ |
|
| 640 | + public static function get_versioned_route_to($relative_route, $version = '4.8.36') |
|
| 641 | + { |
|
| 642 | + return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
| 648 | + * routes that don't conform to the traditional REST CRUD-style). |
|
| 649 | + * |
|
| 650 | + * @deprecated since 4.9.1 |
|
| 651 | + */ |
|
| 652 | + protected function _register_rpc_routes() |
|
| 653 | + { |
|
| 654 | + $routes = array(); |
|
| 655 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 656 | + $routes[ self::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version( |
|
| 657 | + $version, |
|
| 658 | + $hidden_endpoint |
|
| 659 | + ); |
|
| 660 | + } |
|
| 661 | + return $routes; |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + |
|
| 665 | + /** |
|
| 666 | + * @param string $version |
|
| 667 | + * @param boolean $hidden_endpoint |
|
| 668 | + * @return array |
|
| 669 | + */ |
|
| 670 | + protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
| 671 | + { |
|
| 672 | + $this_versions_routes = array(); |
|
| 673 | + // checkin endpoint |
|
| 674 | + $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array( |
|
| 675 | + array( |
|
| 676 | + 'callback' => array( |
|
| 677 | + 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
| 678 | + 'handleRequestToggleCheckin', |
|
| 679 | + ), |
|
| 680 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 681 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 682 | + 'args' => array( |
|
| 683 | + 'force' => array( |
|
| 684 | + 'required' => false, |
|
| 685 | + 'default' => false, |
|
| 686 | + 'description' => __( |
|
| 687 | + // @codingStandardsIgnoreStart |
|
| 688 | + 'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
| 689 | + // @codingStandardsIgnoreEnd |
|
| 690 | + 'event_espresso' |
|
| 691 | + ), |
|
| 692 | + ), |
|
| 693 | + ), |
|
| 694 | + 'callback_args' => array($version), |
|
| 695 | + ), |
|
| 696 | + ); |
|
| 697 | + return apply_filters( |
|
| 698 | + 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
| 699 | + $this_versions_routes, |
|
| 700 | + $version, |
|
| 701 | + $hidden_endpoint |
|
| 702 | + ); |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * Gets the query params that can be used when request one or many |
|
| 708 | + * |
|
| 709 | + * @param EEM_Base $model |
|
| 710 | + * @param string $version |
|
| 711 | + * @return array |
|
| 712 | + */ |
|
| 713 | + protected function _get_response_selection_query_params(\EEM_Base $model, $version, $single_only = false) |
|
| 714 | + { |
|
| 715 | + $query_params = array( |
|
| 716 | + 'include' => array( |
|
| 717 | + 'required' => false, |
|
| 718 | + 'default' => '*', |
|
| 719 | + 'type' => 'string', |
|
| 720 | + ), |
|
| 721 | + 'calculate' => array( |
|
| 722 | + 'required' => false, |
|
| 723 | + 'default' => '', |
|
| 724 | + 'enum' => self::$_field_calculator->retrieveCalculatedFieldsForModel($model), |
|
| 725 | + 'type' => 'string', |
|
| 726 | + // because we accept a CSV'd list of the enumerated strings, WP core validation and sanitization |
|
| 727 | + // freaks out. We'll just validate this argument while handling the request |
|
| 728 | + 'validate_callback' => null, |
|
| 729 | + 'sanitize_callback' => null, |
|
| 730 | + ), |
|
| 731 | + 'password' => array( |
|
| 732 | + 'required' => false, |
|
| 733 | + 'default' => '', |
|
| 734 | + 'type' => 'string' |
|
| 735 | + ) |
|
| 736 | + ); |
|
| 737 | + return apply_filters( |
|
| 738 | + 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
| 739 | + $query_params, |
|
| 740 | + $model, |
|
| 741 | + $version |
|
| 742 | + ); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * Gets the parameters acceptable for delete requests |
|
| 748 | + * |
|
| 749 | + * @param \EEM_Base $model |
|
| 750 | + * @param string $version |
|
| 751 | + * @return array |
|
| 752 | + */ |
|
| 753 | + protected function _get_delete_query_params(\EEM_Base $model, $version) |
|
| 754 | + { |
|
| 755 | + $params_for_delete = array( |
|
| 756 | + 'allow_blocking' => array( |
|
| 757 | + 'required' => false, |
|
| 758 | + 'default' => true, |
|
| 759 | + 'type' => 'boolean', |
|
| 760 | + ), |
|
| 761 | + ); |
|
| 762 | + $params_for_delete['force'] = array( |
|
| 763 | + 'required' => false, |
|
| 764 | + 'default' => false, |
|
| 765 | + 'type' => 'boolean', |
|
| 766 | + ); |
|
| 767 | + return apply_filters( |
|
| 768 | + 'FHEE__EED_Core_Rest_Api___get_delete_query_params', |
|
| 769 | + $params_for_delete, |
|
| 770 | + $model, |
|
| 771 | + $version |
|
| 772 | + ); |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + protected function _get_add_relation_query_params(\EEM_Base $source_model, \EEM_Base $related_model, $version) |
|
| 776 | + { |
|
| 777 | + // if they're related through a HABTM relation, check for any non-FKs |
|
| 778 | + $all_relation_settings = $source_model->relation_settings(); |
|
| 779 | + $relation_settings = $all_relation_settings[ $related_model->get_this_model_name() ]; |
|
| 780 | + $params = array(); |
|
| 781 | + if ($relation_settings instanceof EE_HABTM_Relation && $relation_settings->hasNonKeyFields()) { |
|
| 782 | + foreach ($relation_settings->getNonKeyFields() as $field) { |
|
| 783 | + /* @var $field EE_Model_Field_Base */ |
|
| 784 | + $params[ $field->get_name() ] = array( |
|
| 785 | + 'required' => ! $field->is_nullable(), |
|
| 786 | + 'default' => ModelDataTranslator::prepareFieldValueForJson($field, $field->get_default_value(), $version), |
|
| 787 | + 'type' => $field->getSchemaType(), |
|
| 788 | + 'validate_callbaack' => null, |
|
| 789 | + 'sanitize_callback' => null |
|
| 790 | + ); |
|
| 791 | + } |
|
| 792 | + } |
|
| 793 | + return $params; |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + |
|
| 797 | + /** |
|
| 798 | + * Gets info about reading query params that are acceptable |
|
| 799 | + * |
|
| 800 | + * @param \EEM_Base $model eg 'Event' or 'Venue' |
|
| 801 | + * @param string $version |
|
| 802 | + * @return array describing the args acceptable when querying this model |
|
| 803 | + * @throws EE_Error |
|
| 804 | + */ |
|
| 805 | + protected function _get_read_query_params(\EEM_Base $model, $version) |
|
| 806 | + { |
|
| 807 | + $default_orderby = array(); |
|
| 808 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
| 809 | + $default_orderby[ $key_field->get_name() ] = 'ASC'; |
|
| 810 | + } |
|
| 811 | + return array_merge( |
|
| 812 | + $this->_get_response_selection_query_params($model, $version), |
|
| 813 | + array( |
|
| 814 | + 'where' => array( |
|
| 815 | + 'required' => false, |
|
| 816 | + 'default' => array(), |
|
| 817 | + 'type' => 'object', |
|
| 818 | + // because we accept an almost infinite list of possible where conditions, WP |
|
| 819 | + // core validation and sanitization freaks out. We'll just validate this argument |
|
| 820 | + // while handling the request |
|
| 821 | + 'validate_callback' => null, |
|
| 822 | + 'sanitize_callback' => null, |
|
| 823 | + ), |
|
| 824 | + 'limit' => array( |
|
| 825 | + 'required' => false, |
|
| 826 | + 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
| 827 | + 'type' => array( |
|
| 828 | + 'array', |
|
| 829 | + 'string', |
|
| 830 | + 'integer', |
|
| 831 | + ), |
|
| 832 | + // because we accept a variety of types, WP core validation and sanitization |
|
| 833 | + // freaks out. We'll just validate this argument while handling the request |
|
| 834 | + 'validate_callback' => null, |
|
| 835 | + 'sanitize_callback' => null, |
|
| 836 | + ), |
|
| 837 | + 'order_by' => array( |
|
| 838 | + 'required' => false, |
|
| 839 | + 'default' => $default_orderby, |
|
| 840 | + 'type' => array( |
|
| 841 | + 'object', |
|
| 842 | + 'string', |
|
| 843 | + ),// because we accept a variety of types, WP core validation and sanitization |
|
| 844 | + // freaks out. We'll just validate this argument while handling the request |
|
| 845 | + 'validate_callback' => null, |
|
| 846 | + 'sanitize_callback' => null, |
|
| 847 | + ), |
|
| 848 | + 'group_by' => array( |
|
| 849 | + 'required' => false, |
|
| 850 | + 'default' => null, |
|
| 851 | + 'type' => array( |
|
| 852 | + 'object', |
|
| 853 | + 'string', |
|
| 854 | + ), |
|
| 855 | + // because we accept an almost infinite list of possible groupings, |
|
| 856 | + // WP core validation and sanitization |
|
| 857 | + // freaks out. We'll just validate this argument while handling the request |
|
| 858 | + 'validate_callback' => null, |
|
| 859 | + 'sanitize_callback' => null, |
|
| 860 | + ), |
|
| 861 | + 'having' => array( |
|
| 862 | + 'required' => false, |
|
| 863 | + 'default' => null, |
|
| 864 | + 'type' => 'object', |
|
| 865 | + // because we accept an almost infinite list of possible where conditions, WP |
|
| 866 | + // core validation and sanitization freaks out. We'll just validate this argument |
|
| 867 | + // while handling the request |
|
| 868 | + 'validate_callback' => null, |
|
| 869 | + 'sanitize_callback' => null, |
|
| 870 | + ), |
|
| 871 | + 'caps' => array( |
|
| 872 | + 'required' => false, |
|
| 873 | + 'default' => EEM_Base::caps_read, |
|
| 874 | + 'type' => 'string', |
|
| 875 | + 'enum' => array( |
|
| 876 | + EEM_Base::caps_read, |
|
| 877 | + EEM_Base::caps_read_admin, |
|
| 878 | + EEM_Base::caps_edit, |
|
| 879 | + EEM_Base::caps_delete, |
|
| 880 | + ), |
|
| 881 | + ), |
|
| 882 | + ) |
|
| 883 | + ); |
|
| 884 | + } |
|
| 885 | + |
|
| 886 | + |
|
| 887 | + /** |
|
| 888 | + * Gets parameter information for a model regarding writing data |
|
| 889 | + * |
|
| 890 | + * @param string $model_name |
|
| 891 | + * @param ModelVersionInfo $model_version_info |
|
| 892 | + * @param boolean $create whether this is for request to create (in |
|
| 893 | + * which case we need all required params) or |
|
| 894 | + * just to update (in which case we don't |
|
| 895 | + * need those on every request) |
|
| 896 | + * @return array |
|
| 897 | + */ |
|
| 898 | + protected function _get_write_params( |
|
| 899 | + $model_name, |
|
| 900 | + ModelVersionInfo $model_version_info, |
|
| 901 | + $create = false |
|
| 902 | + ) { |
|
| 903 | + $model = EE_Registry::instance()->load_model($model_name); |
|
| 904 | + $fields = $model_version_info->fieldsOnModelInThisVersion($model); |
|
| 905 | + $args_info = array(); |
|
| 906 | + foreach ($fields as $field_name => $field_obj) { |
|
| 907 | + if ($field_obj->is_auto_increment()) { |
|
| 908 | + // totally ignore auto increment IDs |
|
| 909 | + continue; |
|
| 910 | + } |
|
| 911 | + $arg_info = $field_obj->getSchema(); |
|
| 912 | + $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null; |
|
| 913 | + $arg_info['required'] = $required; |
|
| 914 | + // remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right? |
|
| 915 | + unset($arg_info['readonly']); |
|
| 916 | + $schema_properties = $field_obj->getSchemaProperties(); |
|
| 917 | + if (isset($schema_properties['raw']) |
|
| 918 | + && $field_obj->getSchemaType() === 'object' |
|
| 919 | + ) { |
|
| 920 | + // if there's a "raw" form of this argument, use those properties instead |
|
| 921 | + $arg_info = array_replace( |
|
| 922 | + $arg_info, |
|
| 923 | + $schema_properties['raw'] |
|
| 924 | + ); |
|
| 925 | + } |
|
| 926 | + $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson( |
|
| 927 | + $field_obj, |
|
| 928 | + $field_obj->get_default_value(), |
|
| 929 | + $model_version_info->requestedVersion() |
|
| 930 | + ); |
|
| 931 | + // we do our own validation and sanitization within the controller |
|
| 932 | + if (function_exists('rest_validate_value_from_schema')) { |
|
| 933 | + $sanitize_callback = array( |
|
| 934 | + 'EED_Core_Rest_Api', |
|
| 935 | + 'default_sanitize_callback', |
|
| 936 | + ); |
|
| 937 | + } else { |
|
| 938 | + $sanitize_callback = null; |
|
| 939 | + } |
|
| 940 | + $arg_info['sanitize_callback'] = $sanitize_callback; |
|
| 941 | + $args_info[ $field_name ] = $arg_info; |
|
| 942 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 943 | + $gmt_arg_info = $arg_info; |
|
| 944 | + $gmt_arg_info['description'] = sprintf( |
|
| 945 | + esc_html__( |
|
| 946 | + '%1$s - the value for this field in UTC. Ignored if %2$s is provided.', |
|
| 947 | + 'event_espresso' |
|
| 948 | + ), |
|
| 949 | + $field_obj->get_nicename(), |
|
| 950 | + $field_name |
|
| 951 | + ); |
|
| 952 | + $args_info[ $field_name . '_gmt' ] = $gmt_arg_info; |
|
| 953 | + } |
|
| 954 | + } |
|
| 955 | + return $args_info; |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + |
|
| 959 | + /** |
|
| 960 | + * Replacement for WP API's 'rest_parse_request_arg'. |
|
| 961 | + * If the value is blank but not required, don't bother validating it. |
|
| 962 | + * Also, it uses our email validation instead of WP API's default. |
|
| 963 | + * |
|
| 964 | + * @param $value |
|
| 965 | + * @param WP_REST_Request $request |
|
| 966 | + * @param $param |
|
| 967 | + * @return bool|true|WP_Error |
|
| 968 | + * @throws InvalidArgumentException |
|
| 969 | + * @throws InvalidInterfaceException |
|
| 970 | + * @throws InvalidDataTypeException |
|
| 971 | + */ |
|
| 972 | + public static function default_sanitize_callback($value, WP_REST_Request $request, $param) |
|
| 973 | + { |
|
| 974 | + $attributes = $request->get_attributes(); |
|
| 975 | + if (! isset($attributes['args'][ $param ]) |
|
| 976 | + || ! is_array($attributes['args'][ $param ])) { |
|
| 977 | + $validation_result = true; |
|
| 978 | + } else { |
|
| 979 | + $args = $attributes['args'][ $param ]; |
|
| 980 | + if (( |
|
| 981 | + $value === '' |
|
| 982 | + || $value === null |
|
| 983 | + ) |
|
| 984 | + && (! isset($args['required']) |
|
| 985 | + || $args['required'] === false |
|
| 986 | + ) |
|
| 987 | + ) { |
|
| 988 | + // not required and not provided? that's cool |
|
| 989 | + $validation_result = true; |
|
| 990 | + } elseif (isset($args['format']) |
|
| 991 | + && $args['format'] === 'email' |
|
| 992 | + ) { |
|
| 993 | + $validation_result = true; |
|
| 994 | + if (! self::_validate_email($value)) { |
|
| 995 | + $validation_result = new WP_Error( |
|
| 996 | + 'rest_invalid_param', |
|
| 997 | + esc_html__( |
|
| 998 | + 'The email address is not valid or does not exist.', |
|
| 999 | + 'event_espresso' |
|
| 1000 | + ) |
|
| 1001 | + ); |
|
| 1002 | + } |
|
| 1003 | + } else { |
|
| 1004 | + $validation_result = rest_validate_value_from_schema($value, $args, $param); |
|
| 1005 | + } |
|
| 1006 | + } |
|
| 1007 | + if (is_wp_error($validation_result)) { |
|
| 1008 | + return $validation_result; |
|
| 1009 | + } |
|
| 1010 | + return rest_sanitize_request_arg($value, $request, $param); |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + |
|
| 1014 | + /** |
|
| 1015 | + * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email() |
|
| 1016 | + * |
|
| 1017 | + * @param $email |
|
| 1018 | + * @return bool |
|
| 1019 | + * @throws InvalidArgumentException |
|
| 1020 | + * @throws InvalidInterfaceException |
|
| 1021 | + * @throws InvalidDataTypeException |
|
| 1022 | + */ |
|
| 1023 | + protected static function _validate_email($email) |
|
| 1024 | + { |
|
| 1025 | + try { |
|
| 1026 | + EmailAddressFactory::create($email); |
|
| 1027 | + return true; |
|
| 1028 | + } catch (EmailValidationException $e) { |
|
| 1029 | + return false; |
|
| 1030 | + } |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + |
|
| 1034 | + /** |
|
| 1035 | + * Gets routes for the config |
|
| 1036 | + * |
|
| 1037 | + * @return array @see _register_model_routes |
|
| 1038 | + * @deprecated since version 4.9.1 |
|
| 1039 | + */ |
|
| 1040 | + protected function _register_config_routes() |
|
| 1041 | + { |
|
| 1042 | + $config_routes = array(); |
|
| 1043 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 1044 | + $config_routes[ self::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version( |
|
| 1045 | + $version, |
|
| 1046 | + $hidden_endpoint |
|
| 1047 | + ); |
|
| 1048 | + } |
|
| 1049 | + return $config_routes; |
|
| 1050 | + } |
|
| 1051 | + |
|
| 1052 | + |
|
| 1053 | + /** |
|
| 1054 | + * Gets routes for the config for the specified version |
|
| 1055 | + * |
|
| 1056 | + * @param string $version |
|
| 1057 | + * @param boolean $hidden_endpoint |
|
| 1058 | + * @return array |
|
| 1059 | + */ |
|
| 1060 | + protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
| 1061 | + { |
|
| 1062 | + return array( |
|
| 1063 | + 'config' => array( |
|
| 1064 | + array( |
|
| 1065 | + 'callback' => array( |
|
| 1066 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
| 1067 | + 'handleRequest', |
|
| 1068 | + ), |
|
| 1069 | + 'methods' => WP_REST_Server::READABLE, |
|
| 1070 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 1071 | + 'callback_args' => array($version), |
|
| 1072 | + ), |
|
| 1073 | + ), |
|
| 1074 | + 'site_info' => array( |
|
| 1075 | + array( |
|
| 1076 | + 'callback' => array( |
|
| 1077 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
| 1078 | + 'handleRequestSiteInfo', |
|
| 1079 | + ), |
|
| 1080 | + 'methods' => WP_REST_Server::READABLE, |
|
| 1081 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 1082 | + 'callback_args' => array($version), |
|
| 1083 | + ), |
|
| 1084 | + ), |
|
| 1085 | + ); |
|
| 1086 | + } |
|
| 1087 | + |
|
| 1088 | + |
|
| 1089 | + /** |
|
| 1090 | + * Gets the meta info routes |
|
| 1091 | + * |
|
| 1092 | + * @return array @see _register_model_routes |
|
| 1093 | + * @deprecated since version 4.9.1 |
|
| 1094 | + */ |
|
| 1095 | + protected function _register_meta_routes() |
|
| 1096 | + { |
|
| 1097 | + $meta_routes = array(); |
|
| 1098 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
| 1099 | + $meta_routes[ self::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version( |
|
| 1100 | + $version, |
|
| 1101 | + $hidden_endpoint |
|
| 1102 | + ); |
|
| 1103 | + } |
|
| 1104 | + return $meta_routes; |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + |
|
| 1108 | + /** |
|
| 1109 | + * @param string $version |
|
| 1110 | + * @param boolean $hidden_endpoint |
|
| 1111 | + * @return array |
|
| 1112 | + */ |
|
| 1113 | + protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
| 1114 | + { |
|
| 1115 | + return array( |
|
| 1116 | + 'resources' => array( |
|
| 1117 | + array( |
|
| 1118 | + 'callback' => array( |
|
| 1119 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
| 1120 | + 'handleRequestModelsMeta', |
|
| 1121 | + ), |
|
| 1122 | + 'methods' => WP_REST_Server::READABLE, |
|
| 1123 | + 'hidden_endpoint' => $hidden_endpoint, |
|
| 1124 | + 'callback_args' => array($version), |
|
| 1125 | + ), |
|
| 1126 | + ), |
|
| 1127 | + ); |
|
| 1128 | + } |
|
| 1129 | + |
|
| 1130 | + |
|
| 1131 | + /** |
|
| 1132 | + * Tries to hide old 4.6 endpoints from the |
|
| 1133 | + * |
|
| 1134 | + * @param array $route_data |
|
| 1135 | + * @return array |
|
| 1136 | + * @throws \EE_Error |
|
| 1137 | + */ |
|
| 1138 | + public static function hide_old_endpoints($route_data) |
|
| 1139 | + { |
|
| 1140 | + // allow API clients to override which endpoints get hidden, in case |
|
| 1141 | + // they want to discover particular endpoints |
|
| 1142 | + // also, we don't have access to the request so we have to just grab it from the superglobal |
|
| 1143 | + $force_show_ee_namespace = ltrim( |
|
| 1144 | + EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''), |
|
| 1145 | + '/' |
|
| 1146 | + ); |
|
| 1147 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
| 1148 | + foreach ($relative_urls as $resource_name => $endpoints) { |
|
| 1149 | + foreach ($endpoints as $key => $endpoint) { |
|
| 1150 | + // skip schema and other route options |
|
| 1151 | + if (! is_numeric($key)) { |
|
| 1152 | + continue; |
|
| 1153 | + } |
|
| 1154 | + // by default, hide "hidden_endpoint"s, unless the request indicates |
|
| 1155 | + // to $force_show_ee_namespace, in which case only show that one |
|
| 1156 | + // namespace's endpoints (and hide all others) |
|
| 1157 | + if (($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
| 1158 | + || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
| 1159 | + ) { |
|
| 1160 | + $full_route = '/' . ltrim($namespace, '/'); |
|
| 1161 | + $full_route .= '/' . ltrim($resource_name, '/'); |
|
| 1162 | + unset($route_data[ $full_route ]); |
|
| 1163 | + } |
|
| 1164 | + } |
|
| 1165 | + } |
|
| 1166 | + } |
|
| 1167 | + return $route_data; |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + |
|
| 1171 | + /** |
|
| 1172 | + * Returns an array describing which versions of core support serving requests for. |
|
| 1173 | + * Keys are core versions' major and minor version, and values are the |
|
| 1174 | + * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
| 1175 | + * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
| 1176 | + * the answers table entirely, in which case it would be very difficult for |
|
| 1177 | + * it to serve 4.6-style responses. |
|
| 1178 | + * Versions of core that are missing from this array are unknowns. |
|
| 1179 | + * previous ver |
|
| 1180 | + * |
|
| 1181 | + * @return array |
|
| 1182 | + */ |
|
| 1183 | + public static function version_compatibilities() |
|
| 1184 | + { |
|
| 1185 | + return apply_filters( |
|
| 1186 | + 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
| 1187 | + array( |
|
| 1188 | + '4.8.29' => '4.8.29', |
|
| 1189 | + '4.8.33' => '4.8.29', |
|
| 1190 | + '4.8.34' => '4.8.29', |
|
| 1191 | + '4.8.36' => '4.8.29', |
|
| 1192 | + ) |
|
| 1193 | + ); |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + |
|
| 1197 | + /** |
|
| 1198 | + * Gets the latest API version served. Eg if there |
|
| 1199 | + * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
| 1200 | + * we are on core version 4.8.34, it will return the string "4.8.32" |
|
| 1201 | + * |
|
| 1202 | + * @return string |
|
| 1203 | + */ |
|
| 1204 | + public static function latest_rest_api_version() |
|
| 1205 | + { |
|
| 1206 | + $versions_served = \EED_Core_Rest_Api::versions_served(); |
|
| 1207 | + $versions_served_keys = array_keys($versions_served); |
|
| 1208 | + return end($versions_served_keys); |
|
| 1209 | + } |
|
| 1210 | + |
|
| 1211 | + |
|
| 1212 | + /** |
|
| 1213 | + * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
| 1214 | + * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
| 1215 | + * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
| 1216 | + * We also indicate whether or not this version should be put in the index or not |
|
| 1217 | + * |
|
| 1218 | + * @return array keys are API version numbers (just major and minor numbers), and values |
|
| 1219 | + * are whether or not they should be hidden |
|
| 1220 | + */ |
|
| 1221 | + public static function versions_served() |
|
| 1222 | + { |
|
| 1223 | + $versions_served = array(); |
|
| 1224 | + $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
| 1225 | + $lowest_compatible_version = end($possibly_served_versions); |
|
| 1226 | + reset($possibly_served_versions); |
|
| 1227 | + $versions_served_historically = array_keys($possibly_served_versions); |
|
| 1228 | + $latest_version = end($versions_served_historically); |
|
| 1229 | + reset($versions_served_historically); |
|
| 1230 | + // for each version of core we have ever served: |
|
| 1231 | + foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
| 1232 | + // if it's not above the current core version, and it's compatible with the current version of core |
|
| 1233 | + |
|
| 1234 | + if ($key_versioned_endpoint === $latest_version) { |
|
| 1235 | + // don't hide the latest version in the index |
|
| 1236 | + $versions_served[ $key_versioned_endpoint ] = false; |
|
| 1237 | + } elseif (version_compare($key_versioned_endpoint, $lowest_compatible_version, '>=') |
|
| 1238 | + && version_compare($key_versioned_endpoint, EED_Core_Rest_Api::core_version(), '<') |
|
| 1239 | + ) { |
|
| 1240 | + // include, but hide, previous versions which are still supported |
|
| 1241 | + $versions_served[ $key_versioned_endpoint ] = true; |
|
| 1242 | + } elseif (apply_filters( |
|
| 1243 | + 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
| 1244 | + false, |
|
| 1245 | + $possibly_served_versions |
|
| 1246 | + )) { |
|
| 1247 | + // if a version is no longer supported, don't include it in index or list of versions served |
|
| 1248 | + $versions_served[ $key_versioned_endpoint ] = true; |
|
| 1249 | + } |
|
| 1250 | + } |
|
| 1251 | + return $versions_served; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + |
|
| 1255 | + /** |
|
| 1256 | + * Gets the major and minor version of EE core's version string |
|
| 1257 | + * |
|
| 1258 | + * @return string |
|
| 1259 | + */ |
|
| 1260 | + public static function core_version() |
|
| 1261 | + { |
|
| 1262 | + return apply_filters( |
|
| 1263 | + 'FHEE__EED_Core_REST_API__core_version', |
|
| 1264 | + implode( |
|
| 1265 | + '.', |
|
| 1266 | + array_slice( |
|
| 1267 | + explode( |
|
| 1268 | + '.', |
|
| 1269 | + espresso_version() |
|
| 1270 | + ), |
|
| 1271 | + 0, |
|
| 1272 | + 3 |
|
| 1273 | + ) |
|
| 1274 | + ) |
|
| 1275 | + ); |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + |
|
| 1279 | + /** |
|
| 1280 | + * Gets the default limit that should be used when querying for resources |
|
| 1281 | + * |
|
| 1282 | + * @return int |
|
| 1283 | + */ |
|
| 1284 | + public static function get_default_query_limit() |
|
| 1285 | + { |
|
| 1286 | + // we actually don't use a const because we want folks to always use |
|
| 1287 | + // this method, not the const directly |
|
| 1288 | + return apply_filters( |
|
| 1289 | + 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
| 1290 | + 50 |
|
| 1291 | + ); |
|
| 1292 | + } |
|
| 1293 | + |
|
| 1294 | + |
|
| 1295 | + /** |
|
| 1296 | + * |
|
| 1297 | + * @param string $version api version string (i.e. '4.8.36') |
|
| 1298 | + * @return array |
|
| 1299 | + */ |
|
| 1300 | + public static function getCollectionRoutesIndexedByModelName($version = '') |
|
| 1301 | + { |
|
| 1302 | + $version = empty($version) ? self::latest_rest_api_version() : $version; |
|
| 1303 | + $model_names = self::model_names_with_plural_routes($version); |
|
| 1304 | + $collection_routes = array(); |
|
| 1305 | + foreach ($model_names as $model_name => $model_class_name) { |
|
| 1306 | + $collection_routes[ strtolower($model_name) ] = '/' . self::ee_api_namespace . $version . '/' |
|
| 1307 | + . EEH_Inflector::pluralize_and_lower($model_name); |
|
| 1308 | + } |
|
| 1309 | + return $collection_routes; |
|
| 1310 | + } |
|
| 1311 | + |
|
| 1312 | + |
|
| 1313 | + /** |
|
| 1314 | + * Returns an array of primary key names indexed by model names. |
|
| 1315 | + * @param string $version |
|
| 1316 | + * @return array |
|
| 1317 | + */ |
|
| 1318 | + public static function getPrimaryKeyNamesIndexedByModelName($version = '') |
|
| 1319 | + { |
|
| 1320 | + $version = empty($version) ? self::latest_rest_api_version() : $version; |
|
| 1321 | + $model_names = self::model_names_with_plural_routes($version); |
|
| 1322 | + $primary_key_items = array(); |
|
| 1323 | + foreach ($model_names as $model_name => $model_class_name) { |
|
| 1324 | + $primary_keys = $model_class_name::instance()->get_combined_primary_key_fields(); |
|
| 1325 | + foreach ($primary_keys as $primary_key_name => $primary_key_field) { |
|
| 1326 | + if (count($primary_keys) > 1) { |
|
| 1327 | + $primary_key_items[ strtolower($model_name) ][] = $primary_key_name; |
|
| 1328 | + } else { |
|
| 1329 | + $primary_key_items[ strtolower($model_name) ] = $primary_key_name; |
|
| 1330 | + } |
|
| 1331 | + } |
|
| 1332 | + } |
|
| 1333 | + return $primary_key_items; |
|
| 1334 | + } |
|
| 1335 | + |
|
| 1336 | + /** |
|
| 1337 | + * Determines the EE REST API debug mode is activated, or not. |
|
| 1338 | + * @since 4.9.76.p |
|
| 1339 | + * @return bool |
|
| 1340 | + */ |
|
| 1341 | + public static function debugMode() |
|
| 1342 | + { |
|
| 1343 | + static $debug_mode = null; // could be class prop |
|
| 1344 | + if ($debug_mode === null) { |
|
| 1345 | + $debug_mode = defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE; |
|
| 1346 | + } |
|
| 1347 | + return $debug_mode; |
|
| 1348 | + } |
|
| 1349 | + |
|
| 1350 | + |
|
| 1351 | + |
|
| 1352 | + /** |
|
| 1353 | + * run - initial module setup |
|
| 1354 | + * |
|
| 1355 | + * @access public |
|
| 1356 | + * @param WP $WP |
|
| 1357 | + * @return void |
|
| 1358 | + */ |
|
| 1359 | + public function run($WP) |
|
| 1360 | + { |
|
| 1361 | + } |
|
| 1362 | 1362 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | protected static function _set_hooks_for_changes() |
| 125 | 125 | { |
| 126 | - $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api/changes'), false); |
|
| 126 | + $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES.'rest_api/changes'), false); |
|
| 127 | 127 | foreach ($folder_contents as $classname_in_namespace => $filepath) { |
| 128 | 128 | // ignore the base parent class |
| 129 | 129 | // and legacy named classes |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | ) { |
| 133 | 133 | continue; |
| 134 | 134 | } |
| 135 | - $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
| 135 | + $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\'.$classname_in_namespace; |
|
| 136 | 136 | if (class_exists($full_classname)) { |
| 137 | 137 | $instance_of_class = new $full_classname; |
| 138 | 138 | if ($instance_of_class instanceof ChangesInBase) { |
@@ -177,10 +177,10 @@ discard block |
||
| 177 | 177 | * } |
| 178 | 178 | */ |
| 179 | 179 | // skip route options |
| 180 | - if (! is_numeric($endpoint_key)) { |
|
| 180 | + if ( ! is_numeric($endpoint_key)) { |
|
| 181 | 181 | continue; |
| 182 | 182 | } |
| 183 | - if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
| 183 | + if ( ! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
| 184 | 184 | throw new EE_Error( |
| 185 | 185 | esc_html__( |
| 186 | 186 | // @codingStandardsIgnoreStart |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | } |
| 202 | 202 | if (isset($data_for_single_endpoint['callback_args'])) { |
| 203 | 203 | $callback_args = $data_for_single_endpoint['callback_args']; |
| 204 | - $single_endpoint_args['callback'] = function (\WP_REST_Request $request) use ( |
|
| 204 | + $single_endpoint_args['callback'] = function(\WP_REST_Request $request) use ( |
|
| 205 | 205 | $callback, |
| 206 | 206 | $callback_args |
| 207 | 207 | ) { |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | // the REST API will issue a _doing_it_wrong notice. |
| 219 | 219 | // Since the EE REST API defers capabilities to the db model system, |
| 220 | 220 | // we will just use the generic WP callback for public endpoints |
| 221 | - if (! isset($single_endpoint_args['permission_callback'])) { |
|
| 221 | + if ( ! isset($single_endpoint_args['permission_callback'])) { |
|
| 222 | 222 | $single_endpoint_args['permission_callback'] = '__return_true'; |
| 223 | 223 | } |
| 224 | 224 | $multiple_endpoint_args[] = $single_endpoint_args; |
@@ -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'] = function () use ($schema_callback, $callback_args) { |
|
| 230 | + $multiple_endpoint_args['schema'] = 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 | |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | { |
| 289 | 289 | $ee_routes = array(); |
| 290 | 290 | foreach (self::versions_served() as $version => $hidden_endpoints) { |
| 291 | - $ee_routes[ self::ee_api_namespace . $version ] = self::_get_ee_route_data_for_version( |
|
| 291 | + $ee_routes[self::ee_api_namespace.$version] = self::_get_ee_route_data_for_version( |
|
| 292 | 292 | $version, |
| 293 | 293 | $hidden_endpoints |
| 294 | 294 | ); |
@@ -308,8 +308,8 @@ discard block |
||
| 308 | 308 | */ |
| 309 | 309 | protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
| 310 | 310 | { |
| 311 | - $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
| 312 | - if (! $ee_routes || EED_Core_Rest_Api::debugMode()) { |
|
| 311 | + $ee_routes = get_option(self::saved_routes_option_names.$version, null); |
|
| 312 | + if ( ! $ee_routes || EED_Core_Rest_Api::debugMode()) { |
|
| 313 | 313 | $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
| 314 | 314 | } |
| 315 | 315 | return $ee_routes; |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
| 337 | 337 | ) |
| 338 | 338 | ); |
| 339 | - $option_name = self::saved_routes_option_names . $version; |
|
| 339 | + $option_name = self::saved_routes_option_names.$version; |
|
| 340 | 340 | if (get_option($option_name)) { |
| 341 | 341 | update_option($option_name, $routes, true); |
| 342 | 342 | } else { |
@@ -381,8 +381,8 @@ discard block |
||
| 381 | 381 | { |
| 382 | 382 | $model_routes = array(); |
| 383 | 383 | foreach (self::versions_served() as $version => $hidden_endpoint) { |
| 384 | - $model_routes[ EED_Core_Rest_Api::ee_api_namespace |
|
| 385 | - . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
| 384 | + $model_routes[EED_Core_Rest_Api::ee_api_namespace |
|
| 385 | + . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
| 386 | 386 | } |
| 387 | 387 | return $model_routes; |
| 388 | 388 | } |
@@ -451,13 +451,13 @@ discard block |
||
| 451 | 451 | foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
| 452 | 452 | $model = \EE_Registry::instance()->load_model($model_name); |
| 453 | 453 | // if this isn't a valid model then let's skip iterate to the next item in the loop. |
| 454 | - if (! $model instanceof EEM_Base) { |
|
| 454 | + if ( ! $model instanceof EEM_Base) { |
|
| 455 | 455 | continue; |
| 456 | 456 | } |
| 457 | 457 | // yes we could just register one route for ALL models, but then they wouldn't show up in the index |
| 458 | 458 | $plural_model_route = EED_Core_Rest_Api::get_collection_route($model); |
| 459 | 459 | $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)'); |
| 460 | - $model_routes[ $plural_model_route ] = array( |
|
| 460 | + $model_routes[$plural_model_route] = array( |
|
| 461 | 461 | array( |
| 462 | 462 | 'callback' => array( |
| 463 | 463 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | 'hidden_endpoint' => $hidden_endpoint, |
| 469 | 469 | 'args' => $this->_get_read_query_params($model, $version), |
| 470 | 470 | '_links' => array( |
| 471 | - 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
| 471 | + 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace.$version.$singular_model_route), |
|
| 472 | 472 | ), |
| 473 | 473 | ), |
| 474 | 474 | 'schema' => array( |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | 'callback_args' => array($version, $model_name), |
| 480 | 480 | ), |
| 481 | 481 | ); |
| 482 | - $model_routes[ $singular_model_route ] = array( |
|
| 482 | + $model_routes[$singular_model_route] = array( |
|
| 483 | 483 | array( |
| 484 | 484 | 'callback' => array( |
| 485 | 485 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | EED_Core_Rest_Api::should_have_write_endpoints($model), |
| 497 | 497 | $model |
| 498 | 498 | )) { |
| 499 | - $model_routes[ $plural_model_route ][] = array( |
|
| 499 | + $model_routes[$plural_model_route][] = array( |
|
| 500 | 500 | 'callback' => array( |
| 501 | 501 | 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
| 502 | 502 | 'handleRequestInsert', |
@@ -506,8 +506,8 @@ discard block |
||
| 506 | 506 | 'hidden_endpoint' => $hidden_endpoint, |
| 507 | 507 | 'args' => $this->_get_write_params($model_name, $model_version_info, true), |
| 508 | 508 | ); |
| 509 | - $model_routes[ $singular_model_route ] = array_merge( |
|
| 510 | - $model_routes[ $singular_model_route ], |
|
| 509 | + $model_routes[$singular_model_route] = array_merge( |
|
| 510 | + $model_routes[$singular_model_route], |
|
| 511 | 511 | array( |
| 512 | 512 | array( |
| 513 | 513 | 'callback' => array( |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | '(?P<id>[^\/]+)', |
| 539 | 539 | $relation_obj |
| 540 | 540 | ); |
| 541 | - $model_routes[ $related_route ] = array( |
|
| 541 | + $model_routes[$related_route] = array( |
|
| 542 | 542 | array( |
| 543 | 543 | 'callback' => array( |
| 544 | 544 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
@@ -551,8 +551,8 @@ discard block |
||
| 551 | 551 | ), |
| 552 | 552 | ); |
| 553 | 553 | |
| 554 | - $related_write_route = $related_route . '/' . '(?P<related_id>[^\/]+)'; |
|
| 555 | - $model_routes[ $related_write_route ] = array( |
|
| 554 | + $related_write_route = $related_route.'/'.'(?P<related_id>[^\/]+)'; |
|
| 555 | + $model_routes[$related_write_route] = array( |
|
| 556 | 556 | array( |
| 557 | 557 | 'callback' => array( |
| 558 | 558 | 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | */ |
| 606 | 606 | public static function get_entity_route($model, $id) |
| 607 | 607 | { |
| 608 | - return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id; |
|
| 608 | + return EED_Core_Rest_Api::get_collection_route($model).'/'.$id; |
|
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | $relation_obj->get_other_model()->get_this_model_name(), |
| 626 | 626 | $relation_obj |
| 627 | 627 | ); |
| 628 | - return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
| 628 | + return EED_Core_Rest_Api::get_entity_route($model, $id).'/'.$related_model_name_endpoint_part; |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | |
@@ -639,7 +639,7 @@ discard block |
||
| 639 | 639 | */ |
| 640 | 640 | public static function get_versioned_route_to($relative_route, $version = '4.8.36') |
| 641 | 641 | { |
| 642 | - return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
| 642 | + return '/'.EED_Core_Rest_Api::ee_api_namespace.$version.'/'.$relative_route; |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | |
@@ -653,7 +653,7 @@ discard block |
||
| 653 | 653 | { |
| 654 | 654 | $routes = array(); |
| 655 | 655 | foreach (self::versions_served() as $version => $hidden_endpoint) { |
| 656 | - $routes[ self::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version( |
|
| 656 | + $routes[self::ee_api_namespace.$version] = $this->_get_rpc_route_data_for_version( |
|
| 657 | 657 | $version, |
| 658 | 658 | $hidden_endpoint |
| 659 | 659 | ); |
@@ -776,12 +776,12 @@ discard block |
||
| 776 | 776 | { |
| 777 | 777 | // if they're related through a HABTM relation, check for any non-FKs |
| 778 | 778 | $all_relation_settings = $source_model->relation_settings(); |
| 779 | - $relation_settings = $all_relation_settings[ $related_model->get_this_model_name() ]; |
|
| 779 | + $relation_settings = $all_relation_settings[$related_model->get_this_model_name()]; |
|
| 780 | 780 | $params = array(); |
| 781 | 781 | if ($relation_settings instanceof EE_HABTM_Relation && $relation_settings->hasNonKeyFields()) { |
| 782 | 782 | foreach ($relation_settings->getNonKeyFields() as $field) { |
| 783 | 783 | /* @var $field EE_Model_Field_Base */ |
| 784 | - $params[ $field->get_name() ] = array( |
|
| 784 | + $params[$field->get_name()] = array( |
|
| 785 | 785 | 'required' => ! $field->is_nullable(), |
| 786 | 786 | 'default' => ModelDataTranslator::prepareFieldValueForJson($field, $field->get_default_value(), $version), |
| 787 | 787 | 'type' => $field->getSchemaType(), |
@@ -806,7 +806,7 @@ discard block |
||
| 806 | 806 | { |
| 807 | 807 | $default_orderby = array(); |
| 808 | 808 | foreach ($model->get_combined_primary_key_fields() as $key_field) { |
| 809 | - $default_orderby[ $key_field->get_name() ] = 'ASC'; |
|
| 809 | + $default_orderby[$key_field->get_name()] = 'ASC'; |
|
| 810 | 810 | } |
| 811 | 811 | return array_merge( |
| 812 | 812 | $this->_get_response_selection_query_params($model, $version), |
@@ -840,7 +840,7 @@ discard block |
||
| 840 | 840 | 'type' => array( |
| 841 | 841 | 'object', |
| 842 | 842 | 'string', |
| 843 | - ),// because we accept a variety of types, WP core validation and sanitization |
|
| 843 | + ), // because we accept a variety of types, WP core validation and sanitization |
|
| 844 | 844 | // freaks out. We'll just validate this argument while handling the request |
| 845 | 845 | 'validate_callback' => null, |
| 846 | 846 | 'sanitize_callback' => null, |
@@ -938,7 +938,7 @@ discard block |
||
| 938 | 938 | $sanitize_callback = null; |
| 939 | 939 | } |
| 940 | 940 | $arg_info['sanitize_callback'] = $sanitize_callback; |
| 941 | - $args_info[ $field_name ] = $arg_info; |
|
| 941 | + $args_info[$field_name] = $arg_info; |
|
| 942 | 942 | if ($field_obj instanceof EE_Datetime_Field) { |
| 943 | 943 | $gmt_arg_info = $arg_info; |
| 944 | 944 | $gmt_arg_info['description'] = sprintf( |
@@ -949,7 +949,7 @@ discard block |
||
| 949 | 949 | $field_obj->get_nicename(), |
| 950 | 950 | $field_name |
| 951 | 951 | ); |
| 952 | - $args_info[ $field_name . '_gmt' ] = $gmt_arg_info; |
|
| 952 | + $args_info[$field_name.'_gmt'] = $gmt_arg_info; |
|
| 953 | 953 | } |
| 954 | 954 | } |
| 955 | 955 | return $args_info; |
@@ -972,16 +972,16 @@ discard block |
||
| 972 | 972 | public static function default_sanitize_callback($value, WP_REST_Request $request, $param) |
| 973 | 973 | { |
| 974 | 974 | $attributes = $request->get_attributes(); |
| 975 | - if (! isset($attributes['args'][ $param ]) |
|
| 976 | - || ! is_array($attributes['args'][ $param ])) { |
|
| 975 | + if ( ! isset($attributes['args'][$param]) |
|
| 976 | + || ! is_array($attributes['args'][$param])) { |
|
| 977 | 977 | $validation_result = true; |
| 978 | 978 | } else { |
| 979 | - $args = $attributes['args'][ $param ]; |
|
| 979 | + $args = $attributes['args'][$param]; |
|
| 980 | 980 | if (( |
| 981 | 981 | $value === '' |
| 982 | 982 | || $value === null |
| 983 | 983 | ) |
| 984 | - && (! isset($args['required']) |
|
| 984 | + && ( ! isset($args['required']) |
|
| 985 | 985 | || $args['required'] === false |
| 986 | 986 | ) |
| 987 | 987 | ) { |
@@ -991,7 +991,7 @@ discard block |
||
| 991 | 991 | && $args['format'] === 'email' |
| 992 | 992 | ) { |
| 993 | 993 | $validation_result = true; |
| 994 | - if (! self::_validate_email($value)) { |
|
| 994 | + if ( ! self::_validate_email($value)) { |
|
| 995 | 995 | $validation_result = new WP_Error( |
| 996 | 996 | 'rest_invalid_param', |
| 997 | 997 | esc_html__( |
@@ -1041,7 +1041,7 @@ discard block |
||
| 1041 | 1041 | { |
| 1042 | 1042 | $config_routes = array(); |
| 1043 | 1043 | foreach (self::versions_served() as $version => $hidden_endpoint) { |
| 1044 | - $config_routes[ self::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version( |
|
| 1044 | + $config_routes[self::ee_api_namespace.$version] = $this->_get_config_route_data_for_version( |
|
| 1045 | 1045 | $version, |
| 1046 | 1046 | $hidden_endpoint |
| 1047 | 1047 | ); |
@@ -1096,7 +1096,7 @@ discard block |
||
| 1096 | 1096 | { |
| 1097 | 1097 | $meta_routes = array(); |
| 1098 | 1098 | foreach (self::versions_served() as $version => $hidden_endpoint) { |
| 1099 | - $meta_routes[ self::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version( |
|
| 1099 | + $meta_routes[self::ee_api_namespace.$version] = $this->_get_meta_route_data_for_version( |
|
| 1100 | 1100 | $version, |
| 1101 | 1101 | $hidden_endpoint |
| 1102 | 1102 | ); |
@@ -1148,7 +1148,7 @@ discard block |
||
| 1148 | 1148 | foreach ($relative_urls as $resource_name => $endpoints) { |
| 1149 | 1149 | foreach ($endpoints as $key => $endpoint) { |
| 1150 | 1150 | // skip schema and other route options |
| 1151 | - if (! is_numeric($key)) { |
|
| 1151 | + if ( ! is_numeric($key)) { |
|
| 1152 | 1152 | continue; |
| 1153 | 1153 | } |
| 1154 | 1154 | // by default, hide "hidden_endpoint"s, unless the request indicates |
@@ -1157,9 +1157,9 @@ discard block |
||
| 1157 | 1157 | if (($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
| 1158 | 1158 | || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
| 1159 | 1159 | ) { |
| 1160 | - $full_route = '/' . ltrim($namespace, '/'); |
|
| 1161 | - $full_route .= '/' . ltrim($resource_name, '/'); |
|
| 1162 | - unset($route_data[ $full_route ]); |
|
| 1160 | + $full_route = '/'.ltrim($namespace, '/'); |
|
| 1161 | + $full_route .= '/'.ltrim($resource_name, '/'); |
|
| 1162 | + unset($route_data[$full_route]); |
|
| 1163 | 1163 | } |
| 1164 | 1164 | } |
| 1165 | 1165 | } |
@@ -1233,19 +1233,19 @@ discard block |
||
| 1233 | 1233 | |
| 1234 | 1234 | if ($key_versioned_endpoint === $latest_version) { |
| 1235 | 1235 | // don't hide the latest version in the index |
| 1236 | - $versions_served[ $key_versioned_endpoint ] = false; |
|
| 1236 | + $versions_served[$key_versioned_endpoint] = false; |
|
| 1237 | 1237 | } elseif (version_compare($key_versioned_endpoint, $lowest_compatible_version, '>=') |
| 1238 | 1238 | && version_compare($key_versioned_endpoint, EED_Core_Rest_Api::core_version(), '<') |
| 1239 | 1239 | ) { |
| 1240 | 1240 | // include, but hide, previous versions which are still supported |
| 1241 | - $versions_served[ $key_versioned_endpoint ] = true; |
|
| 1241 | + $versions_served[$key_versioned_endpoint] = true; |
|
| 1242 | 1242 | } elseif (apply_filters( |
| 1243 | 1243 | 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
| 1244 | 1244 | false, |
| 1245 | 1245 | $possibly_served_versions |
| 1246 | 1246 | )) { |
| 1247 | 1247 | // if a version is no longer supported, don't include it in index or list of versions served |
| 1248 | - $versions_served[ $key_versioned_endpoint ] = true; |
|
| 1248 | + $versions_served[$key_versioned_endpoint] = true; |
|
| 1249 | 1249 | } |
| 1250 | 1250 | } |
| 1251 | 1251 | return $versions_served; |
@@ -1303,7 +1303,7 @@ discard block |
||
| 1303 | 1303 | $model_names = self::model_names_with_plural_routes($version); |
| 1304 | 1304 | $collection_routes = array(); |
| 1305 | 1305 | foreach ($model_names as $model_name => $model_class_name) { |
| 1306 | - $collection_routes[ strtolower($model_name) ] = '/' . self::ee_api_namespace . $version . '/' |
|
| 1306 | + $collection_routes[strtolower($model_name)] = '/'.self::ee_api_namespace.$version.'/' |
|
| 1307 | 1307 | . EEH_Inflector::pluralize_and_lower($model_name); |
| 1308 | 1308 | } |
| 1309 | 1309 | return $collection_routes; |
@@ -1324,9 +1324,9 @@ discard block |
||
| 1324 | 1324 | $primary_keys = $model_class_name::instance()->get_combined_primary_key_fields(); |
| 1325 | 1325 | foreach ($primary_keys as $primary_key_name => $primary_key_field) { |
| 1326 | 1326 | if (count($primary_keys) > 1) { |
| 1327 | - $primary_key_items[ strtolower($model_name) ][] = $primary_key_name; |
|
| 1327 | + $primary_key_items[strtolower($model_name)][] = $primary_key_name; |
|
| 1328 | 1328 | } else { |
| 1329 | - $primary_key_items[ strtolower($model_name) ] = $primary_key_name; |
|
| 1329 | + $primary_key_items[strtolower($model_name)] = $primary_key_name; |
|
| 1330 | 1330 | } |
| 1331 | 1331 | } |
| 1332 | 1332 | } |