Skip to content

Commit c944281

Browse files
committed
bug #47189 [Validator] Add additional hint when egulias/email-validator needs to be installed (mpdude)
This PR was merged into the 4.4 branch. Discussion ---------- [Validator] Add additional hint when `egulias/email-validator` needs to be installed | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | When using the `Symfony\Component\Validator\Constraints\Email` constraint with `'mode' => 'strict'`, a helpful error message is shown when the necessary package is not installed. However, when configuring `strict` mode as a framework setting (https://symfony.com/doc/current/reference/configuration/framework.html#email-validation-mode) and omitting the `mode` setting on the constraint itself, that message was missing. Commits ------- 3924498 [Validator] Hint that `egulias/email-validator` needs to be installed for strict mode as default config
2 parents 675756f + 3924498 commit c944281

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Symfony/Component/Validator/Constraints/EmailValidator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ public function validate($value, Constraint $constraint)
100100
}
101101

102102
if (null === $constraint->mode) {
103+
if (Email::VALIDATION_MODE_STRICT === $this->defaultMode && !class_exists(EguliasEmailValidator::class)) {
104+
throw new LogicException(sprintf('The "egulias/email-validator" component is required to make the "%s" constraint default to strict mode.', EguliasEmailValidator::class));
105+
}
106+
103107
$constraint->mode = $this->defaultMode;
104108
}
105109

0 commit comments

Comments
 (0)