1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Box\Spout\Reader\CSV; |
4
|
|
|
|
5
|
|
|
use Box\Spout\Common\Helper\EncodingHelper; |
6
|
|
|
use Box\Spout\Reader\ReaderOptionsCommon; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class ReaderOptions |
10
|
|
|
* This class is used to customize the reader's behavior |
11
|
|
|
* |
12
|
|
|
* @package Box\Spout\Reader\CSV |
13
|
|
|
*/ |
14
|
|
|
class ReaderOptions extends ReaderOptionsCommon |
15
|
|
|
{ |
16
|
|
|
/** @var string Defines the character used to delimit fields (one character only) */ |
17
|
|
|
protected $fieldDelimiter = ','; |
18
|
|
|
|
19
|
|
|
/** @var string Defines the character used to enclose fields (one character only) */ |
20
|
|
|
protected $fieldEnclosure = '"'; |
21
|
|
|
|
22
|
|
|
/** @var string Encoding of the CSV file to be read */ |
23
|
|
|
protected $encoding = EncodingHelper::ENCODING_UTF8; |
24
|
|
|
|
25
|
|
|
/** @var string Defines the End of line */ |
26
|
|
|
protected $endOfLineCharacter = "\n"; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
78 |
|
public function getFieldDelimiter() |
32
|
|
|
{ |
33
|
78 |
|
return $this->fieldDelimiter; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Sets the field delimiter for the CSV. |
38
|
|
|
* Needs to be called before opening the reader. |
39
|
|
|
* |
40
|
|
|
* @param string $fieldDelimiter Character that delimits fields |
41
|
|
|
* @return ReaderOptions |
42
|
|
|
*/ |
43
|
60 |
|
public function setFieldDelimiter($fieldDelimiter) |
44
|
|
|
{ |
45
|
60 |
|
$this->fieldDelimiter = $fieldDelimiter; |
46
|
60 |
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
78 |
|
public function getFieldEnclosure() |
53
|
|
|
{ |
54
|
78 |
|
return $this->fieldEnclosure; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Sets the field enclosure for the CSV. |
59
|
|
|
* Needs to be called before opening the reader. |
60
|
|
|
* |
61
|
|
|
* @param string $fieldEnclosure Character that enclose fields |
62
|
|
|
* @return ReaderOptions |
63
|
|
|
*/ |
64
|
60 |
|
public function setFieldEnclosure($fieldEnclosure) |
65
|
|
|
{ |
66
|
60 |
|
$this->fieldEnclosure = $fieldEnclosure; |
67
|
60 |
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
78 |
|
public function getEncoding() |
74
|
|
|
{ |
75
|
78 |
|
return $this->encoding; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Sets the encoding of the CSV file to be read. |
80
|
|
|
* Needs to be called before opening the reader. |
81
|
|
|
* |
82
|
|
|
* @param string $encoding Encoding of the CSV file to be read |
83
|
|
|
* @return ReaderOptions |
84
|
|
|
*/ |
85
|
72 |
|
public function setEncoding($encoding) |
86
|
|
|
{ |
87
|
72 |
|
$this->encoding = $encoding; |
88
|
72 |
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return string EOL for the CSV |
93
|
|
|
*/ |
94
|
78 |
|
public function getEndOfLineCharacter() |
95
|
|
|
{ |
96
|
78 |
|
return $this->endOfLineCharacter; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Sets the EOL for the CSV. |
101
|
|
|
* Needs to be called before opening the reader. |
102
|
|
|
* |
103
|
|
|
* @param string $endOfLineCharacter used to properly get lines from the CSV file. |
104
|
|
|
* @return ReaderOptions |
105
|
|
|
*/ |
106
|
60 |
|
public function setEndOfLineCharacter($endOfLineCharacter) |
107
|
|
|
{ |
108
|
60 |
|
$this->endOfLineCharacter = $endOfLineCharacter; |
109
|
60 |
|
return $this; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|