1 | <?php |
||
46 | final class EmptyEscapeParser |
||
47 | { |
||
48 | /** |
||
49 | * @internal |
||
50 | */ |
||
51 | const FIELD_BREAKS = [false, '', "\r\n", "\n", "\r"]; |
||
52 | |||
53 | /** |
||
54 | * @var SplFileObject|Stream |
||
55 | */ |
||
56 | private static $document; |
||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | */ |
||
61 | private static $delimiter; |
||
62 | |||
63 | /** |
||
64 | * @var string |
||
65 | */ |
||
66 | private static $enclosure; |
||
67 | |||
68 | /** |
||
69 | * @var string |
||
70 | */ |
||
71 | private static $trim_mask; |
||
72 | |||
73 | /** |
||
74 | * @var string|bool |
||
75 | */ |
||
76 | private static $line; |
||
77 | |||
78 | /** |
||
79 | * Converts the document into a CSV record iterator. |
||
80 | * |
||
81 | * The returned record array is similar to the returned value of fgetcsv |
||
82 | * |
||
83 | * - If the line is empty the record is skipped |
||
84 | * - Otherwise the array contains strings. |
||
85 | * |
||
86 | * @param SplFileObject|Stream $document |
||
87 | */ |
||
88 | 36 | public static function parse($document): Generator |
|
114 | |||
115 | /** |
||
116 | * Filter the submitted document. |
||
117 | * |
||
118 | * @param SplFileObject|Stream $document |
||
119 | * |
||
120 | * @return SplFileObject|Stream |
||
121 | */ |
||
122 | 9 | private static function filterDocument($document) |
|
134 | |||
135 | /** |
||
136 | * Extract field without enclosure as per RFC4180. |
||
137 | * |
||
138 | * - Leading and trailing whitespaces must be removed. |
||
139 | * - trailing line-breaks must be removed. |
||
140 | * |
||
141 | * @return null|string |
||
142 | */ |
||
143 | 33 | private static function extractFieldContent() |
|
158 | |||
159 | /** |
||
160 | * Extract field with enclosure as per RFC4180. |
||
161 | * |
||
162 | * - Field content can spread on multiple document lines. |
||
163 | * - Content inside enclosure must be preserved. |
||
164 | * - Double enclosure sequence must be replaced by single enclosure character. |
||
165 | * - Trailing line break must be removed if they are not part of the field content. |
||
166 | * - Invalid fields content are treated as per fgetcsv behavior. |
||
167 | */ |
||
168 | 24 | private static function extractEnclosedFieldContent(): string |
|
204 | } |
||
205 |