Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Validator] Supports backed enum in constraint groups #45570

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

Conversation

alamirault
Copy link
Contributor

Q A
Branch? 6.1
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #45494
License MIT
Doc PR symfony/symfony-docs/pull/16553

This PR allow to use Backed enum in constraints groups.

#[GreaterThan(value: 4711, groups: [MyCustomEnum::WRITE])]

@tjveldhuizen
Copy link
Contributor

It might be problematic that two values from different enums have the same value. When I would use enums for validation groups, I think I would expect those to result in different validation groups. When used manually, I would have prefixed the groups like foo_c, foo_u, bar_c and bar_u. Maybe the value should be prefixed with the class-string?

enum FooEnum
{
    case Create = 'C';
    case Update = 'U';
}
enum BarEnum
{
    case Combine = 'C';
    case Unset = 'U';
}

@fabpot fabpot modified the milestones: 6.1, 6.2 May 20, 2022
@@ -197,14 +197,32 @@ protected function normalizeOptions(mixed $options): array
public function __set(string $option, mixed $value)
{
if ('groups' === $option) {
$this->groups = (array) $value;
$this->groups = $this->normalizeGroups((array) $value);
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather turn this into $this->groups = array_map('strval', (array) $value); and see php/php-src#8825 implemented in PHP 8.2

@nicolas-grekas
Copy link
Member

On second though, this is similar to #46363: this is an engine-level consideration that should be fixed either by https://wiki.php.net/rfc/fetch_property_in_const_expressions or https://wiki.php.net/rfc/auto-implement_stringable_for_string_backed_enums
Thanks for the PR anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow enum type for validation groups
5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.