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 dedicated event eventArgs #2649

Conversation

yassinefikri
Copy link
Contributor

@yassinefikri yassinefikri commented Jul 13, 2023

Resolves #2648

@codecov-commenter
Copy link

codecov-commenter commented Jul 13, 2023

Codecov Report

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

Comparison is base (3b5b5cb) 79.27% compared to head (cb6be44) 79.40%.

Files Patch % Lines
src/Mapping/Event/Adapter/ORM.php 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2649      +/-   ##
==========================================
+ Coverage   79.27%   79.40%   +0.13%     
==========================================
  Files         162      162              
  Lines        8467     8494      +27     
==========================================
+ Hits         6712     6745      +33     
+ Misses       1755     1749       -6     

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

@yassinefikri yassinefikri force-pushed the feature/softdelete-dedicated-eventargs branch from 0fad774 to ff14977 Compare July 14, 2023 00:32
src/SoftDeleteable/SoftDeleteableListener.php Outdated Show resolved Hide resolved
src/SoftDeleteable/SoftDeleteableListener.php Outdated Show resolved Hide resolved
src/SoftDeleteable/SoftDeleteableListener.php Outdated Show resolved Hide resolved
src/SoftDeleteable/SoftDeleteableListener.php Outdated Show resolved Hide resolved
@franmomu
Copy link
Collaborator

After this change, looks like EventInterface::createLifecycleEventArgsInstance is not used anymore (if so, we should deprecate it):

https://github.com/search?q=repo%3Adoctrine-extensions%2FDoctrineExtensions%20createLifecycleEventArgsInstance&type=code

The problem I see is that we would still triggering deprecations when creating the ORM event, but I don't know if that's avoidable (given that we should still extend from the ORM LifecycleEventArgs to keep BC).

@yassinefikri
Copy link
Contributor Author

I moved the createPreSoftDeleteEventArgs() and createPostSoftDeleteEventArgs() to the ORM/ODM classes as they feel more appropriate to have them (alongside with the createLifecycleEventArgsInstance())

i also deprecated the function createLifecycleEventArgsInstance()

i'm not sure if the deprecations triggered at LifecycleEventArgs construction are avoidable

@yassinefikri yassinefikri requested a review from phansys July 25, 2023 14:07
@franmomu franmomu force-pushed the feature/softdelete-dedicated-eventargs branch from af2dcc4 to c8f4639 Compare October 31, 2023 19:58
@franmomu
Copy link
Collaborator

I've rebased since there were some conflicts with the latest changes.

Copy link
Collaborator

@franmomu franmomu left a comment

Choose a reason for hiding this comment

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

I've left some comments, please add some tests.

Updated: I've made those changes in a new commit, tests still need to be added.

src/Mapping/Event/AdapterInterface.php Outdated Show resolved Hide resolved
src/SoftDeleteable/SoftDeleteableListener.php Outdated Show resolved Hide resolved
src/SoftDeleteable/SoftDeleteableListener.php Outdated Show resolved Hide resolved
src/Mapping/Event/Adapter/ORM.php Outdated Show resolved Hide resolved
src/Mapping/Event/Adapter/ODM.php Outdated Show resolved Hide resolved
@franmomu franmomu force-pushed the feature/softdelete-dedicated-eventargs branch from 96a2450 to 9e3c725 Compare October 31, 2023 20:34
@yassinefikri
Copy link
Contributor Author

i've updated tests, let me know if i'm missing something

@franmomu
Copy link
Collaborator

franmomu commented Nov 1, 2023

I wanted to check if we can somehow avoid the LifecycleEventArgs deprecation, I was thinking that we can do a couple of things.

First of all, check with EventManager::hasListeners() method if there are listeners before creating the events, this way we prevent triggering the deprecation for those who don't have listeners.

And to finally remove the deprecation... I was thinking about creating PreSoftDeleteEventArgs and PostSoftDeleteEventArgs for ORM extending from the LifecycleEventArgs class from persistence and adding the getEntity() and getEntityManager() methods (trigger deprecations inside these methods).

That would create a BC break for someone with a listener typehinted with LifecycleEventArgs from the ORM, in that case we can maybe with Reflection check the listener if it's typehinted and in that case trigger a deprecation telling to change it to the dedicated event and for creating the event we would use AdapterInterface::createLifecycleEventArgsInstance().

If the listener is not typehinted with LifecycleEventArgs from the ORM, then we create the new dedicated event. If the listener is calling getEntity() or getEntityManager() would work, the only problem is if it has instance check with LifecycleEventArgs from the ORM, but I guess that's unlikely to happen.

These are some thoughts that I haven't tried and I don't know if that would work.

@yassinefikri
Copy link
Contributor Author

And to finally remove the deprecation... I was thinking about creating PreSoftDeleteEventArgs and PostSoftDeleteEventArgs for ORM extending from the LifecycleEventArgs class from persistence and adding the getEntity() and getEntityManager() methods (trigger deprecations inside these methods).

i don't get what deprecations should be triggered inside the methods, can you provide an example ?

That would create a BC break for someone with a listener typehinted with LifecycleEventArgs from the ORM, in that case we can maybe with Reflection check the listener if it's typehinted and in that case trigger a deprecation telling to change it to the dedicated event and for creating the event we would use AdapterInterface::createLifecycleEventArgsInstance().

i think it should work but it's gonna get a little more complex to handle cases where there are multiple listeners on the same event

@franmomu franmomu force-pushed the feature/softdelete-dedicated-eventargs branch 2 times, most recently from e27f8bf to 88ac2fa Compare December 4, 2023 22:03
@franmomu
Copy link
Collaborator

franmomu commented Dec 4, 2023

@mbabker what about this? this is similar to #2725 and maintain a BC layer. When not all the listeners have type-hinted the new event class, it dispatches the old event.

Given that this is Softdeleteable behavior I think it is important to try not break BC.

And to finally remove the deprecation... I was thinking about creating PreSoftDeleteEventArgs and PostSoftDeleteEventArgs for ORM extending from the LifecycleEventArgs class from persistence and adding the getEntity() and getEntityManager() methods (trigger deprecations inside these methods).

i don't get what deprecations should be triggered inside the methods, can you provide an example ?

Sorry, I took another approach (adding a new commit), simplifying events and trying to maintain BC.

@franmomu franmomu force-pushed the feature/softdelete-dedicated-eventargs branch from 88ac2fa to cb6be44 Compare December 4, 2023 22:39
@mbabker
Copy link
Contributor

mbabker commented Dec 4, 2023

@mbabker what about this?

Looks fine to me.

@franmomu franmomu merged commit a4f15df into doctrine-extensions:main Dec 5, 2023
18 checks passed
@franmomu
Copy link
Collaborator

franmomu commented Dec 5, 2023

thanks @yassinefikri!

paxal pushed a commit to sportmium/DoctrineExtensions that referenced this pull request Mar 18, 2024
* use dedicated eventArgs

* fix workflow fails

* fix

* move functions to appropriate class

* move functions to appropriate class

* add changelog note

* Move presoftdeletable methods

* update tests to expect dedicated eventargs instances

* Use Pre and Post event args when it is type-hinted

---------

Co-authored-by: Fran Moreno <franmomu@gmail.com>
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.

SoftDeleteable dedicated events eventargs
5 participants