Completed
Pull Request — master (#59)
by Julien
02:49
created

CommonEvents   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A dispatchImage() 0 3 1
A dispatchService() 0 3 1
A dispatchNewVirtualHost() 0 11 2
1
<?php
2
3
namespace TheAentMachine\Aenthill;
4
5
use TheAentMachine\Service\Service;
6
7
final class CommonEvents
8
{
9
    public const ADD_EVENT = 'ADD';
10
    public const START_EVENT = 'START';
11
    public const REPLY_EVENT = 'REPLY';
12
    public const ENVIRONMENT_EVENT = 'ENVIRONMENT';
13
    public const NEW_SERVICE_EVENT = 'NEW_SERVICE';
14
    public const NEW_VIRTUAL_HOST_EVENT = 'NEW_VIRTUAL_HOST';
15
    public const NEW_IMAGE_EVENT = 'NEW_IMAGE';
16
    public const NEW_BUILD_IMAGE_EVENT = 'NEW_BUILD_IMAGE';
17
    public const NEW_DEPLOY_JOB_DOCKER_COMPOSE_EVENT = 'NEW_DEPLOY_JOB_DOCKER_COMPOSE';
18
    public const NEW_DEPLOY_JOB_KUBERNETES_EVENT = 'NEW_DEPLOY_JOB_KUBERNETES';
19
20
    public static function dispatchService(Service $service): void
21
    {
22
        Aenthill::dispatchJson(self::NEW_SERVICE_EVENT, $service);
23
    }
24
25
    /**
26
     * @param string $serviceName
27
     * @param int $virtualPort
28
     * @param string|null $virtualHost
29
     * @return mixed[]|null
30
     */
31
    public static function dispatchNewVirtualHost(string $serviceName, int $virtualPort = 80, string $virtualHost = null): ?array
32
    {
33
        $message = [
34
            'service' => $serviceName,
35
            'virtualPort' => $virtualPort
36
        ];
37
        if ($virtualHost !== null) {
38
            $message['virtualHost'] = $virtualHost;
39
        }
40
41
        return Aenthill::dispatchJson(self::NEW_VIRTUAL_HOST_EVENT, $message);
42
    }
43
44
    public static function dispatchImage(Service $service): void
45
    {
46
        Aenthill::dispatchJson(self::NEW_IMAGE_EVENT, $service->imageJsonSerialize());
47
    }
48
}
49