1
|
|
|
<?php |
2
|
|
|
namespace ParcelValue\ApiClient\Domain\Shipments; |
3
|
|
|
|
4
|
|
|
use WebServCo\Framework\CliResponse; |
5
|
|
|
|
6
|
|
|
final class ShipmentsCommand extends \ParcelValue\ApiClient\AbstractController |
7
|
|
|
{ |
8
|
|
|
protected $logger; |
9
|
|
|
protected $curlBrowser; |
10
|
|
|
|
11
|
|
|
protected $httpResponse; |
12
|
|
|
protected $responseStatus; |
13
|
|
|
protected $responseContent; |
14
|
|
|
protected $responseHeaders; |
15
|
|
|
|
16
|
|
|
public function __construct() |
17
|
|
|
{ |
18
|
|
|
parent::__construct(); |
19
|
|
|
|
20
|
|
|
$this->repository = new ShipmentsRepository($this->outputLoader); |
21
|
|
|
|
22
|
|
|
$this->logger = new \WebServCo\Framework\FileLogger( |
23
|
|
|
__FUNCTION__, |
24
|
|
|
sprintf('%svar/log/', $this->data('path/project', '')), |
25
|
|
|
$this->request() |
26
|
|
|
); |
27
|
|
|
$this->curlBrowser = new \WebServCo\Framework\CurlBrowser($this->logger); |
28
|
|
|
if (\WebServCo\Framework\Environment::ENV_DEV == $this->config()->getEnv()) { |
29
|
|
|
$this->curlBrowser->setSkipSSlVerification(true); |
30
|
|
|
} |
31
|
|
|
$this->curlBrowser->setRequestHeader('Accept', \WebServCo\Api\JsonApi\Structure::CONTENT_TYPE); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function create($clientId, $clientKey, $serverKey) |
35
|
|
|
{ |
36
|
|
|
$this->outputCli(__METHOD__, true); |
37
|
|
|
|
38
|
|
|
$url = sprintf( |
39
|
|
|
'%s%s/shipments', |
40
|
|
|
$this->config()->get('app/api/url'), |
41
|
|
|
$this->config()->get('app/api/version') |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
$jwt = \ParcelValue\Api\AuthenticationToken::generate($clientId, $clientKey, $serverKey); |
45
|
|
|
$this->curlBrowser->setRequestHeader('Authorization', sprintf('Bearer %s', $jwt)); |
46
|
|
|
|
47
|
|
|
$postData = []; |
48
|
|
|
|
49
|
|
|
$this->outputCli('---', true); |
50
|
|
|
$this->outputCli('REQUEST', true); |
51
|
|
|
$this->outputCli(sprintf('POST %s', $url), true); |
52
|
|
|
$this->outputCli(sprintf('Headers: %s', print_r($this->curlBrowser->getRequestHeaders(), true)), true); |
|
|
|
|
53
|
|
|
$this->outputCli(sprintf('POST data: %s', print_r($postData, true)), true); |
54
|
|
|
|
55
|
|
|
$this->httpResponse = $this->curlBrowser->post($url, $postData); |
56
|
|
|
$this->responseStatus = $this->httpResponse->getStatus(); |
57
|
|
|
$this->responseHeaders = $this->httpResponse->getHeaders(); |
58
|
|
|
$this->responseContent = $this->httpResponse->getContent(); |
59
|
|
|
|
60
|
|
|
$this->outputCli('---', true); |
61
|
|
|
$this->outputCli('RESPONSE', true); |
62
|
|
|
$this->outputCli(sprintf('Status code: %s', $this->responseStatus), true); |
63
|
|
|
$this->outputCli(sprintf('Headers: %s', print_r($this->responseHeaders, true)), true); |
64
|
|
|
$this->outputCli(sprintf('Content: %s', print_r(json_decode($this->responseContent), true)), true); |
65
|
|
|
//$this->outputCli(var_export($this->responseStatus), true); |
66
|
|
|
//$this->outputCli(var_export($this->responseHeaders), true); |
67
|
|
|
//$this->outputCli(var_export($this->responseContent), true); |
68
|
|
|
|
69
|
|
|
//$this->outputCli('', true); |
70
|
|
|
return new CliResponse('', true); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.