Completed
Pull Request — master (#24)
by Julien
02:38
created

CommonEvents::canDispatchVirtualHostOrFail()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 14
nc 3
nop 0
dl 0
loc 19
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
4
namespace TheAentMachine;
5
6
use Symfony\Component\Console\Output\OutputInterface;
7
use TheAentMachine\Service\Service;
8
9
class CommonEvents
10
{
11
    private const NEW_SERVICE = 'NEW_SERVICE';
12
    private const NEW_VIRTUAL_HOST = 'NEW_VIRTUAL_HOST';
13
    private const NEW_IMAGE = 'NEW_IMAGE';
14
15
    /** @var AentHelper */
16
    private $aentHelper;
17
18
    /** @var OutputInterface */
19
    private $output;
20
21
    /**
22
     * CommonEvents constructor.
23
     * @param AentHelper $aentHelper
24
     * @param OutputInterface $output
25
     */
26
    public function __construct(AentHelper $aentHelper, OutputInterface $output)
27
    {
28
        $this->aentHelper = $aentHelper;
29
        $this->output = $output;
30
    }
31
32
    public function dispatchService(Service $service): void
33
    {
34
        Aenthill::dispatchJson(self::NEW_SERVICE, $service);
35
    }
36
37
    public function dispatchNewVirtualHost(string $serviceName, int $virtualPort = 80, string $virtualHost = null): ?array
38
    {
39
        $message = [
40
            'service' => $serviceName,
41
            'virtualPort' => $virtualPort
42
        ];
43
        if ($virtualHost !== null) {
44
            $message['virtualHost'] = $virtualHost;
45
        }
46
47
        return Aenthill::dispatchJson(self::NEW_VIRTUAL_HOST, $message);
48
    }
49
50
51
    public function dispatchImage(Service $service): void
52
    {
53
        Aenthill::dispatchJson(self::NEW_IMAGE, $service->imageJsonSerialize());
54
    }
55
}
56