|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Stockbase\Integration\StockbaseApi\Client\DivideIQ; |
|
5
|
|
|
|
|
6
|
|
|
use DivideBV\PHPDivideIQ\DivideIQ; |
|
7
|
|
|
use Magento\Framework\ObjectManagerInterface; |
|
8
|
|
|
use Stockbase\Integration\Model\Config\StockbaseConfiguration; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* DivideIQ client factory. |
|
12
|
|
|
*/ |
|
13
|
|
|
class DivideIQClientFactory |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var ObjectManagerInterface |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $objectManager; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $instanceName; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var StockbaseConfiguration |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $config; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* DivideIQClientFactory constructor. |
|
32
|
|
|
* @param ObjectManagerInterface $objectManager |
|
33
|
|
|
* @param StockbaseConfiguration $config |
|
34
|
|
|
* @param string $instanceName |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct( |
|
37
|
|
|
ObjectManagerInterface $objectManager, |
|
38
|
|
|
StockbaseConfiguration $config, |
|
39
|
|
|
$instanceName = DivideIQ::class |
|
40
|
|
|
) { |
|
41
|
|
|
$this->objectManager = $objectManager; |
|
42
|
|
|
$this->instanceName = $instanceName; |
|
43
|
|
|
$this->config = $config; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Create class instance with specified parameters |
|
48
|
|
|
* |
|
49
|
|
|
* @param array $data |
|
50
|
|
|
* @return DivideIQ |
|
51
|
|
|
*/ |
|
52
|
|
|
public function create(array $data = []) |
|
53
|
|
|
{ |
|
54
|
|
|
//TODO: Cache authentication state using DivideIQ::fromJson() and DivideIQ::toJson() |
|
55
|
|
|
|
|
56
|
|
|
$data = array_merge([ |
|
57
|
|
|
'username' => $this->config->getUsername(), |
|
58
|
|
|
'password' => $this->config->getPassword(), |
|
59
|
|
|
'environment' => $this->config->getEnvironment(), |
|
60
|
|
|
], $data); |
|
61
|
|
|
|
|
62
|
|
|
return $this->objectManager->create($this->instanceName, $data); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|