phonenumberHelper = $phonenumberHelper; $this->logger = $logger; } /** * @param string $value * @param \Chill\MainBundle\Validation\Constraint\PhonenumberConstraint $constraint */ public function validate($value, Constraint $constraint) { if (false === $this->phonenumberHelper->isPhonenumberValidationConfigured()) { $this->logger->debug('[phonenumber] skipping validation due to not configured helper'); return; } if ('' === $value) { return; } switch ($constraint->type) { case 'landline': $isValid = $this->phonenumberHelper->isValidPhonenumberLandOrVoip($value); $message = $constraint->notLandlineMessage; break; case 'mobile': $isValid = $this->phonenumberHelper->isValidPhonenumberMobile($value); $message = $constraint->notMobileMessage; break; case 'any': $isValid = $this->phonenumberHelper->isValidPhonenumberAny($value); $message = $constraint->notValidMessage; break; default: throw new LogicException(sprintf("This type '%s' is not implemented. " . "Possible values are 'mobile', 'landline' or 'any'", $constraint->type)); } if (false === $isValid) { $this->context->addViolation($message, ['%phonenumber%' => $value]); } } }