|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Jean Silva <[email protected]> |
|
4
|
|
|
* @license MIT |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace Jeancsil\FlightSpy\Command; |
|
7
|
|
|
|
|
8
|
|
|
use Jeancsil\FlightSpy\Command\Entity\Parameter; |
|
9
|
|
|
use Jeancsil\FlightSpy\Facade\MultiDealFacade; |
|
10
|
|
|
use Jeancsil\FlightSpy\Validator\ValidatorInterface; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
14
|
|
|
use Psr\Log\LoggerInterface; |
|
15
|
|
|
|
|
16
|
|
|
class SkyscannerCommand extends ContainerAwareCommand |
|
17
|
|
|
{ |
|
18
|
|
|
protected function configure() |
|
19
|
|
|
{ |
|
20
|
|
|
$this |
|
21
|
|
|
->setName('flightspy:skyscanner:live_prices') |
|
22
|
|
|
->setDescription('Look for live prices in Skyscanner for the determined filters') |
|
23
|
|
|
->addOption( |
|
24
|
|
|
Parameter::FILE, |
|
25
|
|
|
null, |
|
26
|
|
|
InputOption::VALUE_OPTIONAL, |
|
27
|
|
|
'Load all your trips watcher from a config file (JSON)' |
|
28
|
|
|
) |
|
29
|
|
|
; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** @inheritdoc*/ |
|
33
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->getValidator() |
|
36
|
|
|
->setTarget($input) |
|
37
|
|
|
->validate(); |
|
38
|
|
|
|
|
39
|
|
|
try { |
|
40
|
|
|
$this->getMultiDeal()->process($input); |
|
41
|
|
|
} catch (\InvalidArgumentException $e) { |
|
42
|
|
|
$this->getLogger() |
|
43
|
|
|
->critical( |
|
44
|
|
|
'Exception caught:' . PHP_EOL . |
|
45
|
|
|
$e->getMessage() . PHP_EOL . |
|
46
|
|
|
$e->getFile() . ':' . $e->getLine() . PHP_EOL |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return ValidatorInterface |
|
53
|
|
|
*/ |
|
54
|
|
|
private function getValidator() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this |
|
57
|
|
|
->getContainer() |
|
58
|
|
|
->get('jeancsil_flight_spy.validator.command_line_parameter'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return MultiDealFacade |
|
63
|
|
|
*/ |
|
64
|
|
|
private function getMultiDeal() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->getContainer() |
|
67
|
|
|
->get('jeancsil_flight_spy.facade.multi_deal'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return LoggerInterface |
|
72
|
|
|
*/ |
|
73
|
|
|
private function getLogger() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this |
|
76
|
|
|
->getContainer() |
|
77
|
|
|
->get('jeancsil_flight_spy.logger.array_logger'); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|