Passed
Pull Request — master (#262)
by Pascal
03:08
created

StdListener::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace ProtoneMedia\LaravelFFMpeg\FFMpeg;
4
5
use Alchemy\BinaryDriver\Listeners\ListenerInterface;
6
use Evenement\EventEmitter;
7
use Symfony\Component\Process\Process;
8
9
class StdListener extends EventEmitter implements ListenerInterface
10
{
11
    /**
12
     * Name of the emitted event.
13
     *
14
     * @var string
15
     */
16
    private $eventName;
17
18
    public function __construct(string $eventName = 'listen')
19
    {
20
        $this->eventName = $eventName;
21
    }
22
23
    private $data = [
24
        Process::ERR => [],
25
        Process::OUT => [],
26
    ];
27
28
    public function handle($type, $data)
29
    {
30
        $lines = preg_split('/\n|\r\n?/', $data);
31
32
        foreach ($lines as $line) {
33
            $line = $this->data[$type][] = trim($line);
34
35
            $this->emit($this->eventName, [$line, $type]);
36
        }
37
    }
38
39
    public function get(): array
40
    {
41
        return $this->data;
42
    }
43
44
    public function forwardedEvents()
45
    {
46
        return [$this->eventName];
47
    }
48
}
49