-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCsvOptions.php
More file actions
83 lines (71 loc) · 2.05 KB
/
CsvOptions.php
File metadata and controls
83 lines (71 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace SubjectivePHP\Csv;
use InvalidArgumentException;
final class CsvOptions
{
/**
* @var string
*/
private $delimiter;
/**
* @var string
*/
private $enclosure;
/**
* @var string
*/
private $escapeChar;
/**
* Construct a new CsvOptions instance.
*
* @param string $delimiter The field delimiter (one character only).
* @param string $enclosure The field enclosure character (one character only).
* @param string $escapeChar The escape character (one character only).
*
* @throws InvalidArgumentException Thrown if $delimiter is not one character.
* @throws InvalidArgumentException Thrown if $enclosure is not one character.
* @throws InvalidArgumentException Thrown if $escapeChar is not one character.
*/
public function __construct(string $delimiter = ',', string $enclosure = '"', string $escapeChar = '\\')
{
if (strlen($delimiter) !== 1) {
throw new InvalidArgumentException('$delimiter must be a single character string');
}
if (strlen($enclosure) !== 1) {
throw new InvalidArgumentException('$enclosure must be a single character string');
}
if (strlen($escapeChar) !== 1) {
throw new InvalidArgumentException('$escapeChar must be a single character string');
}
$this->delimiter = $delimiter;
$this->enclosure = $enclosure;
$this->escapeChar = $escapeChar;
}
/**
* Gets the field delimiter (one character only).
*
* @return string
*/
public function getDelimiter() : string
{
return $this->delimiter;
}
/**
* Gets the field enclosure character (one character only).
*
* @return string
*/
public function getEnclosure() : string
{
return $this->enclosure;
}
/**
* Gets the escape character (one character only).
*
* @return string
*/
public function getEscapeChar() : string
{
return $this->escapeChar;
}
}