|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TheAentMachine\Aent\Event\Orchestrator; |
|
4
|
|
|
|
|
5
|
|
|
use Safe\Exceptions\StringsException; |
|
6
|
|
|
use TheAentMachine\Aent\Context\Context; |
|
7
|
|
|
use TheAentMachine\Aent\Event\AbstractJsonEvent; |
|
8
|
|
|
use function Safe\sprintf; |
|
9
|
|
|
|
|
10
|
|
|
final class OrchestratorChooseEnvironmentEvent extends AbstractJsonEvent |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @return string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected function getEventName(): string |
|
16
|
|
|
{ |
|
17
|
|
|
return 'CHOOSE_ENVIRONMENT'; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @return bool |
|
22
|
|
|
*/ |
|
23
|
|
|
protected function shouldRegisterEvents(): bool |
|
24
|
|
|
{ |
|
25
|
|
|
return false; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @return void |
|
30
|
|
|
* @throws StringsException |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function beforeExecute(): void |
|
33
|
|
|
{ |
|
34
|
|
|
/** @var Context $context */ |
|
35
|
|
|
$context = Context::fromMetadata(); |
|
36
|
|
|
$this->output->writeln(sprintf( |
|
37
|
|
|
"\nš Hello! I'm the aent <info>%s</info> of your <info>%s</info> environment <info>%s</info>.", |
|
38
|
|
|
$this->getAentName(), |
|
39
|
|
|
$context->getEnvironmentType(), |
|
40
|
|
|
$context->getEnvironmentName() |
|
41
|
|
|
)); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param mixed[] $payload |
|
46
|
|
|
* @return mixed[]|null |
|
47
|
|
|
* @throws StringsException |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function executeJsonEvent(array $payload): ?array |
|
50
|
|
|
{ |
|
51
|
|
|
/** @var Context $context */ |
|
52
|
|
|
$context = Context::fromMetadata(); |
|
53
|
|
|
$text = sprintf( |
|
54
|
|
|
"\nDo you want to add the service(s) on your <info>%s</info> environment <info>%s</info>?", |
|
55
|
|
|
$context->getEnvironmentType(), |
|
56
|
|
|
$context->getEnvironmentName() |
|
57
|
|
|
); |
|
58
|
|
|
$response = $this->prompt->confirm($text, null, true); |
|
59
|
|
|
if ($response) { |
|
60
|
|
|
/** @var Context $context */ |
|
61
|
|
|
$context = Context::fromMetadata(); |
|
62
|
|
|
return $context->toArray(); |
|
63
|
|
|
} |
|
64
|
|
|
return null; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function afterExecute(): void |
|
71
|
|
|
{ |
|
72
|
|
|
// Let's do nothing. |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|