| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
|
| 5 |
namespace Yoast\WP\SEO\AI\HTTP_Request\Domain; |
| 6 |
|
| 7 |
/** |
| 8 |
* Class Response |
| 9 |
* Represents a response from the AI Generator API. |
| 10 |
*/ |
| 11 |
class Response { |
| 12 |
|
| 13 |
/** |
| 14 |
* The response body. |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
private $body; |
| 19 |
|
| 20 |
/** |
| 21 |
* The response code. |
| 22 |
* |
| 23 |
* @var int |
| 24 |
*/ |
| 25 |
private $response_code; |
| 26 |
|
| 27 |
/** |
| 28 |
* The response message. |
| 29 |
* |
| 30 |
* @var string |
| 31 |
*/ |
| 32 |
private $message; |
| 33 |
|
| 34 |
/** |
| 35 |
* The error code. |
| 36 |
* |
| 37 |
* @var string |
| 38 |
*/ |
| 39 |
private $error_code; |
| 40 |
|
| 41 |
/** |
| 42 |
* The missing licenses. |
| 43 |
* |
| 44 |
* @var array<string> |
| 45 |
*/ |
| 46 |
private $missing_licenses; |
| 47 |
|
| 48 |
/** |
| 49 |
* The response headers, keyed by lower-cased header name. |
| 50 |
* |
| 51 |
* @var array<string, string|array<string>> |
| 52 |
*/ |
| 53 |
private $headers; |
| 54 |
|
| 55 |
/** |
| 56 |
* Response constructor. |
| 57 |
* |
| 58 |
* @param string $body The response body. |
| 59 |
* @param int $response_code The response code. |
| 60 |
* @param string $message The response message. |
| 61 |
* @param string $error_code The error code. |
| 62 |
* @param array<string> $missing_licenses The missing licenses. |
| 63 |
* @param array<string, string|array<string>> $headers The response headers, keyed by lower-cased header name. |
| 64 |
*/ |
| 65 |
public function __construct( string $body, int $response_code, string $message, string $error_code = '', $missing_licenses = [], array $headers = [] ) { |
| 66 |
$this->body = $body; |
| 67 |
$this->response_code = $response_code; |
| 68 |
$this->message = $message; |
| 69 |
$this->error_code = $error_code; |
| 70 |
$this->missing_licenses = $missing_licenses; |
| 71 |
$this->headers = $headers; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Gets the response body. |
| 76 |
* |
| 77 |
* @return string The response body. |
| 78 |
*/ |
| 79 |
public function get_body() { |
| 80 |
return $this->body; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Gets the response code. |
| 85 |
* |
| 86 |
* @return int The response code. |
| 87 |
*/ |
| 88 |
public function get_response_code(): int { |
| 89 |
return $this->response_code; |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Gets the response message. |
| 94 |
* |
| 95 |
* @return string The response message. |
| 96 |
*/ |
| 97 |
public function get_message(): string { |
| 98 |
return $this->message; |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Gets the error code. |
| 103 |
* |
| 104 |
* @return string The error code. |
| 105 |
*/ |
| 106 |
public function get_error_code(): string { |
| 107 |
return $this->error_code; |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Gets the missing licenses. |
| 112 |
* |
| 113 |
* @return array<string> The missing licenses. |
| 114 |
*/ |
| 115 |
public function get_missing_licenses(): array { |
| 116 |
return $this->missing_licenses; |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Gets the response headers, keyed by lower-cased header name. |
| 121 |
* |
| 122 |
* @return array<string, string|array<string>> The response headers. |
| 123 |
*/ |
| 124 |
public function get_headers(): array { |
| 125 |
return $this->headers; |
| 126 |
} |
| 127 |
} |
| 128 |
|