95 $this->errors[] = $error;
106 $this->warnings[] = $warning;
117 $this->notices[] = $notice;
158 reset($this->errors);
159 return current($this->errors);
169 reset($this->warnings);
170 return current($this->warnings);
180 reset($this->notices);
181 return current($this->notices);
195 if ($propertyPath ===
'' || $propertyPath ===
null) {
198 if (strpos($propertyPath,
'.') !==
false) {
201 if (!isset($this->propertyResults[$propertyPath])) {
202 $this->propertyResults[$propertyPath] =
new self();
203 $this->propertyResults[$propertyPath]->setParent($this);
205 return $this->propertyResults[$propertyPath];
216 if (empty($pathSegments)) {
220 $propertyName = array_shift($pathSegments);
222 if (!isset($this->propertyResults[$propertyName])) {
223 $this->propertyResults[$propertyName] =
new self();
224 $this->propertyResults[$propertyName]->setParent($this);
227 return $this->propertyResults[$propertyName]->recurseThroughResult($pathSegments);
236 $this->errorsExist =
true;
237 if ($this->parent !==
null) {
238 $this->parent->setErrorsExist();
248 $this->warningsExist =
true;
249 if ($this->parent !==
null) {
250 $this->parent->setWarningsExist();
260 $this->noticesExist =
true;
261 if ($this->parent !==
null) {
262 $this->parent->setNoticesExist();
283 $this->warnings = [];
285 $this->warningsExist =
false;
286 $this->noticesExist =
false;
287 $this->errorsExist =
false;
289 $this->propertyResults = [];
299 protected function hasProperty($propertyName, $checkerMethodName)
301 if (!empty($this->{$propertyName})) {
304 foreach ($this->propertyResults as $subResult) {
305 if ($subResult->{$checkerMethodName}()) {
317 public function hasErrors()
319 return $this->hasProperty(
'errors',
'hasErrors');
327 public function hasWarnings()
329 return $this->hasProperty(
'warnings',
'hasWarnings');
337 public function hasNotices()
339 return $this->hasProperty(
'notices',
'hasNotices');
349 public function getFlattenedErrors()
352 $this->flattenTree(
'errors', $result, []);
363 public function getFlattenedWarnings()
366 $this->flattenTree(
'warnings', $result, []);
377 public function getFlattenedNotices()
380 $this->flattenTree(
'notices', $result, []);
393 public function flattenTree($propertyName, &$result, $level)
395 if (!empty($this->$propertyName)) {
396 $result[implode(
'.', $level)] = $this->$propertyName;
398 foreach ($this->propertyResults as $subPropertyName => $subResult) {
399 $level[] = $subPropertyName;
400 $subResult->flattenTree($propertyName, $result, $level);
410 public function merge(Result $otherResult)
412 if ($otherResult->errorsExist) {
413 $this->mergeProperty($otherResult,
'getErrors',
'addError');
415 if ($otherResult->warningsExist) {
416 $this->mergeProperty($otherResult,
'getWarnings',
'addWarning');
418 if ($otherResult->noticesExist) {
419 $this->mergeProperty($otherResult,
'getNotices',
'addNotice');
422 foreach ($otherResult->getSubResults() as $subPropertyName => $subResult) {
424 if (array_key_exists($subPropertyName, $this->propertyResults) && $this->propertyResults[$subPropertyName]->hasMessages()) {
425 $this->forProperty($subPropertyName)->merge($subResult);
427 $this->propertyResults[$subPropertyName] = $subResult;
428 $subResult->setParent($this);
440 protected function mergeProperty(
Result $otherResult, $getterName, $adderName)
442 foreach ($otherResult->$getterName() as $messageInOtherResult) {
443 $this->$adderName($messageInOtherResult);
452 public function getSubResults()
454 return $this->propertyResults;