1 | <?php |
||
24 | class StreamWriter implements WriterInterface, LoggerAwareInterface |
||
25 | { |
||
26 | use OptionalLoggerTrait; |
||
27 | |||
28 | /** @var FormatterInterface */ |
||
29 | private $formatter; |
||
30 | /** @var StreamInterface */ |
||
31 | private $stream; |
||
32 | |||
33 | /** |
||
34 | * @param StreamInterface $stream |
||
35 | * @param FormatterInterface $formatter Optional formatter, if not specified shall be determined based on the |
||
36 | * format of the file |
||
37 | */ |
||
38 | 10 | public function __construct(StreamInterface $stream, FormatterInterface $formatter) |
|
43 | |||
44 | /** |
||
45 | * Adds multiple lines to the CSV document |
||
46 | * |
||
47 | * a simple wrapper method around insertOne |
||
48 | * |
||
49 | * @param Traversable|array $rows a multidimensional array or a Traversable object |
||
50 | * |
||
51 | * @throws InvalidArgumentException If the given rows format is invalid |
||
52 | * |
||
53 | * @return static |
||
54 | */ |
||
55 | 4 | public function insertAll($rows) |
|
63 | |||
64 | /** |
||
65 | * @param Traversable|array $rows |
||
66 | */ |
||
67 | 7 | private function writeBlock($rows) |
|
83 | |||
84 | /** |
||
85 | * Initialise the resource for writing. |
||
86 | * |
||
87 | * If we are at 0, then write initial block, otherwise, remove closing block and add a row separator |
||
88 | * |
||
89 | * This is so we can append a file with special characters at the beginning and end |
||
90 | */ |
||
91 | 7 | private function initialiseForWriting() |
|
106 | |||
107 | /** |
||
108 | * Adds a single line |
||
109 | * |
||
110 | * @param mixed $row an item to insert |
||
111 | * |
||
112 | * @return static |
||
113 | */ |
||
114 | 4 | public function insertOne($row) |
|
119 | } |
||
120 |