1
|
|
|
<?php |
2
|
|
|
namespace keeko\tools\ui; |
3
|
|
|
|
4
|
|
|
use keeko\tools\ui\ModelSkeletonUI; |
5
|
|
|
use Symfony\Component\Console\Question\Question; |
6
|
|
|
use keeko\framework\utils\NameUtils; |
7
|
|
|
|
8
|
|
|
class ResponseUI extends ModelSkeletonUI { |
9
|
|
|
|
10
|
|
|
protected function getLabel() { |
11
|
|
|
return 'responder'; |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
protected function showSkeleton() { |
15
|
|
|
$packageService = $this->getService()->getPackageService(); |
16
|
|
|
$modelService = $this->getService()->getModelService(); |
17
|
|
|
$input = $this->getService()->getIOService()->getInput(); |
18
|
|
|
$name = $input->getArgument('name'); |
|
|
|
|
19
|
|
|
|
20
|
|
|
$names = []; |
21
|
|
|
$module = $packageService->getModule(); |
22
|
|
|
foreach ($module->getActionNames() as $actionName) { |
23
|
|
|
$names[] = $actionName; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
$actionQuestion = new Question('Which action'); |
27
|
|
|
$actionQuestion->setAutocompleterValues($names); |
28
|
|
|
$name = $this->askQuestion($actionQuestion); |
29
|
|
|
$input->setArgument('name', $name); |
30
|
|
|
|
31
|
|
|
// ask which format |
32
|
|
|
$formatQuestion = new Question('Which format', 'json'); |
33
|
|
|
$formatQuestion->setAutocompleterValues(['json', 'html']); |
34
|
|
|
$format = $this->askQuestion($formatQuestion); |
35
|
|
|
$input->setOption('format', $format); |
36
|
|
|
|
37
|
|
|
// ask which template |
38
|
|
|
$action = $packageService->getAction($name); |
39
|
|
|
if (!($format == 'json' && $modelService->isModelAction($action))) { |
|
|
|
|
40
|
|
|
$templates = [ |
41
|
|
|
'html' => ['twig', 'payload', 'blank'], |
42
|
|
|
'json' => ['api', 'payload', 'blank'] |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
$suggestions = isset($templates[$format]) ? $templates[$format] : []; |
46
|
|
|
$default = count($suggestions) ? $suggestions[0] : ''; |
47
|
|
|
$templateQuestion = new Question('Which template', $default); |
48
|
|
|
$templateQuestion->setAutocompleterValues($suggestions); |
49
|
|
|
$template = $this->askQuestion($templateQuestion); |
50
|
|
|
$input->setOption('template', $template); |
51
|
|
|
|
52
|
|
|
// aks for serializer |
53
|
|
|
if ($format == 'json' && $template == 'api') { |
54
|
|
|
$guessedSerializer = NameUtils::toStudlyCase($name) . 'Serializer'; |
55
|
|
|
$serializerQuestion = new Question('Which format', $guessedSerializer); |
56
|
|
|
$serializer = $this->askQuestion($serializerQuestion); |
57
|
|
|
$input->setOption('serializer', $serializer); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.