1 | <?php |
||
7 | class Value |
||
8 | { |
||
9 | /** @var bool */ |
||
10 | private $inQuotes = false; |
||
11 | /** @var bool */ |
||
12 | private $wasQuoted = false; |
||
13 | /** @var ValueParserInterface[] */ |
||
14 | private $valueParsers = []; |
||
15 | /** @var string */ |
||
16 | private $content = ''; |
||
17 | /** @var bool */ |
||
18 | private $isNull = false; |
||
19 | /** @var bool */ |
||
20 | private $hasContent = false; |
||
21 | |||
22 | /** |
||
23 | * Value constructor. |
||
24 | * |
||
25 | * @param array $valueParsers |
||
26 | */ |
||
27 | 9 | public function __construct(array $valueParsers = []) |
|
32 | |||
33 | /** |
||
34 | * @param bool $quoted |
||
35 | * |
||
36 | * @return static |
||
37 | */ |
||
38 | 7 | public function setInQuotes($quoted) |
|
46 | |||
47 | /** |
||
48 | * @param string $content |
||
49 | * |
||
50 | * @return static |
||
51 | */ |
||
52 | 8 | public function addContent($content) |
|
64 | |||
65 | /** |
||
66 | * Indicated that this value is null |
||
67 | */ |
||
68 | 4 | public function setIsNull() |
|
69 | { |
||
70 | 4 | $this->isNull = true; |
|
71 | 4 | $this->hasContent = true; |
|
72 | 4 | } |
|
73 | |||
74 | /** |
||
75 | * @return mixed |
||
76 | */ |
||
77 | 7 | public function getValue() |
|
78 | { |
||
79 | 7 | if ($this->wasQuoted) { |
|
80 | 6 | return $this->content; |
|
81 | 5 | } elseif ($this->isNull) { |
|
82 | 4 | return null; |
|
83 | } else { |
||
84 | 5 | foreach ($this->valueParsers as $valueParser) { |
|
85 | 1 | if ($valueParser->canParseValue($this->content)) { |
|
86 | 1 | return $valueParser->parseValue($this->content); |
|
87 | } |
||
88 | 5 | } |
|
89 | } |
||
90 | |||
91 | 5 | return $this->content; |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * Reset the state |
||
96 | */ |
||
97 | 9 | public function reset() |
|
105 | |||
106 | /** |
||
107 | * @return bool |
||
108 | */ |
||
109 | 7 | public function isInQuotes() |
|
113 | |||
114 | /** |
||
115 | * @return bool |
||
116 | */ |
||
117 | 5 | public function wasQuoted() |
|
121 | |||
122 | /** |
||
123 | * @return bool |
||
124 | */ |
||
125 | 8 | public function isEmpty() |
|
129 | } |
||
130 |