Completed
Push — master ( f0448f...4201d1 )
by Julien
14s
created

Hermes::dispatch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace TheAentMachine\AentDockerCompose\Aenthill;
3
4
use Symfony\Component\Process\Process;
5
6
class Hermes
7
{
8
    const BINARY = 'hermes';
9
10
    /**
11
     * @param string $event
12
     * @param null|string $payload
13
     * @return int
14
     */
15
    public static function dispatch(string $event, ?string $payload = null): int
16
    {
17
        $command = Hermes::BINARY . " dispatch $event";
18
        if (!empty($payload)) {
19
            $command .= " $payload";
20
        }
21
22
        $process = new Process($command);
23
        $process->enableOutput();
24
        $process->setTty(true);
25
26
        return $process->run();
27
    }
28
29
    /**
30
     * @param string $event
31
     * @param null|string $payload
32
     * @return int
33
     */
34
    public static function reply(string $event, ?string $payload = null): int
35
    {
36
        $command = Hermes::BINARY . " reply $event";
37
        if (!empty($payload)) {
38
            $command .= " $payload";
39
        }
40
41
        $process = new Process($command);
42
        $process->enableOutput();
43
        $process->setTty(true);
44
45
        return $process->run();
46
    }
47
}
48