1 | <?php |
||
14 | abstract class ConfigureActionCommand extends Command |
||
15 | { |
||
16 | use FilterInputVariable; |
||
17 | |||
18 | const |
||
19 | ENV_DEV = 'dev', |
||
20 | OPTION_ASSIGNMENT = '='; |
||
21 | |||
22 | private |
||
23 | $dryRun, |
||
|
|||
24 | $isBackupEnabled, |
||
25 | $systemEnvironment, |
||
26 | $name, |
||
27 | $description, |
||
28 | $outputTitle; |
||
29 | |||
30 | protected |
||
31 | $environment; |
||
32 | |||
33 | public function __construct(Application $app, $name, $description, $outputTitle) |
||
47 | |||
48 | protected function configure() |
||
67 | |||
68 | protected function execute(InputInterface $input, OutputInterface $output) |
||
78 | |||
79 | private function processInputs(InputInterface $input) |
||
80 | { |
||
81 | $this->environment = $input->getOption('env'); |
||
82 | $this->systemEnvironment = $input->getOption('system'); |
||
83 | |||
84 | if($input->getOption('dry-run')) |
||
85 | { |
||
86 | $this->dryRun = true; |
||
87 | $this->output->writeln("<fg=cyan>Run in dry-run mode</fg=cyan>"); |
||
88 | } |
||
89 | |||
90 | if($input->getOption('backup')) |
||
91 | { |
||
92 | $this->isBackupEnabled = true; |
||
93 | $this->output->writeln("<fg=cyan>Backup enabled</fg=cyan>"); |
||
94 | } |
||
95 | |||
96 | $profile = $this->app['profile']; |
||
97 | $sourcePath = $input->getArgument('sourcePath'); |
||
98 | if(empty($sourcePath)) |
||
99 | { |
||
100 | if($profile->hasSourcePath() !== true) |
||
101 | { |
||
102 | throw new \RuntimeException('Missing argument sourcePath'); |
||
103 | } |
||
104 | |||
105 | $sourcePath = $profile->getSourcePath(); |
||
106 | } |
||
107 | |||
108 | if(! is_array($sourcePath)) |
||
109 | { |
||
110 | $sourcePath = array($sourcePath); |
||
111 | } |
||
112 | |||
113 | $targetPath = $input->getOption('targetPath'); |
||
114 | |||
115 | if(is_array($targetPath)) |
||
116 | { |
||
117 | throw new \RuntimeException('Invalid argument targetPath : could not be mutiple (single path required as string)'); |
||
118 | } |
||
119 | |||
120 | if(empty($targetPath) && $profile->hasTargetPath() === true) |
||
121 | { |
||
122 | $targetPath = $profile->getTargetPath(); |
||
123 | } |
||
124 | |||
125 | $this->output->writeln(sprintf( |
||
126 | "<info>%s <comment>%s</comment> with <comment>%s</comment> values</info>", |
||
127 | $this->outputTitle, |
||
128 | implode(' ', $sourcePath), |
||
129 | $this->environment |
||
130 | )); |
||
131 | $this->output->writeln(''); |
||
132 | |||
133 | $this->app['sources.path'] = $sourcePath; |
||
134 | $this->app['target.path'] = $targetPath; |
||
135 | |||
136 | $this->processOverridenVariables( |
||
137 | $this->parseOptionWithAssignments($input, 'override') |
||
138 | ); |
||
139 | $this->processCustomData( |
||
140 | $this->parseOptionWithAssignments($input, 'data') |
||
141 | ); |
||
142 | } |
||
143 | |||
144 | abstract protected function launchConfigurationAction(ConfigurableProcessor $processor); |
||
146 | |||
147 | private function configureProcessor(ConfigurableProcessor $processor) |
||
169 | |||
170 | private function parseOptionWithAssignments(InputInterface $input, $optionName) |
||
205 | |||
206 | private function processOverridenVariables(array $overrides) |
||
224 | |||
225 | private function processCustomData(array $data) |
||
241 | } |
||
242 |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.