1 | <?php |
||
19 | class Base { |
||
20 | |||
21 | const header_prefix_for_ee = 'X-EE-'; |
||
22 | |||
23 | const header_prefix_for_wp = 'X-WP-'; |
||
24 | |||
25 | /** |
||
26 | * Contains debug info we'll send back in the response headers |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $_debug_info = array(); |
||
30 | |||
31 | /** |
||
32 | * Indicates whether or not the API is in debug mode |
||
33 | * @var boolean |
||
34 | */ |
||
35 | protected $_debug_mode = false; |
||
36 | |||
37 | /** |
||
38 | * Indicates the version that was requested |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $_requested_version; |
||
42 | |||
43 | /** |
||
44 | * flat array of headers to send in the response |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $_response_headers = array(); |
||
48 | |||
49 | |||
50 | |||
51 | public function __construct() { |
||
54 | |||
55 | |||
56 | /** |
||
57 | * Sets the version the user requested |
||
58 | * @param string $version eg '4.8' |
||
59 | */ |
||
60 | public function set_requested_version( $version ) { |
||
63 | |||
64 | /** |
||
65 | * Sets some debug info that we'll send back in headers |
||
66 | * @param string $key |
||
67 | * @param string|array $info |
||
68 | */ |
||
69 | protected function _set_debug_info( $key, $info ){ |
||
72 | |||
73 | /** |
||
74 | * Sets headers for the response |
||
75 | * |
||
76 | * @param string $header_key , excluding the "X-EE-" part |
||
77 | * @param array|string $value if an array, multiple headers will be added, one |
||
78 | * for each key in the array |
||
79 | * @param boolean $use_ee_prefix whether to use the EE prefix on the header, or fallback to |
||
80 | * the standard WP one |
||
81 | */ |
||
82 | protected function _set_response_header( $header_key, $value, $use_ee_prefix = true ) { |
||
92 | |||
93 | /** |
||
94 | * Returns a flat array of headers to be added to the response |
||
95 | * @return array |
||
96 | */ |
||
97 | protected function _get_response_headers() { |
||
104 | |||
105 | /** |
||
106 | * Adds error notices from EE_Error onto the provided \WP_Error |
||
107 | * @param \WP_Error $wp_error_response |
||
108 | * @return \WP_Error |
||
109 | */ |
||
110 | protected function _add_ee_errors_to_response( \WP_Error $wp_error_response ) { |
||
121 | |||
122 | |||
123 | |||
124 | /** |
||
125 | * Sends a response, but also makes sure to attach headers that |
||
126 | * are handy for debugging. |
||
127 | * Specifically, we assume folks will want to know what exactly was the DB query that got run, |
||
128 | * what exactly was the Models query that got run, what capabilities came into play, what fields were omitted from |
||
129 | * the response, others? |
||
130 | * |
||
131 | * @param array|\WP_Error|\Exception $response |
||
132 | * @return \WP_REST_Response |
||
133 | */ |
||
134 | public function send_response( $response ) { |
||
166 | |||
167 | /** |
||
168 | * Converts the \WP_Error into `WP_REST_Response. |
||
169 | * Mostly this is just a copy-and-paste from \WP_REST_Server::error_to_response |
||
170 | * (which is protected) |
||
171 | * @param \WP_Error $wp_error |
||
172 | * @return \WP_REST_Response |
||
173 | */ |
||
174 | protected function _create_rest_response_from_wp_error( \WP_Error $wp_error ) { |
||
200 | |||
201 | /** |
||
202 | * Array of headers derived from EE success, attention, and error messages |
||
203 | * @return array |
||
204 | */ |
||
205 | protected function _get_headers_from_ee_notices() { |
||
223 | |||
224 | /** |
||
225 | * Finds which version of the API was requested given the route, and returns it. |
||
226 | * eg in a request to "mysite.com/wp-json/ee/v4.8.29/events/123" this would return |
||
227 | * "4.8.29" |
||
228 | * @param string $route |
||
229 | * @return string |
||
230 | */ |
||
231 | public function get_requested_version( $route = null ) { |
||
244 | |||
245 | |||
246 | |||
247 | /** |
||
248 | * Applies the regex to the route, then creates an array using the values of |
||
249 | * $match_keys as keys (but ignores the full pattern match). Returns the array of matches. |
||
250 | * For example, if you call |
||
251 | * parse_route( '/ee/v4.8/events', '~\/ee\/v([^/]*)\/(.*)~', array( 'version', 'model' ) ) |
||
252 | * it will return array( 'version' => '4.8', 'model' => 'events' ) |
||
253 | * |
||
254 | * @param string $route |
||
255 | * @param string $regex |
||
256 | * @param array $match_keys EXCLUDING matching the entire regex |
||
257 | * @return array where $match_keys are the keys (the first value of $match_keys |
||
258 | * becomes the first key of the return value, etc. Eg passing in $match_keys of |
||
259 | * array( 'model', 'id' ), will, if the regex is successful, will return |
||
260 | * array( 'model' => 'foo', 'id' => 'bar' ) |
||
261 | * @throws \EE_Error if it couldn't be parsed |
||
262 | */ |
||
263 | public function parse_route( $route, $regex, $match_keys ) { |
||
285 | } |
||
286 | |||
287 | // End of file Base.php |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.