vendor/symfony/validator/Constraints/Email.php line 79

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Validator\Constraints;
  11. use Egulias\EmailValidator\EmailValidator as StrictEmailValidator;
  12. use Symfony\Component\Validator\Constraint;
  13. use Symfony\Component\Validator\Exception\InvalidArgumentException;
  14. use Symfony\Component\Validator\Exception\LogicException;
  15. /**
  16.  * @Annotation
  17.  * @Target({"PROPERTY", "METHOD", "ANNOTATION"})
  18.  *
  19.  * @author Bernhard Schussek <bschussek@gmail.com>
  20.  */
  21. class Email extends Constraint
  22. {
  23.     public const VALIDATION_MODE_HTML5 'html5';
  24.     public const VALIDATION_MODE_STRICT 'strict';
  25.     public const VALIDATION_MODE_LOOSE 'loose';
  26.     public const INVALID_FORMAT_ERROR 'bd79c0ab-ddba-46cc-a703-a7a4b08de310';
  27.     /**
  28.      * @deprecated since Symfony 4.2.
  29.      */
  30.     public const MX_CHECK_FAILED_ERROR 'bf447c1c-0266-4e10-9c6c-573df282e413';
  31.     /**
  32.      * @deprecated since Symfony 4.2.
  33.      */
  34.     public const HOST_CHECK_FAILED_ERROR '7da53a8b-56f3-4288-bb3e-ee9ede4ef9a1';
  35.     protected static $errorNames = [
  36.         self::INVALID_FORMAT_ERROR => 'STRICT_CHECK_FAILED_ERROR',
  37.         self::MX_CHECK_FAILED_ERROR => 'MX_CHECK_FAILED_ERROR',
  38.         self::HOST_CHECK_FAILED_ERROR => 'HOST_CHECK_FAILED_ERROR',
  39.     ];
  40.     /**
  41.      * @var string[]
  42.      *
  43.      * @internal
  44.      */
  45.     public static $validationModes = [
  46.         self::VALIDATION_MODE_HTML5,
  47.         self::VALIDATION_MODE_STRICT,
  48.         self::VALIDATION_MODE_LOOSE,
  49.     ];
  50.     public $message 'This value is not a valid email address.';
  51.     /**
  52.      * @deprecated since Symfony 4.2.
  53.      */
  54.     public $checkMX false;
  55.     /**
  56.      * @deprecated since Symfony 4.2.
  57.      */
  58.     public $checkHost false;
  59.     /**
  60.      * @deprecated since Symfony 4.1, set mode to "strict" instead.
  61.      */
  62.     public $strict;
  63.     public $mode;
  64.     public $normalizer;
  65.     public function __construct($options null)
  66.     {
  67.         if (\is_array($options) && \array_key_exists('strict'$options)) {
  68.             @trigger_error(sprintf('The "strict" property is deprecated since Symfony 4.1. Use "mode"=>"%s" instead.'self::VALIDATION_MODE_STRICT), \E_USER_DEPRECATED);
  69.         }
  70.         if (\is_array($options) && \array_key_exists('checkMX'$options)) {
  71.             @trigger_error('The "checkMX" option is deprecated since Symfony 4.2.', \E_USER_DEPRECATED);
  72.         }
  73.         if (\is_array($options) && \array_key_exists('checkHost'$options)) {
  74.             @trigger_error('The "checkHost" option is deprecated since Symfony 4.2.', \E_USER_DEPRECATED);
  75.         }
  76.         if (\is_array($options) && \array_key_exists('mode'$options) && !\in_array($options['mode'], self::$validationModestrue)) {
  77.             throw new InvalidArgumentException('The "mode" parameter value is not valid.');
  78.         }
  79.         parent::__construct($options);
  80.         if ((self::VALIDATION_MODE_STRICT === $this->mode || true === $this->strict) && !class_exists(StrictEmailValidator::class)) {
  81.             // throw new LogicException(sprintf('The "egulias/email-validator" component is required to use the "%s" constraint in strict mode.', __CLASS__));
  82.             @trigger_error(sprintf('Using the "%s" constraint in strict mode without the "egulias/email-validator" component installed is deprecated since Symfony 4.2.'__CLASS__), \E_USER_DEPRECATED);
  83.         }
  84.         if (null !== $this->normalizer && !\is_callable($this->normalizer)) {
  85.             throw new InvalidArgumentException(sprintf('The "normalizer" option must be a valid callable ("%s" given).', \is_object($this->normalizer) ? \get_class($this->normalizer) : \gettype($this->normalizer)));
  86.         }
  87.     }
  88. }