dbout / symfony-constraints
Symfony 验证约束
dev-master
2020-09-12 16:35 UTC
Requires
- symfony/validator: ^4.0
This package is auto-updated.
Last update: 2024-09-13 02:08:23 UTC
README
包含一系列为 Symfony 4 设计的验证约束。
安装
composer require dbout/symfony-constraints
约束
-
Latitude
允许验证纬度。纬度必须在 -90度 和 90度 之间。/** * @Dbout\SfConstraints\Validator\Constraints\Latitude() */ private $latitude;
-
Longitude
允许验证经度。经度必须在 -180度 和 180度 之间。/** * @Dbout\SfConstraints\Validator\Constraints\Longitude() */ private $longitude;
-
NotHtml
允许验证不包含 HTML 代码的字符串。/** * @Dbout\SfConstraints\Validator\Constraints\NotHtml() */ private $description;
-
Password
允许验证密码。/** * @Dbout\SfConstraints\Validator\Constraints\Password() */ private $plainPassword;
-
Phone
允许验证法国格式的电话号码。/** * @Dbout\SfConstraints\Validator\Constraints\Phone() */ private $phone;
-
Username
允许验证用户名,用户名长度必须在 3 到 25 个字符之间,只能包含字母、数字或下划线。/** * @Dbout\SfConstraints\Validator\Constraints\Username(message="Le pseudo doit être compris entre 3 et 25 caractères et non doit contenir aucun caractères spécial") */ private $username;
-
PostalCode
允许验证法国格式的邮政编码。/** * @Dbout\SfConstraints\Validator\Constraints\PostalCode() */ private $postalCode;
-
UniqueEntity
允许根据属性验证实体的唯一性。此约束与 Doctrine 的UniqueEntity
约束类似,唯一的区别是这个约束可以通过ValidatorInterface
服务在外部进行验证。/** * @Dbout\SfConstraints\Validator\Constraints\UniqueEntity(message="Un compte existe déjà avec cette adresse email.") */ private $email;
使用此约束需要注入服务
@doctrine.orm.entity_manager
。services : .... Dbout\SfConstraints\Validator\Constraints\UniqueEntityValidator: arguments: ['@doctrine.orm.entity_manager'] tags: - { name: validator.constraint_validator }