/usr/share/php/Symfony/Bundle/FrameworkBundle/Validator/ConstraintValidatorFactory.php is in php-symfony-framework-bundle 2.7.10-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | <?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\Bundle\FrameworkBundle\Validator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
use Symfony\Component\Validator\ConstraintValidatorInterface;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
/**
* Uses a service container to create constraint validators.
*
* A constraint validator should be tagged as "validator.constraint_validator"
* in the service container and include an "alias" attribute:
*
* <service id="some_doctrine_validator">
* <argument type="service" id="doctrine.orm.some_entity_manager" />
* <tag name="validator.constraint_validator" alias="some_alias" />
* </service>
*
* A constraint may then return this alias in its validatedBy() method:
*
* public function validatedBy()
* {
* return 'some_alias';
* }
*
* @author Kris Wallsmith <kris@symfony.com>
*/
class ConstraintValidatorFactory implements ConstraintValidatorFactoryInterface
{
protected $container;
protected $validators;
/**
* Constructor.
*
* @param ContainerInterface $container The service container
* @param array $validators An array of validators
*/
public function __construct(ContainerInterface $container, array $validators = array())
{
$this->container = $container;
$this->validators = $validators;
}
/**
* Returns the validator for the supplied constraint.
*
* @param Constraint $constraint A constraint
*
* @return ConstraintValidatorInterface A validator for the supplied constraint
*
* @throws UnexpectedTypeException When the validator is not an instance of ConstraintValidatorInterface
*/
public function getInstance(Constraint $constraint)
{
$name = $constraint->validatedBy();
if (!isset($this->validators[$name])) {
$this->validators[$name] = new $name();
} elseif (is_string($this->validators[$name])) {
$this->validators[$name] = $this->container->get($this->validators[$name]);
}
if (!$this->validators[$name] instanceof ConstraintValidatorInterface) {
throw new UnexpectedTypeException($this->validators[$name], 'Symfony\Component\Validator\ConstraintValidatorInterface');
}
return $this->validators[$name];
}
}
|