Skip to content

[Workflow] Allow use of UnitEnum and BackedEnum in workflow places #44306

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

Conversation

alexandre-daubois
Copy link
Member

Q A
Branch? 6.1
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #44203
License MIT
Doc PR To be done

ℹ️ Meant to be merged on 6.1, waiting for the branch to open.

One thing should be noted here. Currently, subject marking is done with the following form: ['place_a' => 1, 'place_b' => 1], which is not possible to reproduce with enumerations. Indeed, you're not allowed to use enumeration cases as array keys.
That's why, when using enumerations, subject marking is stored using a simple list of cases, like [FooEnum::Bar, FooEnum::Baz].
I think this solution is ok, as it seems $nbToken (the 1 affected to places in marking) seems to not be used anywhere at this time.

@alexandre-daubois alexandre-daubois force-pushed the feat/enum-workflow branch 4 times, most recently from 7b8b394 to 632cd5b Compare November 29, 2021 09:53
@stof
Copy link
Member

stof commented Nov 29, 2021

I think this solution is ok, as it seems $nbToken (the 1 affected to places in marking) seems to not be used anywhere at this time.

IIRC, those nbToken are useful for non-state-machine workflows, which can have multiple places.

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

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

Let's say, I'd create an enum soley for the purpose of having a closed declaration fo all possible places of a workflow. Why would I want to enumerate the enumeration again?

Istead of declaring…

new Definition([Suit::Hearts, Suit::Diamonds, Suit::Clubs, Suit::Spades], …);

… wouldn't I want to do this instead?

new Definition(Suit::class, …);

public static function getTypedValue(string $place): string|\UnitEnum
{
try {
return \constant($place);
Copy link
Member

Choose a reason for hiding this comment

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

should we look for :: in the string first to avoid trying to load constants in such case ?

Copy link
Member

Choose a reason for hiding this comment

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

Looking at this class, I really wonder if we shouldn't limit this feature to backed enums. If a developer does not want us to serialize an enum they declared, we should not guess how to serialize it anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

At first I thought of only add support of BackedEnums and being able to use BackedEnum::tryFrom but in any case, I've been confronted to the problem that in the marking store, we don't really have any way to guess which enumeration we should use to tryFrom 😕

Copy link
Member

@derrabus derrabus Nov 30, 2021

Choose a reason for hiding this comment

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

which enumeration we should use

How many enumerations should a user be allowed to use for a single workflow? Should they be allowed to mix and match values from different enums or even enum values and scalars?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a choice I had a hard time making 😅 I'm torn between "we can do it, why limit ourselves" and "it doesn't make sense to allow 3 different enumerations and scalars for a workflow". So I proposed this PR by accepting the most permissive solution, but if you feel that this is not the right option, I will gladly make the changes 😄

public static function getTypedValue(string $place): string|\UnitEnum
{
try {
return \constant($place);
Copy link
Member

Choose a reason for hiding this comment

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

What about strings that may look like something that is a constant name in something else than an enum ? String place names can be anything.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, I'll add a check to be sure that if \constant doesn't throw an exception, we're dealing with an enumeration. 👍

@alexandre-daubois alexandre-daubois force-pushed the feat/enum-workflow branch 2 times, most recently from 32398a8 to d4e033f Compare November 29, 2021 10:33
@alexandre-daubois alexandre-daubois changed the title [Workflow] Add support of UnitEnum and BackedEnum to workflow places [Workflow] Allow use of UnitEnum and BackedEnum in workflow places Nov 29, 2021
@derrabus derrabus changed the base branch from 6.0 to 6.1 November 30, 2021 09:34
@lyrixx
Copy link
Member

lyrixx commented Mar 22, 2022

I started to review the PR, but the lot of changes scares me :)

I raised some consideration in the issue ; let's continue the discussion there

@lyrixx
Copy link
Member

lyrixx commented Mar 23, 2022

It's always heartbreaking to refuse a PR, but we agree with @alexandre-daubois (PR author) that it does not worth it.

Thanks again for the hard work, and sorry for the waste of time.

@lyrixx lyrixx closed this Mar 23, 2022
@nicolas-grekas
Copy link
Member

This would be better solved at the engine-level, see php/php-src#8825

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.

8 participants