DuplexFifo::__destruct()   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 0
1
<?php
2
/**
3
 * Process Library
4
 * @author Tao <[email protected]>
5
 */
6
namespace Slince\Process\Pipe;
7
8
class DuplexFifo
9
{
10
    /**
11
     * The read stream
12
     * @var ReadableFifo
13
     */
14
    protected $readFifo;
15
16
    /**
17
     * The write stream,
18
     * @var WritableFifo
19
     */
20
    protected $writeFifo;
21
22
    public function __construct($pathname, $readBlocking = true, $writeBlocking = true)
23
    {
24
        $this->readFifo = new ReadableFifo($pathname, $readBlocking);
25
        $this->writeFifo = new WritableFifo($pathname, $writeBlocking);
26
    }
27
28
    /**
29
     * Sets the read fifo blocking mode
30
     * @param boolean $blocking
31
     */
32
    public function setReadBlocking($blocking)
33
    {
34
        $this->readFifo->setBlocking($blocking);
35
    }
36
37
    /**
38
     * Sets the read fifo blocking mode
39
     * @param boolean $blocking
40
     */
41
    public function setWriteBlocking($blocking)
42
    {
43
        $this->writeFifo->setBlocking($blocking);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function read()
50
    {
51
        return $this->readFifo->read();
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function write($message)
58
    {
59
        return $this->writeFifo->write($message);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function close()
66
    {
67
        is_null($this->readFifo) || $this->readFifo->close();
68
        is_null($this->writeFifo) || $this->writeFifo->close();
69
    }
70
71
    /**
72
     * Gets the read-only fifo
73
     * @return ReadableFifo
74
     */
75
    public function getReadFifo()
76
    {
77
        return $this->readFifo;
78
    }
79
80
    /**
81
     * Gets the write-only fifo
82
     * @return WritableFifo
83
     */
84
    public function getWriteFifo()
85
    {
86
        return $this->writeFifo;
87
    }
88
89
    public function __destruct()
90
    {
91
        $this->close();
92
    }
93
}
94