2010-06-24 09:40:05 +01:00
|
|
|
<?php
|
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
namespace Symfony\Component\Validator;
|
2010-06-24 09:40:05 +01:00
|
|
|
|
|
|
|
class ConstraintViolationList implements \IteratorAggregate, \Countable
|
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
protected $violations = array();
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function __toString()
|
2010-06-24 09:40:05 +01:00
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
$string = '';
|
|
|
|
|
|
|
|
foreach ($this->violations as $violation) {
|
2010-07-01 01:10:28 +01:00
|
|
|
$root = $violation->getRoot();
|
|
|
|
$class = is_object($root) ? get_class($root) : $root;
|
2010-06-24 10:24:08 +01:00
|
|
|
$string .= <<<EOF
|
2010-07-01 01:10:28 +01:00
|
|
|
{$class}.{$violation->getPropertyPath()}:
|
|
|
|
{$violation->getMessage()}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
|
|
|
EOF;
|
2010-06-24 10:24:08 +01:00
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
return $string;
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function add(ConstraintViolation $violation)
|
|
|
|
{
|
|
|
|
$this->violations[] = $violation;
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function addAll(ConstraintViolationList $violations)
|
2010-06-24 09:40:05 +01:00
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
foreach ($violations->violations as $violation) {
|
|
|
|
$this->violations[] = $violation;
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
}
|
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function getIterator()
|
|
|
|
{
|
|
|
|
return new \ArrayIterator($this->violations);
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
public function count()
|
|
|
|
{
|
|
|
|
return count($this->violations);
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
}
|