respect-validation/library/Exceptions/RecursiveExceptionIterator.php
Henrique Moody ef8a8f4b27
Turn LICENSE file into plain/text
There is no need for that file to be a Markdown, and it can be a plain
text file.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-23 16:21:34 +02:00

82 lines
1.6 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 file
* that was distributed with this source code.
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
use ArrayIterator;
use Countable;
use RecursiveIterator;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
*/
final class RecursiveExceptionIterator implements RecursiveIterator, Countable
{
/**
* @var ArrayIterator|ValidationException[]
*/
private $exceptions;
public function __construct(NestedValidationException $parent)
{
$this->exceptions = new ArrayIterator($parent->getChildren());
}
public function count(): int
{
return $this->exceptions->count();
}
public function hasChildren(): bool
{
if (!$this->valid()) {
return false;
}
return $this->current() instanceof NestedValidationException;
}
public function getChildren(): self
{
return new static($this->current());
}
/**
* @return ValidationException|NestedValidationException
*/
public function current(): ValidationException
{
return $this->exceptions->current();
}
public function key(): int
{
return $this->exceptions->key();
}
public function next(): void
{
$this->exceptions->next();
}
public function rewind(): void
{
$this->exceptions->rewind();
}
public function valid(): bool
{
return $this->exceptions->valid();
}
}