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