diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index ab55275b20b2c..40115dcc09f46 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -480,6 +480,7 @@ private function addValidationSection(ArrayNodeDefinition $rootNode) ->end() ->scalarNode('translation_domain')->defaultValue('validators')->end() ->booleanNode('strict_email')->defaultFalse()->end() + ->booleanNode('use_dns')->defaultTrue()->end() ->end() ->end() ->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 324915ecb211d..adb7dac39afda 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -770,6 +770,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder $definition = $container->findDefinition('validator.email'); $definition->replaceArgument(0, $config['strict_email']); + $definition->replaceArgument(1, $config['use_dns']); if (array_key_exists('enable_annotations', $config) && $config['enable_annotations']) { $validatorBuilder->addMethodCall('enableAnnotationMapping', array(new Reference('annotation_reader'))); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml index ce317f35e1abc..b35efaa9bcbb7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml @@ -48,6 +48,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 9a73e95890d19..0ed513d50ebbc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -211,6 +211,7 @@ protected static function getBundleDefaultConfig() 'static_method' => array('loadValidatorMetadata'), 'translation_domain' => 'validators', 'strict_email' => false, + 'use_dns' => true, ), 'annotations' => array( 'cache' => 'file', diff --git a/src/Symfony/Component/Validator/Constraints/EmailValidator.php b/src/Symfony/Component/Validator/Constraints/EmailValidator.php index f804f17cabfcf..3eb6f4194c08c 100644 --- a/src/Symfony/Component/Validator/Constraints/EmailValidator.php +++ b/src/Symfony/Component/Validator/Constraints/EmailValidator.php @@ -26,9 +26,15 @@ class EmailValidator extends ConstraintValidator */ private $isStrict; - public function __construct($strict = false) + /** + * @var bool + */ + private $useDNS; + + public function __construct($strict = false, $useDNS = true) { $this->isStrict = $strict; + $this->useDNS = $useDNS; } /** @@ -80,23 +86,25 @@ public function validate($value, Constraint $constraint) $host = substr($value, strpos($value, '@') + 1); - // Check for host DNS resource records - if ($constraint->checkMX) { - if (!$this->checkMX($host)) { + if ($this->useDNS) { + // Check for host DNS resource records + if ($constraint->checkMX) { + if (!$this->checkMX($host)) { + $this->context->buildViolation($constraint->message) + ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Email::MX_CHECK_FAILED_ERROR) + ->addViolation(); + } + + return; + } + + if ($constraint->checkHost && !$this->checkHost($host)) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) - ->setCode(Email::MX_CHECK_FAILED_ERROR) + ->setCode(Email::HOST_CHECK_FAILED_ERROR) ->addViolation(); } - - return; - } - - if ($constraint->checkHost && !$this->checkHost($host)) { - $this->context->buildViolation($constraint->message) - ->setParameter('{{ value }}', $this->formatValue($value)) - ->setCode(Email::HOST_CHECK_FAILED_ERROR) - ->addViolation(); } }