Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Workflow] Add EventNameTrait to compute event name strings in subscribers#54344

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@squrious
Copy link
Contributor

QA
Branch?7.1
Bug fix?no
New feature?yes
Deprecations?no
IssuesN/A
LicenseMIT

Hello!

Using the event dispatcher, we usually use event's class name to configure the event to listen to. For workflow, we
still have to use raw strings:

class WorkflowPostSubscriberimplements EventSubscriberInterface{publicstaticfunctiongetSubscribedEvents():array    {return ['workflow.post.entered.published' =>'onPublishedEntered',                ];    }}

Using class names is more clear about what event we use (easier to know which event to use in the listener). Even if we already have attributes to define event listeners, the event subscriber way could be improved.

Proposal

This PR adds a trait to improve DX when using workflow events in event subscribers.

class WorkflowPostSubscriberimplements EventSubscriberInterface{publicstaticfunctiongetSubscribedEvents():array    {return [            PublishedEvent::get(workflowName:'post', placeName:'entered') =>'onPublishedEntered',                ];    }}

For a better DX, theEventNameTrait provides two methods:getNameForPlace andgetNameForTransition, so the second
argument of::get and its PHPDoc are consistent with the event type.

In event classes, it is used like:

class EnterEventextends Event{use EventNameTrait {        use getNameForPlaceaspublic get;    }// ...}

Cheers!

@lyrixx
Copy link
Member

Did you see#51210?

@squrious
Copy link
ContributorAuthor

Did you see#51210?

Yes! But as event subscribers allow to register events too, shouldn't we take care of their DX too? Or maybe I could leverage the existing code for this?

@lyrixx
Copy link
Member

IMHO, event listener are better thank event subscriber now.

But I think we can do something for the subscriber too. I'll review it

@derrabus
Copy link
Member

But as event subscribers allow to register events too, shouldn't we take care of their DX too?

No. I'd rather get rid of subscribers, tbh. From my POV, the only reason subscribers still exist, is the amount of busy work we would force upon downstream code if we removed them. Regarding DX improvements, I'd keep our efforts focused on attribute-based listeners.

@lyrixx
Copy link
Member

@derrabus with SF full stack, it's easy to register listener, but without the framework, it's harder. I think it's still better to merge this PR once ready

@squrioussquriousforce-pushed theworkflow/improve-event-names-dx branch from6ef6cb5 to194a623CompareMarch 20, 2024 14:10
@squrious
Copy link
ContributorAuthor

Thanks for your feedback! I addressed your comments :)

Copy link
Member

@lyrixxlyrixx left a comment

Choose a reason for hiding this comment

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

Can you add a note in the CHANGELOG ?

👍🏼

@squrioussquriousforce-pushed theworkflow/improve-event-names-dx branch from2e4ecd0 tod231549CompareMarch 20, 2024 14:26
@squrious
Copy link
ContributorAuthor

Can you add a note in the CHANGELOG ?

👍🏼

Done!

Copy link
Member

@lyrixxlyrixx left a comment

Choose a reason for hiding this comment

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

Thanks

trait EventNameTrait
{
/**
* Get event name for workflow and transition.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
*Get event name for workflowand transition.
*Gets the event namefor workflowand transition.

}

/**
* Get event name for workflow and place.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
*Get event name for workflowand place.
*Gets the event namefor workflowand place.

@fabpotfabpotforce-pushed theworkflow/improve-event-names-dx branch from0aad8af to742221fCompareMarch 21, 2024 10:37
@fabpot
Copy link
Member

Thank you@squrious.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@stofstofstof left review comments

@fabpotfabpotfabpot approved these changes

@lyrixxlyrixxlyrixx approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

7.1

Development

Successfully merging this pull request may close these issues.

7 participants

@squrious@lyrixx@derrabus@fabpot@nicolas-grekas@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp