| @@ 9-53 (lines=45) @@ | ||
| 6 | ||
| 7 | use Chubbyphp\ApiHttp\ApiProblem\AbstractApiProblem; |
|
| 8 | ||
| 9 | final class MethodNotAllowed extends AbstractApiProblem |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * @var string[] |
|
| 13 | */ |
|
| 14 | private $allowedMethods = []; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @param string[] $allowedMethods |
|
| 18 | * @param string|null $detail |
|
| 19 | * @param string|null $instance |
|
| 20 | */ |
|
| 21 | public function __construct(array $allowedMethods, string $detail = null, string $instance = null) |
|
| 22 | { |
|
| 23 | parent::__construct( |
|
| 24 | 'https://tools.ietf.org/html/rfc2616#section-10.4.6', |
|
| 25 | 405, |
|
| 26 | 'Method Not Allowed', |
|
| 27 | $detail, |
|
| 28 | $instance |
|
| 29 | ); |
|
| 30 | ||
| 31 | $this->allowedMethods = $allowedMethods; |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * @return array |
|
| 36 | */ |
|
| 37 | public function getHeaders(): array |
|
| 38 | { |
|
| 39 | if ([] === $this->allowedMethods) { |
|
| 40 | return []; |
|
| 41 | } |
|
| 42 | ||
| 43 | return ['Allow' => implode(',', $this->allowedMethods)]; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @return string[] |
|
| 48 | */ |
|
| 49 | public function getAllowedMethods(): array |
|
| 50 | { |
|
| 51 | return $this->allowedMethods; |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| @@ 9-53 (lines=45) @@ | ||
| 6 | ||
| 7 | use Chubbyphp\ApiHttp\ApiProblem\AbstractApiProblem; |
|
| 8 | ||
| 9 | final class NotAcceptable extends AbstractApiProblem |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * @var string[] |
|
| 13 | */ |
|
| 14 | private $acceptableMediaTypes = []; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @param string[] $acceptableMediaTypes |
|
| 18 | * @param string|null $detail |
|
| 19 | * @param string|null $instance |
|
| 20 | */ |
|
| 21 | public function __construct(array $acceptableMediaTypes, string $detail = null, string $instance = null) |
|
| 22 | { |
|
| 23 | parent::__construct( |
|
| 24 | 'https://tools.ietf.org/html/rfc2616#section-10.4.7', |
|
| 25 | 406, |
|
| 26 | 'Not Acceptable', |
|
| 27 | $detail, |
|
| 28 | $instance |
|
| 29 | ); |
|
| 30 | ||
| 31 | $this->acceptableMediaTypes = $acceptableMediaTypes; |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * @return array |
|
| 36 | */ |
|
| 37 | public function getHeaders(): array |
|
| 38 | { |
|
| 39 | if ([] === $this->acceptableMediaTypes) { |
|
| 40 | return []; |
|
| 41 | } |
|
| 42 | ||
| 43 | return ['X-Acceptable' => implode(',', $this->acceptableMediaTypes)]; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @return string[] |
|
| 48 | */ |
|
| 49 | public function getAcceptableMediaTypes(): array |
|
| 50 | { |
|
| 51 | return $this->acceptableMediaTypes; |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| @@ 9-53 (lines=45) @@ | ||
| 6 | ||
| 7 | use Chubbyphp\ApiHttp\ApiProblem\AbstractApiProblem; |
|
| 8 | ||
| 9 | final class Unauthorized extends AbstractApiProblem |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * @var string[] |
|
| 13 | */ |
|
| 14 | private $authorizationTypes = []; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @param string[] $authorizationTypes |
|
| 18 | * @param string|null $detail |
|
| 19 | * @param string|null $instance |
|
| 20 | */ |
|
| 21 | public function __construct(array $authorizationTypes, string $detail = null, string $instance = null) |
|
| 22 | { |
|
| 23 | parent::__construct( |
|
| 24 | 'https://tools.ietf.org/html/rfc2616#section-10.4.2', |
|
| 25 | 401, |
|
| 26 | 'Unauthorized', |
|
| 27 | $detail, |
|
| 28 | $instance |
|
| 29 | ); |
|
| 30 | ||
| 31 | $this->authorizationTypes = $authorizationTypes; |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * @return array |
|
| 36 | */ |
|
| 37 | public function getHeaders(): array |
|
| 38 | { |
|
| 39 | if ([] === $this->authorizationTypes) { |
|
| 40 | return []; |
|
| 41 | } |
|
| 42 | ||
| 43 | return ['WWW-Authenticate' => implode(',', $this->authorizationTypes)]; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @return string[] |
|
| 48 | */ |
|
| 49 | public function getAuthorizationTypes(): array |
|
| 50 | { |
|
| 51 | return $this->authorizationTypes; |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||