1 | <?php |
||
14 | abstract class AbstractCommand extends Command |
||
15 | { |
||
16 | /** |
||
17 | * {@inheritdoc} |
||
18 | */ |
||
19 | 1 | protected function configure() |
|
20 | { |
||
21 | 1 | $this |
|
22 | 1 | ->addArgument('dist', InputOption::VALUE_REQUIRED, 'From file', Config::DEFAULT_DIST) |
|
23 | 1 | ->addArgument('target', InputOption::VALUE_REQUIRED, 'To file', Config::DEFAULT_TARGET) |
|
24 | 1 | ->addOption('remove-outdated', 'r', InputOption::VALUE_NONE, 'Remove old env variables', false); |
|
25 | } |
||
26 | |||
27 | /** |
||
28 | * {@inheritdoc} |
||
29 | * |
||
30 | * @throws InvalidArgumentException |
||
31 | */ |
||
32 | protected function execute(InputInterface $input, OutputInterface $output) |
||
33 | { |
||
34 | $config = $this->createConfig($input); |
||
35 | $processor = $this->createProcessor($input, $output); |
||
36 | |||
37 | $this->doExecute($processor, $config); |
||
38 | |||
39 | return 0; |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * @param InputInterface $input |
||
44 | * |
||
45 | * @return Config |
||
46 | * |
||
47 | * @throws InvalidArgumentException |
||
48 | */ |
||
49 | private function createConfig(InputInterface $input) |
||
50 | { |
||
51 | $dist = $input->getArgument('dist'); |
||
52 | $target = $input->getArgument('target'); |
||
53 | $removeOutdated = $input->getOption('remove-outdated'); |
||
54 | |||
55 | return new Config($dist, $target, !$removeOutdated); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @param InputInterface $input |
||
60 | * @param OutputInterface $output |
||
61 | * |
||
62 | * @return Processor |
||
63 | */ |
||
64 | private function createProcessor(InputInterface $input, OutputInterface $output) |
||
65 | { |
||
66 | return new Processor(new ConsoleIO($input, $output)); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @param Processor $processor |
||
71 | * @param Config $config |
||
72 | */ |
||
73 | abstract protected function doExecute(Processor $processor, Config $config); |
||
74 | } |
||
75 |