8000 Remove `GuardEvent::getContext()` method and add `HasContextTrait` trait by hhamon · Pull Request #51493 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Remove GuardEvent::getContext() method and add HasContextTrait trait #51493

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
Aug 30, 2023

Conversation

hhamon
Copy link
Contributor
@hhamon hhamon commented Aug 26, 2023
Q A
Branch? 7.0
Bug fix? no
New feature? no
Deprecations? no
Tickets Related to #51484
License MIT
Doc PR ~

As discussed with @lyrixx, the GuardEvent::getContext method was confusing as the context given as the 3rd argument to the WorflowInterface::appy() method is never passed along to the guard events. According to @lyrixx, the guard listeners must take any decisions based on the subject itself and not on the given contextual data (which are supposed to remain metadata). As a consequence, calling the GuardEvent::getContext() method always returned an empty context array so far.

To prevent this confusion any longer, the method has been deprecated in Symfony 6.4 (see #51484) and removed in this PR. The GuardEvent class hierarchy no longer has the getContext method while other event classes keep having it.

@hhamon hhamon requested a review from lyrixx as a code owner August 26, 2023 11:29
@carsonbot carsonbot added this to the 7.0 milestone Aug 26, 2023
@hhamon hhamon force-pushed the remove-guard-event-get-context branch 3 times, most recently from e9c9d72 to 16b7e82 Compare August 26, 2023 11:38
*/
trait HasContextTrait
{
private array $context = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the property private instead of protected as all concrete classes using this trait are already all final. Although it may be a potential BC break, it should not as event classes are final and internal. Application code should are not supposed to extend the base abstract Event class to produce new subtypes of workflow events.

* @author Grégoire Pineau <lyrixx@lyrixx.info>
* @author Hugo Hamon <hugohamon@neuf.fr>
*
* @internal
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trait is marked internal as it's not supposed to be used outside of the Workflow component itself.

*
* @internal
*/
trait HasContextTrait
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure about the naming of this trait although it's purely made for an internal use. I was also thinking of naming it HoldContextTrait. Any other better suggestions are welcome and appreciated.

@hhamon hhamon force-pushed the remove-guard-event-get-context branch from 16b7e82 to 56e8101 Compare August 26, 2023 18:26
@hhamon hhamon changed the title Remove GuardEvent::getContext() method and add HasContextTrait trait [Workflow] Remove GuardEvent::getContext() method and add HasContextTrait trait Aug 26, 2023
@hhamon hhamon force-pushed the remove-guard-event-get-context branch from 56e8101 to 2aee3ae Compare August 28, 2023 11:51
Copy link
Member
@lyrixx lyrixx left a comment

Choose a reason for hiding this comment

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

Thanks

@carsonbot carsonbot changed the title [Workflow] Remove GuardEvent::getContext() method and add HasContextTrait trait Remove GuardEvent::getContext() method and add HasContextTrait trait Aug 30, 2023
@fabpot
Copy link
Member
fabpot commented Aug 30, 2023

Thank you @hhamon.

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.

4 participants
0