1 | <?php |
||
10 | class WebhookResponse |
||
11 | { |
||
12 | /** |
||
13 | * @var int |
||
14 | */ |
||
15 | protected $httpStatusCode; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $body; |
||
21 | |||
22 | /** |
||
23 | * @var Response |
||
24 | */ |
||
25 | protected $symfonyResponse; |
||
26 | |||
27 | /** |
||
28 | * @param \Exception $e |
||
29 | * |
||
30 | * @return WebhookResponse |
||
31 | */ |
||
32 | public static function fromException(\Exception $e) |
||
40 | |||
41 | /** |
||
42 | * @param string $xsollaErrorCode |
||
43 | * @param string $message |
||
44 | * @param int $httpStatus |
||
45 | * |
||
46 | * @return WebhookResponse |
||
47 | */ |
||
48 | public static function fromErrorCode($xsollaErrorCode, $message = '', $httpStatus = 500) |
||
49 | { |
||
50 | $body = array( |
||
51 | 'error' => array( |
||
52 | 'code' => $xsollaErrorCode, |
||
53 | 'message' => $message, |
||
54 | ), |
||
55 | ); |
||
56 | $encodedBody = XsollaClient::jsonEncode($body); |
||
57 | |||
58 | return new static($httpStatus, $encodedBody); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param int $httpStatusCode |
||
63 | * @param string $body |
||
64 | */ |
||
65 | 3 | public function __construct($httpStatusCode = 204, $body = null) |
|
66 | { |
||
67 | 3 | $this->symfonyResponse = new Response($body, $httpStatusCode); |
|
68 | 3 | $this->symfonyResponse->headers->set('x-xsolla-sdk', Version::getVersion()); |
|
69 | 3 | if ($body) { |
|
|
|||
70 | 3 | $contentType = 'application/json'; |
|
71 | } else { |
||
72 | $contentType = 'text/plain'; |
||
73 | } |
||
74 | 3 | $this->symfonyResponse->headers->set('content-type', $contentType); |
|
75 | 3 | } |
|
76 | |||
77 | /** |
||
78 | * @return Response |
||
79 | */ |
||
80 | 3 | public function getSymfonyResponse() |
|
84 | |||
85 | 9 | protected function validateStringParameter($name, $value) |
|
86 | { |
||
98 | } |
||
99 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: