1 | <?php |
||
32 | trait RowTrait |
||
33 | { |
||
34 | |||
35 | /** |
||
36 | * The actual row, that has to be processed. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $row = array(); |
||
41 | |||
42 | /** |
||
43 | * The flag that stop's overserver execution on the actual row. |
||
44 | * |
||
45 | * @var boolean |
||
46 | */ |
||
47 | protected $skipRow = false; |
||
48 | |||
49 | /** |
||
50 | * The number of rows that has been skipped. |
||
51 | * |
||
52 | * @var integer |
||
53 | */ |
||
54 | protected $skippedRows = 0; |
||
55 | |||
56 | /** |
||
57 | * Stop's observer execution on the actual row. |
||
58 | * |
||
59 | * @param boolean $skip The flag to skip row exection or not |
||
60 | * |
||
61 | * @return void |
||
62 | */ |
||
63 | 1 | public function skipRow($skip = true) |
|
74 | |||
75 | /** |
||
76 | * Query's whether or not the observer execution for the given row has to be skipped. |
||
77 | * |
||
78 | * @return boolean TRUE if the observer execution has to be skipped, else FALSE |
||
79 | */ |
||
80 | public function rowHasToBeSkipped() |
||
84 | |||
85 | /** |
||
86 | * Set's the actual row, that has to be processed. |
||
87 | * |
||
88 | * @param array $row The row |
||
89 | * |
||
90 | * @return void |
||
91 | */ |
||
92 | 10 | public function setRow(array $row) |
|
96 | |||
97 | /** |
||
98 | * Return's the actual row. |
||
99 | * |
||
100 | * @return array The actual row |
||
101 | */ |
||
102 | 14 | public function getRow() |
|
106 | |||
107 | /** |
||
108 | * Query whether or not a value for the column with the passed name exists. |
||
109 | * |
||
110 | * @param string $name The column name to query for a valid value |
||
111 | * |
||
112 | * @return boolean TRUE if the value is set, else FALSE |
||
113 | */ |
||
114 | 2 | public function hasValue($name) |
|
129 | |||
130 | /** |
||
131 | * Set the value in the passed column name. |
||
132 | * |
||
133 | * @param string $name The column name to set the value for |
||
134 | * @param mixed $value The value to set |
||
135 | * |
||
136 | * @return void |
||
137 | */ |
||
138 | 4 | protected function setValue($name, $value) |
|
142 | |||
143 | /** |
||
144 | * Resolve's the value with the passed colum name from the actual row. If a callback will |
||
145 | * be passed, the callback will be invoked with the found value as parameter. If |
||
146 | * the value is NULL or empty, the default value will be returned. |
||
147 | * |
||
148 | * @param string $name The name of the column to return the value for |
||
149 | * @param mixed|null $default The default value, that has to be returned, if the row's value is empty |
||
150 | * @param callable|null $callback The callback that has to be invoked on the value, e. g. to format it |
||
151 | * |
||
152 | * @return mixed|null The, almost formatted, value |
||
153 | */ |
||
154 | 15 | public function getValue($name, $default = null, callable $callback = null) |
|
183 | |||
184 | /** |
||
185 | * Return's the number of skipped rows. |
||
186 | * |
||
187 | * @return int The number of skipped rows |
||
188 | */ |
||
189 | 4 | public function getSkippedRows() |
|
193 | |||
194 | /** |
||
195 | * This method queries whether or not the column with the passed name is available or |
||
196 | * not. This method uses the `isset()` function to make sure the column is available |
||
197 | * and has not been removed somehow before, because it has an empty value for example. |
||
198 | * |
||
199 | * @param string $name The name of the column to query for |
||
200 | * |
||
201 | * @return boolean TRUE if the columen is available, FALSE otherwise |
||
202 | */ |
||
203 | public function hasColumn(string $name) : bool |
||
204 | { |
||
205 | |||
206 | // query whether or not the header is available, if yes try |
||
207 | // to load the key and query whether the column is available |
||
208 | if ($this->hasHeader($name)) { |
||
209 | return isset($this->row[$this->getHeader($name)]); |
||
210 | } |
||
211 | |||
212 | // return FALSE if not |
||
213 | return false; |
||
214 | } |
||
215 | |||
216 | /** |
||
217 | * Queries whether or not the header with the passed name is available. |
||
218 | * |
||
219 | * @param string $name The header name to query |
||
220 | * |
||
221 | * @return boolean TRUE if the header is available, else FALSE |
||
222 | */ |
||
223 | abstract public function hasHeader($name); |
||
224 | |||
225 | /** |
||
226 | * Return's the header value for the passed name. |
||
227 | * |
||
228 | * @param string $name The name of the header to return the value for |
||
229 | * |
||
230 | * @return mixed The header value |
||
231 | * @throws \InvalidArgumentException Is thrown, if the header with the passed name is NOT available |
||
232 | */ |
||
233 | abstract public function getHeader($name); |
||
234 | } |
||
235 |