Assert\Assertion::email PHP Method

email() public static method

Assert that value is an email adress (using input_filter/FILTER_VALIDATE_EMAIL).
public static email ( mixed $value, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$message string | null
$propertyPath string | null
return boolean
    public static function email($value, $message = null, $propertyPath = null)
    {
        static::string($value, $message, $propertyPath);
        if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
            $message = sprintf($message ?: 'Value "%s" was expected to be a valid e-mail address.', static::stringify($value));
            throw static::createException($value, $message, static::INVALID_EMAIL, $propertyPath);
        } else {
            $host = substr($value, strpos($value, '@') + 1);
            // Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3
            if (version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false) {
                $message = sprintf($message ?: 'Value "%s" was expected to be a valid e-mail address.', static::stringify($value));
                throw static::createException($value, $message, static::INVALID_EMAIL, $propertyPath);
            }
        }
        return true;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @param string $value
  */
 private function __construct($value)
 {
     if (!empty($value)) {
         Guard::email($value, 'Email Address is invalid');
     }
     $this->value = $value;
 }
All Usage Examples Of Assert\Assertion::email