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