/** * {@inheritDoc} */ 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::getLanguages())) { $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::getLanguages())) { $this->setMessage($constraint->message, array('{{ value }}' => $value)); return false; } return true; }
public function testGetLanguages() { $languages = Locale::getLanguages(); $this->assertTrue(in_array('pt_BR', $languages)); }
public function testGetLanguages() { $languages = Locale::getLanguages(); $this->assertContains('pt_BR', $languages); }
public function getLanguages() { return json_encode(\Symfony\Component\Locale\Locale::getLanguages()); }