use Doctrine\Common\Annotations\CachedReader;
use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Cache\ArrayCache;
-use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\Translation\IdentityTranslator;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Context\ExecutionContextFactory;
-use Symfony\Component\Validator\Exception\InvalidArgumentException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\Validator\Mapping\Cache\CacheInterface;
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
+use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Validator\Mapping\Loader\LoaderChain;
+use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader;
use Symfony\Component\Validator\Mapping\Loader\XmlFileLoader;
-use Symfony\Component\Validator\Mapping\Loader\XmlFilesLoader;
use Symfony\Component\Validator\Mapping\Loader\YamlFileLoader;
-use Symfony\Component\Validator\Mapping\Loader\YamlFilesLoader;
use Symfony\Component\Validator\Validator\RecursiveValidator;
/**
*/
private $translationDomain;
- /**
- * @var PropertyAccessorInterface|null
- */
- private $propertyAccessor;
-
/**
* {@inheritdoc}
*/
*/
public function setConstraintValidatorFactory(ConstraintValidatorFactoryInterface $validatorFactory)
{
- if (null !== $this->propertyAccessor) {
- throw new ValidatorException('You cannot set a validator factory after setting a custom property accessor. Remove the call to setPropertyAccessor() if you want to call setConstraintValidatorFactory().');
- }
-
$this->validatorFactory = $validatorFactory;
return $this;
}
/**
- * {@inheritdoc}
- *
- * @deprecated since version 2.5, to be removed in 3.0.
- * The validator will function without a property accessor.
+ * @return LoaderInterface[]
*/
- public function setPropertyAccessor(PropertyAccessorInterface $propertyAccessor)
+ public function getLoaders()
{
- @trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. The validator will function without a property accessor.', E_USER_DEPRECATED);
+ $loaders = array();
- if (null !== $this->validatorFactory) {
- throw new ValidatorException('You cannot set a property accessor after setting a custom validator factory. Configure your validator factory instead.');
+ foreach ($this->xmlMappings as $xmlMapping) {
+ $loaders[] = new XmlFileLoader($xmlMapping);
}
- $this->propertyAccessor = $propertyAccessor;
-
- return $this;
- }
+ foreach ($this->yamlMappings as $yamlMappings) {
+ $loaders[] = new YamlFileLoader($yamlMappings);
+ }
- /**
- * {@inheritdoc}
- *
- * @deprecated since version 2.7, to be removed in 3.0.
- */
- public function setApiVersion($apiVersion)
- {
- @trigger_error('The '.__METHOD__.' method is deprecated in version 2.7 and will be removed in version 3.0.', E_USER_DEPRECATED);
+ foreach ($this->methodMappings as $methodName) {
+ $loaders[] = new StaticMethodLoader($methodName);
+ }
- if (!in_array($apiVersion, array(Validation::API_VERSION_2_4, Validation::API_VERSION_2_5, Validation::API_VERSION_2_5_BC))) {
- throw new InvalidArgumentException(sprintf('The requested API version is invalid: "%s"', $apiVersion));
+ if ($this->annotationReader) {
+ $loaders[] = new AnnotationLoader($this->annotationReader);
}
- return $this;
+ return $loaders;
}
/**
$metadataFactory = $this->metadataFactory;
if (!$metadataFactory) {
- $loaders = array();
-
- if (count($this->xmlMappings) > 1) {
- $loaders[] = new XmlFilesLoader($this->xmlMappings);
- } elseif (1 === count($this->xmlMappings)) {
- $loaders[] = new XmlFileLoader($this->xmlMappings[0]);
- }
-
- if (count($this->yamlMappings) > 1) {
- $loaders[] = new YamlFilesLoader($this->yamlMappings);
- } elseif (1 === count($this->yamlMappings)) {
- $loaders[] = new YamlFileLoader($this->yamlMappings[0]);
- }
-
- foreach ($this->methodMappings as $methodName) {
- $loaders[] = new StaticMethodLoader($methodName);
- }
-
- if ($this->annotationReader) {
- $loaders[] = new AnnotationLoader($this->annotationReader);
- }
-
+ $loaders = $this->getLoaders();
$loader = null;
if (count($loaders) > 1) {
$metadataFactory = new LazyLoadingMetadataFactory($loader, $this->metadataCache);
}
- $validatorFactory = $this->validatorFactory ?: new ConstraintValidatorFactory($this->propertyAccessor);
+ $validatorFactory = $this->validatorFactory ?: new ConstraintValidatorFactory();
$translator = $this->translator;
if (null === $translator) {