CoreFiles by mySites.guru
ConstraintValidatorFactory.php42 lines, 1,185 bytes, from Joomla_5.4.2-Stable-Full_Package.zip
Raw History Compare with 5.4.1
md5
718d001a1bdefcc54ef80155a0d8b1d0
sha1
e822debce57b72661343cfd9d9033e38a19621bb
sha256
8fa6772e0a508f5d0de5cabab1887463a9a33b35b966364f20e3c60297bb1997
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * 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\Constraints\ExpressionValidator;

/**
 * Default implementation of the ConstraintValidatorFactoryInterface.
 *
 * This enforces the convention that the validatedBy() method on any
 * Constraint will return the class name of the ConstraintValidator that
 * should validate the Constraint.
 *
 * @author Bernhard Schussek <[email protected]>
 */
class ConstraintValidatorFactory implements ConstraintValidatorFactoryInterface
{
    protected $validators = [];

    public function __construct(array $validators = [])
    {
        $this->validators = $validators;
    }

    public function getInstance(Constraint $constraint): ConstraintValidatorInterface
    {
        if ('validator.expression' === $name = $class = $constraint->validatedBy()) {
            $class = ExpressionValidator::class;
        }

        return $this->validators[$name] ??= new $class();
    }
}

The same content is in 133 releases, Joomla 5.1.0-beta1 to 6.2.1-rc1. See them all, or every version of this file.