Total Complexity | 5 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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() |
||
47 | } |
||
48 | } |
||
49 |