1 | <?php |
||
33 | class FetchCommand extends Command |
||
34 | { |
||
35 | use LoggerAwareTrait; |
||
36 | |||
37 | /** |
||
38 | * @var ManagerInterface |
||
39 | */ |
||
40 | protected $manager; |
||
41 | |||
42 | /** |
||
43 | * @var SourcesRegistryInterface |
||
44 | */ |
||
45 | protected $sourcesRegistry; |
||
46 | |||
47 | /** |
||
48 | * @var SymfonyStyle |
||
49 | */ |
||
50 | protected $outputStyle; |
||
51 | |||
52 | /** |
||
53 | * @var NotificationInterface[] |
||
54 | */ |
||
55 | protected $successNotifications; |
||
56 | |||
57 | /** |
||
58 | * @var NotificationInterface[] |
||
59 | */ |
||
60 | protected $errorNotifications; |
||
61 | |||
62 | public function __construct(ManagerInterface $manager, SourcesRegistryInterface $sourcesRegistry) |
||
70 | |||
71 | /** |
||
72 | * Add success notification to command notifications stack. |
||
73 | * |
||
74 | * @param NotificationInterface $notification Success notification to add. |
||
75 | * @return FetchCommand $this Fluent interface. |
||
76 | */ |
||
77 | public function addSuccessNotification(NotificationInterface $notification) |
||
82 | |||
83 | /** |
||
84 | * Add error notification to command notifications stack. |
||
85 | * |
||
86 | * @param NotificationInterface $notification Error notification to add. |
||
87 | * @return FetchCommand $this Fluent interface. |
||
88 | */ |
||
89 | public function addErrorNotification(NotificationInterface $notification) |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | protected function configure() |
||
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | protected function execute(InputInterface $input, OutputInterface $output) |
||
141 | |||
142 | /** |
||
143 | * Clean date from console input. |
||
144 | * |
||
145 | * @param InputInterface $input Console input. |
||
146 | * @param OutputStyle $outputStyle Output style to use. |
||
147 | * @return FetchCommand $this Fluent interface. |
||
148 | * |
||
149 | * @throws \Exception |
||
150 | */ |
||
151 | protected function cleanInputDate(InputInterface $input, OutputStyle $outputStyle) |
||
170 | |||
171 | /** |
||
172 | * Clean sources from console input. |
||
173 | * |
||
174 | * @param InputInterface $input Console input. |
||
175 | * @param OutputStyle $outputStyle Output style to use. |
||
176 | * @return FetchCommand $this Fluent interface. |
||
177 | * |
||
178 | * @throws \Exception |
||
179 | */ |
||
180 | protected function cleanInputSources(InputInterface $input, OutputStyle $outputStyle) |
||
204 | |||
205 | /** |
||
206 | * Display command begin note. |
||
207 | * |
||
208 | * @param InputInterface $input Console input. |
||
209 | * @param OutputStyle $outputStyle Console style. |
||
210 | * @return FetchCommand $this Fluent interface. |
||
211 | */ |
||
212 | protected function displayCommandBegin(InputInterface $input, OutputStyle $outputStyle) |
||
225 | |||
226 | /** |
||
227 | * Do fetch rates. |
||
228 | * |
||
229 | * @param InputInterface $input Console input. |
||
230 | * @return RateInterface[] Fetched rates. |
||
231 | * @throws \Exception |
||
232 | */ |
||
233 | protected function doFetch(InputInterface $input) |
||
260 | |||
261 | /** |
||
262 | * Display command success note. |
||
263 | * |
||
264 | * @param OutputStyle $outputStyle |
||
265 | * @return FetchCommand $this Fluent interface. |
||
266 | */ |
||
267 | protected function displayCommandSuccess(OutputStyle $outputStyle) |
||
272 | |||
273 | /** |
||
274 | * Display command error note. |
||
275 | * |
||
276 | * @param OutputStyle $outputStyle |
||
277 | * @return FetchCommand $this Fluent interface. |
||
278 | */ |
||
279 | protected function displayCommandError(OutputStyle $outputStyle) |
||
284 | |||
285 | /** |
||
286 | * Dispatch success notifications. |
||
287 | * |
||
288 | * @param null|array $source Sources for which command is executed. |
||
289 | * @param \DateTime $date Date for which rates are fetched. |
||
290 | * @param RateInterface[] $rates Fetched rates |
||
291 | * @return FetchCommand $this Fluent interface. |
||
292 | */ |
||
293 | protected function dispatchSuccessNotifications($source, \DateTime $date, array $rates) |
||
306 | |||
307 | /** |
||
308 | * Dispatch error notifications. |
||
309 | * |
||
310 | * @param null|array $source Sources for which command is executed. |
||
311 | * @param \DateTime $date Date for which rates are fetched. |
||
312 | * @return FetchCommand $this Fluent interface. |
||
313 | */ |
||
314 | protected function dispatchErrorNotifications($source, \DateTime $date) |
||
326 | } |
||
327 |