Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @Callback()
- */
- public function validatePostalCode(ExecutionContextInterface $context)
- {
- $constraint = new ZipCode([
- 'country' => $this->country,
- ]);
- $violations = $context->getValidator()->validate($this->postalCode, $constraint);
- foreach ($violations as $violation) {
- /* @var $violation ConstraintViolationInterface */
- $builder = $context->buildViolation($violation->getMessage(), $violation->getParameters());
- $builder->atPath('postalCode')
- ->setCode($violation->getCode())
- ->setInvalidValue($violation->getInvalidValue());
- // getPlural is only in ConstraintViolation prior to 3.0
- if (method_exists($violation, 'getPlural')) {
- $builder->setPlural($violation->getPlural());
- }
- // getCause is only in ConstraintViolation, not in ConstraintViolationInterface even in v3.0
- if (method_exists($violation, 'getCause')) {
- $builder->setCause($violation->getCause());
- }
- $builder->addViolation();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement