1 | <?php |
||
30 | abstract class CloudCommand extends ContainerAwareCommand |
||
31 | { |
||
32 | /** |
||
33 | * {@inheritDoc} |
||
34 | */ |
||
35 | protected function configure() |
||
36 | { |
||
37 | $this->setName(static::$defaultName); // BC with Symfony Console 3.3 and older not handling the property automatically |
||
38 | $this->addOption( |
||
39 | 'cloud', |
||
40 | '-c', |
||
41 | InputOption::VALUE_REQUIRED, |
||
42 | 'Cloud on which the command is executed.' |
||
43 | ); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @return \Xabbuh\PandaClient\Api\CloudManager |
||
48 | */ |
||
49 | protected function getCloudManager() |
||
50 | { |
||
51 | return $this->getContainer()->get('xabbuh_panda.cloud_manager'); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Get the cloud to work on. |
||
56 | * |
||
57 | * @param \Symfony\Component\Console\Input\InputInterface $input |
||
58 | * |
||
59 | * @return \Xabbuh\PandaClient\Api\CloudInterface |
||
60 | */ |
||
61 | protected function getCloud(InputInterface $input) |
||
62 | { |
||
63 | if (null === $input->getOption('cloud')) { |
||
64 | return $this->getCloudManager()->getDefaultCloud(); |
||
65 | } |
||
66 | |||
67 | return $this->getCloudManager()->getCloud($input->getOption('cloud')); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Executes the actual command (to be implemented by subclasses, will be called automatically). |
||
72 | * |
||
73 | * @param InputInterface $input |
||
74 | * @param OutputInterface $output |
||
75 | */ |
||
76 | abstract protected function doExecuteCommand(InputInterface $input, OutputInterface $output); |
||
77 | |||
78 | /** |
||
79 | * {@inheritDoc} |
||
80 | */ |
||
81 | protected function execute(InputInterface $input, OutputInterface $output) |
||
93 | } |
||
94 |