WritableFifo::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 4
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 WritableFifo extends AbstractFifo
11
{
12
    public function __construct($pathname, $blocking = true, $mode = 'w+', $permission = 0666)
13
    {
14
        parent::__construct($pathname, $blocking, $mode, $permission);
15
    }
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function read()
21
    {
22
        throw new RuntimeException("Cannot read data from an write-only fifo");
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function write($message)
29
    {
30
        $stream = $this->getStream();
31
        return fwrite($stream, $message, strlen($message));
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getStream()
38
    {
39
        $stream = parent::getStream();
40
        if ($this->blocking === false) {
41
            stream_set_blocking($stream, false);
42
        }
43
        return $stream;
44
    }
45
46
    public function setBlocking($blocking)
47
    {
48
        parent::setBlocking($blocking);
49
        if (!is_null($this->stream)) {
50
            stream_set_blocking($this->stream, $blocking);
51
        }
52
    }
53
}
54