Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
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
Prev Previous commit
Address PR Comments
  • Loading branch information
patrick-mcdougle committed Mar 14, 2016
commit 4d10fcaaf23c556c02adb8367b8c698867c3a85a
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ private function addValidationSection(ArrayNodeDefinition $rootNode)
->end()
->scalarNode('translation_domain')->defaultValue('validators')->end()
->booleanNode('strict_email')->defaultFalse()->end()
->booleanNode('prevent_dns_lookups')->defaultFalse()->end()
->booleanNode('use_dns')->defaultTrue()->end()
->end()
->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder

$definition = $container->findDefinition('validator.email');
$definition->replaceArgument(0, $config['strict_email']);
$definition->replaceArgument(1, $config['prevent_dns_lookups']);
$definition->replaceArgument(1, $config['use_dns']);

if (array_key_exists('enable_annotations', $config) && $config['enable_annotations']) {
$validatorBuilder->addMethodCall('enableAnnotationMapping', array(new Reference('annotation_reader')));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected static function getBundleDefaultConfig()
'static_method' => array('loadValidatorMetadata'),
'translation_domain' => 'validators',
'strict_email' => false,
'prevent_dns_lookups' => false,
'use_dns' => true,
),
'annotations' => array(
'cache' => 'file',
Expand Down
34 changes: 18 additions & 16 deletions src/Symfony/Component/Validator/Constraints/EmailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class EmailValidator extends ConstraintValidator
/**
* @var bool
*/
private $preventDNSLookups;
private $useDNS;

public function __construct($strict = false, $preventDNSLookups = false)
public function __construct($strict = false, $useDNS = true)
{
$this->isStrict = $strict;
$this->preventDNSLookups = $preventDNSLookups;
$this->useDNS = $useDNS;
}

/**
Expand Down Expand Up @@ -86,23 +86,25 @@ public function validate($value, Constraint $constraint)

$host = substr($value, strpos($value, '@') + 1);

// Check for host DNS resource records
if (!$this->preventDNSLookups && $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 (!$this->preventDNSLookups && $constraint->checkHost && !$this->checkHost($host)) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Email::HOST_CHECK_FAILED_ERROR)
->addViolation();
}
}

Expand Down