1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Level23\Druid\Lookups\ParseSpecs; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @internal |
8
|
|
|
*/ |
9
|
|
|
class CsvParseSpec implements ParseSpecInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Specify the CSV parse spec. |
13
|
|
|
* |
14
|
|
|
* @param array<int,string>|null $columns |
15
|
|
|
* @param string|null $keyColumn |
16
|
|
|
* @param string|null $valueColumn |
17
|
|
|
* @param bool $hasHeaderRow |
18
|
|
|
* @param int $skipHeaderRows |
19
|
|
|
*/ |
20
|
3 |
|
public function __construct( |
21
|
|
|
protected ?array $columns, |
22
|
|
|
protected ?string $keyColumn = null, |
23
|
|
|
protected ?string $valueColumn = null, |
24
|
|
|
protected bool $hasHeaderRow = false, |
25
|
|
|
protected int $skipHeaderRows = 0 |
26
|
|
|
) { |
27
|
|
|
|
28
|
3 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return array<string,bool|array<int,string>|string|int> |
32
|
|
|
*/ |
33
|
3 |
|
public function toArray(): array |
34
|
|
|
{ |
35
|
3 |
|
$response = [ |
36
|
3 |
|
'format' => 'csv', |
37
|
3 |
|
'hasHeaderRow' => $this->hasHeaderRow, |
38
|
3 |
|
]; |
39
|
|
|
|
40
|
3 |
|
if ($this->columns !== null) { |
41
|
3 |
|
$response['columns'] = $this->columns; |
42
|
|
|
} |
43
|
|
|
|
44
|
3 |
|
if ($this->keyColumn !== null) { |
45
|
3 |
|
$response['keyColumn'] = $this->keyColumn; |
46
|
|
|
} |
47
|
3 |
|
if ($this->valueColumn !== null) { |
48
|
3 |
|
$response['valueColumn'] = $this->valueColumn; |
49
|
|
|
} |
50
|
3 |
|
if ($this->skipHeaderRows !== 0) { |
51
|
|
|
$response['skipHeaderRows'] = $this->skipHeaderRows; |
52
|
|
|
} |
53
|
|
|
|
54
|
3 |
|
return $response; |
55
|
|
|
} |
56
|
|
|
} |