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