Skip to content

Simplified EmailValidator using native PHP validation function. #89

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ protected function configure()
->setName('doctrine:ensure-production-settings')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
->setHelp(<<<EOT
The <info>doctrine:cache:clear-metadata</info> command clears all metadata cache for the default entity manager:
The <info>doctrine:ensure-production-settings</info> command ensures that Doctrine is properly configured for a production environment.:

<info>./app/console doctrine:cache:clear-metadata</info>
<info>./app/console doctrine:ensure-production-settings</info>

You can also optionally specify the <comment>--em</comment> option to specify which entity manager to clear the cache for:
You can also optionally specify the <comment>--em</comment> option to specify which entity manager to use:

<info>./app/console doctrine:cache:clear-metadata --em=default</info>
<info>./app/console doctrine:ensure-production-settings --em=default</info>
EOT
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function parse(\Twig_Token $token)
$body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);

if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
throw new \Twig_Error_Syntax('A message must be a simple text', -1);
throw new \Twig_Error_Syntax(sprintf('A message must be a simple text (line %s)', $lineno), -1);
}

$stream->expect(\Twig_Token::BLOCK_END_TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

class EmailValidator extends ConstraintValidator
{
const PATTERN = '/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i';

public function isValid($value, Constraint $constraint)
{
Expand All @@ -31,7 +30,7 @@ public function isValid($value, Constraint $constraint)

$value = (string)$value;

if (!preg_match(self::PATTERN, $value)) {
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter_var isn't compliant with the email specification, but I guess it's still better than the old pattern, until someone has the time to integrate that other email parsing lib..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not necessarily better than the old pattern (although thats a very bad one). The disadvantage of FILTER_VALIDATE_EMAIL is that you can change the pattern through an ini constant.

$this->setMessage($constraint->message, array('{{ value }}' => $value));

return false;
Expand Down