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
<?php
/**
* @copyright Vertex. All rights reserved. https://www.vertexinc.com/
* @author Mediotype https://www.mediotype.com/
*/
namespace Vertex\Tax\Model\Plugin;
use Magento\Framework\ObjectManagerInterface;
use Vertex\Utility\ServiceActionPerformer;
use Vertex\Utility\ServiceActionPerformerFactory;
use Vertex\Utility\SoapClientFactory;
/**
* Replaces a Vertex SDK Factory with Magento 2 dependency injection
*/
class ServiceActionPerformerFactoryPlugin
{
/** @var ObjectManagerInterface */
private $objectManager;
/**
* @param ObjectManagerInterface $objectManager
*/
public function __construct(ObjectManagerInterface $objectManager)
{
$this->objectManager = $objectManager;
}
/**
* Change Vertex SDK's Factory to utilize ObjectManager
*
* @todo Convert to afterCreate once we only support Magento 2.2+
*
* @param ServiceActionPerformerFactory $factory
* @param callable $proceed
* @param array $parameters
* @return ServiceActionPerformer
*/
public function aroundCreate(ServiceActionPerformerFactory $factory, callable $proceed, array $parameters)
{
// Call the original to trigger its checks & exceptions
$performer = $proceed($parameters);
unset($performer);
if (!isset($parameters['soapClientFactory'])) {
// This is necessary to ensure that the plugins for the SoapClientFactory are utilized
$parameters['soapClientFactory'] = $this->objectManager->get(SoapClientFactory::class);
}
return $this->objectManager->create(ServiceActionPerformer::class, $parameters);
}
}