1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace TheAentMachine; |
5
|
|
|
|
6
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Symfony\Component\Console\Question\Question; |
10
|
|
|
use TheAentMachine\Exception\CannotHandleEventException; |
11
|
|
|
use TheAentMachine\Service\Service; |
12
|
|
|
|
13
|
|
|
class CommonEvents |
14
|
|
|
{ |
15
|
|
|
private const NEW_DOCKER_SERVICE_INFO = 'NEW_DOCKER_SERVICE_INFO'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @throws CannotHandleEventException |
19
|
|
|
*/ |
20
|
|
|
public function dispatchService(Service $service, QuestionHelper $helper, InputInterface $input, OutputInterface $output): void |
21
|
|
|
{ |
22
|
|
|
$this->canDispatchServiceOrFail($helper, $input, $output); |
23
|
|
|
|
24
|
|
|
Hermes::dispatchJson(self::NEW_DOCKER_SERVICE_INFO, $service); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @throws CannotHandleEventException |
29
|
|
|
*/ |
30
|
|
|
public function canDispatchServiceOrFail(QuestionHelper $helper, InputInterface $input, OutputInterface $output): void |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
// Disableing this whole piece of code until we can properly add an Aent from a container |
33
|
|
|
/*$canHandle = Hercule::canHandleEvent(self::NEW_DOCKER_SERVICE_INFO); |
34
|
|
|
|
35
|
|
|
if (!$canHandle) { |
36
|
|
|
$output->writeln('<error>Heads up!</error>'); |
37
|
|
|
$output->writeln('It seems that Aenthill does not know how or where to store this new service. You need to install a dedicated Aent for this.'); |
38
|
|
|
$output->writeln('Most of the time, you want to put this service in a docker-compose.yml file. We have a pretty good Aent for this: <info>theaentmachine/aent-docker-compose</info>.'); |
39
|
|
|
$question = new Question('Do you want me to add this Aent for you? (y/n) ', 'y'); |
40
|
|
|
$question->setValidator(function (string $value) { |
41
|
|
|
$value = \strtolower(trim($value)); |
42
|
|
|
|
43
|
|
|
if ($value !== 'y' && $value !== 'n') { |
44
|
|
|
throw new \InvalidArgumentException('Please type "y" or "n"'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $value; |
48
|
|
|
}); |
49
|
|
|
$answer = $helper->ask($input, $output, $question); |
50
|
|
|
|
51
|
|
|
if ($answer === 'y') { |
52
|
|
|
Hercule::addAent('theaentmachine/aent-docker-compose'); |
53
|
|
|
} else { |
54
|
|
|
throw CannotHandleEventException::cannotHandleEvent(self::NEW_DOCKER_SERVICE_INFO); |
55
|
|
|
} |
56
|
|
|
}*/ |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.