1 | <?php |
||
18 | class ChronopostFtpAdapter extends AbstractFtpAdapter implements DeliveryServiceInterface |
||
19 | { |
||
20 | use ExceptionThrower, ChronopostCodesTransformer; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $fileStructure = [ |
||
26 | 'accountNumber' => 8, |
||
27 | 'subAccountNumber' => 3, |
||
28 | 'date' => 8, |
||
29 | 'expeditionRef' => 35, |
||
30 | 'target' => 35, |
||
31 | 'chronopostNumber' => 13, |
||
32 | 'chronopostBarcode' => 45, |
||
33 | 'status' => 3, |
||
34 | 'statusReason' => 3, |
||
35 | 'statusDate' => 8, |
||
36 | 'statusTime' => 4, |
||
37 | 'zipcode' => 9, |
||
38 | 'receiver' => 35, |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * File pattern to retrieve, will be validated by preg_match |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $filePattern = '/CHRARCONSEIL_EDP02_40478001_/'; |
||
47 | |||
48 | /** |
||
49 | * @var FixedWidthColumnsParser |
||
50 | */ |
||
51 | protected $fixedWidthParser; |
||
52 | |||
53 | |||
54 | /** |
||
55 | * Paths of the already downloaded files |
||
56 | * |
||
57 | * @var array |
||
58 | */ |
||
59 | protected $downloadedFiles = []; |
||
60 | |||
61 | /** |
||
62 | * Parsed events locally and temporary stored |
||
63 | * |
||
64 | * @var array | DeliveryEvent[] |
||
65 | */ |
||
66 | protected $events = []; |
||
67 | |||
68 | /** |
||
69 | * Parsed events locally and temporary stored, indexed by internal number |
||
70 | * |
||
71 | * @var array | DeliveryEvent[] |
||
72 | */ |
||
73 | protected $eventsByInternalNumber = []; |
||
74 | |||
75 | /** |
||
76 | * Number of file parsed while searching for a delivery before it throws a DataNotFoundException |
||
77 | * |
||
78 | * @var int |
||
79 | */ |
||
80 | protected $depth = 168;// 1 week |
||
81 | |||
82 | /** |
||
83 | * ChronopostFtpAdapter constructor. |
||
84 | * @param array $config |
||
85 | */ |
||
86 | public function __construct(array $config) |
||
94 | |||
95 | /** |
||
96 | * @param string $trackingNumber |
||
97 | * |
||
98 | * @return DeliveryStatus |
||
99 | */ |
||
100 | public function getDeliveryStatus($trackingNumber) |
||
104 | |||
105 | /** |
||
106 | * @param array $trackingNumbers |
||
107 | * |
||
108 | * @return array | DeliveryStatus[] |
||
109 | */ |
||
110 | public function getDeliveryStatuses($trackingNumbers) |
||
120 | |||
121 | |||
122 | /** |
||
123 | * @param $trackingNumber |
||
124 | * |
||
125 | * @return DeliveryEvent |
||
126 | * |
||
127 | * @throws DataNotFoundException |
||
128 | */ |
||
129 | public function getLastEvent($trackingNumber) |
||
143 | |||
144 | /** |
||
145 | * @param array $trackingNumbers |
||
146 | * |
||
147 | * @return array | DeliveryEvent[] |
||
148 | */ |
||
149 | public function getLastEventForMultipleDeliveries($trackingNumbers) |
||
159 | |||
160 | /** |
||
161 | * @param string $reference |
||
162 | * |
||
163 | * @return string |
||
164 | */ |
||
165 | public function getTrackingNumberByInternalReference($reference) |
||
179 | |||
180 | /** |
||
181 | * @param array $references |
||
182 | * |
||
183 | * @return void |
||
184 | */ |
||
185 | public function getTrackingNumbersByInternalReferences($references) |
||
189 | |||
190 | |||
191 | /** |
||
192 | * Retrieve one more file and save the events it in the local store if the are more recent |
||
193 | */ |
||
194 | protected function retrieveOneMoreFile() |
||
214 | |||
215 | /** |
||
216 | * Retrieve the path of the more recent unread file |
||
217 | * so if a new file is remotely created before this method is called, its path will be returned |
||
218 | * |
||
219 | * @return string |
||
220 | */ |
||
221 | protected function getLastUnreadFilePath() |
||
251 | |||
252 | /** |
||
253 | * @param $path |
||
254 | * |
||
255 | * @return array | DeliveryEvent[] |
||
256 | */ |
||
257 | protected function retrieveFileEvents($path) |
||
286 | } |
||
287 |
This check looks for type mismatches where the missing type is
false
. This is usually indicative of an error condtion.Consider the follow example
This function either returns a new
DateTime
object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returnedfalse
before passing on the value to another function or method that may not be able to handle afalse
.