1 | <?php |
||
33 | class ProblemDetails implements \JsonSerializable |
||
34 | { |
||
35 | const MIME_TYPE_JSON = 'application/problem+json'; |
||
36 | const REGEX_NAMES = '/^[a-z][a-z0-9_]{2,}$/i'; |
||
37 | |||
38 | /** |
||
39 | * @var \Psr\Http\Message\UriInterface An absolute URI that identifies the problem type |
||
40 | */ |
||
41 | protected $type; |
||
42 | /** |
||
43 | * @var string A short, human-readable summary of the problem type |
||
44 | */ |
||
45 | protected $title; |
||
46 | /** |
||
47 | * @var int The HTTP status code generated by the origin server for this occurrence of the problem |
||
48 | */ |
||
49 | protected $status; |
||
50 | /** |
||
51 | * @var string A human-readable explanation specific to this occurrence of the problem |
||
52 | */ |
||
53 | protected $detail; |
||
54 | /** |
||
55 | * @var \Psr\Http\Message\UriInterface An absolute URI that identifies the specific occurrence of the problem |
||
56 | */ |
||
57 | protected $instance; |
||
58 | /** |
||
59 | * @var array<string,mixed> Map of `string` names to `mixed` values |
||
60 | */ |
||
61 | protected $extensions = []; |
||
62 | /** |
||
63 | * @var array Cached output |
||
64 | */ |
||
65 | protected $output; |
||
66 | |||
67 | /** |
||
68 | * Creates a new ProblemDetails. |
||
69 | * |
||
70 | * The `extensions` parameter, if provided, must be an associative array |
||
71 | * matching names to values. Each name must follow the guidelines in the |
||
72 | * RFC, namely start with a letter, be at least three characters long, and |
||
73 | * only contain alpha, digit, and the underscore. The values can be of any |
||
74 | * type, but be aware that the values must be easily converted to JSON. You |
||
75 | * pretty much always want these values to be immutable. |
||
76 | * |
||
77 | * @param \Psr\Http\Message\UriInterface|null $type An absolute URI that identifies the problem type |
||
78 | * @param string|null $title A short, human-readable summary of the problem type |
||
79 | * @param int $status The HTTP status code generated by the origin server for this occurrence of the problem |
||
80 | * @param string|null $detail A human-readable explanation specific to this occurrence of the problem |
||
81 | * @param \Psr\Http\Message\UriInterface|null $instance An absolute URI that identifies the specific occurrence of the problem |
||
82 | * @param array $extensions Additional members to the ProblemDetails |
||
83 | */ |
||
84 | 8 | public function __construct(UriInterface $type = null, string $title = null, int $status = 0, string $detail = null, \Psr\Http\Message\UriInterface $instance = null, array $extensions = []) |
|
98 | |||
99 | /** |
||
100 | * Gets the absolute URI that identifies the problem type |
||
101 | * |
||
102 | * @return \Psr\Http\Message\UriInterface|null The problem type URI (or null) |
||
103 | */ |
||
104 | 1 | public function getType(): ?UriInterface |
|
108 | |||
109 | /** |
||
110 | * Gets the short, human-readable summary of the problem type. |
||
111 | * |
||
112 | * @return string|null A summary of the problem type |
||
113 | */ |
||
114 | 1 | public function getTitle(): ?string |
|
118 | |||
119 | /** |
||
120 | * Gets the HTTP status code generated by the origin server for this occurrence of the problem |
||
121 | * |
||
122 | * @return int The status code |
||
123 | */ |
||
124 | 1 | public function getStatus(): int |
|
128 | |||
129 | /** |
||
130 | * Gets a human readable explanation specific to this occurrence of the problem. |
||
131 | * |
||
132 | * @return string|null An explanation specific to this occurrence of the problem |
||
133 | */ |
||
134 | 1 | public function getDetail(): ?string |
|
138 | |||
139 | /** |
||
140 | * Gets the absolute URI that identifies the specific occurrence of the problem. |
||
141 | * |
||
142 | * @return \Psr\Http\Message\UriInterface|null The URI that identifies the specific occurrence of the problem (or null) |
||
143 | */ |
||
144 | 1 | public function getInstance(): ?UriInterface |
|
148 | |||
149 | /** |
||
150 | * Gets an array of any extension members defined. |
||
151 | * |
||
152 | * @return array Any extension members, never null. |
||
153 | */ |
||
154 | 1 | public function getExtensions(): array |
|
158 | |||
159 | /** |
||
160 | * Returns a JSON representation of this problem. |
||
161 | * |
||
162 | * @return string The JSON representation |
||
163 | */ |
||
164 | 1 | public function __toString(): string |
|
168 | |||
169 | /** |
||
170 | * A JSON representation of this problem. |
||
171 | * |
||
172 | * @return string The JSON representation |
||
173 | */ |
||
174 | 6 | public function toJson(): string |
|
178 | |||
179 | /** |
||
180 | * Gets a serializable representation of this problem. |
||
181 | * |
||
182 | * @return array<string,mixed> This problem detail as an associative array |
||
183 | */ |
||
184 | 6 | public function toArray(): array |
|
206 | |||
207 | /** |
||
208 | * Returns the JSON representation. |
||
209 | * |
||
210 | * @return array<string,mixed> This problem detail as an associative array |
||
211 | */ |
||
212 | 3 | public function jsonSerialize() |
|
216 | |||
217 | /** |
||
218 | * Adds this problem detail to a PSR-7 HTTP response. |
||
219 | * |
||
220 | * @param ResponseInterface $response The HTTP response |
||
221 | * @return ResponseInterface The new response |
||
222 | */ |
||
223 | 1 | public function send(ResponseInterface $response): ResponseInterface |
|
228 | } |
||
229 |