/** * Checks if the passed value is valid. * * @param mixed $value The value that should be validated * @param Constraint $constraint The constraint for the validation * * @api */ public function validate($value, Constraint $constraint) { if (null === $value || '' === $value) { return; } if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) { throw new UnexpectedTypeException($value, 'string'); } $value = (string) $value; if (!in_array($value, \Symfony\Component\Locale\Locale::getCountries())) { $this->context->addViolation($constraint->message, array('{{ value }}' => $value)); } }
public function isValid($value, Constraint $constraint) { if (null === $value || '' === $value) { return true; } if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString()'))) { throw new UnexpectedTypeException($value, 'string'); } $value = (string) $value; if (!in_array($value, Locale::getCountries())) { $this->setMessage($constraint->message, array('{{ value }}' => $value)); return false; } return true; }
public function testGetCountries() { $countries = Locale::getCountries(); $this->assertTrue(in_array('BR', $countries)); }
public function testGetCountriesForSwitzerland() { $countries = Locale::getCountries(); $this->assertContains('CH', $countries); }
public function getCountries() { return json_encode(\Symfony\Component\Locale\Locale::getCountries()); }