1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace SlevomatEET; |
4
|
|
|
|
5
|
|
|
use SlevomatEET\Cryptography\CryptographyService; |
6
|
|
|
use SlevomatEET\Driver\SoapClientDriver; |
7
|
|
|
use const SOAP_1_1; |
8
|
|
|
use const WSDL_CACHE_DISK; |
9
|
|
|
|
10
|
|
|
class SoapClient extends \SoapClient |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** @var CryptographyService */ |
14
|
|
|
private $cryptoService; |
15
|
|
|
|
16
|
|
|
/** @var SoapClientDriver */ |
17
|
|
|
private $clientDriver; |
18
|
|
|
|
19
|
1 |
|
public function __construct(string $wsdl, CryptographyService $cryptoService, SoapClientDriver $clientDriver) |
20
|
|
|
{ |
21
|
|
|
$options = [ |
22
|
1 |
|
'soap_version' => SOAP_1_1, |
23
|
|
|
'encoding' => 'UTF-8', |
24
|
|
|
'trace' => true, |
25
|
|
|
'exceptions' => true, |
26
|
|
|
'cache_wsdl' => WSDL_CACHE_DISK, |
27
|
|
|
]; |
28
|
1 |
|
parent::__construct($wsdl, $options); |
|
|
|
|
29
|
1 |
|
$this->cryptoService = $cryptoService; |
30
|
1 |
|
$this->clientDriver = $clientDriver; |
31
|
1 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param mixed[] $parameters |
35
|
|
|
* @return mixed |
36
|
|
|
*/ |
37
|
1 |
|
public function OdeslaniTrzby(array $parameters) |
38
|
|
|
{ |
39
|
1 |
|
return $this->__soapCall(__FUNCTION__, ['Trzba' => $parameters]); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint |
44
|
|
|
* |
45
|
|
|
* @param string $request |
46
|
|
|
* @param string $location |
47
|
|
|
* @param string $action |
48
|
|
|
* @param int $version |
49
|
|
|
* @param int $oneWay |
50
|
|
|
* @return string|null |
51
|
|
|
*/ |
52
|
1 |
|
public function __doRequest($request, $location, $action, $version, $oneWay = 0): ?string |
53
|
|
|
{ |
54
|
1 |
|
$signedRequest = $this->cryptoService->addWSESignature($request); |
55
|
1 |
|
$response = $this->clientDriver->send($signedRequest, $location, $action, $version); |
56
|
|
|
|
57
|
|
|
if ($oneWay === 1) { |
58
|
|
|
return null; |
59
|
|
|
} |
60
|
|
|
return $response; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: