parse($value, PhoneNumberUtil::UNKNOWN_REGION); } catch (NumberParseException) { $this->addViolation($value, $constraint); return; } } if (false === $phoneUtil->isValidNumber($phoneNumber)) { $this->addViolation($value, $constraint); return; } } /** * Add a violation. * * @param mixed $value the value that should be validated * @param Constraint $constraint the constraint for the validation */ private function addViolation($value, Constraint $constraint): void { $this->context->addViolation( $constraint->getMessage(), ['{{ value }}' => $value] ); } }