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

FileWriter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
cbo 4
dl 0
loc 27
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0
lcom 1
1
<?php
2
namespace WebStream\IO\Writer;
3
4
use WebStream\IO\FileOutputStream;
5
use WebStream\Exception\Extend\IOException;
6
7
/**
8
 * FileWriter
9
 * @author Ryuichi TANAKA.
10
 * @since 2016/02/24
11
 * @version 0.7
12
 */
13
class FileWriter extends OutputStreamWriter
14
{
15
    /**
16
     * constructor
17
     * @param mixed $file ファイルオブジェクトまたはファイルパス
18
     */
19
    public function __construct($file, bool $isAppend = false, int $bufferSize = null)
20
    {
21
        parent::__construct(new FileOutputStream($file, $isAppend));
22
23
        // fwriteのデフォルトバッファリングサイズは8KBなので、指定無しの場合は8KBになる
24
        // また、同じストリームに対して出力を行うプロセスが複数ある場合、8KBごとに停止する
25
        // see: http://php.net/manual/ja/function.stream-set-write-buffer.php
26
        if ($bufferSize !== null && stream_set_write_buffer($this->stream, $bufferSize) !== 0) {
27
            throw new IOException("Failed to change the buffer size.");
28
        }
29
    }
30
31
    /**
32
     * ファイルに書き込む
33
     * @param mixed $data 書き込みデータ
34
     */
35
    public function write($data)
36
    {
37
        $this->stream->write($data);
38
    }
39
}
40