Completed
Push — master ( 2e5bdd...9e2471 )
by Ryuichi
05:26
created

OutputStreamWriter   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
cbo 1
dl 0
loc 66
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0
lcom 1
1
<?php
2
namespace WebStream\IO\Writer;
3
4
use WebStream\IO\OutputStream;
5
use WebStream\Exception\Extend\InvalidArgumentException;
6
7
/**
8
 * OutputStreamWriter
9
 * @author Ryuichi TANAKA.
10
 * @since 2016/02/24
11
 * @version 0.7
12
 */
13
class OutputStreamWriter
14
{
15
    /**
16
     * @var OutputStream 出力ストリーム
17
     */
18
    protected $stream;
19
20
    /**
21
     * constructor
22
     * @param OutputStream $stream 出力ストリーム
23
     */
24
    public function __construct(OutputStream $stream)
25
    {
26
        $this->stream = $stream;
27
    }
28
29
    /**
30
     * destructor
31
     */
32
    public function __destruct()
33
    {
34
        $this->close();
35
    }
36
37
    /**
38
     * バッファリングしているすべての出力バイトを書き出し、出力ストリームを閉じる
39
     * @throws WebStream\Exception\Extend\IOException
40
     */
41
    public function close()
42
    {
43
        $this->stream->close();
44
    }
45
46
    /**
47
     * 出力ストリームに書き出す
48
     * @param mixed $buf 出力データ
49
     * @throws WebStream\Exception\Extend\IOException
50
     */
51
    public function write($buf)
52
    {
53
        $args = func_get_args();
54
        $off = array_key_exists(1, $args) ? $args[1] : null;
55
        $len = array_key_exists(2, $args) ? $args[2] : null;
56
57
        $this->stream->write($buf, $off, $len);
58
    }
59
60
    /**
61
     * バッファリングしているすべての出力バイトを出力ストリームを閉じずに強制的に書き出す
62
     * writeを実行した時点では書き出されておらず、flushした時点ですべて書き出す
63
     * @throws WebStream\Exception\Extend\IOException
64
     */
65
    public function flush()
66
    {
67
        $this->stream->flush();
68
    }
69
70
    /**
71
     * 改行を書き出す
72
     * @throws WebStream\Exception\Extend\IOException
73
     */
74
    public function newLine()
75
    {
76
        $this->stream->write(PHP_EOL);
77
    }
78
}
79