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
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
5 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
5 days ago
Uploader.php
1 month ago
Request.php
316 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 | * Get a safe input value with whitelist. |
| 151 | * |
| 152 | * @param string $key The key to retrieve. |
| 153 | * @param mixed $default Default value if the key doesn't exist. |
| 154 | * @param array $whitelist Array of allowed values. |
| 155 | * |
| 156 | * @return mixed |
| 157 | * |
| 158 | * @since 1.0.0 |
| 159 | */ |
| 160 | public function get_whitelisted(string $key, $default = null, array $whitelist = []); |
| 161 | /** |
| 162 | * Get a date value. |
| 163 | * |
| 164 | * @param string $key The key to retrieve. |
| 165 | * @param string|null $default Default value if the key doesn't exist. |
| 166 | * |
| 167 | * @return string |
| 168 | * |
| 169 | * @since 1.0.0 |
| 170 | */ |
| 171 | public function get_date(string $key, $default = null); |
| 172 | /** |
| 173 | * Get a datetime value. |
| 174 | * |
| 175 | * @param string $key The key to retrieve. |
| 176 | * @param string|null $default Default value if the key doesn't exist. |
| 177 | * |
| 178 | * @return string |
| 179 | * |
| 180 | * @since 1.0.0 |
| 181 | */ |
| 182 | public function get_datetime(string $key, $default = null); |
| 183 | /** |
| 184 | * Get a text with sanitization applied. |
| 185 | * |
| 186 | * @param string $key The key to retrieve. |
| 187 | * @param string|null $default Default value if the key doesn't exist. |
| 188 | * |
| 189 | * @return string|null |
| 190 | * |
| 191 | * @since 1.0.0 |
| 192 | */ |
| 193 | public function get_text(string $key, $default = null); |
| 194 | /** |
| 195 | * Get a html supported content with sanitization applied. |
| 196 | * |
| 197 | * @param string $key The key to retrieve. |
| 198 | * @param string|null $default Default value if the key doesn't exist. |
| 199 | * |
| 200 | * @return string|null |
| 201 | * |
| 202 | * @since 1.0.0 |
| 203 | */ |
| 204 | public function get_html(string $key, $default = null); |
| 205 | /** |
| 206 | * Get a email with sanitization applied. |
| 207 | * |
| 208 | * @param string $key The key to retrieve. |
| 209 | * @param string|null $default Default value if the key doesn't exist. |
| 210 | * |
| 211 | * @return string|null |
| 212 | * |
| 213 | * @since 1.0.0 |
| 214 | */ |
| 215 | public function get_email(string $key, $default = null); |
| 216 | /** |
| 217 | * Get a url with sanitization applied. |
| 218 | * |
| 219 | * @param string $key The key to retrieve. |
| 220 | * @param string|null $default Default value if the key doesn't exist. |
| 221 | * |
| 222 | * @return string|null |
| 223 | * |
| 224 | * @since 1.0.0 |
| 225 | */ |
| 226 | public function get_url(string $key, $default = null); |
| 227 | /** |
| 228 | * Get a key value with sanitization applied. |
| 229 | * |
| 230 | * @param string $key The key to retrieve. |
| 231 | * @param string|null $default Default value if the key doesn't exist. |
| 232 | * |
| 233 | * @return string|null |
| 234 | * |
| 235 | * @since 1.0.0 |
| 236 | */ |
| 237 | public function get_key(string $key, $default = null); |
| 238 | /** |
| 239 | * Get a title value with sanitization applied. |
| 240 | * |
| 241 | * @param string $key The key to retrieve. |
| 242 | * @param string|null $default Default value if the key doesn't exist. |
| 243 | * |
| 244 | * @return string|null |
| 245 | * |
| 246 | * @since 1.0.0 |
| 247 | */ |
| 248 | public function get_title(string $key, $default = null); |
| 249 | /** |
| 250 | * Get a file name with sanitization applied. |
| 251 | * |
| 252 | * @param string $key The key to retrieve. |
| 253 | * @param string|null $default Default value if the key doesn't exist. |
| 254 | * |
| 255 | * @return string|null |
| 256 | * |
| 257 | * @since 1.0.0 |
| 258 | */ |
| 259 | public function get_file_name(string $key, $default = null); |
| 260 | /** |
| 261 | * Get mime type with sanitization applied. |
| 262 | * |
| 263 | * @param string $key The key to retrieve. |
| 264 | * @param string|null $default Default value if the key doesn't exist. |
| 265 | * |
| 266 | * @return string|null |
| 267 | * |
| 268 | * @since 1.0.0 |
| 269 | */ |
| 270 | public function get_mime_type(string $key, $default = null); |
| 271 | /** |
| 272 | * Get an integer value. |
| 273 | * |
| 274 | * @param string $key The key to retrieve. |
| 275 | * @param int|null $default Default value if the key doesn't exist. |
| 276 | * |
| 277 | * @return int|null |
| 278 | * |
| 279 | * @since 1.0.0 |
| 280 | */ |
| 281 | public function get_int(string $key, $default = null); |
| 282 | /** |
| 283 | * Get a boolean value. |
| 284 | * |
| 285 | * @param string $key The key to retrieve. |
| 286 | * @param bool $default Default value if the key doesn't exist. |
| 287 | * |
| 288 | * @return bool |
| 289 | * |
| 290 | * @since 1.0.0 |
| 291 | */ |
| 292 | public function get_bool(string $key, bool $default = \false); |
| 293 | /** |
| 294 | * Get a float value. |
| 295 | * |
| 296 | * @param string $key The key to retrieve. |
| 297 | * @param float|null $default Default value if the key doesn't exist. |
| 298 | * |
| 299 | * @return float|null |
| 300 | * |
| 301 | * @since 1.0.0 |
| 302 | */ |
| 303 | public function get_float(string $key, $default = null); |
| 304 | /** |
| 305 | * Get an array value. |
| 306 | * |
| 307 | * @param string $key The key to retrieve. |
| 308 | * @param array|null $default Default value if the key doesn't exist. |
| 309 | * |
| 310 | * @return array|null |
| 311 | * |
| 312 | * @since 1.0.0 |
| 313 | */ |
| 314 | public function get_array(string $key, $default = null); |
| 315 | } |
| 316 |