1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PimpayBundle\Service; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class SoapClientService |
7
|
|
|
* @package PimpayBundle\Service |
8
|
|
|
*/ |
9
|
|
|
class SoapClientService extends \SoapClient |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var ApiService |
13
|
|
|
*/ |
14
|
|
|
protected $apiService; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var resource |
18
|
|
|
*/ |
19
|
|
|
protected $context; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* SoapClient constructor. |
23
|
|
|
* @param ApiService $apiService |
24
|
|
|
* @param mixed $wsdl |
25
|
|
|
* @param array|null $options |
26
|
|
|
*/ |
27
|
|
|
public function __construct(ApiService $apiService, string $wsdl, array $options = null) |
28
|
|
|
{ |
29
|
|
|
$this->apiService = $apiService; |
30
|
|
|
$this->context = stream_context_create(); |
31
|
|
|
$options = array_merge($options, ['stream_context' => $this->context]); |
32
|
|
|
|
33
|
|
|
parent::__construct($wsdl, $options); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$clientHeader = new \SoapHeader('urn:PlatformApiWsdl', 'client', 'phpSdk @ 2017-06-27 12:35:57', false); |
36
|
|
|
$versionHeader = new \SoapHeader('urn:PlatformApiWsdl', 'version', 'v2_6', false); |
37
|
|
|
$signatureHeader = new \SoapHeader('urn:PlatformApiWsdl', 'signature', null, false); |
38
|
|
|
|
39
|
|
|
$this->__setSoapHeaders([$clientHeader, $versionHeader, $signatureHeader]); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param string $request |
44
|
|
|
* @param string $location |
45
|
|
|
* @param string $action |
46
|
|
|
* @param int $version |
47
|
|
|
* @param int $oneWay |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
public function __doRequest($request, $location, $action, $version, $oneWay = 0) |
51
|
|
|
{ |
52
|
|
|
$request = $this->apiService->getCryptoHandler()->injectSignature($this, $request); |
53
|
|
|
|
54
|
|
|
return parent::__doRequest($request, $location, $action, $version, $oneWay); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return resource |
59
|
|
|
*/ |
60
|
|
|
public function getStreamContext() |
61
|
|
|
{ |
62
|
|
|
return $this->context; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
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: