1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LWI\DeliveryTracking\Command; |
4
|
|
|
|
5
|
|
|
use LWI\DeliveryTracking\Adapter\ChronopostFtpAdapter; |
6
|
|
|
use LWI\DeliveryTracking\DeliveryTracking; |
7
|
|
|
use League\CLImate\CLImate; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class StatusFromReferenceCommand |
11
|
|
|
*/ |
12
|
|
|
class StatusFromReferenceCommand extends BaseCommand |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Command configuration |
16
|
|
|
*/ |
17
|
|
|
public function configure() |
18
|
|
|
{ |
19
|
|
|
$this |
20
|
|
|
->setName('statusFromRef') |
21
|
|
|
->setDescription('Get delivery status from internal reference') |
22
|
|
|
->setArgumentsDefinition([ |
23
|
|
|
'reference' => [ |
24
|
|
|
'description' => 'The internal delivery reference.', |
25
|
|
|
], |
26
|
|
|
]) |
27
|
|
|
; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param CLImate $cli |
32
|
|
|
* @param array $arguments |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
public function execute(CLImate $cli, $arguments) |
36
|
|
|
{ |
37
|
|
|
if (!$arguments['reference']) { |
38
|
|
|
$cli->error('ERROR. No reference provided.'); |
39
|
|
|
return null; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$cli->comment('Warning: this command may be slow. It may download and parse a lot of file.'); |
43
|
|
|
$cli->comment( |
44
|
|
|
'I you know the tracking number, you may want to use the `tracking:status [trackingNumber]` command' |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
$chronopostAdapter = new ChronopostFtpAdapter([ |
48
|
|
|
'host' => 'ftpserv.chronopost.fr', |
49
|
|
|
'username' => 'arconseil', |
50
|
|
|
'password' => '!arcnsl$', |
51
|
|
|
]); |
52
|
|
|
$deliveryTracking = new DeliveryTracking($chronopostAdapter); |
53
|
|
|
|
54
|
|
|
$cli->br(); |
55
|
|
|
try { |
56
|
|
|
$status = $deliveryTracking->getDeliveryStatusByInternalReference($arguments['reference']); |
57
|
|
|
|
58
|
|
|
$cli->out(sprintf( |
59
|
|
|
'Delivery #%s is <green>%s</green>', |
60
|
|
|
$arguments['reference'], |
61
|
|
|
$status |
62
|
|
|
)); |
63
|
|
|
|
64
|
|
|
$trackingNumber = $deliveryTracking->getTrackingNumberByInternalReference($arguments['reference']); |
65
|
|
|
|
66
|
|
|
$cli->whisper(sprintf('The associated tracking Number is %s.', $trackingNumber)); |
67
|
|
|
} catch (\Exception $e) { |
68
|
|
|
$cli->error(sprintf('ERROR. %s', $e->getMessage())); |
69
|
|
|
} |
70
|
|
|
$cli->br(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|