blob: bb92b8795d9ea306f0ca24ed28c43e6216acd73f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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;
}
);
}
}
|