friendship ended with social-app. php is my new best friend
at main 6.4 kB view raw
1<?php 2 3declare(strict_types=1); 4 5namespace Fetch\Interfaces; 6 7use ArrayAccess; 8use Fetch\Enum\ContentType; 9use Fetch\Enum\Status; 10use Psr\Http\Message\ResponseInterface as PsrResponseInterface; 11use SimpleXMLElement; 12 13interface Response extends ArrayAccess, PsrResponseInterface 14{ 15 /** 16 * Create a new response from a base response. 17 */ 18 public static function createFromBase(PsrResponseInterface $response): self; 19 20 /** 21 * Create a response with JSON content. 22 */ 23 public static function withJson( 24 mixed $data, 25 int|Status $status = Status::OK, 26 array $headers = [], 27 int $options = 0 28 ): self; 29 30 /** 31 * Create a redirect response. 32 */ 33 public static function withRedirect( 34 string $location, 35 int|Status $status = Status::FOUND, 36 array $headers = [] 37 ): self; 38 39 /** 40 * Create a response with no content. 41 */ 42 public static function noContent(array $headers = []): self; 43 44 /** 45 * Create a response for a created resource. 46 */ 47 public static function created( 48 string $location, 49 mixed $data = null, 50 array $headers = [] 51 ): self; 52 53 /** 54 * Get the body as a JSON-decoded array or object. 55 */ 56 public function json(bool $assoc = true, bool $throwOnError = true, int $depth = 512, int $options = 0): mixed; 57 58 /** 59 * Check if the response status code is a redirect (3xx). 60 */ 61 public function redirect(): bool; 62 63 /** 64 * Get the body as a JSON-decoded object. 65 */ 66 public function object(bool $throwOnError = true): object; 67 68 /** 69 * Get the body as a JSON-decoded array. 70 */ 71 public function array(bool $throwOnError = true): array; 72 73 /** 74 * Get the body as plain text. 75 */ 76 public function text(): string; 77 78 /** 79 * Get the raw body content. 80 */ 81 public function body(): string; 82 83 /** 84 * Get the body as a stream (simulating a "blob" in JavaScript). 85 * 86 * @return resource|false 87 */ 88 public function blob(); 89 90 /** 91 * Get the body as an array buffer (binary data). 92 */ 93 public function arrayBuffer(): string; 94 95 /** 96 * Get the status text for the response. 97 */ 98 public function statusText(): string; 99 100 /** 101 * Get the status code of the response. 102 */ 103 public function status(): int; 104 105 /** 106 * Get the status as an enum. 107 */ 108 public function statusEnum(): ?Status; 109 110 /** 111 * Check if the response status code is informational (1xx). 112 */ 113 public function isInformational(): bool; 114 115 /** 116 * Check if the response status code is OK (2xx). 117 */ 118 public function ok(): bool; 119 120 /** 121 * Check if the response status code is a success (2xx). 122 */ 123 public function successful(): bool; 124 125 /** 126 * Check if the response status code is a redirection (3xx). 127 */ 128 public function isRedirection(): bool; 129 130 /** 131 * Check if the response status code is a client error (4xx). 132 */ 133 public function isClientError(): bool; 134 135 /** 136 * Check if the response status code is a server error (5xx). 137 */ 138 public function isServerError(): bool; 139 140 /** 141 * Determine if the response is a client or server error. 142 */ 143 public function failed(): bool; 144 145 /** 146 * Determine if the response indicates a client error occurred. 147 */ 148 public function clientError(): bool; 149 150 /** 151 * Determine if the response indicates a server error occurred. 152 */ 153 public function serverError(): bool; 154 155 /** 156 * Get the Content-Type header from the response. 157 */ 158 public function contentType(): ?string; 159 160 /** 161 * Get the Content-Type as an enum. 162 */ 163 public function contentTypeEnum(): ?ContentType; 164 165 /** 166 * Check if the response has JSON content. 167 */ 168 public function hasJsonContent(): bool; 169 170 /** 171 * Check if the response has HTML content. 172 */ 173 public function hasHtmlContent(): bool; 174 175 /** 176 * Check if the response has text content. 177 */ 178 public function hasTextContent(): bool; 179 180 /** 181 * Get the headers from the response as an array. 182 */ 183 public function headers(): array; 184 185 /** 186 * Get a specific header from the response. 187 */ 188 public function header(string $header): ?string; 189 190 /** 191 * Parse the body as XML. 192 */ 193 public function xml(int $options = 0, bool $throwOnError = true): ?SimpleXMLElement; 194 195 /** 196 * Check if the response has the given status code. 197 */ 198 public function isStatus(int|Status $status): bool; 199 200 /** 201 * Check if the response has a 200 status code. 202 */ 203 public function isOk(): bool; 204 205 /** 206 * Check if the response has a 201 status code. 207 */ 208 public function isCreated(): bool; 209 210 /** 211 * Check if the response has a 202 status code. 212 */ 213 public function isAccepted(): bool; 214 215 /** 216 * Check if the response has a 204 status code. 217 */ 218 public function isNoContent(): bool; 219 220 /** 221 * Check if the response has a 301 status code. 222 */ 223 public function isMovedPermanently(): bool; 224 225 /** 226 * Check if the response has a 302 status code. 227 */ 228 public function isFound(): bool; 229 230 /** 231 * Check if the response has a 400 status code. 232 */ 233 public function isBadRequest(): bool; 234 235 /** 236 * Check if the response has a 401 status code. 237 */ 238 public function isUnauthorized(): bool; 239 240 /** 241 * Check if the response has a 403 status code. 242 */ 243 public function isForbidden(): bool; 244 245 /** 246 * Check if the response has a 404 status code. 247 */ 248 public function isNotFound(): bool; 249 250 /** 251 * Check if the response has a 409 status code. 252 */ 253 public function isConflict(): bool; 254 255 /** 256 * Check if the response has a 422 status code. 257 */ 258 public function isUnprocessableEntity(): bool; 259 260 /** 261 * Check if the response has a 429 status code. 262 */ 263 public function isTooManyRequests(): bool; 264 265 /** 266 * Check if the response has a 500 status code. 267 */ 268 public function isInternalServerError(): bool; 269 270 /** 271 * Check if the response has a 503 status code. 272 */ 273 public function isServiceUnavailable(): bool; 274 275 /** 276 * Get the value for a given key from the JSON response. 277 */ 278 public function get(string $key, mixed $default = null): mixed; 279}