|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Larium\Pay\Client; |
|
6
|
|
|
|
|
7
|
|
|
use Http\Discovery\Psr17FactoryDiscovery; |
|
8
|
|
|
use Psr\Http\Message\RequestInterface; |
|
9
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
10
|
|
|
|
|
11
|
|
|
class XmlClient extends AbstractClient |
|
12
|
|
|
{ |
|
13
|
|
|
private array $headers = []; |
|
14
|
|
|
|
|
15
|
|
|
public function __construct( |
|
16
|
|
|
private readonly string $uri, |
|
17
|
|
|
array $options = [] |
|
18
|
|
|
) { |
|
19
|
|
|
$this->options = $options; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function addHeader(string $name, string $value): void |
|
23
|
|
|
{ |
|
24
|
|
|
$this->headers[$name] = $value; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Post given xml string to remote gateway. |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $xml |
|
31
|
|
|
* @return array @see self::resolveResponse |
|
32
|
|
|
*/ |
|
33
|
|
|
public function post(string $xml): array |
|
34
|
|
|
{ |
|
35
|
|
|
$factory = Psr17FactoryDiscovery::findRequestFactory(); |
|
36
|
|
|
$request = $factory->createRequest('POST', $this->uri, $this->headers, $xml); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
return $this->resolveResponse($this->sendRequest($request)); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Resolve the response from client. |
|
43
|
|
|
* |
|
44
|
|
|
* @param ResponseInterface $response |
|
45
|
|
|
* @return array An array with following values: |
|
46
|
|
|
* 'status' : The Http status of response |
|
47
|
|
|
* 'headers' : An array of response headers |
|
48
|
|
|
* 'body' : The response string. |
|
49
|
|
|
* 'raw_response': The raw body response for logging purposes. |
|
50
|
|
|
* 'raw_request' : The raw body request for logging purposes. |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function resolveResponse(ResponseInterface $response): array |
|
53
|
|
|
{ |
|
54
|
|
|
$body = $response->getBody()->__toString(); |
|
55
|
|
|
|
|
56
|
|
|
return [ |
|
57
|
|
|
'status' => $response->getStatusCode(), |
|
58
|
|
|
'headers' => $response->getHeaders(), |
|
59
|
|
|
'body' => $body, |
|
60
|
|
|
'raw_response' => $body, |
|
61
|
|
|
'raw_request' => $this->rawRequest, |
|
62
|
|
|
]; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
protected function authenticate(RequestInterface $request): RequestInterface |
|
66
|
|
|
{ |
|
67
|
|
|
return $request; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.