dev-master
9999999-devSymfony validation component for predaddy
MIT
The Requires
The Development Requires
validation symfony predaddy
Wallogit.com
2017 © Pedro Peláez
Symfony validation component for predaddy
| master |
|---|
![]() |
![]() |
The ValidationInterceptor provided by this library helps validating messages posted to predaddy MessageBus.
It is based on Symfony Validator component., (*2)
$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:, (*3)
AnnotationRegistry::registerAutoloadNamespace('Symfony\Component\Validator\Constraint', 'path/to/symfony/library/validator');
Symfony validation component for predaddy
MIT
validation symfony predaddy