* * 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:----p8JQ7ng52D5Oh7UlcNGWBLjRjgdcLZBGmfmjKVeM7m/q0BNgpYasQiLsXDuO7EaVGnOVyO/Fmc1LbtAmAkoYmM9TLZywehZufQn4jnOF7IDUMHetCiR564qG+lkWOZsREyb7m1/H9QFh9ij1PJfJc7DNyA966hp0uc3Y+GHB8tNWINZMl7/o4CCU0Dnlfsj3E8iMFiIcGtBA8B/mBamszf5p0o7hyW61bVCC85Ht7bjGZJW1wrpL/hblb8cOuYakdZxs0cEIiR7sHDbUUuES0/ozEVmy1mdlUi7tBtm1ka2FWQzsfVKBBu9qTgq42BgiZ8M9OjYW1/kSlQ113tuQlakOm9K9+Fi/1lxjsXkwHj5mqt1cFT4voGw52DRr2hCNTs778f9nokAPoJ7FBBxiQ/g7sWXCJ/HoiKgGmiHB68R7jIQqqedYfMasRr52OiytumpbrGq9AmH6DlFFoe37Rd+lOexlRNIpgGlr1+A7vw4ohABhYJwo8e27Rk05eObLq3G/VzUzh8HAkDEuSCLY2Slfg7BKDGqSf+eDbiv2YnlGCYAQvRrbKc/ArftLc0RifPW37uSJ3esfmHFtewbYZiCi+Qi+3nKtoCfcyNbKuHEP5L3g59P3ReB6Uw6IZrZJG7NPEvgEzMTRwytYpnA76l23SjS7BkHLCE8iOKYds94=----ATTACHMENT:----NDI0MDg3Mjc0MDEzNDg5MCAxMzUyNzg1MzI5MjQzMzA3IDc3MzUwMjg4OTY0ODI5NzA=