@@ -19,159 +19,159 @@ discard block |
||
| 19 | 19 | class ExceptionStackTraceDisplay |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var string |
|
| 24 | - * @since 4.10.24.p |
|
| 25 | - */ |
|
| 26 | - private $class_name = ''; |
|
| 22 | + /** |
|
| 23 | + * @var string |
|
| 24 | + * @since 4.10.24.p |
|
| 25 | + */ |
|
| 26 | + private $class_name = ''; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var string |
|
| 30 | - * @since 4.10.24.p |
|
| 31 | - */ |
|
| 32 | - private $error_code = ''; |
|
| 28 | + /** |
|
| 29 | + * @var string |
|
| 30 | + * @since 4.10.24.p |
|
| 31 | + */ |
|
| 32 | + private $error_code = ''; |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param Exception $exception |
|
| 37 | - * @throws Exception |
|
| 38 | - */ |
|
| 39 | - public function __construct(Exception $exception) |
|
| 40 | - { |
|
| 41 | - if (WP_DEBUG && ! defined('EE_TESTS_DIR')) { |
|
| 42 | - $this->displayException($exception); |
|
| 43 | - } else { |
|
| 44 | - throw $exception; |
|
| 45 | - } |
|
| 46 | - } |
|
| 35 | + /** |
|
| 36 | + * @param Exception $exception |
|
| 37 | + * @throws Exception |
|
| 38 | + */ |
|
| 39 | + public function __construct(Exception $exception) |
|
| 40 | + { |
|
| 41 | + if (WP_DEBUG && ! defined('EE_TESTS_DIR')) { |
|
| 42 | + $this->displayException($exception); |
|
| 43 | + } else { |
|
| 44 | + throw $exception; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @access protected |
|
| 51 | - * @param Exception $exception |
|
| 52 | - * @throws ReflectionException |
|
| 53 | - */ |
|
| 54 | - protected function displayException(Exception $exception) |
|
| 55 | - { |
|
| 56 | - // get separate user and developer messages if they exist |
|
| 57 | - $msg = explode('||', $exception->getMessage()); |
|
| 58 | - $user_msg = $msg[0]; |
|
| 59 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 60 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 61 | - // process trace info |
|
| 62 | - $trace_details = $this->traceDetails($exception); |
|
| 63 | - $code = $exception->getCode() ?: $this->error_code; |
|
| 64 | - // add helpful developer messages if debugging is on |
|
| 65 | - // or generic non-identifying messages for non-privileged users |
|
| 66 | - $error_message = WP_DEBUG |
|
| 67 | - ? $this->developerError($exception, $msg, $code, $trace_details) |
|
| 68 | - : $this->genericError($msg, $code); |
|
| 69 | - // start gathering output |
|
| 70 | - $output = ' |
|
| 49 | + /** |
|
| 50 | + * @access protected |
|
| 51 | + * @param Exception $exception |
|
| 52 | + * @throws ReflectionException |
|
| 53 | + */ |
|
| 54 | + protected function displayException(Exception $exception) |
|
| 55 | + { |
|
| 56 | + // get separate user and developer messages if they exist |
|
| 57 | + $msg = explode('||', $exception->getMessage()); |
|
| 58 | + $user_msg = $msg[0]; |
|
| 59 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
| 60 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
| 61 | + // process trace info |
|
| 62 | + $trace_details = $this->traceDetails($exception); |
|
| 63 | + $code = $exception->getCode() ?: $this->error_code; |
|
| 64 | + // add helpful developer messages if debugging is on |
|
| 65 | + // or generic non-identifying messages for non-privileged users |
|
| 66 | + $error_message = WP_DEBUG |
|
| 67 | + ? $this->developerError($exception, $msg, $code, $trace_details) |
|
| 68 | + : $this->genericError($msg, $code); |
|
| 69 | + // start gathering output |
|
| 70 | + $output = ' |
|
| 71 | 71 | <div id="ee-error-message" class="error"> |
| 72 | 72 | ' . $error_message . ' |
| 73 | 73 | </div>'; |
| 74 | - $styles = $this->exceptionStyles(); |
|
| 75 | - $scripts = $this->printScripts(true); |
|
| 76 | - if (defined('DOING_AJAX')) { |
|
| 77 | - echo wp_json_encode(array('error' => $styles . $output . $scripts)); |
|
| 78 | - exit(); |
|
| 79 | - } |
|
| 80 | - echo $styles, $output, $scripts; // already escaped |
|
| 81 | - } |
|
| 74 | + $styles = $this->exceptionStyles(); |
|
| 75 | + $scripts = $this->printScripts(true); |
|
| 76 | + if (defined('DOING_AJAX')) { |
|
| 77 | + echo wp_json_encode(array('error' => $styles . $output . $scripts)); |
|
| 78 | + exit(); |
|
| 79 | + } |
|
| 80 | + echo $styles, $output, $scripts; // already escaped |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | |
| 84 | - private function genericError($msg, $code) |
|
| 85 | - { |
|
| 86 | - return ' |
|
| 84 | + private function genericError($msg, $code) |
|
| 85 | + { |
|
| 86 | + return ' |
|
| 87 | 87 | <p> |
| 88 | 88 | <span class="ee-error-user-msg-spn">' . trim($msg) . '</span> <sup>' . $code . '</sup> |
| 89 | 89 | </p>'; |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @throws ReflectionException |
|
| 95 | - */ |
|
| 96 | - private function developerError(Exception $exception, $msg, $code, $trace_details) |
|
| 97 | - { |
|
| 98 | - $time = time(); |
|
| 99 | - return ' |
|
| 93 | + /** |
|
| 94 | + * @throws ReflectionException |
|
| 95 | + */ |
|
| 96 | + private function developerError(Exception $exception, $msg, $code, $trace_details) |
|
| 97 | + { |
|
| 98 | + $time = time(); |
|
| 99 | + return ' |
|
| 100 | 100 | <div class="ee-error-dev-msg-dv"> |
| 101 | 101 | <p class="ee-error-dev-msg-pg"> |
| 102 | 102 | ' |
| 103 | - . sprintf( |
|
| 104 | - esc_html__('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'), |
|
| 105 | - '<strong class="ee-error-dev-msg-str">', |
|
| 106 | - get_class($exception), |
|
| 107 | - '</strong> <span>', |
|
| 108 | - $code . '</span>' |
|
| 109 | - ) |
|
| 110 | - . '<br /> |
|
| 103 | + . sprintf( |
|
| 104 | + esc_html__('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'), |
|
| 105 | + '<strong class="ee-error-dev-msg-str">', |
|
| 106 | + get_class($exception), |
|
| 107 | + '</strong> <span>', |
|
| 108 | + $code . '</span>' |
|
| 109 | + ) |
|
| 110 | + . '<br /> |
|
| 111 | 111 | <span class="big-text">"' . trim($msg) . '"</span><br/> |
| 112 | 112 | <a id="display-ee-error-trace-1' |
| 113 | - . $time |
|
| 114 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1' |
|
| 115 | - . $time |
|
| 116 | - . '"> |
|
| 113 | + . $time |
|
| 114 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1' |
|
| 115 | + . $time |
|
| 116 | + . '"> |
|
| 117 | 117 | ' . esc_html__('click to view backtrace and class/method details', 'event_espresso') . ' |
| 118 | 118 | </a><br /> |
| 119 | 119 | ' |
| 120 | - . $exception->getFile() |
|
| 121 | - . sprintf( |
|
| 122 | - esc_html__('%1$s( line no: %2$s )%3$s', 'event_espresso'), |
|
| 123 | - ' <span class="small-text lt-grey-text">', |
|
| 124 | - $exception->getLine(), |
|
| 125 | - '</span>' |
|
| 126 | - ) |
|
| 127 | - . ' |
|
| 120 | + . $exception->getFile() |
|
| 121 | + . sprintf( |
|
| 122 | + esc_html__('%1$s( line no: %2$s )%3$s', 'event_espresso'), |
|
| 123 | + ' <span class="small-text lt-grey-text">', |
|
| 124 | + $exception->getLine(), |
|
| 125 | + '</span>' |
|
| 126 | + ) |
|
| 127 | + . ' |
|
| 128 | 128 | </p> |
| 129 | 129 | <div id="ee-error-trace-1' |
| 130 | - . $time |
|
| 131 | - . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
| 130 | + . $time |
|
| 131 | + . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
| 132 | 132 | ' |
| 133 | - . $trace_details |
|
| 134 | - . $this->classDetails() . ' |
|
| 133 | + . $trace_details |
|
| 134 | + . $this->classDetails() . ' |
|
| 135 | 135 | </div> |
| 136 | 136 | </div>'; |
| 137 | - } |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * @throws ReflectionException |
|
| 142 | - */ |
|
| 143 | - private function classDetails() |
|
| 144 | - { |
|
| 145 | - if (empty($this->class_name)) { |
|
| 146 | - return ''; |
|
| 147 | - } |
|
| 148 | - $a = new ReflectionClass($this->class_name); |
|
| 149 | - return ' |
|
| 140 | + /** |
|
| 141 | + * @throws ReflectionException |
|
| 142 | + */ |
|
| 143 | + private function classDetails() |
|
| 144 | + { |
|
| 145 | + if (empty($this->class_name)) { |
|
| 146 | + return ''; |
|
| 147 | + } |
|
| 148 | + $a = new ReflectionClass($this->class_name); |
|
| 149 | + return ' |
|
| 150 | 150 | <div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;"> |
| 151 | 151 | <div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;"> |
| 152 | 152 | <h3>' . esc_html__('Class Details', 'event_espresso') . '</h3> |
| 153 | 153 | <pre>' . $a . '</pre> |
| 154 | 154 | </div> |
| 155 | 155 | </div>'; |
| 156 | - } |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * @param Exception $exception |
|
| 160 | - * @return string |
|
| 161 | - * @throws ReflectionException |
|
| 162 | - * @since 4.10.24.p |
|
| 163 | - */ |
|
| 164 | - private function traceDetails(Exception $exception) |
|
| 165 | - { |
|
| 166 | - $trace = $exception->getTrace(); |
|
| 167 | - if (empty($trace)) { |
|
| 168 | - return esc_html__( |
|
| 169 | - 'Sorry, but no trace information was available for this exception.', |
|
| 170 | - 'event_espresso' |
|
| 171 | - ); |
|
| 172 | - } |
|
| 158 | + /** |
|
| 159 | + * @param Exception $exception |
|
| 160 | + * @return string |
|
| 161 | + * @throws ReflectionException |
|
| 162 | + * @since 4.10.24.p |
|
| 163 | + */ |
|
| 164 | + private function traceDetails(Exception $exception) |
|
| 165 | + { |
|
| 166 | + $trace = $exception->getTrace(); |
|
| 167 | + if (empty($trace)) { |
|
| 168 | + return esc_html__( |
|
| 169 | + 'Sorry, but no trace information was available for this exception.', |
|
| 170 | + 'event_espresso' |
|
| 171 | + ); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - $trace_details = ' |
|
| 174 | + $trace_details = ' |
|
| 175 | 175 | <div id="ee-trace-details"> |
| 176 | 176 | <table> |
| 177 | 177 | <tr> |
@@ -180,160 +180,160 @@ discard block |
||
| 180 | 180 | <th scope="col" class="ee-align-left" style="width:40%;">File</th> |
| 181 | 181 | <th scope="col" class="ee-align-left"> |
| 182 | 182 | ' . esc_html__('Class', 'event_espresso') |
| 183 | - . '->' |
|
| 184 | - . esc_html__('Method( arguments )', 'event_espresso') . ' |
|
| 183 | + . '->' |
|
| 184 | + . esc_html__('Method( arguments )', 'event_espresso') . ' |
|
| 185 | 185 | </th> |
| 186 | 186 | </tr>'; |
| 187 | - $last_on_stack = count($trace) - 1; |
|
| 188 | - // reverse array so that stack is in proper chronological order |
|
| 189 | - $sorted_trace = array_reverse($trace); |
|
| 190 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
| 191 | - $this->class_name = isset($trace['class']) ? $trace['class'] : ''; |
|
| 192 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
| 193 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
| 194 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
| 195 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
| 196 | - $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args; |
|
| 197 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
| 198 | - if (empty($file) && ! empty($this->class_name)) { |
|
| 199 | - $a = new ReflectionClass($this->class_name); |
|
| 200 | - $file = $a->getFileName(); |
|
| 201 | - if (empty($line) && ! empty($function)) { |
|
| 202 | - try { |
|
| 203 | - // if $function is a closure, this throws an exception |
|
| 204 | - $b = new ReflectionMethod($this->class_name, $function); |
|
| 205 | - $line = $b->getStartLine(); |
|
| 206 | - } catch (Exception $closure_exception) { |
|
| 207 | - $line = 'unknown'; |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - if ($nmbr === $last_on_stack) { |
|
| 212 | - $file = $exception->getFile() ?: $file; |
|
| 213 | - $line = $exception->getLine() ?: $line; |
|
| 214 | - $this->error_code = $this->generate_error_code($file, $trace['function'], $line); |
|
| 215 | - } |
|
| 216 | - $file = EEH_File::standardise_directory_separators($file); |
|
| 217 | - $nmbr = ! empty($nmbr) ? $nmbr : ' '; |
|
| 218 | - $line = ! empty($line) ? $line : ' '; |
|
| 219 | - $file = ! empty($file) ? $file : ' '; |
|
| 220 | - $type = ! empty($type) ? $type : ''; |
|
| 221 | - $function = ! empty($function) ? $function : ''; |
|
| 222 | - $args = ! empty($args) ? '( ' . $args . ' )' : '()'; |
|
| 223 | - $trace_details .= ' |
|
| 187 | + $last_on_stack = count($trace) - 1; |
|
| 188 | + // reverse array so that stack is in proper chronological order |
|
| 189 | + $sorted_trace = array_reverse($trace); |
|
| 190 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
| 191 | + $this->class_name = isset($trace['class']) ? $trace['class'] : ''; |
|
| 192 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
| 193 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
| 194 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
| 195 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
| 196 | + $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args; |
|
| 197 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
| 198 | + if (empty($file) && ! empty($this->class_name)) { |
|
| 199 | + $a = new ReflectionClass($this->class_name); |
|
| 200 | + $file = $a->getFileName(); |
|
| 201 | + if (empty($line) && ! empty($function)) { |
|
| 202 | + try { |
|
| 203 | + // if $function is a closure, this throws an exception |
|
| 204 | + $b = new ReflectionMethod($this->class_name, $function); |
|
| 205 | + $line = $b->getStartLine(); |
|
| 206 | + } catch (Exception $closure_exception) { |
|
| 207 | + $line = 'unknown'; |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + if ($nmbr === $last_on_stack) { |
|
| 212 | + $file = $exception->getFile() ?: $file; |
|
| 213 | + $line = $exception->getLine() ?: $line; |
|
| 214 | + $this->error_code = $this->generate_error_code($file, $trace['function'], $line); |
|
| 215 | + } |
|
| 216 | + $file = EEH_File::standardise_directory_separators($file); |
|
| 217 | + $nmbr = ! empty($nmbr) ? $nmbr : ' '; |
|
| 218 | + $line = ! empty($line) ? $line : ' '; |
|
| 219 | + $file = ! empty($file) ? $file : ' '; |
|
| 220 | + $type = ! empty($type) ? $type : ''; |
|
| 221 | + $function = ! empty($function) ? $function : ''; |
|
| 222 | + $args = ! empty($args) ? '( ' . $args . ' )' : '()'; |
|
| 223 | + $trace_details .= ' |
|
| 224 | 224 | <tr> |
| 225 | 225 | <td class="ee-align-right">' . $nmbr . '</td> |
| 226 | 226 | <td class="ee-align-right">' . $line . '</td> |
| 227 | 227 | <td class="ee-align-left">' . $file . '</td> |
| 228 | 228 | <td class="ee-align-left">' . $this->class_name . $type . $function . $args . '</td> |
| 229 | 229 | </tr>'; |
| 230 | - } |
|
| 231 | - $trace_details .= ' |
|
| 230 | + } |
|
| 231 | + $trace_details .= ' |
|
| 232 | 232 | </table> |
| 233 | 233 | </div>'; |
| 234 | - return $trace_details; |
|
| 235 | - } |
|
| 234 | + return $trace_details; |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | 237 | |
| 238 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 239 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
| 238 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 239 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
| 240 | 240 | |
| 241 | - /** |
|
| 242 | - * generate string from exception trace args |
|
| 243 | - * |
|
| 244 | - * @param array $arguments |
|
| 245 | - * @param int $indent |
|
| 246 | - * @param bool $array |
|
| 247 | - * @return string |
|
| 248 | - */ |
|
| 249 | - private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false) |
|
| 250 | - { |
|
| 251 | - $args = array(); |
|
| 252 | - $args_count = count($arguments); |
|
| 253 | - if ($args_count > 2) { |
|
| 254 | - $indent++; |
|
| 255 | - $args[] = '<br />'; |
|
| 256 | - } |
|
| 257 | - $x = 0; |
|
| 258 | - foreach ($arguments as $arg) { |
|
| 259 | - $x++; |
|
| 260 | - for ($i = 0; $i < $indent; $i++) { |
|
| 261 | - $args[] = ' '; |
|
| 262 | - } |
|
| 263 | - if (is_string($arg)) { |
|
| 264 | - if (! $array && strlen($arg) > 75) { |
|
| 265 | - $args[] = '<br />'; |
|
| 266 | - for ($i = 0; $i <= $indent; $i++) { |
|
| 267 | - $args[] = ' '; |
|
| 268 | - } |
|
| 269 | - $args[] = "'" . $arg . "'<br />"; |
|
| 270 | - } else { |
|
| 271 | - $args[] = " '" . $arg . "'"; |
|
| 272 | - } |
|
| 273 | - } elseif (is_array($arg)) { |
|
| 274 | - $arg_count = count($arg); |
|
| 275 | - if ($arg_count > 2) { |
|
| 276 | - $indent++; |
|
| 277 | - $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')'; |
|
| 278 | - $indent--; |
|
| 279 | - } elseif ($arg_count === 0) { |
|
| 280 | - $args[] = ' array()'; |
|
| 281 | - } else { |
|
| 282 | - $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )'; |
|
| 283 | - } |
|
| 284 | - } elseif ($arg === null) { |
|
| 285 | - $args[] = ' null'; |
|
| 286 | - } elseif (is_bool($arg)) { |
|
| 287 | - $args[] = $arg ? ' true' : ' false'; |
|
| 288 | - } elseif (is_object($arg)) { |
|
| 289 | - $args[] = get_class($arg); |
|
| 290 | - } elseif (is_resource($arg)) { |
|
| 291 | - $args[] = get_resource_type($arg); |
|
| 292 | - } else { |
|
| 293 | - $args[] = $arg; |
|
| 294 | - } |
|
| 295 | - if ($x === $args_count) { |
|
| 296 | - if ($args_count > 2) { |
|
| 297 | - $args[] = '<br />'; |
|
| 298 | - $indent--; |
|
| 299 | - for ($i = 1; $i < $indent; $i++) { |
|
| 300 | - $args[] = ' '; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } else { |
|
| 304 | - $args[] = $args_count > 2 ? ',<br />' : ', '; |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - return implode('', $args); |
|
| 308 | - } |
|
| 241 | + /** |
|
| 242 | + * generate string from exception trace args |
|
| 243 | + * |
|
| 244 | + * @param array $arguments |
|
| 245 | + * @param int $indent |
|
| 246 | + * @param bool $array |
|
| 247 | + * @return string |
|
| 248 | + */ |
|
| 249 | + private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false) |
|
| 250 | + { |
|
| 251 | + $args = array(); |
|
| 252 | + $args_count = count($arguments); |
|
| 253 | + if ($args_count > 2) { |
|
| 254 | + $indent++; |
|
| 255 | + $args[] = '<br />'; |
|
| 256 | + } |
|
| 257 | + $x = 0; |
|
| 258 | + foreach ($arguments as $arg) { |
|
| 259 | + $x++; |
|
| 260 | + for ($i = 0; $i < $indent; $i++) { |
|
| 261 | + $args[] = ' '; |
|
| 262 | + } |
|
| 263 | + if (is_string($arg)) { |
|
| 264 | + if (! $array && strlen($arg) > 75) { |
|
| 265 | + $args[] = '<br />'; |
|
| 266 | + for ($i = 0; $i <= $indent; $i++) { |
|
| 267 | + $args[] = ' '; |
|
| 268 | + } |
|
| 269 | + $args[] = "'" . $arg . "'<br />"; |
|
| 270 | + } else { |
|
| 271 | + $args[] = " '" . $arg . "'"; |
|
| 272 | + } |
|
| 273 | + } elseif (is_array($arg)) { |
|
| 274 | + $arg_count = count($arg); |
|
| 275 | + if ($arg_count > 2) { |
|
| 276 | + $indent++; |
|
| 277 | + $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')'; |
|
| 278 | + $indent--; |
|
| 279 | + } elseif ($arg_count === 0) { |
|
| 280 | + $args[] = ' array()'; |
|
| 281 | + } else { |
|
| 282 | + $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )'; |
|
| 283 | + } |
|
| 284 | + } elseif ($arg === null) { |
|
| 285 | + $args[] = ' null'; |
|
| 286 | + } elseif (is_bool($arg)) { |
|
| 287 | + $args[] = $arg ? ' true' : ' false'; |
|
| 288 | + } elseif (is_object($arg)) { |
|
| 289 | + $args[] = get_class($arg); |
|
| 290 | + } elseif (is_resource($arg)) { |
|
| 291 | + $args[] = get_resource_type($arg); |
|
| 292 | + } else { |
|
| 293 | + $args[] = $arg; |
|
| 294 | + } |
|
| 295 | + if ($x === $args_count) { |
|
| 296 | + if ($args_count > 2) { |
|
| 297 | + $args[] = '<br />'; |
|
| 298 | + $indent--; |
|
| 299 | + for ($i = 1; $i < $indent; $i++) { |
|
| 300 | + $args[] = ' '; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } else { |
|
| 304 | + $args[] = $args_count > 2 ? ',<br />' : ', '; |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + return implode('', $args); |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | 310 | |
| 311 | - /** |
|
| 312 | - * create error code from filepath, function name, |
|
| 313 | - * and line number where exception or error was thrown |
|
| 314 | - * |
|
| 315 | - * @access protected |
|
| 316 | - * @param string $file |
|
| 317 | - * @param string $func |
|
| 318 | - * @param string $line |
|
| 319 | - * @return string |
|
| 320 | - */ |
|
| 321 | - protected function generate_error_code($file = '', $func = '', $line = '') |
|
| 322 | - { |
|
| 323 | - $file_bits = explode('.', basename($file)); |
|
| 324 | - $error_code = ! empty($file_bits[0]) ? $file_bits[0] : ''; |
|
| 325 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
| 326 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
| 327 | - return $error_code; |
|
| 328 | - } |
|
| 311 | + /** |
|
| 312 | + * create error code from filepath, function name, |
|
| 313 | + * and line number where exception or error was thrown |
|
| 314 | + * |
|
| 315 | + * @access protected |
|
| 316 | + * @param string $file |
|
| 317 | + * @param string $func |
|
| 318 | + * @param string $line |
|
| 319 | + * @return string |
|
| 320 | + */ |
|
| 321 | + protected function generate_error_code($file = '', $func = '', $line = '') |
|
| 322 | + { |
|
| 323 | + $file_bits = explode('.', basename($file)); |
|
| 324 | + $error_code = ! empty($file_bits[0]) ? $file_bits[0] : ''; |
|
| 325 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
| 326 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
| 327 | + return $error_code; |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | 330 | |
| 331 | - /** |
|
| 332 | - * @return string |
|
| 333 | - */ |
|
| 334 | - private function exceptionStyles() |
|
| 335 | - { |
|
| 336 | - return ' |
|
| 331 | + /** |
|
| 332 | + * @return string |
|
| 333 | + */ |
|
| 334 | + private function exceptionStyles() |
|
| 335 | + { |
|
| 336 | + return ' |
|
| 337 | 337 | <style media="screen"> |
| 338 | 338 | #ee-error-message { |
| 339 | 339 | max-width:90% !important; |
@@ -391,34 +391,34 @@ discard block |
||
| 391 | 391 | color: #999; |
| 392 | 392 | } |
| 393 | 393 | </style>'; |
| 394 | - } |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | 396 | |
| 397 | - /** |
|
| 398 | - * _print_scripts |
|
| 399 | - * |
|
| 400 | - * @param bool $force_print |
|
| 401 | - * @return string |
|
| 402 | - */ |
|
| 403 | - private function printScripts($force_print = false) |
|
| 404 | - { |
|
| 405 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
| 406 | - // if script is already enqueued then we can just get out |
|
| 407 | - if (wp_script_is('ee_error_js')) { |
|
| 408 | - return ''; |
|
| 409 | - } |
|
| 410 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
| 411 | - wp_enqueue_style('espresso_default'); |
|
| 412 | - wp_enqueue_style('espresso_custom_css'); |
|
| 413 | - wp_enqueue_script('ee_error_js'); |
|
| 414 | - wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
| 415 | - return ''; |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - $jquery = esc_url_raw(includes_url() . 'js/jquery/jquery.js'); |
|
| 419 | - $core = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . espresso_version()); |
|
| 420 | - $ee_error = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js?ver=' . espresso_version()); |
|
| 421 | - return ' |
|
| 397 | + /** |
|
| 398 | + * _print_scripts |
|
| 399 | + * |
|
| 400 | + * @param bool $force_print |
|
| 401 | + * @return string |
|
| 402 | + */ |
|
| 403 | + private function printScripts($force_print = false) |
|
| 404 | + { |
|
| 405 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
| 406 | + // if script is already enqueued then we can just get out |
|
| 407 | + if (wp_script_is('ee_error_js')) { |
|
| 408 | + return ''; |
|
| 409 | + } |
|
| 410 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
| 411 | + wp_enqueue_style('espresso_default'); |
|
| 412 | + wp_enqueue_style('espresso_custom_css'); |
|
| 413 | + wp_enqueue_script('ee_error_js'); |
|
| 414 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
| 415 | + return ''; |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + $jquery = esc_url_raw(includes_url() . 'js/jquery/jquery.js'); |
|
| 419 | + $core = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . espresso_version()); |
|
| 420 | + $ee_error = esc_url_raw(EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js?ver=' . espresso_version()); |
|
| 421 | + return ' |
|
| 422 | 422 | <script> |
| 423 | 423 | /* <![CDATA[ */ |
| 424 | 424 | const ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
@@ -428,5 +428,5 @@ discard block |
||
| 428 | 428 | <script src="' . $core . '" type="text/javascript" ></script> |
| 429 | 429 | <script src="' . $ee_error . '" type="text/javascript" ></script> |
| 430 | 430 | '; |
| 431 | - } |
|
| 431 | + } |
|
| 432 | 432 | } |
@@ -17,495 +17,495 @@ |
||
| 17 | 17 | class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * $_COOKIE parameters |
|
| 22 | - * |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - protected $cookies; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * $_FILES parameters |
|
| 29 | - * |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $files; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * true if current user appears to be some kind of bot |
|
| 36 | - * |
|
| 37 | - * @var bool |
|
| 38 | - */ |
|
| 39 | - protected $is_bot; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var RequestParams |
|
| 43 | - */ |
|
| 44 | - protected $request_params; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var RequestTypeContextCheckerInterface |
|
| 48 | - */ |
|
| 49 | - protected $request_type; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var ServerParams |
|
| 53 | - */ |
|
| 54 | - protected $server_params; |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - public function __construct( |
|
| 58 | - RequestParams $request_params, |
|
| 59 | - ServerParams $server_params, |
|
| 60 | - array $cookies = [], |
|
| 61 | - array $files = [] |
|
| 62 | - ) { |
|
| 63 | - $this->cookies = ! empty($cookies) |
|
| 64 | - ? $cookies |
|
| 65 | - : filter_input_array(INPUT_COOKIE, FILTER_SANITIZE_STRING); |
|
| 66 | - $this->files = ! empty($files) ? $files : $_FILES; |
|
| 67 | - $this->request_params = $request_params; |
|
| 68 | - $this->server_params = $server_params; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param RequestTypeContextCheckerInterface $type |
|
| 74 | - */ |
|
| 75 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
| 76 | - { |
|
| 77 | - $this->request_type = $type; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @return array |
|
| 83 | - */ |
|
| 84 | - public function getParams() |
|
| 85 | - { |
|
| 86 | - return $this->request_params->getParams(); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @return array |
|
| 92 | - */ |
|
| 93 | - public function postParams() |
|
| 94 | - { |
|
| 95 | - return $this->request_params->postParams(); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @return array |
|
| 101 | - */ |
|
| 102 | - public function cookieParams() |
|
| 103 | - { |
|
| 104 | - return $this->cookies; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @return array |
|
| 110 | - */ |
|
| 111 | - public function serverParams() |
|
| 112 | - { |
|
| 113 | - return $this->server_params->getAllServerParams(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @param string $key |
|
| 119 | - * @param mixed|null $default |
|
| 120 | - * @return array|int|float|string |
|
| 121 | - */ |
|
| 122 | - public function getServerParam($key, $default = null) |
|
| 123 | - { |
|
| 124 | - return $this->server_params->getServerParam($key, $default); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @param string $key |
|
| 130 | - * @param array|int|float|string $value |
|
| 131 | - * @return void |
|
| 132 | - */ |
|
| 133 | - public function setServerParam($key, $value) |
|
| 134 | - { |
|
| 135 | - $this->server_params->setServerParam($key, $value); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param string $key |
|
| 141 | - * @return bool |
|
| 142 | - */ |
|
| 143 | - public function serverParamIsSet($key) |
|
| 144 | - { |
|
| 145 | - return $this->server_params->serverParamIsSet($key); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @return array |
|
| 151 | - */ |
|
| 152 | - public function filesParams() |
|
| 153 | - { |
|
| 154 | - return $this->files; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * returns sanitized contents of $_REQUEST |
|
| 160 | - * |
|
| 161 | - * @return array |
|
| 162 | - */ |
|
| 163 | - public function requestParams() |
|
| 164 | - { |
|
| 165 | - return $this->request_params->requestParams(); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @param string $key |
|
| 171 | - * @param mixed|null $value |
|
| 172 | - * @param bool $override_ee |
|
| 173 | - * @return void |
|
| 174 | - */ |
|
| 175 | - public function setRequestParam($key, $value, $override_ee = false) |
|
| 176 | - { |
|
| 177 | - $this->request_params->setRequestParam($key, $value, $override_ee); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * merges the incoming array of parameters into the existing request parameters |
|
| 183 | - * |
|
| 184 | - * @param array $request_params |
|
| 185 | - * @return void |
|
| 186 | - * @since 4.10.24.p |
|
| 187 | - */ |
|
| 188 | - public function mergeRequestParams(array $request_params) |
|
| 189 | - { |
|
| 190 | - $this->request_params->mergeRequestParams($request_params); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * returns sanitized value for a request param if the given key exists |
|
| 196 | - * |
|
| 197 | - * @param string $key |
|
| 198 | - * @param mixed|null $default |
|
| 199 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
| 200 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
| 201 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
| 202 | - * @return array|bool|float|int|string |
|
| 203 | - */ |
|
| 204 | - public function getRequestParam($key, $default = null, $type = 'string', $is_array = false, $delimiter = '') |
|
| 205 | - { |
|
| 206 | - return $this->request_params->getRequestParam($key, $default, $type, $is_array, $delimiter); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * check if param exists |
|
| 212 | - * |
|
| 213 | - * @param string $key |
|
| 214 | - * @return bool |
|
| 215 | - */ |
|
| 216 | - public function requestParamIsSet($key) |
|
| 217 | - { |
|
| 218 | - return $this->request_params->requestParamIsSet($key); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 224 | - * and return the sanitized value for the first match found |
|
| 225 | - * wildcards can be either of the following: |
|
| 226 | - * ? to represent a single character of any type |
|
| 227 | - * * to represent one or more characters of any type |
|
| 228 | - * |
|
| 229 | - * @param string $pattern |
|
| 230 | - * @param mixed|null $default |
|
| 231 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
| 232 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
| 233 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
| 234 | - * @return array|bool|float|int|string |
|
| 235 | - */ |
|
| 236 | - public function getMatch($pattern, $default = null, $type = 'string', $is_array = false, $delimiter = '') |
|
| 237 | - { |
|
| 238 | - return $this->request_params->getMatch($pattern, $default, $type, $is_array, $delimiter); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 244 | - * wildcards can be either of the following: |
|
| 245 | - * ? to represent a single character of any type |
|
| 246 | - * * to represent one or more characters of any type |
|
| 247 | - * returns true if a match is found or false if not |
|
| 248 | - * |
|
| 249 | - * @param string $pattern |
|
| 250 | - * @return bool |
|
| 251 | - */ |
|
| 252 | - public function matches($pattern) |
|
| 253 | - { |
|
| 254 | - return $this->request_params->matches($pattern); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * remove param |
|
| 260 | - * |
|
| 261 | - * @param $key |
|
| 262 | - * @param bool $unset_from_global_too |
|
| 263 | - */ |
|
| 264 | - public function unSetRequestParam($key, $unset_from_global_too = false) |
|
| 265 | - { |
|
| 266 | - $this->request_params->unSetRequestParam($key, $unset_from_global_too); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * remove params |
|
| 272 | - * |
|
| 273 | - * @param array $keys |
|
| 274 | - * @param bool $unset_from_global_too |
|
| 275 | - */ |
|
| 276 | - public function unSetRequestParams(array $keys, $unset_from_global_too = false) |
|
| 277 | - { |
|
| 278 | - $this->request_params->unSetRequestParams($keys, $unset_from_global_too); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * @return string |
|
| 284 | - */ |
|
| 285 | - public function ipAddress() |
|
| 286 | - { |
|
| 287 | - return $this->server_params->ipAddress(); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison. |
|
| 293 | - * |
|
| 294 | - * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to |
|
| 295 | - * "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return |
|
| 296 | - * "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/". |
|
| 297 | - * @return string |
|
| 298 | - */ |
|
| 299 | - public function requestUri($relativeToWpRoot = false) |
|
| 300 | - { |
|
| 301 | - return $this->server_params->requestUri(); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * @return string |
|
| 307 | - */ |
|
| 308 | - public function userAgent() |
|
| 309 | - { |
|
| 310 | - return $this->server_params->userAgent(); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * @param string $user_agent |
|
| 316 | - */ |
|
| 317 | - public function setUserAgent($user_agent = '') |
|
| 318 | - { |
|
| 319 | - $this->server_params->setUserAgent($user_agent); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * @return bool |
|
| 325 | - */ |
|
| 326 | - public function isBot() |
|
| 327 | - { |
|
| 328 | - return $this->is_bot; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * @param bool $is_bot |
|
| 334 | - */ |
|
| 335 | - public function setIsBot($is_bot) |
|
| 336 | - { |
|
| 337 | - $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * @return bool |
|
| 343 | - */ |
|
| 344 | - public function isActivation() |
|
| 345 | - { |
|
| 346 | - return $this->request_type->isActivation(); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * @param $is_activation |
|
| 352 | - * @return bool |
|
| 353 | - */ |
|
| 354 | - public function setIsActivation($is_activation) |
|
| 355 | - { |
|
| 356 | - return $this->request_type->setIsActivation($is_activation); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * @return bool |
|
| 362 | - */ |
|
| 363 | - public function isAdmin() |
|
| 364 | - { |
|
| 365 | - return $this->request_type->isAdmin(); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * @return bool |
|
| 371 | - */ |
|
| 372 | - public function isAdminAjax() |
|
| 373 | - { |
|
| 374 | - return $this->request_type->isAdminAjax(); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * @return bool |
|
| 380 | - */ |
|
| 381 | - public function isAjax() |
|
| 382 | - { |
|
| 383 | - return $this->request_type->isAjax(); |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * @return bool |
|
| 389 | - */ |
|
| 390 | - public function isEeAjax() |
|
| 391 | - { |
|
| 392 | - return $this->request_type->isEeAjax(); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * @return bool |
|
| 398 | - */ |
|
| 399 | - public function isOtherAjax() |
|
| 400 | - { |
|
| 401 | - return $this->request_type->isOtherAjax(); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * @return bool |
|
| 407 | - */ |
|
| 408 | - public function isApi() |
|
| 409 | - { |
|
| 410 | - return $this->request_type->isApi(); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * @return bool |
|
| 416 | - */ |
|
| 417 | - public function isCli() |
|
| 418 | - { |
|
| 419 | - return $this->request_type->isCli(); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * @return bool |
|
| 425 | - */ |
|
| 426 | - public function isCron() |
|
| 427 | - { |
|
| 428 | - return $this->request_type->isCron(); |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * @return bool |
|
| 434 | - */ |
|
| 435 | - public function isFeed() |
|
| 436 | - { |
|
| 437 | - return $this->request_type->isFeed(); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * @return bool |
|
| 443 | - */ |
|
| 444 | - public function isFrontend() |
|
| 445 | - { |
|
| 446 | - return $this->request_type->isFrontend(); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * @return bool |
|
| 452 | - */ |
|
| 453 | - public function isFrontAjax() |
|
| 454 | - { |
|
| 455 | - return $this->request_type->isFrontAjax(); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * @return bool |
|
| 461 | - */ |
|
| 462 | - public function isIframe() |
|
| 463 | - { |
|
| 464 | - return $this->request_type->isIframe(); |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * @return bool |
|
| 470 | - */ |
|
| 471 | - public function isWordPressApi() |
|
| 472 | - { |
|
| 473 | - return $this->request_type->isWordPressApi(); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * @return bool |
|
| 479 | - */ |
|
| 480 | - public function isWordPressHeartbeat() |
|
| 481 | - { |
|
| 482 | - return $this->request_type->isWordPressHeartbeat(); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * @return bool |
|
| 488 | - */ |
|
| 489 | - public function isWordPressScrape() |
|
| 490 | - { |
|
| 491 | - return $this->request_type->isWordPressScrape(); |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * @return string |
|
| 497 | - */ |
|
| 498 | - public function slug() |
|
| 499 | - { |
|
| 500 | - return $this->request_type->slug(); |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * @return RequestTypeContextCheckerInterface |
|
| 506 | - */ |
|
| 507 | - public function getRequestType() |
|
| 508 | - { |
|
| 509 | - return $this->request_type; |
|
| 510 | - } |
|
| 20 | + /** |
|
| 21 | + * $_COOKIE parameters |
|
| 22 | + * |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + protected $cookies; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * $_FILES parameters |
|
| 29 | + * |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $files; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * true if current user appears to be some kind of bot |
|
| 36 | + * |
|
| 37 | + * @var bool |
|
| 38 | + */ |
|
| 39 | + protected $is_bot; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var RequestParams |
|
| 43 | + */ |
|
| 44 | + protected $request_params; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var RequestTypeContextCheckerInterface |
|
| 48 | + */ |
|
| 49 | + protected $request_type; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var ServerParams |
|
| 53 | + */ |
|
| 54 | + protected $server_params; |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + public function __construct( |
|
| 58 | + RequestParams $request_params, |
|
| 59 | + ServerParams $server_params, |
|
| 60 | + array $cookies = [], |
|
| 61 | + array $files = [] |
|
| 62 | + ) { |
|
| 63 | + $this->cookies = ! empty($cookies) |
|
| 64 | + ? $cookies |
|
| 65 | + : filter_input_array(INPUT_COOKIE, FILTER_SANITIZE_STRING); |
|
| 66 | + $this->files = ! empty($files) ? $files : $_FILES; |
|
| 67 | + $this->request_params = $request_params; |
|
| 68 | + $this->server_params = $server_params; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param RequestTypeContextCheckerInterface $type |
|
| 74 | + */ |
|
| 75 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
| 76 | + { |
|
| 77 | + $this->request_type = $type; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @return array |
|
| 83 | + */ |
|
| 84 | + public function getParams() |
|
| 85 | + { |
|
| 86 | + return $this->request_params->getParams(); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @return array |
|
| 92 | + */ |
|
| 93 | + public function postParams() |
|
| 94 | + { |
|
| 95 | + return $this->request_params->postParams(); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @return array |
|
| 101 | + */ |
|
| 102 | + public function cookieParams() |
|
| 103 | + { |
|
| 104 | + return $this->cookies; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @return array |
|
| 110 | + */ |
|
| 111 | + public function serverParams() |
|
| 112 | + { |
|
| 113 | + return $this->server_params->getAllServerParams(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @param string $key |
|
| 119 | + * @param mixed|null $default |
|
| 120 | + * @return array|int|float|string |
|
| 121 | + */ |
|
| 122 | + public function getServerParam($key, $default = null) |
|
| 123 | + { |
|
| 124 | + return $this->server_params->getServerParam($key, $default); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @param string $key |
|
| 130 | + * @param array|int|float|string $value |
|
| 131 | + * @return void |
|
| 132 | + */ |
|
| 133 | + public function setServerParam($key, $value) |
|
| 134 | + { |
|
| 135 | + $this->server_params->setServerParam($key, $value); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param string $key |
|
| 141 | + * @return bool |
|
| 142 | + */ |
|
| 143 | + public function serverParamIsSet($key) |
|
| 144 | + { |
|
| 145 | + return $this->server_params->serverParamIsSet($key); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @return array |
|
| 151 | + */ |
|
| 152 | + public function filesParams() |
|
| 153 | + { |
|
| 154 | + return $this->files; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * returns sanitized contents of $_REQUEST |
|
| 160 | + * |
|
| 161 | + * @return array |
|
| 162 | + */ |
|
| 163 | + public function requestParams() |
|
| 164 | + { |
|
| 165 | + return $this->request_params->requestParams(); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @param string $key |
|
| 171 | + * @param mixed|null $value |
|
| 172 | + * @param bool $override_ee |
|
| 173 | + * @return void |
|
| 174 | + */ |
|
| 175 | + public function setRequestParam($key, $value, $override_ee = false) |
|
| 176 | + { |
|
| 177 | + $this->request_params->setRequestParam($key, $value, $override_ee); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * merges the incoming array of parameters into the existing request parameters |
|
| 183 | + * |
|
| 184 | + * @param array $request_params |
|
| 185 | + * @return void |
|
| 186 | + * @since 4.10.24.p |
|
| 187 | + */ |
|
| 188 | + public function mergeRequestParams(array $request_params) |
|
| 189 | + { |
|
| 190 | + $this->request_params->mergeRequestParams($request_params); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * returns sanitized value for a request param if the given key exists |
|
| 196 | + * |
|
| 197 | + * @param string $key |
|
| 198 | + * @param mixed|null $default |
|
| 199 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
| 200 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
| 201 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
| 202 | + * @return array|bool|float|int|string |
|
| 203 | + */ |
|
| 204 | + public function getRequestParam($key, $default = null, $type = 'string', $is_array = false, $delimiter = '') |
|
| 205 | + { |
|
| 206 | + return $this->request_params->getRequestParam($key, $default, $type, $is_array, $delimiter); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * check if param exists |
|
| 212 | + * |
|
| 213 | + * @param string $key |
|
| 214 | + * @return bool |
|
| 215 | + */ |
|
| 216 | + public function requestParamIsSet($key) |
|
| 217 | + { |
|
| 218 | + return $this->request_params->requestParamIsSet($key); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 224 | + * and return the sanitized value for the first match found |
|
| 225 | + * wildcards can be either of the following: |
|
| 226 | + * ? to represent a single character of any type |
|
| 227 | + * * to represent one or more characters of any type |
|
| 228 | + * |
|
| 229 | + * @param string $pattern |
|
| 230 | + * @param mixed|null $default |
|
| 231 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
| 232 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
| 233 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
| 234 | + * @return array|bool|float|int|string |
|
| 235 | + */ |
|
| 236 | + public function getMatch($pattern, $default = null, $type = 'string', $is_array = false, $delimiter = '') |
|
| 237 | + { |
|
| 238 | + return $this->request_params->getMatch($pattern, $default, $type, $is_array, $delimiter); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 244 | + * wildcards can be either of the following: |
|
| 245 | + * ? to represent a single character of any type |
|
| 246 | + * * to represent one or more characters of any type |
|
| 247 | + * returns true if a match is found or false if not |
|
| 248 | + * |
|
| 249 | + * @param string $pattern |
|
| 250 | + * @return bool |
|
| 251 | + */ |
|
| 252 | + public function matches($pattern) |
|
| 253 | + { |
|
| 254 | + return $this->request_params->matches($pattern); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * remove param |
|
| 260 | + * |
|
| 261 | + * @param $key |
|
| 262 | + * @param bool $unset_from_global_too |
|
| 263 | + */ |
|
| 264 | + public function unSetRequestParam($key, $unset_from_global_too = false) |
|
| 265 | + { |
|
| 266 | + $this->request_params->unSetRequestParam($key, $unset_from_global_too); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * remove params |
|
| 272 | + * |
|
| 273 | + * @param array $keys |
|
| 274 | + * @param bool $unset_from_global_too |
|
| 275 | + */ |
|
| 276 | + public function unSetRequestParams(array $keys, $unset_from_global_too = false) |
|
| 277 | + { |
|
| 278 | + $this->request_params->unSetRequestParams($keys, $unset_from_global_too); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * @return string |
|
| 284 | + */ |
|
| 285 | + public function ipAddress() |
|
| 286 | + { |
|
| 287 | + return $this->server_params->ipAddress(); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison. |
|
| 293 | + * |
|
| 294 | + * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to |
|
| 295 | + * "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return |
|
| 296 | + * "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/". |
|
| 297 | + * @return string |
|
| 298 | + */ |
|
| 299 | + public function requestUri($relativeToWpRoot = false) |
|
| 300 | + { |
|
| 301 | + return $this->server_params->requestUri(); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * @return string |
|
| 307 | + */ |
|
| 308 | + public function userAgent() |
|
| 309 | + { |
|
| 310 | + return $this->server_params->userAgent(); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * @param string $user_agent |
|
| 316 | + */ |
|
| 317 | + public function setUserAgent($user_agent = '') |
|
| 318 | + { |
|
| 319 | + $this->server_params->setUserAgent($user_agent); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * @return bool |
|
| 325 | + */ |
|
| 326 | + public function isBot() |
|
| 327 | + { |
|
| 328 | + return $this->is_bot; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * @param bool $is_bot |
|
| 334 | + */ |
|
| 335 | + public function setIsBot($is_bot) |
|
| 336 | + { |
|
| 337 | + $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * @return bool |
|
| 343 | + */ |
|
| 344 | + public function isActivation() |
|
| 345 | + { |
|
| 346 | + return $this->request_type->isActivation(); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * @param $is_activation |
|
| 352 | + * @return bool |
|
| 353 | + */ |
|
| 354 | + public function setIsActivation($is_activation) |
|
| 355 | + { |
|
| 356 | + return $this->request_type->setIsActivation($is_activation); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * @return bool |
|
| 362 | + */ |
|
| 363 | + public function isAdmin() |
|
| 364 | + { |
|
| 365 | + return $this->request_type->isAdmin(); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * @return bool |
|
| 371 | + */ |
|
| 372 | + public function isAdminAjax() |
|
| 373 | + { |
|
| 374 | + return $this->request_type->isAdminAjax(); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * @return bool |
|
| 380 | + */ |
|
| 381 | + public function isAjax() |
|
| 382 | + { |
|
| 383 | + return $this->request_type->isAjax(); |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * @return bool |
|
| 389 | + */ |
|
| 390 | + public function isEeAjax() |
|
| 391 | + { |
|
| 392 | + return $this->request_type->isEeAjax(); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * @return bool |
|
| 398 | + */ |
|
| 399 | + public function isOtherAjax() |
|
| 400 | + { |
|
| 401 | + return $this->request_type->isOtherAjax(); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * @return bool |
|
| 407 | + */ |
|
| 408 | + public function isApi() |
|
| 409 | + { |
|
| 410 | + return $this->request_type->isApi(); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * @return bool |
|
| 416 | + */ |
|
| 417 | + public function isCli() |
|
| 418 | + { |
|
| 419 | + return $this->request_type->isCli(); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * @return bool |
|
| 425 | + */ |
|
| 426 | + public function isCron() |
|
| 427 | + { |
|
| 428 | + return $this->request_type->isCron(); |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * @return bool |
|
| 434 | + */ |
|
| 435 | + public function isFeed() |
|
| 436 | + { |
|
| 437 | + return $this->request_type->isFeed(); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * @return bool |
|
| 443 | + */ |
|
| 444 | + public function isFrontend() |
|
| 445 | + { |
|
| 446 | + return $this->request_type->isFrontend(); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * @return bool |
|
| 452 | + */ |
|
| 453 | + public function isFrontAjax() |
|
| 454 | + { |
|
| 455 | + return $this->request_type->isFrontAjax(); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * @return bool |
|
| 461 | + */ |
|
| 462 | + public function isIframe() |
|
| 463 | + { |
|
| 464 | + return $this->request_type->isIframe(); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * @return bool |
|
| 470 | + */ |
|
| 471 | + public function isWordPressApi() |
|
| 472 | + { |
|
| 473 | + return $this->request_type->isWordPressApi(); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * @return bool |
|
| 479 | + */ |
|
| 480 | + public function isWordPressHeartbeat() |
|
| 481 | + { |
|
| 482 | + return $this->request_type->isWordPressHeartbeat(); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * @return bool |
|
| 488 | + */ |
|
| 489 | + public function isWordPressScrape() |
|
| 490 | + { |
|
| 491 | + return $this->request_type->isWordPressScrape(); |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * @return string |
|
| 497 | + */ |
|
| 498 | + public function slug() |
|
| 499 | + { |
|
| 500 | + return $this->request_type->slug(); |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * @return RequestTypeContextCheckerInterface |
|
| 506 | + */ |
|
| 507 | + public function getRequestType() |
|
| 508 | + { |
|
| 509 | + return $this->request_type; |
|
| 510 | + } |
|
| 511 | 511 | } |
@@ -14,327 +14,327 @@ |
||
| 14 | 14 | class RequestParams |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * $_GET parameters |
|
| 19 | - * |
|
| 20 | - * @var array |
|
| 21 | - */ |
|
| 22 | - protected $get; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * $_POST parameters |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $post; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * $_REQUEST parameters |
|
| 33 | - * |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 36 | - protected $request; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var RequestSanitizer |
|
| 40 | - */ |
|
| 41 | - protected $sanitizer; |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * RequestParams constructor. |
|
| 46 | - * |
|
| 47 | - * @param RequestSanitizer $sanitizer |
|
| 48 | - * @param array $get |
|
| 49 | - * @param array $post |
|
| 50 | - */ |
|
| 51 | - public function __construct(RequestSanitizer $sanitizer, array $get = [], array $post = []) |
|
| 52 | - { |
|
| 53 | - $this->sanitizer = $sanitizer; |
|
| 54 | - $this->get = ! empty($get) ? $get : $_GET; |
|
| 55 | - $this->post = ! empty($post) ? $post : $_POST; |
|
| 56 | - $this->request = array_merge($this->get, $this->post); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @return array |
|
| 62 | - */ |
|
| 63 | - public function getParams() |
|
| 64 | - { |
|
| 65 | - return $this->get; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @return array |
|
| 71 | - */ |
|
| 72 | - public function postParams() |
|
| 73 | - { |
|
| 74 | - return $this->post; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * returns contents of $_REQUEST |
|
| 80 | - * |
|
| 81 | - * @return array |
|
| 82 | - */ |
|
| 83 | - public function requestParams() |
|
| 84 | - { |
|
| 85 | - return $this->request; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @param string $key |
|
| 91 | - * @param mixed|null $value |
|
| 92 | - * @param bool $override_ee |
|
| 93 | - * @return void |
|
| 94 | - */ |
|
| 95 | - public function setRequestParam($key, $value, $override_ee = false) |
|
| 96 | - { |
|
| 97 | - // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
| 98 | - if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) { |
|
| 99 | - $this->request[ $key ] = $value; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * merges the incoming array of parameters into the existing request parameters |
|
| 106 | - * |
|
| 107 | - * @param array $request_params |
|
| 108 | - * @return void |
|
| 109 | - * @since 4.10.24.p |
|
| 110 | - */ |
|
| 111 | - public function mergeRequestParams(array $request_params) |
|
| 112 | - { |
|
| 113 | - $this->request = array_merge_recursive($this->request, $request_params); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * returns the value for a request param if the given key exists |
|
| 119 | - * |
|
| 120 | - * @param string $key |
|
| 121 | - * @param mixed|null $default |
|
| 122 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
| 123 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
| 124 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
| 125 | - * @return array|bool|float|int|string |
|
| 126 | - */ |
|
| 127 | - public function getRequestParam($key, $default = null, $type = 'string', $is_array = false, $delimiter = '') |
|
| 128 | - { |
|
| 129 | - return $this->sanitizer->clean( |
|
| 130 | - $this->parameterDrillDown($key, $default, 'get'), |
|
| 131 | - $type, |
|
| 132 | - $is_array, |
|
| 133 | - $delimiter |
|
| 134 | - ); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * check if param exists |
|
| 140 | - * |
|
| 141 | - * @param string $key |
|
| 142 | - * @return bool |
|
| 143 | - */ |
|
| 144 | - public function requestParamIsSet($key) |
|
| 145 | - { |
|
| 146 | - return (bool) $this->parameterDrillDown($key); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 152 | - * and return the value for the first match found |
|
| 153 | - * wildcards can be either of the following: |
|
| 154 | - * ? to represent a single character of any type |
|
| 155 | - * * to represent one or more characters of any type |
|
| 156 | - * |
|
| 157 | - * @param string $pattern |
|
| 158 | - * @param mixed|null $default |
|
| 159 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
| 160 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
| 161 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
| 162 | - * @return array|bool|float|int|string |
|
| 163 | - */ |
|
| 164 | - public function getMatch($pattern, $default = null, $type = 'string', $is_array = false, $delimiter = '') |
|
| 165 | - { |
|
| 166 | - return $this->sanitizer->clean( |
|
| 167 | - $this->parameterDrillDown($pattern, $default, 'match'), |
|
| 168 | - $type, |
|
| 169 | - $is_array, |
|
| 170 | - $delimiter |
|
| 171 | - ); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 177 | - * wildcards can be either of the following: |
|
| 178 | - * ? to represent a single character of any type |
|
| 179 | - * * to represent one or more characters of any type |
|
| 180 | - * returns true if a match is found or false if not |
|
| 181 | - * |
|
| 182 | - * @param string $pattern |
|
| 183 | - * @return bool |
|
| 184 | - */ |
|
| 185 | - public function matches($pattern) |
|
| 186 | - { |
|
| 187 | - return (bool) $this->parameterDrillDown($pattern, false, 'match', 'bool'); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
| 193 | - * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
| 194 | - * and used to search through the current request's parameter keys |
|
| 195 | - * @param array $request_params The array of request parameters to search through |
|
| 196 | - * @param mixed $default [optional] The value to be returned if no match is found. |
|
| 197 | - * Default is null |
|
| 198 | - * @param string $return [optional] Controls what kind of value is returned. |
|
| 199 | - * Options are: |
|
| 200 | - * 'bool' will return true or false if match is found or not |
|
| 201 | - * 'key' will return the first key found that matches the supplied pattern |
|
| 202 | - * 'value' will return the value for the first request parameter |
|
| 203 | - * whose key matches the supplied pattern |
|
| 204 | - * Default is 'value' |
|
| 205 | - * @return boolean|string |
|
| 206 | - */ |
|
| 207 | - private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
| 208 | - { |
|
| 209 | - $return = in_array($return, ['bool', 'key', 'value'], true) |
|
| 210 | - ? $return |
|
| 211 | - : 'is_set'; |
|
| 212 | - // replace wildcard chars with regex chars |
|
| 213 | - $pattern = str_replace( |
|
| 214 | - ['\*', '\?'], |
|
| 215 | - ['.*', '.'], |
|
| 216 | - preg_quote($pattern, '/') |
|
| 217 | - ); |
|
| 218 | - foreach ($request_params as $key => $request_param) { |
|
| 219 | - if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
| 220 | - // return value for request param |
|
| 221 | - if ($return === 'value') { |
|
| 222 | - return $request_param; |
|
| 223 | - } |
|
| 224 | - // or actual key or true just to indicate it was found |
|
| 225 | - return $return === 'key' ? $key : true; |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - // match not found so return default value or false |
|
| 229 | - return $return === 'value' ? $default : false; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * the supplied key can be a simple string to represent a "top-level" request parameter |
|
| 235 | - * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
| 236 | - * by using square brackets to surround keys for deeper array elements. |
|
| 237 | - * For example : |
|
| 238 | - * if the supplied $key was: "first[second][third]" |
|
| 239 | - * then this will attempt to drill down into the request parameter array to find a value. |
|
| 240 | - * Given the following request parameters: |
|
| 241 | - * array( |
|
| 242 | - * 'first' => array( |
|
| 243 | - * 'second' => array( |
|
| 244 | - * 'third' => 'has a value' |
|
| 245 | - * ) |
|
| 246 | - * ) |
|
| 247 | - * ) |
|
| 248 | - * would return true if default parameters were set |
|
| 249 | - * |
|
| 250 | - * @param string $callback |
|
| 251 | - * @param $key |
|
| 252 | - * @param null $default |
|
| 253 | - * @param string $return |
|
| 254 | - * @param mixed $request_params |
|
| 255 | - * @return bool|mixed|null |
|
| 256 | - */ |
|
| 257 | - private function parameterDrillDown( |
|
| 258 | - $key, |
|
| 259 | - $default = null, |
|
| 260 | - $callback = 'is_set', |
|
| 261 | - $return = 'value', |
|
| 262 | - $request_params = [] |
|
| 263 | - ) { |
|
| 264 | - $callback = in_array($callback, ['is_set', 'get', 'match'], true) |
|
| 265 | - ? $callback |
|
| 266 | - : 'is_set'; |
|
| 267 | - $request_params = ! empty($request_params) |
|
| 268 | - ? $request_params |
|
| 269 | - : $this->request; |
|
| 270 | - // does incoming key represent an array like 'first[second][third]' ? |
|
| 271 | - if (strpos($key, '[') !== false) { |
|
| 272 | - // turn it into an actual array |
|
| 273 | - $key = str_replace(']', '', $key); |
|
| 274 | - $keys = explode('[', $key); |
|
| 275 | - $key = array_shift($keys); |
|
| 276 | - if ($callback === 'match') { |
|
| 277 | - $real_key = $this->match($key, $request_params, $default, 'key'); |
|
| 278 | - $key = $real_key ?: $key; |
|
| 279 | - } |
|
| 280 | - // check if top level key exists |
|
| 281 | - if (isset($request_params[ $key ])) { |
|
| 282 | - // build a new key to pass along like: 'second[third]' |
|
| 283 | - // or just 'second' depending on depth of keys |
|
| 284 | - $key_string = array_shift($keys); |
|
| 285 | - if (! empty($keys)) { |
|
| 286 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
| 287 | - } |
|
| 288 | - return $this->parameterDrillDown( |
|
| 289 | - $key_string, |
|
| 290 | - $default, |
|
| 291 | - $callback, |
|
| 292 | - $return, |
|
| 293 | - $request_params[ $key ] |
|
| 294 | - ); |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - if ($callback === 'is_set') { |
|
| 298 | - return isset($request_params[ $key ]); |
|
| 299 | - } |
|
| 300 | - if ($callback === 'match') { |
|
| 301 | - return $this->match($key, $request_params, $default, $return); |
|
| 302 | - } |
|
| 303 | - return isset($request_params[ $key ]) |
|
| 304 | - ? $request_params[ $key ] |
|
| 305 | - : $default; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * remove param |
|
| 311 | - * |
|
| 312 | - * @param $key |
|
| 313 | - * @param bool $unset_from_global_too |
|
| 314 | - */ |
|
| 315 | - public function unSetRequestParam($key, $unset_from_global_too = false) |
|
| 316 | - { |
|
| 317 | - // because unset may not actually remove var |
|
| 318 | - $this->get[ $key ] = null; |
|
| 319 | - $this->post[ $key ] = null; |
|
| 320 | - $this->request[ $key ] = null; |
|
| 321 | - unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]); |
|
| 322 | - if ($unset_from_global_too) { |
|
| 323 | - unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]); |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * remove params |
|
| 330 | - * |
|
| 331 | - * @param array $keys |
|
| 332 | - * @param bool $unset_from_global_too |
|
| 333 | - */ |
|
| 334 | - public function unSetRequestParams(array $keys, $unset_from_global_too = false) |
|
| 335 | - { |
|
| 336 | - foreach ($keys as $key) { |
|
| 337 | - $this->unSetRequestParam($key, $unset_from_global_too); |
|
| 338 | - } |
|
| 339 | - } |
|
| 17 | + /** |
|
| 18 | + * $_GET parameters |
|
| 19 | + * |
|
| 20 | + * @var array |
|
| 21 | + */ |
|
| 22 | + protected $get; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * $_POST parameters |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $post; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * $_REQUEST parameters |
|
| 33 | + * |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | + protected $request; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var RequestSanitizer |
|
| 40 | + */ |
|
| 41 | + protected $sanitizer; |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * RequestParams constructor. |
|
| 46 | + * |
|
| 47 | + * @param RequestSanitizer $sanitizer |
|
| 48 | + * @param array $get |
|
| 49 | + * @param array $post |
|
| 50 | + */ |
|
| 51 | + public function __construct(RequestSanitizer $sanitizer, array $get = [], array $post = []) |
|
| 52 | + { |
|
| 53 | + $this->sanitizer = $sanitizer; |
|
| 54 | + $this->get = ! empty($get) ? $get : $_GET; |
|
| 55 | + $this->post = ! empty($post) ? $post : $_POST; |
|
| 56 | + $this->request = array_merge($this->get, $this->post); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @return array |
|
| 62 | + */ |
|
| 63 | + public function getParams() |
|
| 64 | + { |
|
| 65 | + return $this->get; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @return array |
|
| 71 | + */ |
|
| 72 | + public function postParams() |
|
| 73 | + { |
|
| 74 | + return $this->post; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * returns contents of $_REQUEST |
|
| 80 | + * |
|
| 81 | + * @return array |
|
| 82 | + */ |
|
| 83 | + public function requestParams() |
|
| 84 | + { |
|
| 85 | + return $this->request; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @param string $key |
|
| 91 | + * @param mixed|null $value |
|
| 92 | + * @param bool $override_ee |
|
| 93 | + * @return void |
|
| 94 | + */ |
|
| 95 | + public function setRequestParam($key, $value, $override_ee = false) |
|
| 96 | + { |
|
| 97 | + // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
| 98 | + if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) { |
|
| 99 | + $this->request[ $key ] = $value; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * merges the incoming array of parameters into the existing request parameters |
|
| 106 | + * |
|
| 107 | + * @param array $request_params |
|
| 108 | + * @return void |
|
| 109 | + * @since 4.10.24.p |
|
| 110 | + */ |
|
| 111 | + public function mergeRequestParams(array $request_params) |
|
| 112 | + { |
|
| 113 | + $this->request = array_merge_recursive($this->request, $request_params); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * returns the value for a request param if the given key exists |
|
| 119 | + * |
|
| 120 | + * @param string $key |
|
| 121 | + * @param mixed|null $default |
|
| 122 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
| 123 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
| 124 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
| 125 | + * @return array|bool|float|int|string |
|
| 126 | + */ |
|
| 127 | + public function getRequestParam($key, $default = null, $type = 'string', $is_array = false, $delimiter = '') |
|
| 128 | + { |
|
| 129 | + return $this->sanitizer->clean( |
|
| 130 | + $this->parameterDrillDown($key, $default, 'get'), |
|
| 131 | + $type, |
|
| 132 | + $is_array, |
|
| 133 | + $delimiter |
|
| 134 | + ); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * check if param exists |
|
| 140 | + * |
|
| 141 | + * @param string $key |
|
| 142 | + * @return bool |
|
| 143 | + */ |
|
| 144 | + public function requestParamIsSet($key) |
|
| 145 | + { |
|
| 146 | + return (bool) $this->parameterDrillDown($key); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 152 | + * and return the value for the first match found |
|
| 153 | + * wildcards can be either of the following: |
|
| 154 | + * ? to represent a single character of any type |
|
| 155 | + * * to represent one or more characters of any type |
|
| 156 | + * |
|
| 157 | + * @param string $pattern |
|
| 158 | + * @param mixed|null $default |
|
| 159 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
| 160 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
| 161 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
| 162 | + * @return array|bool|float|int|string |
|
| 163 | + */ |
|
| 164 | + public function getMatch($pattern, $default = null, $type = 'string', $is_array = false, $delimiter = '') |
|
| 165 | + { |
|
| 166 | + return $this->sanitizer->clean( |
|
| 167 | + $this->parameterDrillDown($pattern, $default, 'match'), |
|
| 168 | + $type, |
|
| 169 | + $is_array, |
|
| 170 | + $delimiter |
|
| 171 | + ); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 177 | + * wildcards can be either of the following: |
|
| 178 | + * ? to represent a single character of any type |
|
| 179 | + * * to represent one or more characters of any type |
|
| 180 | + * returns true if a match is found or false if not |
|
| 181 | + * |
|
| 182 | + * @param string $pattern |
|
| 183 | + * @return bool |
|
| 184 | + */ |
|
| 185 | + public function matches($pattern) |
|
| 186 | + { |
|
| 187 | + return (bool) $this->parameterDrillDown($pattern, false, 'match', 'bool'); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
| 193 | + * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
| 194 | + * and used to search through the current request's parameter keys |
|
| 195 | + * @param array $request_params The array of request parameters to search through |
|
| 196 | + * @param mixed $default [optional] The value to be returned if no match is found. |
|
| 197 | + * Default is null |
|
| 198 | + * @param string $return [optional] Controls what kind of value is returned. |
|
| 199 | + * Options are: |
|
| 200 | + * 'bool' will return true or false if match is found or not |
|
| 201 | + * 'key' will return the first key found that matches the supplied pattern |
|
| 202 | + * 'value' will return the value for the first request parameter |
|
| 203 | + * whose key matches the supplied pattern |
|
| 204 | + * Default is 'value' |
|
| 205 | + * @return boolean|string |
|
| 206 | + */ |
|
| 207 | + private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
| 208 | + { |
|
| 209 | + $return = in_array($return, ['bool', 'key', 'value'], true) |
|
| 210 | + ? $return |
|
| 211 | + : 'is_set'; |
|
| 212 | + // replace wildcard chars with regex chars |
|
| 213 | + $pattern = str_replace( |
|
| 214 | + ['\*', '\?'], |
|
| 215 | + ['.*', '.'], |
|
| 216 | + preg_quote($pattern, '/') |
|
| 217 | + ); |
|
| 218 | + foreach ($request_params as $key => $request_param) { |
|
| 219 | + if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
| 220 | + // return value for request param |
|
| 221 | + if ($return === 'value') { |
|
| 222 | + return $request_param; |
|
| 223 | + } |
|
| 224 | + // or actual key or true just to indicate it was found |
|
| 225 | + return $return === 'key' ? $key : true; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + // match not found so return default value or false |
|
| 229 | + return $return === 'value' ? $default : false; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * the supplied key can be a simple string to represent a "top-level" request parameter |
|
| 235 | + * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
| 236 | + * by using square brackets to surround keys for deeper array elements. |
|
| 237 | + * For example : |
|
| 238 | + * if the supplied $key was: "first[second][third]" |
|
| 239 | + * then this will attempt to drill down into the request parameter array to find a value. |
|
| 240 | + * Given the following request parameters: |
|
| 241 | + * array( |
|
| 242 | + * 'first' => array( |
|
| 243 | + * 'second' => array( |
|
| 244 | + * 'third' => 'has a value' |
|
| 245 | + * ) |
|
| 246 | + * ) |
|
| 247 | + * ) |
|
| 248 | + * would return true if default parameters were set |
|
| 249 | + * |
|
| 250 | + * @param string $callback |
|
| 251 | + * @param $key |
|
| 252 | + * @param null $default |
|
| 253 | + * @param string $return |
|
| 254 | + * @param mixed $request_params |
|
| 255 | + * @return bool|mixed|null |
|
| 256 | + */ |
|
| 257 | + private function parameterDrillDown( |
|
| 258 | + $key, |
|
| 259 | + $default = null, |
|
| 260 | + $callback = 'is_set', |
|
| 261 | + $return = 'value', |
|
| 262 | + $request_params = [] |
|
| 263 | + ) { |
|
| 264 | + $callback = in_array($callback, ['is_set', 'get', 'match'], true) |
|
| 265 | + ? $callback |
|
| 266 | + : 'is_set'; |
|
| 267 | + $request_params = ! empty($request_params) |
|
| 268 | + ? $request_params |
|
| 269 | + : $this->request; |
|
| 270 | + // does incoming key represent an array like 'first[second][third]' ? |
|
| 271 | + if (strpos($key, '[') !== false) { |
|
| 272 | + // turn it into an actual array |
|
| 273 | + $key = str_replace(']', '', $key); |
|
| 274 | + $keys = explode('[', $key); |
|
| 275 | + $key = array_shift($keys); |
|
| 276 | + if ($callback === 'match') { |
|
| 277 | + $real_key = $this->match($key, $request_params, $default, 'key'); |
|
| 278 | + $key = $real_key ?: $key; |
|
| 279 | + } |
|
| 280 | + // check if top level key exists |
|
| 281 | + if (isset($request_params[ $key ])) { |
|
| 282 | + // build a new key to pass along like: 'second[third]' |
|
| 283 | + // or just 'second' depending on depth of keys |
|
| 284 | + $key_string = array_shift($keys); |
|
| 285 | + if (! empty($keys)) { |
|
| 286 | + $key_string .= '[' . implode('][', $keys) . ']'; |
|
| 287 | + } |
|
| 288 | + return $this->parameterDrillDown( |
|
| 289 | + $key_string, |
|
| 290 | + $default, |
|
| 291 | + $callback, |
|
| 292 | + $return, |
|
| 293 | + $request_params[ $key ] |
|
| 294 | + ); |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + if ($callback === 'is_set') { |
|
| 298 | + return isset($request_params[ $key ]); |
|
| 299 | + } |
|
| 300 | + if ($callback === 'match') { |
|
| 301 | + return $this->match($key, $request_params, $default, $return); |
|
| 302 | + } |
|
| 303 | + return isset($request_params[ $key ]) |
|
| 304 | + ? $request_params[ $key ] |
|
| 305 | + : $default; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * remove param |
|
| 311 | + * |
|
| 312 | + * @param $key |
|
| 313 | + * @param bool $unset_from_global_too |
|
| 314 | + */ |
|
| 315 | + public function unSetRequestParam($key, $unset_from_global_too = false) |
|
| 316 | + { |
|
| 317 | + // because unset may not actually remove var |
|
| 318 | + $this->get[ $key ] = null; |
|
| 319 | + $this->post[ $key ] = null; |
|
| 320 | + $this->request[ $key ] = null; |
|
| 321 | + unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]); |
|
| 322 | + if ($unset_from_global_too) { |
|
| 323 | + unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]); |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * remove params |
|
| 330 | + * |
|
| 331 | + * @param array $keys |
|
| 332 | + * @param bool $unset_from_global_too |
|
| 333 | + */ |
|
| 334 | + public function unSetRequestParams(array $keys, $unset_from_global_too = false) |
|
| 335 | + { |
|
| 336 | + foreach ($keys as $key) { |
|
| 337 | + $this->unSetRequestParam($key, $unset_from_global_too); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | 340 | } |
@@ -16,195 +16,195 @@ |
||
| 16 | 16 | interface RequestInterface extends RequestTypeContextCheckerInterface |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @param RequestTypeContextCheckerInterface $type |
|
| 21 | - */ |
|
| 22 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
| 19 | + /** |
|
| 20 | + * @param RequestTypeContextCheckerInterface $type |
|
| 21 | + */ |
|
| 22 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @return array |
|
| 27 | - */ |
|
| 28 | - public function getParams(); |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @return array |
|
| 33 | - */ |
|
| 34 | - public function postParams(); |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @return array |
|
| 39 | - */ |
|
| 40 | - public function cookieParams(); |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @return array |
|
| 45 | - */ |
|
| 46 | - public function serverParams(); |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @param string $key |
|
| 51 | - * @param mixed|null $default |
|
| 52 | - * @return array|int|float|string |
|
| 53 | - */ |
|
| 54 | - public function getServerParam($key, $default = null); |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param string $key |
|
| 59 | - * @param array|int|float|string $value |
|
| 60 | - * @return void |
|
| 61 | - */ |
|
| 62 | - public function setServerParam($key, $value); |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @param string $key |
|
| 67 | - * @return bool |
|
| 68 | - */ |
|
| 69 | - public function serverParamIsSet($key); |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @return array |
|
| 74 | - */ |
|
| 75 | - public function filesParams(); |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * returns sanitized contents of $_REQUEST |
|
| 80 | - * |
|
| 81 | - * @return array |
|
| 82 | - */ |
|
| 83 | - public function requestParams(); |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @param string $key |
|
| 88 | - * @param string $value |
|
| 89 | - * @param bool $override_ee |
|
| 90 | - * @return void |
|
| 91 | - */ |
|
| 92 | - public function setRequestParam($key, $value, $override_ee = false); |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * returns the value for a request param if the given key exists |
|
| 97 | - * |
|
| 98 | - * @param string $key |
|
| 99 | - * @param mixed|null $default |
|
| 100 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
| 101 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
| 102 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
| 103 | - * @return array|bool|float|int|string |
|
| 104 | - */ |
|
| 105 | - public function getRequestParam($key, $default = null, $type = 'string', $is_array = false, $delimiter = ''); |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * check if param exists |
|
| 110 | - * |
|
| 111 | - * @param string $key |
|
| 112 | - * @return bool |
|
| 113 | - */ |
|
| 114 | - public function requestParamIsSet($key); |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 119 | - * and return the value for the first match found |
|
| 120 | - * wildcards can be either of the following: |
|
| 121 | - * ? to represent a single character of any type |
|
| 122 | - * * to represent one or more characters of any type |
|
| 123 | - * |
|
| 124 | - * @param string $pattern |
|
| 125 | - * @param mixed|null $default |
|
| 126 | - * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
| 127 | - * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
| 128 | - * @param string $delimiter for CSV type strings that should be returned as an array |
|
| 129 | - * @return array|bool|float|int|string |
|
| 130 | - */ |
|
| 131 | - public function getMatch($pattern, $default = null, $type = 'string', $is_array = false, $delimiter = ''); |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 136 | - * wildcards can be either of the following: |
|
| 137 | - * ? to represent a single character of any type |
|
| 138 | - * * to represent one or more characters of any type |
|
| 139 | - * returns true if a match is found or false if not |
|
| 140 | - * |
|
| 141 | - * @param string $pattern |
|
| 142 | - * @return false|int |
|
| 143 | - */ |
|
| 144 | - public function matches($pattern); |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * remove param |
|
| 149 | - * |
|
| 150 | - * @param string $key |
|
| 151 | - * @param bool $unset_from_global_too |
|
| 152 | - */ |
|
| 153 | - public function unSetRequestParam($key, $unset_from_global_too = false); |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * remove params |
|
| 158 | - * |
|
| 159 | - * @param array $keys |
|
| 160 | - * @param bool $unset_from_global_too |
|
| 161 | - */ |
|
| 162 | - public function unSetRequestParams(array $keys, $unset_from_global_too = false); |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @return string |
|
| 167 | - */ |
|
| 168 | - public function ipAddress(); |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not. |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - public function requestUri($relativeToWpRoot = false); |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - public function userAgent(); |
|
| 182 | - |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @param string $user_agent |
|
| 186 | - */ |
|
| 187 | - public function setUserAgent($user_agent = ''); |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * @return bool |
|
| 192 | - */ |
|
| 193 | - public function isBot(); |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * @param bool $is_bot |
|
| 198 | - */ |
|
| 199 | - public function setIsBot($is_bot); |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * merges the incoming array of parameters into the existing request parameters |
|
| 204 | - * |
|
| 205 | - * @param array $request_params |
|
| 206 | - * @return mixed |
|
| 207 | - * @since 4.10.24.p |
|
| 208 | - */ |
|
| 209 | - public function mergeRequestParams(array $request_params); |
|
| 25 | + /** |
|
| 26 | + * @return array |
|
| 27 | + */ |
|
| 28 | + public function getParams(); |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @return array |
|
| 33 | + */ |
|
| 34 | + public function postParams(); |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @return array |
|
| 39 | + */ |
|
| 40 | + public function cookieParams(); |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @return array |
|
| 45 | + */ |
|
| 46 | + public function serverParams(); |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param string $key |
|
| 51 | + * @param mixed|null $default |
|
| 52 | + * @return array|int|float|string |
|
| 53 | + */ |
|
| 54 | + public function getServerParam($key, $default = null); |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param string $key |
|
| 59 | + * @param array|int|float|string $value |
|
| 60 | + * @return void |
|
| 61 | + */ |
|
| 62 | + public function setServerParam($key, $value); |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @param string $key |
|
| 67 | + * @return bool |
|
| 68 | + */ |
|
| 69 | + public function serverParamIsSet($key); |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @return array |
|
| 74 | + */ |
|
| 75 | + public function filesParams(); |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * returns sanitized contents of $_REQUEST |
|
| 80 | + * |
|
| 81 | + * @return array |
|
| 82 | + */ |
|
| 83 | + public function requestParams(); |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @param string $key |
|
| 88 | + * @param string $value |
|
| 89 | + * @param bool $override_ee |
|
| 90 | + * @return void |
|
| 91 | + */ |
|
| 92 | + public function setRequestParam($key, $value, $override_ee = false); |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * returns the value for a request param if the given key exists |
|
| 97 | + * |
|
| 98 | + * @param string $key |
|
| 99 | + * @param mixed|null $default |
|
| 100 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
| 101 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
| 102 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
| 103 | + * @return array|bool|float|int|string |
|
| 104 | + */ |
|
| 105 | + public function getRequestParam($key, $default = null, $type = 'string', $is_array = false, $delimiter = ''); |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * check if param exists |
|
| 110 | + * |
|
| 111 | + * @param string $key |
|
| 112 | + * @return bool |
|
| 113 | + */ |
|
| 114 | + public function requestParamIsSet($key); |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 119 | + * and return the value for the first match found |
|
| 120 | + * wildcards can be either of the following: |
|
| 121 | + * ? to represent a single character of any type |
|
| 122 | + * * to represent one or more characters of any type |
|
| 123 | + * |
|
| 124 | + * @param string $pattern |
|
| 125 | + * @param mixed|null $default |
|
| 126 | + * @param string $type the expected data type for the parameter's value, ie: string, int, bool, etc |
|
| 127 | + * @param bool $is_array if true, then parameter value will be treated as an array of $type |
|
| 128 | + * @param string $delimiter for CSV type strings that should be returned as an array |
|
| 129 | + * @return array|bool|float|int|string |
|
| 130 | + */ |
|
| 131 | + public function getMatch($pattern, $default = null, $type = 'string', $is_array = false, $delimiter = ''); |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 136 | + * wildcards can be either of the following: |
|
| 137 | + * ? to represent a single character of any type |
|
| 138 | + * * to represent one or more characters of any type |
|
| 139 | + * returns true if a match is found or false if not |
|
| 140 | + * |
|
| 141 | + * @param string $pattern |
|
| 142 | + * @return false|int |
|
| 143 | + */ |
|
| 144 | + public function matches($pattern); |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * remove param |
|
| 149 | + * |
|
| 150 | + * @param string $key |
|
| 151 | + * @param bool $unset_from_global_too |
|
| 152 | + */ |
|
| 153 | + public function unSetRequestParam($key, $unset_from_global_too = false); |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * remove params |
|
| 158 | + * |
|
| 159 | + * @param array $keys |
|
| 160 | + * @param bool $unset_from_global_too |
|
| 161 | + */ |
|
| 162 | + public function unSetRequestParams(array $keys, $unset_from_global_too = false); |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @return string |
|
| 167 | + */ |
|
| 168 | + public function ipAddress(); |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not. |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + public function requestUri($relativeToWpRoot = false); |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + public function userAgent(); |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @param string $user_agent |
|
| 186 | + */ |
|
| 187 | + public function setUserAgent($user_agent = ''); |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * @return bool |
|
| 192 | + */ |
|
| 193 | + public function isBot(); |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * @param bool $is_bot |
|
| 198 | + */ |
|
| 199 | + public function setIsBot($is_bot); |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * merges the incoming array of parameters into the existing request parameters |
|
| 204 | + * |
|
| 205 | + * @param array $request_params |
|
| 206 | + * @return mixed |
|
| 207 | + * @since 4.10.24.p |
|
| 208 | + */ |
|
| 209 | + public function mergeRequestParams(array $request_params); |
|
| 210 | 210 | } |