1 | <?php |
||
23 | class CSV implements Loadable { |
||
24 | |||
25 | use Supports; |
||
26 | |||
27 | const XMLNS = 'urn:carica-json-dom.2013'; |
||
28 | const DEFAULT_QNAME = '_'; |
||
29 | |||
30 | private $_delimiter = ','; |
||
31 | private $_enclosure = '"'; |
||
32 | private $_escape = '\\'; |
||
33 | |||
34 | /** |
||
35 | * @return string[] |
||
36 | */ |
||
37 | 13 | public function getSupported(): array { |
|
40 | |||
41 | /** |
||
42 | * @see Loadable::load |
||
43 | * @param mixed $source |
||
44 | * @param string $contentType |
||
45 | * @param array|\Traversable|Options $options |
||
46 | * @return Document|Result|NULL |
||
47 | * @throws \InvalidArgumentException |
||
48 | * @throws \FluentDOM\Exceptions\InvalidSource |
||
49 | */ |
||
50 | 8 | public function load($source, string $contentType, $options = []) { |
|
63 | |||
64 | /** |
||
65 | * @see Loadable::loadFragment |
||
66 | * |
||
67 | * @param string $source |
||
68 | * @param string $contentType |
||
69 | * @param array|\Traversable|Options $options |
||
70 | * @return DocumentFragment|NULL |
||
71 | * @throws \InvalidArgumentException |
||
72 | * @throws \FluentDOM\Exceptions\InvalidSource |
||
73 | */ |
||
74 | 3 | public function loadFragment($source, string $contentType, $options = []) { |
|
87 | |||
88 | /** |
||
89 | * Append the provided lines to the parent. |
||
90 | * |
||
91 | * @param \DOMNode $parent |
||
92 | * @param array|\Traversable $lines |
||
93 | * @param $hasHeaderLine |
||
94 | * @param array $columns |
||
95 | */ |
||
96 | 9 | private function appendLines(\DOMNode $parent, $lines, $hasHeaderLine, array $columns = NULL) { |
|
118 | |||
119 | /** |
||
120 | * @param Element $parent |
||
121 | * @param string $name |
||
122 | * @param string $value |
||
123 | */ |
||
124 | 9 | private function appendField(Element $parent, $name, $value) { |
|
131 | |||
132 | /** |
||
133 | * @param array $record |
||
134 | * @param bool $hasHeaderLine |
||
135 | * @param array|NULL $columns |
||
136 | * @return array |
||
137 | */ |
||
138 | 9 | private function getHeaders(array $record, $hasHeaderLine, $columns = NULL): array { |
|
139 | 9 | if (is_array($columns)) { |
|
140 | 2 | $headers = []; |
|
141 | 2 | foreach ($record as $index => $field) { |
|
142 | 2 | $key = $hasHeaderLine ? $field : $index; |
|
143 | 2 | $headers[$index] = $columns[$key] ?? FALSE; |
|
144 | } |
||
145 | 2 | return $headers; |
|
146 | } |
||
147 | 7 | if ($hasHeaderLine) { |
|
148 | 5 | return $record; |
|
149 | } |
||
150 | 2 | return array_keys($record); |
|
151 | } |
||
152 | |||
153 | /** |
||
154 | * @param mixed $source |
||
155 | * @param Options $options |
||
156 | * @return NULL|\Traversable |
||
157 | * @throws \FluentDOM\Exceptions\InvalidSource |
||
158 | */ |
||
159 | 10 | private function getLines($source, Options $options) { |
|
181 | |||
182 | /** |
||
183 | * @param array|\Traversable|Options $options |
||
184 | */ |
||
185 | 11 | private function configure($options) { |
|
190 | |||
191 | /** |
||
192 | * @param array|\Traversable|Options $options |
||
193 | * @return Options |
||
194 | * @throws \InvalidArgumentException |
||
195 | */ |
||
196 | 11 | public function getOptions($options): Options { |
|
207 | } |
||
208 | |||
209 | } |