SoapClientFactoryPlugin.php 1.5 KB

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