Passed
Push — master ( b23da5...cc1845 )
by Amin
04:10
created

FFMpegListener   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 35
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A forwardedEvents() 0 3 1
A __construct() 0 3 1
A handle() 0 4 2
1
<?php
2
3
/**
4
 * This file is part of the PHP-FFmpeg-video-streaming package.
5
 *
6
 * (c) Amin Yazdanpanah <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
13
namespace Streaming;
14
15
16
use Alchemy\BinaryDriver\Listeners\ListenerInterface;
17
use Evenement\EventEmitter;
18
19
class FFMpegListener extends EventEmitter implements ListenerInterface
20
{
21
    /** @var string */
22
    private $event;
23
24
    /**
25
     * FFMpegListener constructor.
26
     * @param string $event
27
     */
28
    public function __construct($event = 'listen')
29
    {
30
        $this->event = $event;
31
    }
32
33
    /**
34
     * Handle the output of a ProcessRunner
35
     *
36
     * @param string $type The data type, one of Process::ERR, Process::OUT constants
37
     * @param string $data The output
38
     */
39
    public function handle($type, $data)
40
    {
41
        foreach (explode(PHP_EOL, $data) as $line) {
42
            $this->emit($this->event, [$line]);
43
        }
44
    }
45
46
    /**
47
     * An array of events that should be forwarded to BinaryInterface
48
     *
49
     * @return array
50
     */
51
    public function forwardedEvents()
52
    {
53
        return [$this->event];
54
    }
55
}