View source
<?php
namespace Symfony\Component\Validator\Context;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\MetadataFactoryInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
class LegacyExecutionContext extends ExecutionContext {
private $metadataFactory;
public function __construct(ValidatorInterface $validator, $root, MetadataFactoryInterface $metadataFactory, TranslatorInterface $translator, $translationDomain = null) {
parent::__construct($validator, $root, $translator, $translationDomain);
$this->metadataFactory = $metadataFactory;
}
public function addViolation($message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null) {
if (func_num_args() > 2) {
$this
->buildViolation($message, $parameters)
->setInvalidValue($invalidValue)
->setPlural($plural)
->setCode($code)
->addViolation();
return;
}
parent::addViolation($message, $parameters);
}
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null) {
if (func_num_args() > 2) {
$this
->buildViolation($message, $parameters)
->atPath($subPath)
->setInvalidValue($invalidValue)
->setPlural($plural)
->setCode($code)
->addViolation();
return;
}
$this
->buildViolation($message, $parameters)
->atPath($subPath)
->addViolation();
}
public function validate($value, $subPath = '', $groups = null, $traverse = false, $deep = false) {
if (is_array($value)) {
$constraint = new Valid(array(
'traverse' => true,
'deep' => $deep,
));
return $this
->getValidator()
->inContext($this)
->atPath($subPath)
->validate($value, $constraint, $groups);
}
if ($traverse && $value instanceof \Traversable) {
$constraint = new Valid(array(
'traverse' => true,
'deep' => $deep,
));
return $this
->getValidator()
->inContext($this)
->atPath($subPath)
->validate($value, $constraint, $groups);
}
return $this
->getValidator()
->inContext($this)
->atPath($subPath)
->validate($value, null, $groups);
}
public function validateValue($value, $constraints, $subPath = '', $groups = null) {
return $this
->getValidator()
->inContext($this)
->atPath($subPath)
->validate($value, $constraints, $groups);
}
public function getMetadataFactory() {
return $this->metadataFactory;
}
}