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

Use custom lifecycle event classes for the soft-deleteable lifecycle events #2725

Closed
wants to merge 1 commit into from

Conversation

mbabker
Copy link
Contributor

@mbabker mbabker commented Nov 20, 2023

Ref: #2708

In ORM 3.0, the Doctrine\ORM\Event\LifecycleEventArgs class is removed and the ORM's lifecycle event classes directly extend Doctrine\Persistence\Event\LifecycleEventArgs. This makes the ORM's implementation of Gedmo\Mapping\Event\AdapterInterface::createLifecycleEventArgsInstance() unusable on 3.0 since it no longer has its own lifecycle event args subclass.

Currently, the only use of this method inside the package is for the soft-deleteable extension's events.

My solution to this ORM deprecation comes with a minor B/C break; instead of dispatching the events with manager-specific event classes, the events are now dispatched with custom subclasses of Doctrine\Persistence\Event\LifecycleEventArgs for both supported managers. The B/C break here is that event listeners which typehint against Doctrine\ODM\MongoDB\Event\LifecycleEventArgs and Doctrine\ORM\Event\LifecycleEventArgs will be broken because the class inheritance chain is changed. This would also deprecate the implementations of Gedmo\Mapping\Event\AdapterInterface::createLifecycleEventArgsInstance() (currently soft-required through @method annotations).

There is an alternative solution that only has a B/C break for ORM users; changing this method to always use the Doctrine\Persistence\Event\LifecycleEventArgs class while the ODM adapter still uses its manager-specific subclass.

But because of the ORM 3.0 class removal, there will have to be a B/C break at some point, and I figured this would be the best alternative going forward.

Copy link

codecov bot commented Nov 20, 2023

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (9d5c15d) 79.33% compared to head (b2465cf) 79.13%.

Files Patch % Lines
src/Mapping/Event/Adapter/ORM.php 0.00% 6 Missing ⚠️
src/Mapping/Event/Adapter/ODM.php 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2725      +/-   ##
==========================================
- Coverage   79.33%   79.13%   -0.21%     
==========================================
  Files         162      162              
  Lines        8460     8477      +17     
==========================================
- Hits         6712     6708       -4     
- Misses       1748     1769      +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@franmomu
Copy link
Collaborator

There is also #2649 that tries to avoid the BC break (I have to take a look again at it)

@mbabker
Copy link
Contributor Author

mbabker commented Nov 28, 2023

I think the one thing I don't like about #2649 is that it hides the ORM B/C break (and inherently leaves an unfixable deprecation in the package and downstream apps running on ORM 2) by using conditional inheritance, and it'll still silently change the class inheritance when one upgrades from ORM 2 to 3. And, IMO, there really isn't a need for separate classes per manager for these events. So this implementation is simpler but has more B/C implications, the other PR has less downstream B/C concern but adds technical debt.

@mbabker
Copy link
Contributor Author

mbabker commented Dec 4, 2023

Close in favor of #2649

@mbabker mbabker closed this Dec 4, 2023
@mbabker mbabker deleted the use-custom-events branch December 4, 2023 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants