1
|
|
|
<?php |
2
|
|
|
namespace keeko\tools\ui; |
3
|
|
|
|
4
|
|
|
use keeko\tools\ui\AbstractUI; |
5
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
6
|
|
|
use Symfony\Component\Console\Question\Question; |
7
|
|
|
|
8
|
|
|
abstract class ModelSkeletonUI extends AbstractUI { |
9
|
|
|
|
10
|
|
|
public function show() { |
11
|
|
|
$input = $this->io->getInput(); |
12
|
|
|
$name = $input->getArgument('name'); |
13
|
|
|
$model = $input->getOption('model'); |
14
|
|
|
|
15
|
|
|
if ($model !== null) { |
16
|
|
|
return; |
17
|
|
|
} else if ($name !== null) { |
18
|
|
|
$generateModel = false; |
19
|
|
|
} else { |
20
|
|
|
$label = $this->getLabel(); |
21
|
|
|
$label = (in_array($label[0], ['a', 'e', 'i', 'o', 'u']) ? 'an' : 'a') . ' ' . $label; |
22
|
|
|
$modelQuestion = new ConfirmationQuestion('Do you want to generate ' . $label . ' based off a model?'); |
23
|
|
|
$generateModel = $this->askConfirmation($modelQuestion); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
// ask questions for a model |
27
|
|
|
if ($generateModel !== false) { |
28
|
|
|
$modelService = $this->command->getService()->getModelService(); |
29
|
|
|
$schema = str_replace(getcwd(), '', $modelService->getSchema()); |
30
|
|
|
$allQuestion = new ConfirmationQuestion(sprintf('For all models in the schema (%s)?', $schema)); |
31
|
|
|
$allModels = $this->askConfirmation($allQuestion); |
32
|
|
|
|
33
|
|
|
if (!$allModels) { |
34
|
|
|
$modelQuestion = new Question('Which model'); |
35
|
|
|
$modelQuestion->setAutocompleterValues($modelService->getModelNames()); |
36
|
|
|
$model = $this->askQuestion($modelQuestion); |
37
|
|
|
$input->setOption('model', $model); |
38
|
|
|
} |
39
|
|
|
} else { |
40
|
|
|
$this->showSkeleton(); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
abstract protected function showSkeleton(); |
|
|
|
|
45
|
|
|
|
46
|
|
|
abstract protected function getLabel(); |
|
|
|
|
47
|
|
|
} |
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@return
doc comment to communicate to implementors of these methods what they are expected to return.