This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Validator/ValidatorContext.php
Bernhard Schussek efe42cbb1f [Validator] Refactored the GraphWalker into an implementation of the Visitor design pattern.
With this refactoring comes a decoupling of the validator from the structure of
the underlying metadata. This way it is possible for Drupal to use the validator
for validating their Entity API by using their own metadata layer, which is not
modeled as classes and properties/getter methods.
2012-11-24 13:00:28 +01:00

114 lines
3.2 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Validator;
use Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface;
use Symfony\Component\Validator\Mapping\ClassMetadataFactoryAdapter;
/**
* Default implementation of ValidatorContextInterface
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
* {@link Validation::createValidatorBuilder()} instead.
*/
class ValidatorContext implements ValidatorContextInterface
{
/**
* @var MetadataFactoryInterface
*/
private $metadataFactory;
/**
* The class metadata factory used in the new validator
* @var ClassMetadataFactoryInterface
*/
protected $classMetadataFactory = null;
/**
* The constraint validator factory used in the new validator
* @var ConstraintValidatorFactoryInterface
*/
protected $constraintValidatorFactory = null;
/**
* {@inheritDoc}
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
* {@link Validation::createValidatorBuilder()} instead.
*/
public function setClassMetadataFactory(ClassMetadataFactoryInterface $classMetadataFactory)
{
if ($classMetadataFactory instanceof MetadataFactoryInterface) {
$this->metadataFactory = $classMetadataFactory;
} else {
$this->metadataFactory = new ClassMetadataFactoryAdapter($classMetadataFactory);
}
$this->classMetadataFactory = $classMetadataFactory;
return $this;
}
/**
* {@inheritDoc}
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
* {@link Validation::createValidatorBuilder()} instead.
*/
public function setConstraintValidatorFactory(ConstraintValidatorFactoryInterface $constraintValidatorFactory)
{
$this->constraintValidatorFactory = $constraintValidatorFactory;
return $this;
}
/**
* {@inheritDoc}
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
* {@link Validation::createValidator()} instead.
*/
public function getValidator()
{
return new Validator(
$this->metadataFactory,
$this->constraintValidatorFactory
);
}
/**
* Returns the class metadata factory used in the new validator
*
* @return ClassMetadataFactoryInterface The factory instance
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
*/
public function getClassMetadataFactory()
{
return $this->classMetadataFactory;
}
/**
* Returns the constraint validator factory used in the new validator
*
* @return ConstraintValidatorFactoryInterface The factory instance
*
* @deprecated Deprecated since version 2.1, to be removed in 2.3.
*/
public function getConstraintValidatorFactory()
{
return $this->constraintValidatorFactory;
}
}