1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* @copyright Vertex. All rights reserved. https://www.vertexinc.com/
* @author Mediotype https://www.mediotype.com/
*/
namespace Vertex\Tax\Model\Plugin;
use Vertex\Tax\Model\Api\Utility\SoapClientRegistry;
use Vertex\Utility\SoapClientFactory;
/**
* Plugin to SoapClientFactory
*/
class SoapClientFactoryPlugin
{
/** @var SoapClientRegistry */
private $clientRegistry;
/**
* @param SoapClientRegistry $clientRegistry
*/
public function __construct(SoapClientRegistry $clientRegistry)
{
$this->clientRegistry = $clientRegistry;
}
/**
* After a {@see \SoapClient} is created, set it as the latest in the client registry
*
* @param SoapClientFactory $factory
* @param \SoapClient $client
* @return \SoapClient
*/
public function afterCreate(SoapClientFactory $factory, \SoapClient $client)
{
$this->clientRegistry->setLastClient($client);
return $client;
}
/**
* Add a connection timeout of 12 to the default options used by {@see SoapClientFactory}
*
* @param SoapClientFactory $factory
* @param array $options
* @return array
*/
public function afterGetDefaultOptions(SoapClientFactory $factory, array $options)
{
return array_merge(
$options,
[
'stream_context' => [
'connection_timeout' => 12
]
]
);
}
}