@@ 9-64 (lines=56) @@ | ||
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 $title |
|
19 | * @param string|null $detail |
|
20 | * @param string|null $instance |
|
21 | */ |
|
22 | public function __construct(array $allowedMethods, string $title, string $detail = null, string $instance = null) |
|
23 | { |
|
24 | parent::__construct($title, $detail, $instance); |
|
25 | ||
26 | $this->allowedMethods = $allowedMethods; |
|
27 | } |
|
28 | ||
29 | /** |
|
30 | * @return int |
|
31 | */ |
|
32 | public function getStatus(): int |
|
33 | { |
|
34 | return 405; |
|
35 | } |
|
36 | ||
37 | /** |
|
38 | * @return array |
|
39 | */ |
|
40 | public function getHeaders(): array |
|
41 | { |
|
42 | if ([] === $this->allowedMethods) { |
|
43 | return []; |
|
44 | } |
|
45 | ||
46 | return ['Allow' => implode(',', $this->allowedMethods)]; |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * @return string |
|
51 | */ |
|
52 | public function getType(): string |
|
53 | { |
|
54 | return 'https://tools.ietf.org/html/rfc2616#section-10.4.6'; |
|
55 | } |
|
56 | ||
57 | /** |
|
58 | * @return string[] |
|
59 | */ |
|
60 | public function getAllowedMethods(): array |
|
61 | { |
|
62 | return $this->allowedMethods; |
|
63 | } |
|
64 | } |
|
65 |
@@ 9-64 (lines=56) @@ | ||
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 $title |
|
19 | * @param string|null $detail |
|
20 | * @param string|null $instance |
|
21 | */ |
|
22 | public function __construct(array $acceptableMediaTypes, string $title, string $detail = null, string $instance = null) |
|
23 | { |
|
24 | parent::__construct($title, $detail, $instance); |
|
25 | ||
26 | $this->acceptableMediaTypes = $acceptableMediaTypes; |
|
27 | } |
|
28 | ||
29 | /** |
|
30 | * @return int |
|
31 | */ |
|
32 | public function getStatus(): int |
|
33 | { |
|
34 | return 406; |
|
35 | } |
|
36 | ||
37 | /** |
|
38 | * @return array |
|
39 | */ |
|
40 | public function getHeaders(): array |
|
41 | { |
|
42 | if ([] === $this->acceptableMediaTypes) { |
|
43 | return []; |
|
44 | } |
|
45 | ||
46 | return ['X-Acceptable' => implode(',', $this->acceptableMediaTypes)]; |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * @return string |
|
51 | */ |
|
52 | public function getType(): string |
|
53 | { |
|
54 | return 'https://tools.ietf.org/html/rfc2616#section-10.4.7'; |
|
55 | } |
|
56 | ||
57 | /** |
|
58 | * @return string[] |
|
59 | */ |
|
60 | public function getAcceptableMediaTypes(): array |
|
61 | { |
|
62 | return $this->acceptableMediaTypes; |
|
63 | } |
|
64 | } |
|
65 |
@@ 9-64 (lines=56) @@ | ||
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 $title |
|
19 | * @param string|null $detail |
|
20 | * @param string|null $instance |
|
21 | */ |
|
22 | public function __construct(array $authorizationTypes, string $title, string $detail = null, string $instance = null) |
|
23 | { |
|
24 | parent::__construct($title, $detail, $instance); |
|
25 | ||
26 | $this->authorizationTypes = $authorizationTypes; |
|
27 | } |
|
28 | ||
29 | /** |
|
30 | * @return int |
|
31 | */ |
|
32 | public function getStatus(): int |
|
33 | { |
|
34 | return 401; |
|
35 | } |
|
36 | ||
37 | /** |
|
38 | * @return array |
|
39 | */ |
|
40 | public function getHeaders(): array |
|
41 | { |
|
42 | if ([] === $this->authorizationTypes) { |
|
43 | return []; |
|
44 | } |
|
45 | ||
46 | return ['WWW-Authenticate' => implode(',', $this->authorizationTypes)]; |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * @return string |
|
51 | */ |
|
52 | public function getType(): string |
|
53 | { |
|
54 | return 'https://tools.ietf.org/html/rfc2616#section-10.4.2'; |
|
55 | } |
|
56 | ||
57 | /** |
|
58 | * @return string[] |
|
59 | */ |
|
60 | public function getAuthorizationTypes(): array |
|
61 | { |
|
62 | return $this->authorizationTypes; |
|
63 | } |
|
64 | } |
|
65 |