1 | <?php |
||
35 | class Client implements ClientInterface, LoggerAwareInterface |
||
36 | { |
||
37 | |||
38 | use LoggerAware; |
||
39 | |||
40 | /** |
||
41 | * @var \Psr\Http\Message\UriInterface |
||
42 | */ |
||
43 | public $baseUri; |
||
44 | |||
45 | /** |
||
46 | * @var \XOrder\Credentials |
||
47 | */ |
||
48 | public $credentials; |
||
49 | |||
50 | /** |
||
51 | * @var \GuzzleHttp\ClientInterface |
||
52 | */ |
||
53 | public $http; |
||
54 | |||
55 | /** |
||
56 | * @var \XOrder\Contracts\SessionInterface |
||
57 | */ |
||
58 | public $session; |
||
59 | |||
60 | /** |
||
61 | * Constructor |
||
62 | * |
||
63 | * @param \XOrder\Credentials|null $credentials |
||
64 | */ |
||
65 | 42 | public function __construct(Credentials $credentials = null) |
|
70 | |||
71 | /** |
||
72 | * Logout from the |
||
73 | */ |
||
74 | 42 | public function __destruct() |
|
78 | |||
79 | /** |
||
80 | * Get the credentials. |
||
81 | * |
||
82 | * @return \XOrder\Credentials |
||
83 | */ |
||
84 | 24 | public function credentials() |
|
93 | |||
94 | /** |
||
95 | * Get the logon xml. |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | 10 | public function getLogonMessage() |
|
105 | |||
106 | /** |
||
107 | * Get the logout xml. |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | 10 | public function getLogoutMessage() |
|
117 | |||
118 | /** |
||
119 | * Build a uri based on the baseUri. |
||
120 | * |
||
121 | * @param string $path |
||
122 | * @return \Psr\Http\Message\UriInterface |
||
123 | */ |
||
124 | 20 | public function getUri($path) |
|
128 | |||
129 | /** |
||
130 | * Check if the client has the login credentials. |
||
131 | * |
||
132 | * @return boolean |
||
133 | */ |
||
134 | 24 | public function hasCredentials() |
|
138 | |||
139 | /** |
||
140 | * Check if the client has an active session. |
||
141 | * |
||
142 | * @return boolean |
||
143 | */ |
||
144 | 42 | public function hasSession() |
|
148 | |||
149 | /** |
||
150 | * Get the guzzle client. If one doesn't exist |
||
151 | * we'll create one. |
||
152 | * |
||
153 | * @return \GuzzleHttp\Client |
||
154 | */ |
||
155 | 20 | public function http() |
|
163 | |||
164 | /** |
||
165 | * Login to the Container World LoginServlet. |
||
166 | * |
||
167 | * @param \XOrder\Credentials [$credentials] |
||
168 | * @return \XOrder\Client |
||
169 | */ |
||
170 | 8 | public function login(Credentials $credentials = null) |
|
192 | |||
193 | /** |
||
194 | * End the session with the container world xOrder servlet. |
||
195 | * |
||
196 | * @return \XOrder\Response|boolean |
||
197 | */ |
||
198 | 42 | public function logout() |
|
220 | |||
221 | /** |
||
222 | * Generate a new request messsage. |
||
223 | * |
||
224 | * @param string $method |
||
225 | * @param string $uri |
||
226 | * @param array $headers |
||
227 | * @param string $body |
||
228 | * @return \Psr\Http\Message\RequestInterface |
||
229 | */ |
||
230 | 18 | public function makeRequest($method, $uri, $headers, $body) |
|
234 | |||
235 | /** |
||
236 | * Check if the HTTP request returns a valid response. |
||
237 | * |
||
238 | * @param \Psr\Http\Message\ResponseInterface $response |
||
239 | * @return boolean |
||
240 | */ |
||
241 | 16 | public function responseOK(ResponseInterface $response) |
|
245 | |||
246 | /** |
||
247 | * Send an order to the xOrder servlet. |
||
248 | * |
||
249 | * @param \XOrder\XOrder $xorder |
||
250 | * @param boolean $validate |
||
251 | * @return \XOrder\Response |
||
252 | */ |
||
253 | 4 | public function send(XOrder $xorder, $validate = false) |
|
276 | |||
277 | /** |
||
278 | * Get the session object. If one doesn't exist |
||
279 | * we'll create one. |
||
280 | * |
||
281 | * @return \XOrder\Contracts\SessionInterface |
||
282 | */ |
||
283 | 12 | public function session() |
|
292 | |||
293 | /** |
||
294 | * Set the base URI. |
||
295 | * |
||
296 | * @param Psr\Http\Message\UriInterface $uri |
||
297 | */ |
||
298 | 4 | public function setBaseUri(UriInterface $uri) |
|
303 | |||
304 | /** |
||
305 | * Set the HTP Client. |
||
306 | * |
||
307 | * @param \GuzzleHttp\ClientInterface $client |
||
308 | */ |
||
309 | 18 | public function setHttpClient(HttpClientInterface $client) |
|
314 | |||
315 | /** |
||
316 | * Send a request to the XOrder Servlet to validate |
||
317 | * the passed order. |
||
318 | * |
||
319 | * @param \XOrder\XOrder $xorder |
||
320 | * @return \XOrder\Response |
||
321 | */ |
||
322 | 4 | public function validate(XOrder $xorder) |
|
326 | } |
||
327 |