|
6 | 6 |
|
7 | 7 | use CXml\Builder; |
8 | 8 | use CXml\Context; |
9 | | -use CXml\Exception\CXmlAuthenticationInvalidException; |
10 | | -use CXml\Exception\CXmlConflictException; |
11 | | -use CXml\Exception\CXmlCredentialInvalidException; |
12 | 9 | use CXml\Exception\CXmlException; |
13 | | -use CXml\Exception\CXmlExpectationFailedException; |
14 | | -use CXml\Exception\CXmlNotAcceptableException; |
15 | | -use CXml\Exception\CXmlNotImplementedException; |
16 | | -use CXml\Exception\CXmlPreconditionFailedException; |
17 | 10 | use CXml\Handler\HandlerInterface; |
18 | 11 | use CXml\Handler\HandlerRegistryInterface; |
19 | 12 | use CXml\Model\CXml; |
|
32 | 25 |
|
33 | 26 | class Processor |
34 | 27 | { |
35 | | - // according to cXML reference document |
36 | | - private static array $exceptionMapping = [ |
37 | | - CXmlAuthenticationInvalidException::class => 401, |
38 | | - CXmlNotAcceptableException::class => 406, |
39 | | - CXmlConflictException::class => 409, |
40 | | - CXmlPreconditionFailedException::class => 412, |
41 | | - CXmlExpectationFailedException::class => 417, |
42 | | - CXmlCredentialInvalidException::class => 417, |
43 | | - CXmlNotImplementedException::class => 450, |
44 | | - ]; |
45 | | - |
46 | | - // TODO create enum for this? |
47 | | - private static array $exceptionCodeMapping = [ |
48 | | - // cxml |
49 | | - 450 => 'Not Implemented', |
50 | | - |
51 | | - // http - shamelessly copied from Symfony\Component\HttpFoundation\Response |
52 | | - 100 => 'Continue', |
53 | | - 101 => 'Switching Protocols', |
54 | | - 102 => 'Processing', // RFC2518 |
55 | | - 103 => 'Early Hints', |
56 | | - 200 => 'OK', |
57 | | - 201 => 'Created', |
58 | | - 202 => 'Accepted', |
59 | | - 203 => 'Non-Authoritative Information', |
60 | | - 204 => 'No Content', |
61 | | - 205 => 'Reset Content', |
62 | | - 206 => 'Partial Content', |
63 | | - 207 => 'Multi-Status', // RFC4918 |
64 | | - 208 => 'Already Reported', // RFC5842 |
65 | | - 226 => 'IM Used', // RFC3229 |
66 | | - 300 => 'Multiple Choices', |
67 | | - 301 => 'Moved Permanently', |
68 | | - 302 => 'Found', |
69 | | - 303 => 'See Other', |
70 | | - 304 => 'Not Modified', |
71 | | - 305 => 'Use Proxy', |
72 | | - 307 => 'Temporary Redirect', |
73 | | - 308 => 'Permanent Redirect', // RFC7238 |
74 | | - 400 => 'Bad Request', |
75 | | - 401 => 'Unauthorized', |
76 | | - 402 => 'Payment Required', |
77 | | - 403 => 'Forbidden', |
78 | | - 404 => 'Not Found', |
79 | | - 405 => 'Method Not Allowed', |
80 | | - 406 => 'Not Acceptable', |
81 | | - 407 => 'Proxy Authentication Required', |
82 | | - 408 => 'Request Timeout', |
83 | | - 409 => 'Conflict', |
84 | | - 410 => 'Gone', |
85 | | - 411 => 'Length Required', |
86 | | - 412 => 'Precondition Failed', |
87 | | - 413 => 'Payload Too Large', |
88 | | - 414 => 'URI Too Long', |
89 | | - 415 => 'Unsupported Media Type', |
90 | | - 416 => 'Range Not Satisfiable', |
91 | | - 417 => 'Expectation Failed', |
92 | | - 418 => "I'm a teapot", // RFC2324 |
93 | | - 421 => 'Misdirected Request', // RFC7540 |
94 | | - 422 => 'Unprocessable Entity', // RFC4918 |
95 | | - 423 => 'Locked', // RFC4918 |
96 | | - 424 => 'Failed Dependency', // RFC4918 |
97 | | - 425 => 'Too Early', // RFC-ietf-httpbis-replay-04 |
98 | | - 426 => 'Upgrade Required', // RFC2817 |
99 | | - 428 => 'Precondition Required', // RFC6585 |
100 | | - 429 => 'Too Many Requests', // RFC6585 |
101 | | - 431 => 'Request Header Fields Too Large', // RFC6585 |
102 | | - 451 => 'Unavailable For Legal Reasons', // RFC7725 |
103 | | - 500 => 'Internal Server Error', |
104 | | - 501 => 'Not Implemented', |
105 | | - 502 => 'Bad Gateway', |
106 | | - 503 => 'Service Unavailable', |
107 | | - 504 => 'Gateway Timeout', |
108 | | - 505 => 'HTTP Version Not Supported', |
109 | | - 506 => 'Variant Also Negotiates', // RFC2295 |
110 | | - 507 => 'Insufficient Storage', // RFC4918 |
111 | | - 508 => 'Loop Detected', // RFC5842 |
112 | | - 510 => 'Not Extended', // RFC2774 |
113 | | - 511 => 'Network Authentication Required', // RFC6585 |
114 | | - ]; |
115 | | - |
116 | 28 | public function __construct(private readonly HeaderProcessor $headerProcessor, private readonly HandlerRegistryInterface $handlerRegistry, private readonly Builder $builder, private readonly ?EventDispatcherInterface $eventDispatcher = null) |
117 | 29 | { |
118 | 30 | } |
@@ -242,15 +154,4 @@ private function processRequest(Request $request, Context $context): CXml |
242 | 154 | ->payload($response) |
243 | 155 | ->build(); |
244 | 156 | } |
245 | | - |
246 | | - public function buildResponseForException(CXmlException $exception): CXml |
247 | | - { |
248 | | - $statusCode = self::$exceptionMapping[$exception::class] ?? 500; |
249 | | - $statusText = self::$exceptionCodeMapping[$statusCode] ?? 'Unknown status'; |
250 | | - $status = new Status($statusCode, $statusText, $exception->getMessage()); |
251 | | - |
252 | | - return $this->builder |
253 | | - ->status($status) |
254 | | - ->build(); |
255 | | - } |
256 | 157 | } |
0 commit comments