1 | <?php |
||
29 | trait IsWritable |
||
30 | { |
||
31 | /** |
||
32 | * Write single line to file/stream |
||
33 | * |
||
34 | * Writes a line to the file/stream (if it is writable) |
||
35 | * |
||
36 | * @param string $line The line to be written to the stream |
||
37 | * @param string $eol The end of line string |
||
38 | * @return int The number of bytes written to the stream |
||
39 | * @throws CSVelte\Exception\IOException |
||
40 | */ |
||
41 | 14 | public function writeLine($line, $eol = PHP_EOL) |
|
45 | |||
46 | /** |
||
47 | * Assert that this file/stream object is readable. |
||
48 | * |
||
49 | * @return void |
||
50 | * @throws CSVelte\Exception\IOException if stream isn't readable |
||
51 | */ |
||
52 | 16 | protected function assertIsWritable() |
|
53 | { |
||
54 | 16 | if (!$this->isWritable()) { |
|
55 | 1 | throw new IOException("Stream not writable: " . $this->getName(), IOException::ERR_NOT_WRITABLE); |
|
56 | } |
||
57 | 15 | } |
|
58 | |||
59 | abstract public function getName(); |
||
60 | |||
61 | abstract public function isWritable(); |
||
62 | |||
63 | abstract public function write($str); |
||
64 | |||
65 | } |
||
66 |