1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ThreePlCentral; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
6
|
|
|
use GuzzleHttp\Psr7; |
7
|
|
|
|
8
|
|
|
class Request implements RequestInterface |
9
|
|
|
{ |
10
|
|
|
private $id; |
11
|
|
|
private $customerId; |
12
|
|
|
private $facilityId; |
13
|
|
|
private $login; |
14
|
|
|
private $password; |
15
|
|
|
private $method; |
16
|
|
|
private $url; |
17
|
|
|
private $template; |
18
|
|
|
|
19
|
|
|
public function __construct(string $method, string $url) |
20
|
|
|
{ |
21
|
|
|
$this->method = $method; |
22
|
|
|
$this->url = $url; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function fetch(array $data): ResponseInterface |
26
|
|
|
{ |
27
|
|
|
$client = new Client(); |
28
|
|
|
$request = new Psr7\Request( |
29
|
|
|
$this->method, |
30
|
|
|
'https://secure-wms.com/webserviceexternal/contracts.asmx', |
31
|
|
|
[ |
32
|
|
|
'SOAPAction' => $this->url, |
33
|
|
|
'Content-Type' => 'text/xml; charset=utf-8' |
34
|
|
|
], |
35
|
|
|
$this->getBody($data) |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
try { |
39
|
|
|
$reponse = $client->send($request); |
40
|
|
|
var_dump($reponse); |
|
|
|
|
41
|
|
|
} catch (\Exception $error) { |
42
|
|
|
throw new Exception($error->getMessage(), $error->getCode(), $error); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
private function getBody(array $data): string |
47
|
|
|
{ |
48
|
|
|
$content = file_get_contents($this->template); |
49
|
|
|
|
50
|
|
|
$data = array_merge($data, [ |
51
|
|
|
'ThreePLID' => $this->getId(), |
52
|
|
|
'Login' => $this->getLogin(), |
53
|
|
|
'Password' => $this->getPassword(), |
54
|
|
|
'CustomerID' => $this->getCustomerId(), |
55
|
|
|
'FacilityID' => $this->getFacilityId() |
56
|
|
|
]); |
57
|
|
|
|
58
|
|
|
foreach ($data as $prop => $value) { |
59
|
|
|
$content = str_replace("{{$prop}}", $value, $content); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $content; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function setTemplate(string $template) |
66
|
|
|
{ |
67
|
|
|
$this->template = $template; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getId(): string |
71
|
|
|
{ |
72
|
|
|
return $this->id; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function setId(string $id) |
76
|
|
|
{ |
77
|
|
|
$this->id = $id; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getCustomerId(): string |
81
|
|
|
{ |
82
|
|
|
return $this->customerId; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function setCustomerId(string $customerId) |
86
|
|
|
{ |
87
|
|
|
$this->customerId = $customerId; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getFacilityId(): string |
91
|
|
|
{ |
92
|
|
|
return $this->facilityId; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function setFacilityId(string $facilityId) |
96
|
|
|
{ |
97
|
|
|
$this->facilityId = $facilityId; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function getLogin(): string |
101
|
|
|
{ |
102
|
|
|
return $this->login; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function setLogin(string $login) |
106
|
|
|
{ |
107
|
|
|
$this->login = $login; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function getPassword(): string |
111
|
|
|
{ |
112
|
|
|
return $this->password; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function setPassword(string $password) |
116
|
|
|
{ |
117
|
|
|
$this->password = $password; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|