Skip to content

[FrameworkBundle] Ensure Email class exists before using it #60373

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

Merged
merged 1 commit into from
May 8, 2025
Merged
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 @@ -1067,7 +1067,7 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e
->validate()->castToArray()->end()
->end()
->scalarNode('translation_domain')->defaultValue('validators')->end()
->enumNode('email_validation_mode')->values(Email::VALIDATION_MODES + ['loose'])->end()
->enumNode('email_validation_mode')->values((class_exists(Email::class) ? Email::VALIDATION_MODES : ['html5-allow-no-tld', 'html5', 'strict']) + ['loose'])->end()
Copy link
Member Author

@Kocal Kocal May 7, 2025

Choose a reason for hiding this comment

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

Since I believe email_validation_mode won't be used if symfony/mailer is not installed, maybe we can just keep it empty:

Suggested change
->enumNode('email_validation_mode')->values((class_exists(Email::class) ? Email::VALIDATION_MODES : ['html5-allow-no-tld', 'html5', 'strict']) + ['loose'])->end()
->enumNode('email_validation_mode')->values(class_exists(Email::class) ? Email::VALIDATION_MODES + ['loose'] : [])->end()

Copy link
Member

Choose a reason for hiding this comment

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

I would keep it the way you changed it here for the same reason we kept loose in #60365, let's better be defensive here as we don't know how people configured their applications

Copy link

Choose a reason for hiding this comment

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

After upgrading to Symfony 7.2.7 we observe this error:

In EnumNode.php line 82:
                                                                               
  The value "loose" is not allowed for path "framework.validation.email_valid  
  ation_mode". Permissible values: "html5-allow-no-tld", "html5", "strict"     
                                                                               

Error: Process completed with exit code 1.

Our configuration is:

framework:
    ...
    validation:
        ...
        email_validation_mode: loose

From bin/console config:dump-reference framework we observe:

framework:
...
    validation:
        ...
        email_validation_mode: html5 # One of "html5-allow-no-tld"; "html5"; "strict"

I think this should use array_merge() instead of the + operator to correctly merge the arrays.

Copy link
Contributor

Choose a reason for hiding this comment

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

can you please create a new issue or a pull request? Thanks

Copy link

Choose a reason for hiding this comment

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

Sure, will open a PR.

Copy link

@rhel-eo rhel-eo Jun 5, 2025

Choose a reason for hiding this comment

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

->arrayNode('mapping')
->addDefaultsIfNotSet()
->fixXmlConfig('path')
Expand Down
Loading