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
|
|
|
|
2010-08-20 22:09:55 +01:00
|
|
|
use Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface;
|
2010-06-24 09:40:05 +01:00
|
|
|
|
|
|
|
class ValidationContext
|
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
protected $root;
|
|
|
|
protected $propertyPath;
|
|
|
|
protected $class;
|
|
|
|
protected $property;
|
|
|
|
protected $group;
|
|
|
|
protected $violations;
|
|
|
|
protected $graphWalker;
|
|
|
|
protected $metadataFactory;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
$root,
|
|
|
|
GraphWalker $graphWalker,
|
2010-09-24 15:34:58 +01:00
|
|
|
ClassMetadataFactoryInterface $metadataFactory
|
2010-06-24 10:24:08 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
$this->root = $root;
|
|
|
|
$this->graphWalker = $graphWalker;
|
|
|
|
$this->metadataFactory = $metadataFactory;
|
|
|
|
$this->violations = new ConstraintViolationList();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __clone()
|
|
|
|
{
|
|
|
|
$this->violations = clone $this->violations;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addViolation($message, array $params, $invalidValue)
|
|
|
|
{
|
|
|
|
$this->violations->add(new ConstraintViolation(
|
2010-09-24 15:34:58 +01:00
|
|
|
$message,
|
|
|
|
$params,
|
2010-06-24 10:24:08 +01:00
|
|
|
$this->root,
|
|
|
|
$this->propertyPath,
|
|
|
|
$invalidValue
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getViolations()
|
|
|
|
{
|
|
|
|
return $this->violations;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRoot()
|
|
|
|
{
|
|
|
|
return $this->root;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPropertyPath($propertyPath)
|
|
|
|
{
|
|
|
|
$this->propertyPath = $propertyPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPropertyPath()
|
|
|
|
{
|
|
|
|
return $this->propertyPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCurrentClass($class)
|
|
|
|
{
|
|
|
|
$this->class = $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCurrentClass()
|
|
|
|
{
|
|
|
|
return $this->class;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCurrentProperty($property)
|
|
|
|
{
|
|
|
|
$this->property = $property;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCurrentProperty()
|
|
|
|
{
|
|
|
|
return $this->property;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setGroup($group)
|
|
|
|
{
|
|
|
|
$this->group = $group;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getGroup()
|
|
|
|
{
|
|
|
|
return $this->group;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getGraphWalker()
|
|
|
|
{
|
|
|
|
return $this->graphWalker;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getClassMetadataFactory()
|
|
|
|
{
|
|
|
|
return $this->metadataFactory;
|
|
|
|
}
|
2010-06-24 09:40:05 +01:00
|
|
|
}
|