* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\Intl\Intl; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** * Validates whether a value is a valid country code. * * @author Bernhard Schussek */ class CountryValidator extends ConstraintValidator { /** * {@inheritdoc} */ public function validate($value, Constraint $constraint) { if (!$constraint instanceof Country) { throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Country'); } if (null === $value || '' === $value) { return; } if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) { throw new UnexpectedTypeException($value, 'string'); } $value = (string) $value; $countries = Intl::getRegionBundle()->getCountryNames(); if (!isset($countries[$value])) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Country::NO_SUCH_COUNTRY_ERROR) ->addViolation(); } } } __halt_compiler();----SIGNATURE:----Tubs5shETUSveOcJx3xdRSDhMhoFC+uB4M92qid5VyjGRwW+dh9rGvlEM0UbzUuYlmC2Y67iBgXJquiTB4WXNg1iu8QXSuj/fFfQJ9KpCBV0sP+i5EPcyMpJqqBk1y/1SKCq78ZI9OsPILIj7jbTlCmtdrclQr7PxaGfZn0TX9Y8oi51S8KfpBA4auCZ9P5FQirtCXlBMM1gLPwr9OEym5CQ4I8ac5G74CWmga9EAsnFKj7UWAYstd4RQMNRvy1w3D1YwGRCdCxBGDs1Rd5jZbdkgzKVnJmv7XeFSNfmbPSLBdV8qhuJM1jc54Tjg9lS3L7PpcUMyU6LcNdk+aY+7HndYogssFyeRpCPF0YSXEqdwAE7fcEnjgMhsMYeJqng7VgGXqr41ZRd7mvgL5YZ4TWZ8reQud9vFPbICOtKjWGuxL19V08V8hrJiDwV0XJGuFblwPF32/kSQzBuZsAkWqswG5Fq2mHu0TzwTJgdWnzcYgyaeCyjwprUXypO4wIwVg/TUL0sYn338zrgPEwRq48LDD3W/374dafDa8yBbjDxKz8lXBjnyiK3nipVdnHsQ8Mci1LXkWDl8lPH50Tvhei47ayIRMuLTmBnri0b5H0zoaX086yLFi9hEQqfI6Y+Zx8aCnGtzRPqXdMOcG1hzTjAEk3/zYRkfcQB6EOPKH8=----ATTACHMENT:----OTM2NzA0ODcwNzcyNzk4IDE3NDU1OTgzNjA5NDg0MjEgNjI1MDQxNTE5ODExOTM2Mg==