-
Notifications
You must be signed in to change notification settings - Fork 14
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
Multiple hooks for one action can be added, but they have to be currently deleted completely #131
Comments
very good one! So we need an optional ident to set to a hook so we can identify it for removal, e.g. |
@PhilippGrashoff "optional ident" would be the best, but as different priority can be set, for most of the purposes optional "priority parameter in remove method" would be enought and implementing should be very easy + there would be 100% backcompatibility. Wdyt? |
Can you give me one real-life use-case when deleting hooks is useful? |
@DarkSide666 I have some custom persistence manager. And if this manager is used, hook is added to the managed object when processing and removed when done. When the object is not processed thru this manager instance, the hook should never be fired. Of course, it can we solved differently, but I do not see any issue with this approach. With this PR also one-time hooks can be written very easily like:
|
@DarkSide666 a very simple example is if you use save() in an afterSave() hook. This leads to an infinite save() after save().
Actually, that code even shows a better example by stopping hooks from executing extra code if all you want really is a plain save() operation.... |
I see. So, yes, maybe that can be handy in these situations, but still should be used with care. |
See https://github.com/atk4/core/blob/develop/src/HookTrait.php#L98
Specific hook should be possible to delete by name and priority.
The text was updated successfully, but these errors were encountered: