predaddy/predaddy-symfony-validator
Composer 安装命令:
composer require predaddy/predaddy-symfony-validator
包简介
Symfony validation component for predaddy
README 文档
README
| master |
|---|
The ValidationInterceptor provided by this library helps validating messages posted to predaddy MessageBus.
It is based on Symfony Validator component.
Usage
$bus = SimpleMessageBus::builder() ->withInterceptors([new ValidatorInterceptor()]) ->build();
class CreateUser { /** * @Assert\Length(min = 3) * @Assert\NotBlank */ private $name; /** * @Assert\Email * @Assert\NotBlank */ private $email; public function __construct($name, $email) { $this->name = $name; $this->email = $email; } /** * @Assert\True(message = "The user should have a Google Mail account") */ public function isGmailUser() { return false !== strpos($this->email, '@gmail.com'); } public function __toString() { return Objects::toStringHelper($this) ->add('name', $this->name) ->add('email', $this->email) ->toString(); } }
try { $bus->post(new CreateUser('John Doe', 'john@example.com')); } catch (ValidationException $e) { $e->getViolationList(); }
If you use annotation constraints, do not forget to register its namespace:
AnnotationRegistry::registerAutoloadNamespace('Symfony\Component\Validator\Constraint', 'path/to/symfony/library/validator');
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2014-11-08