Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Add fluent Email validation rule #54067

Open
wants to merge 5 commits into
base: 11.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 35 additions & 32 deletions src/Illuminate/Validation/Rules/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ class Email implements Rule, DataAwareRule, ValidatorAwareRule
{
use Conditionable, Macroable;

public bool $strict = false;
public bool $rfcCompliantWithoutWarnings = false;

public bool $dns = false;
public bool $domainExists = false;
SanderMuller marked this conversation as resolved.
Show resolved Hide resolved

public bool $spoof = false;
public bool $preventEmailSpoofing = false;

public bool $filter = false;
public bool $basicFormat = false;
SanderMuller marked this conversation as resolved.
Show resolved Hide resolved

public bool $filter_unicode = false;
public bool $basicFormatUnicodeAllowed = false;

public bool $rfc = false;
public bool $rfcCompliant = false;

/**
* An array of custom rules that will be merged into the validation rules.
Expand Down Expand Up @@ -113,79 +113,82 @@ public static function default()
*/
public static function strictSecurity()
{
return (new self())->strict()->dns()->spoof();
return (new self())
->rfcCompliantWithoutWarnings()
->domainExists()
->preventEmailSpoofing();
}

/**
* Validate against NoRFCWarningsValidation.
* Validate against RFCValidation.
*
* @return $this
*/
public function strict()
public function rfcCompliant()
{
$this->strict = true;
$this->rfcCompliant = true;

return $this;
}

/**
* Validate against DNSCheckValidation.
* Requires the PHP intl extension.
* Validate against NoRFCWarningsValidation.
*
* @return $this
*/
public function dns()
public function rfcCompliantWithoutWarnings()
{
$this->dns = true;
$this->rfcCompliantWithoutWarnings = true;

return $this;
}

/**
* Validate against SpoofCheckValidation.
* Validate against DNSCheckValidation.
* Requires the PHP intl extension.
*
* @return $this
*/
public function spoof()
public function domainExists()
{
$this->spoof = true;
$this->domainExists = true;

return $this;
}

/**
* Validate against FilterEmailValidation.
* Validate against SpoofCheckValidation.
* Requires the PHP intl extension.
*
* @return $this
*/
public function filter()
public function preventEmailSpoofing()
{
$this->filter = true;
$this->preventEmailSpoofing = true;

return $this;
}

/**
* Validate against FilterEmailValidation::unicode().
* Validate against FilterEmailValidation.
*
* @return $this
*/
public function filterUnicode()
public function basicFormat()
{
$this->filter_unicode = true;
$this->basicFormat = true;

return $this;
}

/**
* Validate against RFCValidation.
* Validate against FilterEmailValidation::unicode().
*
* @return $this
*/
public function rfc()
public function basicFormatUnicodeAllowed()
{
$this->rfc = true;
$this->basicFormatUnicodeAllowed = true;

return $this;
}
Expand Down Expand Up @@ -253,27 +256,27 @@ protected function buildValidationRules()
{
$rules = [];

if ($this->rfc) {
if ($this->rfcCompliant) {
$rules[] = new RFCValidation;
}

if ($this->strict) {
if ($this->rfcCompliantWithoutWarnings) {
$rules[] = new NoRFCWarningsValidation;
}

if ($this->dns) {
if ($this->domainExists) {
$rules[] = new DNSCheckValidation;
}

if ($this->spoof) {
if ($this->preventEmailSpoofing) {
$rules[] = new SpoofCheckValidation;
}

if ($this->filter) {
if ($this->basicFormat) {
$rules[] = new FilterEmailValidation;
}

if ($this->filter_unicode) {
if ($this->basicFormatUnicodeAllowed) {
$rules[] = FilterEmailValidation::unicode();
}

Expand Down
Loading