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