scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 1 <?php
2  
3 /*
4 * This file is part of Alchemy\BinaryDriver.
5 *
6 * (c) Alchemy <info@alchemy.fr>
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 namespace Alchemy\BinaryDriver\Listeners;
13  
14 use Evenement\EventEmitter;
15 use Symfony\Component\Process\Process;
16  
17 class DebugListener extends EventEmitter implements ListenerInterface
18 {
19 private $prefixOut;
20 private $prefixErr;
21 private $eventOut;
22 private $eventErr;
23  
24 public function __construct($prefixOut = '[OUT] ', $prefixErr = '[ERROR] ', $eventOut = 'debug', $eventErr = 'debug')
25 {
26 $this->prefixOut = $prefixOut;
27 $this->prefixErr = $prefixErr;
28 $this->eventOut = $eventOut;
29 $this->eventErr = $eventErr;
30 }
31  
32 /**
33 * {@inheritdoc}
34 */
35 public function handle($type, $data)
36 {
37 if (Process::ERR === $type) {
38 $this->emitLines($this->eventErr, $this->prefixErr, $data);
39 } elseif (Process::OUT === $type) {
40 $this->emitLines($this->eventOut, $this->prefixOut, $data);
41 }
42 }
43  
44 /**
45 * {@inheritdoc}
46 */
47 public function forwardedEvents()
48 {
49 return array_unique(array($this->eventErr, $this->eventOut));
50 }
51  
52 private function emitLines($event, $prefix, $lines)
53 {
54 foreach (explode("\n", $lines) as $line) {
55 $this->emit($event, array($prefix . $line));
56 }
57 }
58 }