1 | <?php |
||
22 | class Command extends \Symfony\Component\Console\Command\Command |
||
23 | { |
||
24 | /** |
||
25 | * The commander configuration. |
||
26 | * |
||
27 | * @var Config |
||
28 | */ |
||
29 | private $configuration; |
||
30 | |||
31 | /** |
||
32 | * The commander. |
||
33 | * |
||
34 | * @var Commander |
||
35 | */ |
||
36 | private $commander; |
||
37 | |||
38 | /** |
||
39 | * {@inheritdoc} |
||
40 | */ |
||
41 | 8 | protected function configure() |
|
42 | { |
||
43 | 8 | $this->addOption( |
|
44 | 8 | 'configuration', |
|
45 | 8 | 'c', |
|
46 | 8 | InputOption::VALUE_OPTIONAL, |
|
47 | 8 | 'The commander configuration', |
|
48 | 4 | 'commander.json' |
|
49 | 4 | ); |
|
50 | 8 | } |
|
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | 4 | protected function initialize(InputInterface $input, OutputInterface $output) |
|
56 | { |
||
57 | 4 | $filename = $input->getOption('configuration'); |
|
58 | |||
59 | 4 | if (!file_exists($filename)) { |
|
60 | 2 | $this->configuration = new Config(); |
|
61 | 2 | return; |
|
62 | } |
||
63 | |||
64 | /** @var ConfigLoaderHelper $helper */ |
||
65 | 2 | $helper = $this->getHelper(ConfigLoaderHelper::class); |
|
66 | 2 | $this->configuration = $helper->getLoader()->load($filename); |
|
67 | 2 | } |
|
68 | |||
69 | /** |
||
70 | * Get commander configuration. |
||
71 | * |
||
72 | * @return Config |
||
73 | * |
||
74 | * @throws \LogicException |
||
75 | */ |
||
76 | 6 | public function getConfiguration() |
|
77 | { |
||
78 | 6 | if (null === $this->configuration) { |
|
79 | 2 | throw new \LogicException('The commander configuration is not available before initialization'); |
|
80 | } |
||
81 | |||
82 | 4 | return $this->configuration; |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * Get operational commander. |
||
87 | * |
||
88 | * @return Commander |
||
89 | * |
||
90 | * @throws \LogicException |
||
91 | */ |
||
92 | public function getCommander() |
||
106 | } |
||
107 |