|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TheAentMachine\Aent\Event\ReverseProxy; |
|
4
|
|
|
|
|
5
|
|
|
use Safe\Exceptions\StringsException; |
|
6
|
|
|
use TheAentMachine\Aent\Context\Context; |
|
7
|
|
|
use TheAentMachine\Aent\Event\AbstractJsonEvent; |
|
8
|
|
|
use TheAentMachine\Aent\Payload\ReverseProxy\ReverseProxyNewVirtualHostPayload; |
|
9
|
|
|
use TheAentMachine\Service\Exception\ServiceException; |
|
10
|
|
|
use TheAentMachine\Service\Service; |
|
11
|
|
|
use function Safe\sprintf; |
|
12
|
|
|
|
|
13
|
|
|
abstract class AbstractNewVirtualHostEvent extends AbstractJsonEvent |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @param ReverseProxyNewVirtualHostPayload $payload |
|
17
|
|
|
* @return Service |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract protected function populateService(ReverseProxyNewVirtualHostPayload $payload): Service; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @return string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected function getEventName(): string |
|
25
|
|
|
{ |
|
26
|
|
|
return 'NEW_VIRTUAL_HOST'; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @return bool |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function shouldRegisterEvents(): bool |
|
33
|
|
|
{ |
|
34
|
|
|
return false; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @return void |
|
39
|
|
|
* @throws StringsException |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function beforeExecute(): void |
|
42
|
|
|
{ |
|
43
|
|
|
/** @var Context $context */ |
|
44
|
|
|
$context = Context::fromMetadata(); |
|
45
|
|
|
$this->output->writeln(sprintf( |
|
46
|
|
|
"\nš Hello! I'm the aent <info>%s</info> and I'm going to configure the virtual host of your service on your <info>%s</info> environment <info>%s</info>.", |
|
47
|
|
|
$this->getAentName(), |
|
48
|
|
|
$context->getEnvironmentType(), |
|
49
|
|
|
$context->getEnvironmentName() |
|
50
|
|
|
)); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param array $payload |
|
55
|
|
|
* @return array|null |
|
56
|
|
|
* @throws ServiceException |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function executeJsonEvent(array $payload): ?array |
|
59
|
|
|
{ |
|
60
|
|
|
$payload = ReverseProxyNewVirtualHostPayload::fromArray($payload); |
|
61
|
|
|
$service = $this->populateService($payload); |
|
62
|
|
|
return $service->jsonSerialize(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return void |
|
67
|
|
|
* @throws StringsException |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function afterExecute(): void |
|
70
|
|
|
{ |
|
71
|
|
|
/** @var Context $context */ |
|
72
|
|
|
$context = Context::fromMetadata(); |
|
73
|
|
|
$this->output->writeln(sprintf( |
|
74
|
|
|
"\nI've successfully configured the virtual host of your service on your <info>%s</info> environment <info>%s</info>.", |
|
75
|
|
|
$context->getEnvironmentType(), |
|
76
|
|
|
$context->getEnvironmentName() |
|
77
|
|
|
)); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|