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