|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace h4kuna\Ares; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @author Milan Matějček |
|
7
|
|
|
*/ |
|
8
|
|
|
class Data implements IData, \ArrayAccess, \Iterator, \Countable |
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
private $data = []; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @param bool $isActive |
|
15
|
|
|
*/ |
|
16
|
|
|
public function setActive($isActive) |
|
17
|
|
|
{ |
|
18
|
|
|
$this->data['active'] = $isActive; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function setCity($city) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->data['city'] = $city; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function setCompany($company) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->data['company'] = $company; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function setCourt($court) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->data['court'] = $court; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function setCreated(\DateTime $date) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->data['created'] = $date; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function setFileNumber($fileNumber) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->data['file_number'] = $fileNumber; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function setPerson($isPerson) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->data['person'] = $isPerson; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function setStreet($street) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->data['street'] = $street; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function setIN($in) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->data['in'] = $in; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function setTIN($tin) |
|
62
|
|
|
{ |
|
63
|
|
|
$this->data['tin'] = $tin; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function setVatpay($vatPay) |
|
67
|
|
|
{ |
|
68
|
|
|
$this->data['vat_pay'] = $vatPay; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function setZip($zip) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->data['zip'] = $zip; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
private function setFileNumberAndCourt() |
|
77
|
|
|
{ |
|
78
|
|
|
if (!isset($this->data['court_all']) && array_key_exists('file_number', $this->data) && array_key_exists('court', $this->data)) { |
|
79
|
|
|
$this->data['court_all'] = $this->data['file_number'] . ', ' . $this->data['court']; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Copy data |
|
85
|
|
|
* @param array $map |
|
86
|
|
|
* @return array |
|
87
|
|
|
*/ |
|
88
|
|
|
public function toArray(array $map = []) |
|
89
|
|
|
{ |
|
90
|
|
|
$this->setFileNumberAndCourt(); |
|
91
|
|
|
if (!$map) { |
|
|
|
|
|
|
92
|
|
|
return $this->data; |
|
93
|
|
|
} |
|
94
|
|
|
$out = []; |
|
95
|
|
|
foreach ($map as $k => $v) { |
|
96
|
|
|
if ($this->offsetExists($k)) { |
|
97
|
|
|
if (!$v) { |
|
98
|
|
|
$v = $k; |
|
99
|
|
|
} |
|
100
|
|
|
$out[$v] = $this->data[$k]; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
return $out; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function __toString() |
|
107
|
|
|
{ |
|
108
|
|
|
$data = $this->toArray(); |
|
109
|
|
|
if ($data['created'] instanceof \DateTime) { |
|
110
|
|
|
$data['created'] = $data['created']->format(\DateTime::ISO8601); |
|
111
|
|
|
} |
|
112
|
|
|
return json_encode($data); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* ARRAY-ACCESS INTERFACE ************************************************** |
|
117
|
|
|
* ************************************************************************* |
|
118
|
|
|
*/ |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* |
|
122
|
|
|
* @param string $offset |
|
123
|
|
|
* @return bool |
|
124
|
|
|
*/ |
|
125
|
|
|
public function offsetExists($offset) |
|
126
|
|
|
{ |
|
127
|
|
|
return array_key_exists($offset, $this->data); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Return value from array |
|
132
|
|
|
* @param string $offset |
|
133
|
|
|
* @return string |
|
134
|
|
|
* @throws DataOffsetDoesNotExists |
|
135
|
|
|
*/ |
|
136
|
|
|
public function offsetGet($offset) |
|
137
|
|
|
{ |
|
138
|
|
|
if ($offset === 'court_all') { |
|
139
|
|
|
$this->setFileNumberAndCourt(); |
|
140
|
|
|
} |
|
141
|
|
|
if ($this->offsetExists($offset)) { |
|
142
|
|
|
return $this->data[$offset]; |
|
143
|
|
|
} |
|
144
|
|
|
throw new DataOffsetDoesNotExists($offset); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @param string $offset |
|
149
|
|
|
* @param string $value |
|
150
|
|
|
* @return string |
|
151
|
|
|
*/ |
|
152
|
|
|
public function offsetSet($offset, $value) |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->data[$offset] = $value; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Remove value from array |
|
159
|
|
|
* @param string $offset |
|
160
|
|
|
* @return void |
|
161
|
|
|
*/ |
|
162
|
|
|
public function offsetUnset($offset) |
|
163
|
|
|
{ |
|
164
|
|
|
unset($this->data[$offset]); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* ITERATOR INTERFACE ****************************************************** |
|
169
|
|
|
* ************************************************************************* |
|
170
|
|
|
*/ |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Actual value |
|
174
|
|
|
* @return void |
|
175
|
|
|
*/ |
|
176
|
|
|
public function current() |
|
177
|
|
|
{ |
|
178
|
|
|
return current($this->data); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Actual key of value |
|
183
|
|
|
* @return string |
|
184
|
|
|
*/ |
|
185
|
|
|
public function key() |
|
186
|
|
|
{ |
|
187
|
|
|
return key($this->data); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Next value |
|
192
|
|
|
* @return string |
|
193
|
|
|
*/ |
|
194
|
|
|
public function next() |
|
195
|
|
|
{ |
|
196
|
|
|
return next($this->data); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** @retrun void */ |
|
200
|
|
|
public function rewind() |
|
201
|
|
|
{ |
|
202
|
|
|
reset($this->data); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** @return bool */ |
|
206
|
|
|
public function valid() |
|
207
|
|
|
{ |
|
208
|
|
|
return array_key_exists($this->key(), $this->data); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* COUNTABLE INTERFACE ***************************************************** |
|
213
|
|
|
* ************************************************************************* |
|
214
|
|
|
*/ |
|
215
|
|
|
|
|
216
|
|
|
/** @return int */ |
|
217
|
|
|
public function count() |
|
218
|
|
|
{ |
|
219
|
|
|
return count($this->data); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
} |
|
223
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.