mirror of
https://github.com/Respect/Validation.git
synced 2024-06-29 10:40:24 +02:00
5a41a6bf0c
When the exception has only one related exception, there is no need to display it's messages unless it has an user-defined template.
58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Respect/Validation.
|
|
*
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
*
|
|
* For the full copyright and license information, please view the "LICENSE.md"
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Respect\Validation;
|
|
|
|
use RecursiveArrayIterator;
|
|
use Respect\Validation\Exceptions\AbstractNestedException;
|
|
|
|
class ExceptionIterator extends RecursiveArrayIterator
|
|
{
|
|
protected $fullRelated;
|
|
|
|
public function __construct($target, $fullRelated = false)
|
|
{
|
|
$this->fullRelated = $fullRelated;
|
|
parent::__construct(is_array($target) ? $target : array($target));
|
|
}
|
|
|
|
public function current()
|
|
{
|
|
$current = parent::current();
|
|
if ($this->fullRelated
|
|
|| $current->hasCustomTemplate()
|
|
|| !$current instanceof AbstractNestedException) {
|
|
return $current;
|
|
}
|
|
|
|
$currentRelated = $current->getRelated(false);
|
|
if (count($currentRelated) == 1) {
|
|
return current($currentRelated);
|
|
}
|
|
|
|
return $current;
|
|
}
|
|
|
|
public function hasChildren()
|
|
{
|
|
if (!$this->current() instanceof AbstractNestedException) {
|
|
return false;
|
|
} else {
|
|
return (boolean) $this->current()->getRelated($this->fullRelated);
|
|
}
|
|
}
|
|
|
|
public function getChildren()
|
|
{
|
|
return new static($this->current()->getRelated($this->fullRelated), $this->fullRelated);
|
|
}
|
|
}
|