1: <?php
2: namespace Worldline\Connect\Sdk\Communication;
3:
4: /**
5: * Class ResponseClassMap
6: *
7: * @package Worldline\Connect\Sdk\Communication
8: */
9: class ResponseClassMap
10: {
11: /**
12: * @var string
13: */
14: public string $defaultSuccessResponseClassName = '';
15:
16: /**
17: * @var string
18: */
19: public string $defaultErrorResponseClassName = '';
20:
21: /**
22: * @var string[]
23: */
24: private array $responseClassNamesByHttpStatusCode = array();
25:
26: /**
27: * @param int $httpStatusCode
28: * @param string $responseClassName
29: *
30: * @return $this
31: */
32: public function addResponseClassName(int $httpStatusCode, string $responseClassName): ResponseClassMap
33: {
34: $this->responseClassNamesByHttpStatusCode[$httpStatusCode] = $responseClassName;
35: return $this;
36: }
37:
38: /**
39: * @param int $httpStatusCode
40: *
41: * @return string
42: */
43: public function getResponseClassName(int $httpStatusCode): string
44: {
45: if (array_key_exists($httpStatusCode, $this->responseClassNamesByHttpStatusCode)) {
46: return $this->responseClassNamesByHttpStatusCode[$httpStatusCode];
47: }
48: if ($httpStatusCode < 400) {
49: return $this->defaultSuccessResponseClassName;
50: }
51: return $this->defaultErrorResponseClassName;
52: }
53: }
54: