diff options
Diffstat (limited to 'src/App.php')
-rw-r--r-- | src/App.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/App.php b/src/App.php new file mode 100644 index 0000000..bb92b87 --- /dev/null +++ b/src/App.php @@ -0,0 +1,58 @@ +<?php + +namespace FBeans\Blaflight; + +use FBeans\Blaflight\Flight\Helper; +use FBeans\BlaIRC\Command; +use FBeans\BlaIRC\Application as BlaApplication; +use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +// XXX: make a nice config thing +// XXX: Make nice output sugar +class App extends BlaApplication +{ + protected $config; + + protected function getConfig(string $value = null) + { + if (!$this->config) { + $config = include __DIR__ . '/../config.php'; + $this->config = $config; + } + + if (!$value) { + return $config; + } + + if (!array_key_exists($value, $config)) { + throw new Exception('Failed loading config value `' . $value . '`'); + } + + return $config[$value]; + } + + public function initCommands() + { + $api_key = $this->getConfig('api_key'); + + $this->addCommand( + 'flight:check {flight}', + function (InputInterface $input, OutputInterface $output) use ($api_key) { + $flight_data = (new Helper($api_key))->getFlightByIata($input->getArgument('flight')); + $output->writeLn($flight_data); + return Command::SUCCESS; + } + ); + + $this->addCommand( + 'flight {flight}', + function (InputInterface $input, OutputInterface $output) use ($api_key) { + $flight_data = (new Helper($api_key))->getFlightByIata($input->getArgument('flight')); + $output->writeLn($flight_data); + return Command::SUCCESS; + } + ); + } +} |