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 | 4 | 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) |
|
75 | |||
76 | /** |
||
77 | * Initialise the resource for writing. |
||
78 | * |
||
79 | * If we are at 0, then write initial block, otherwise, remove closing block and add a row separator |
||
80 | * |
||
81 | * This is so we can append a file with special characters at the beginning and end |
||
82 | * |
||
83 | * @param StreamInterface $stream |
||
84 | */ |
||
85 | 4 | private function initialiseForWriting(StreamInterface $stream) |
|
100 | |||
101 | /** |
||
102 | * Adds a single line |
||
103 | * |
||
104 | * @param mixed $row an item to insert |
||
105 | * |
||
106 | * @return static |
||
107 | */ |
||
108 | 2 | public function insertOne($row) |
|
112 | } |
||
113 |