Valida que un valor es un código de idioma válido.
Aplica a | propiedad o método |
Opciones | |
Clase | Symfony\Component\Validator\Constraints\Language |
Validador | Symfony\Component\Validator\Constraints\LanguageValidator |
# src/UserBundle/Resources/config/validation.yml
Acme\UserBundle\Entity\User:
properties:
preferredLanguage:
- Language:
// src/Acme/UserBundle/Entity/User.php
namespace Acme\UserBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class User
{
/**
* @Assert\Language
*/
protected $preferredLanguage;
}
<!-- src/Acme/UserBundle/Resources/config/validation.xml -->
<class name="Acme\UserBundle\Entity\User">
<property name="preferredLanguage">
<constraint name="Language" />
</property>
</class>
// src/Acme/UserBundle/Entity/User.php
namespace Acme\UserBundle\Entity;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;
class User
{
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('preferredLanguage', new Assert\Language());
}
}