Support
1 month ago
Action.php
1 month ago
Cacheable.php
1 month ago
Capability.php
1 month ago
CastAttribute.php
1 month ago
Constant.php
1 month ago
Container.php
1 month ago
Discoverable.php
1 month ago
Event.php
1 month ago
Executor.php
4 days ago
Exportable.php
1 month ago
Importable.php
1 month ago
Middleware.php
1 month ago
Migration.php
1 month ago
Parser.php
1 month ago
Registrable.php
1 month ago
Request.php
4 days ago
Response.php
1 month ago
RewriteRule.php
1 month ago
Rule.php
1 month ago
ServiceProvider.php
1 month ago
Shortcode.php
1 month ago
SomoyInterface.php
2 weeks ago
Uploader.php
1 month ago
Request.php
493 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Contract for interacting with an HTTP request in a normalized way. |
| 5 | * This interface abstracts key methods for accessing request data, headers, routes, and HTTP method. |
| 6 | * |
| 7 | * @package Framework |
| 8 | * @subpackage Contracts |
| 9 | * @since 1.0.0 |
| 10 | */ |
| 11 | namespace Kirki\Framework\Contracts; |
| 12 | |
| 13 | \defined('ABSPATH') || exit; |
| 14 | interface Request |
| 15 | { |
| 16 | /** |
| 17 | * Get the HTTP method of the request (GET, POST, etc). |
| 18 | * |
| 19 | * @return string |
| 20 | * |
| 21 | * @since 1.0.0 |
| 22 | */ |
| 23 | public function get_method(); |
| 24 | /** |
| 25 | * Get the requested route or endpoint. |
| 26 | * |
| 27 | * @return string |
| 28 | * |
| 29 | * @since 1.0.0 |
| 30 | */ |
| 31 | public function get_route(); |
| 32 | /** |
| 33 | * Get all HTTP headers from the request. |
| 34 | * |
| 35 | * @return array |
| 36 | * |
| 37 | * @since 1.0.0 |
| 38 | */ |
| 39 | public function get_headers(); |
| 40 | /** |
| 41 | * Get a single HTTP header from the request. |
| 42 | * |
| 43 | * @param string $name The name. |
| 44 | * @param mixed $default The default. |
| 45 | * |
| 46 | * @return mixed |
| 47 | * |
| 48 | * @since 1.0.0 |
| 49 | */ |
| 50 | public function get_header(string $name, $default = null); |
| 51 | /** |
| 52 | * Get all request input attributes. |
| 53 | * |
| 54 | * @return array |
| 55 | * |
| 56 | * @since 1.0.0 |
| 57 | */ |
| 58 | public function all(); |
| 59 | /** |
| 60 | * Get the validated data from the request. |
| 61 | * |
| 62 | * @return array|null |
| 63 | * |
| 64 | * @since 1.0.0 |
| 65 | */ |
| 66 | public function validated(); |
| 67 | /** |
| 68 | * Validate the request data. |
| 69 | * |
| 70 | * @param array $rules The rules to validate. |
| 71 | * |
| 72 | * @return array |
| 73 | * |
| 74 | * @since 1.0.0 |
| 75 | */ |
| 76 | public function validate(array $rules); |
| 77 | /** |
| 78 | * Get the sanitized data from the request. |
| 79 | * |
| 80 | * @return array |
| 81 | * |
| 82 | * @since 1.0.0 |
| 83 | */ |
| 84 | public function sanitized(); |
| 85 | /** |
| 86 | * Get request data excluding specified attributes. |
| 87 | * |
| 88 | * @param array $attributes Keys to exclude. |
| 89 | * |
| 90 | * @return array |
| 91 | * |
| 92 | * @since 1.0.0 |
| 93 | */ |
| 94 | public function except(array $attributes); |
| 95 | /** |
| 96 | * Get a single attribute by key. |
| 97 | * |
| 98 | * @param string $key The key to retrieve. |
| 99 | * |
| 100 | * @return mixed|null |
| 101 | * |
| 102 | * @since 1.0.0 |
| 103 | */ |
| 104 | public function only(string $key); |
| 105 | /** |
| 106 | * Alias of `only()`. Get input value by key. |
| 107 | * |
| 108 | * @param string $key The key to retrieve. |
| 109 | * |
| 110 | * @return mixed|null |
| 111 | * |
| 112 | * @since 1.0.0 |
| 113 | */ |
| 114 | public function input(string $key); |
| 115 | /** |
| 116 | * Get a value from the request with optional default and type casting. |
| 117 | * |
| 118 | * @param string $key The key to retrieve. |
| 119 | * @param mixed $default Default value if the key doesn't exist. |
| 120 | * @param string|null $type Optional type to cast the result to: |
| 121 | * int, float, bool, string, array with proper sanitization. |
| 122 | * |
| 123 | * @return mixed |
| 124 | * |
| 125 | * @since 1.0.0 |
| 126 | */ |
| 127 | public function get(string $key, $default = null, $type = null); |
| 128 | /** |
| 129 | * Check if the request has the provided key |
| 130 | * |
| 131 | * @param string $key The key. |
| 132 | * |
| 133 | * @return bool |
| 134 | * |
| 135 | * @since 1.0.0 |
| 136 | */ |
| 137 | public function has(string $key); |
| 138 | /** |
| 139 | * Get a string value. |
| 140 | * |
| 141 | * @param string $key The key to retrieve. |
| 142 | * @param string|null $default Default value if the key doesn't exist. |
| 143 | * |
| 144 | * @return string |
| 145 | * |
| 146 | * @since 1.0.0 |
| 147 | */ |
| 148 | public function get_string(string $key, $default = null); |
| 149 | /** |
| 150 | * Alias of `get_string()`. |
| 151 | * |
| 152 | * @param string $key The key to retrieve. |
| 153 | * @param string|null $default Default value if the key doesn't exist. |
| 154 | * |
| 155 | * @return string |
| 156 | * |
| 157 | * @since 1.0.0 |
| 158 | */ |
| 159 | public function string(string $key, $default = null); |
| 160 | /** |
| 161 | * Get a safe input value with whitelist. |
| 162 | * |
| 163 | * @param string $key The key to retrieve. |
| 164 | * @param mixed $default Default value if the key doesn't exist. |
| 165 | * @param array $whitelist Array of allowed values. |
| 166 | * |
| 167 | * @return mixed |
| 168 | * |
| 169 | * @since 1.0.0 |
| 170 | */ |
| 171 | public function get_whitelisted(string $key, $default = null, array $whitelist = []); |
| 172 | /** |
| 173 | * Alias of `get_whitelisted()`. |
| 174 | * |
| 175 | * @param string $key The key to retrieve. |
| 176 | * @param mixed $default Default value if the key doesn't exist. |
| 177 | * @param array $whitelist Array of allowed values. |
| 178 | * |
| 179 | * @return mixed |
| 180 | * |
| 181 | * @since 1.0.0 |
| 182 | */ |
| 183 | public function whitelisted(string $key, $default = null, array $whitelist = []); |
| 184 | /** |
| 185 | * Get a date value. |
| 186 | * |
| 187 | * @param string $key The key to retrieve. |
| 188 | * @param string|null $default Default value if the key doesn't exist. |
| 189 | * |
| 190 | * @return string |
| 191 | * |
| 192 | * @since 1.0.0 |
| 193 | */ |
| 194 | public function get_date(string $key, $default = null); |
| 195 | /** |
| 196 | * Alias of `get_date()`. |
| 197 | * |
| 198 | * @param string $key The key to retrieve. |
| 199 | * @param string|null $default Default value if the key doesn't exist. |
| 200 | * |
| 201 | * @return string |
| 202 | * |
| 203 | * @since 1.0.0 |
| 204 | */ |
| 205 | public function date(string $key, $default = null); |
| 206 | /** |
| 207 | * Get a datetime value. |
| 208 | * |
| 209 | * @param string $key The key to retrieve. |
| 210 | * @param string|null $default Default value if the key doesn't exist. |
| 211 | * |
| 212 | * @return string |
| 213 | * |
| 214 | * @since 1.0.0 |
| 215 | */ |
| 216 | public function get_datetime(string $key, $default = null); |
| 217 | /** |
| 218 | * Alias of `get_datetime()`. |
| 219 | * |
| 220 | * @param string $key The key to retrieve. |
| 221 | * @param string|null $default Default value if the key doesn't exist. |
| 222 | * |
| 223 | * @return string |
| 224 | * |
| 225 | * @since 1.0.0 |
| 226 | */ |
| 227 | public function datetime(string $key, $default = null); |
| 228 | /** |
| 229 | * Get a text with sanitization applied. |
| 230 | * |
| 231 | * @param string $key The key to retrieve. |
| 232 | * @param string|null $default Default value if the key doesn't exist. |
| 233 | * |
| 234 | * @return string|null |
| 235 | * |
| 236 | * @since 1.0.0 |
| 237 | */ |
| 238 | public function get_text(string $key, $default = null); |
| 239 | /** |
| 240 | * Alias of `get_text()`. |
| 241 | * |
| 242 | * @param string $key The key to retrieve. |
| 243 | * @param string|null $default Default value if the key doesn't exist. |
| 244 | * |
| 245 | * @return string|null |
| 246 | * |
| 247 | * @since 1.0.0 |
| 248 | */ |
| 249 | public function text(string $key, $default = null); |
| 250 | /** |
| 251 | * Get a html supported content with sanitization applied. |
| 252 | * |
| 253 | * @param string $key The key to retrieve. |
| 254 | * @param string|null $default Default value if the key doesn't exist. |
| 255 | * |
| 256 | * @return string|null |
| 257 | * |
| 258 | * @since 1.0.0 |
| 259 | */ |
| 260 | public function get_html(string $key, $default = null); |
| 261 | /** |
| 262 | * Alias of `get_html()`. |
| 263 | * |
| 264 | * @param string $key The key to retrieve. |
| 265 | * @param string|null $default Default value if the key doesn't exist. |
| 266 | * |
| 267 | * @return string|null |
| 268 | * |
| 269 | * @since 1.0.0 |
| 270 | */ |
| 271 | public function html(string $key, $default = null); |
| 272 | /** |
| 273 | * Get a email with sanitization applied. |
| 274 | * |
| 275 | * @param string $key The key to retrieve. |
| 276 | * @param string|null $default Default value if the key doesn't exist. |
| 277 | * |
| 278 | * @return string|null |
| 279 | * |
| 280 | * @since 1.0.0 |
| 281 | */ |
| 282 | public function get_email(string $key, $default = null); |
| 283 | /** |
| 284 | * Alias of `get_email()`. |
| 285 | * |
| 286 | * @param string $key The key to retrieve. |
| 287 | * @param string|null $default Default value if the key doesn't exist. |
| 288 | * |
| 289 | * @return string|null |
| 290 | * |
| 291 | * @since 1.0.0 |
| 292 | */ |
| 293 | public function email(string $key, $default = null); |
| 294 | /** |
| 295 | * Get a url with sanitization applied. |
| 296 | * |
| 297 | * @param string $key The key to retrieve. |
| 298 | * @param string|null $default Default value if the key doesn't exist. |
| 299 | * |
| 300 | * @return string|null |
| 301 | * |
| 302 | * @since 1.0.0 |
| 303 | */ |
| 304 | public function get_url(string $key, $default = null); |
| 305 | /** |
| 306 | * Alias of `get_url()`. |
| 307 | * |
| 308 | * @param string $key The key to retrieve. |
| 309 | * @param string|null $default Default value if the key doesn't exist. |
| 310 | * |
| 311 | * @return string|null |
| 312 | * |
| 313 | * @since 1.0.0 |
| 314 | */ |
| 315 | public function url(string $key, $default = null); |
| 316 | /** |
| 317 | * Get a key value with sanitization applied. |
| 318 | * |
| 319 | * @param string $key The key to retrieve. |
| 320 | * @param string|null $default Default value if the key doesn't exist. |
| 321 | * |
| 322 | * @return string|null |
| 323 | * |
| 324 | * @since 1.0.0 |
| 325 | */ |
| 326 | public function get_key(string $key, $default = null); |
| 327 | /** |
| 328 | * Alias of `get_key()`. |
| 329 | * |
| 330 | * @param string $key The key to retrieve. |
| 331 | * @param string|null $default Default value if the key doesn't exist. |
| 332 | * |
| 333 | * @return string|null |
| 334 | * |
| 335 | * @since 1.0.0 |
| 336 | */ |
| 337 | public function key(string $key, $default = null); |
| 338 | /** |
| 339 | * Get a title value with sanitization applied. |
| 340 | * |
| 341 | * @param string $key The key to retrieve. |
| 342 | * @param string|null $default Default value if the key doesn't exist. |
| 343 | * |
| 344 | * @return string|null |
| 345 | * |
| 346 | * @since 1.0.0 |
| 347 | */ |
| 348 | public function get_title(string $key, $default = null); |
| 349 | /** |
| 350 | * Alias of `get_title()`. |
| 351 | * |
| 352 | * @param string $key The key to retrieve. |
| 353 | * @param string|null $default Default value if the key doesn't exist. |
| 354 | * |
| 355 | * @return string|null |
| 356 | * |
| 357 | * @since 1.0.0 |
| 358 | */ |
| 359 | public function title(string $key, $default = null); |
| 360 | /** |
| 361 | * Get a file name with sanitization applied. |
| 362 | * |
| 363 | * @param string $key The key to retrieve. |
| 364 | * @param string|null $default Default value if the key doesn't exist. |
| 365 | * |
| 366 | * @return string|null |
| 367 | * |
| 368 | * @since 1.0.0 |
| 369 | */ |
| 370 | public function get_file_name(string $key, $default = null); |
| 371 | /** |
| 372 | * Alias of `get_file_name()`. |
| 373 | * |
| 374 | * @param string $key The key to retrieve. |
| 375 | * @param string|null $default Default value if the key doesn't exist. |
| 376 | * |
| 377 | * @return string|null |
| 378 | * |
| 379 | * @since 1.0.0 |
| 380 | */ |
| 381 | public function file_name(string $key, $default = null); |
| 382 | /** |
| 383 | * Get mime type with sanitization applied. |
| 384 | * |
| 385 | * @param string $key The key to retrieve. |
| 386 | * @param string|null $default Default value if the key doesn't exist. |
| 387 | * |
| 388 | * @return string|null |
| 389 | * |
| 390 | * @since 1.0.0 |
| 391 | */ |
| 392 | public function get_mime_type(string $key, $default = null); |
| 393 | /** |
| 394 | * Alias of `get_mime_type()`. |
| 395 | * |
| 396 | * @param string $key The key to retrieve. |
| 397 | * @param string|null $default Default value if the key doesn't exist. |
| 398 | * |
| 399 | * @return string|null |
| 400 | * |
| 401 | * @since 1.0.0 |
| 402 | */ |
| 403 | public function mime_type(string $key, $default = null); |
| 404 | /** |
| 405 | * Get an integer value. |
| 406 | * |
| 407 | * @param string $key The key to retrieve. |
| 408 | * @param int|null $default Default value if the key doesn't exist. |
| 409 | * |
| 410 | * @return int|null |
| 411 | * |
| 412 | * @since 1.0.0 |
| 413 | */ |
| 414 | public function get_int(string $key, $default = null); |
| 415 | /** |
| 416 | * Alias of `get_int()`. |
| 417 | * |
| 418 | * @param string $key The key to retrieve. |
| 419 | * @param int|null $default Default value if the key doesn't exist. |
| 420 | * |
| 421 | * @return int|null |
| 422 | * |
| 423 | * @since 1.0.0 |
| 424 | */ |
| 425 | public function int(string $key, $default = null); |
| 426 | /** |
| 427 | * Get a boolean value. |
| 428 | * |
| 429 | * @param string $key The key to retrieve. |
| 430 | * @param bool $default Default value if the key doesn't exist. |
| 431 | * |
| 432 | * @return bool |
| 433 | * |
| 434 | * @since 1.0.0 |
| 435 | */ |
| 436 | public function get_bool(string $key, bool $default = \false); |
| 437 | /** |
| 438 | * Alias of `get_bool()`. |
| 439 | * |
| 440 | * @param string $key The key to retrieve. |
| 441 | * @param bool $default Default value if the key doesn't exist. |
| 442 | * |
| 443 | * @return bool |
| 444 | * |
| 445 | * @since 1.0.0 |
| 446 | */ |
| 447 | public function bool(string $key, bool $default = \false); |
| 448 | /** |
| 449 | * Get a float value. |
| 450 | * |
| 451 | * @param string $key The key to retrieve. |
| 452 | * @param float|null $default Default value if the key doesn't exist. |
| 453 | * |
| 454 | * @return float|null |
| 455 | * |
| 456 | * @since 1.0.0 |
| 457 | */ |
| 458 | public function get_float(string $key, $default = null); |
| 459 | /** |
| 460 | * Alias of `get_float()`. |
| 461 | * |
| 462 | * @param string $key The key to retrieve. |
| 463 | * @param float|null $default Default value if the key doesn't exist. |
| 464 | * |
| 465 | * @return float|null |
| 466 | * |
| 467 | * @since 1.0.0 |
| 468 | */ |
| 469 | public function float(string $key, $default = null); |
| 470 | /** |
| 471 | * Get an array value. |
| 472 | * |
| 473 | * @param string $key The key to retrieve. |
| 474 | * @param array|null $default Default value if the key doesn't exist. |
| 475 | * |
| 476 | * @return array|null |
| 477 | * |
| 478 | * @since 1.0.0 |
| 479 | */ |
| 480 | public function get_array(string $key, $default = null); |
| 481 | /** |
| 482 | * Alias of `get_array()`. |
| 483 | * |
| 484 | * @param string $key The key to retrieve. |
| 485 | * @param array|null $default Default value if the key doesn't exist. |
| 486 | * |
| 487 | * @return array|null |
| 488 | * |
| 489 | * @since 1.0.0 |
| 490 | */ |
| 491 | public function array(string $key, $default = null); |
| 492 | } |
| 493 |