ReadableFifo::read()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
rs 9.4285
cc 3
eloc 9
nc 3
nop 0
1
<?php
2
/**
3
 * Process Library
4
 * @author Tao <[email protected]>
5
 */
6
namespace Slince\Process\Pipe;
7
8
use Slince\Process\Exception\RuntimeException;
9
10
class ReadableFifo extends AbstractFifo
11
{
12
    public function __construct($pathname, $blocking = true, $mode = 'r+', $permission = 0666)
13
    {
14
        parent::__construct($pathname, $blocking, $mode, $permission);
15
    }
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function read()
21
    {
22
        $stream = $this->getStream();
23
        if ($this->blocking) {
24
            $read = [$stream];
25
            $write = [];
26
            $except = [];
27
            if (stream_select($read, $write, $except, null) > 0) {
28
                return stream_get_contents($stream);
29
            }
30
        }
31
        return stream_get_contents($stream);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function write($message)
38
    {
39
        throw new RuntimeException("Cannot write some data to an write-only fifo");
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getStream()
46
    {
47
        $stream = parent::getStream();
48
        stream_set_blocking($stream, false);
49
        return $stream;
50
    }
51
}
52