Skip to content
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

Support array of enums #333

Merged
merged 1 commit into from
May 17, 2023
Merged

Support array of enums #333

merged 1 commit into from
May 17, 2023

Conversation

lstrojny
Copy link
Contributor

Support array of enums, so that e.g. with ODM you can do something like this

#[Field(enumType: Variant::class]
private array $variants = [];

@malarzm malarzm changed the base branch from 3.1.x to 3.2.x May 16, 2023 17:58
@malarzm malarzm added the Enhancement New feature or request label May 16, 2023
@malarzm malarzm added this to the 3.2.0 milestone May 16, 2023
@malarzm
Copy link
Member

malarzm commented May 16, 2023

@lstrojny thanks for the PR! I took the liberty and retargeted this to 3.2.0 as this is a feature.

I took a quick look into ODM and if I'm not mistaken the changes here in doctrine/persistence will on its own allow combining collection and hash types with enumType?

@lstrojny
Copy link
Contributor Author

That is correct. In fact I am using the feature branch with ODM and it just works

malarzm
malarzm previously approved these changes May 16, 2023
Copy link
Member

@malarzm malarzm left a comment

Choose a reason for hiding this comment

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

Also please squash your commits afterwards

Comment on lines 80 to 83
/** @var string[]|int[] $values */
$values = array_map([self::class, 'fromEnum'], $enum);

return $values;
Copy link
Member

Choose a reason for hiding this comment

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

Let's avoid recursion in favour of something along

Suggested change
/** @var string[]|int[] $values */
$values = array_map([self::class, 'fromEnum'], $enum);
return $values;
return array_map(fn(BackedEnum $e) => $e->value, $enum);

Copy link
Member

Choose a reason for hiding this comment

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

But compatible with PHP 7.2 :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@malarzm
Copy link
Member

malarzm commented May 16, 2023

Thanks! I've PRed doctrine/mongodb-odm#2532 with a test for future us. I'll see if there are any plans for releasing 3.2.0 here.

@malarzm malarzm merged commit 63fee8c into doctrine:3.2.x May 17, 2023
13 checks passed
@malarzm
Copy link
Member

malarzm commented May 17, 2023

Thanks @lstrojny! I'll be releasing 3.2.0 shortly so you may get back to stable branch ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants