-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add BeforeMarshalEventInterface #17990
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
Conversation
Such changes should target 5.next directly (minimum). |
This is not a backward compatible change and would have to wait till 6.0, if approved. I do like the idea of enforcing the signature for the callback methods, but not too sure about this implementation. If someone adds the |
@ADmad an alternative approach could be to add empty methods like |
Yes, adding empty methods is an option too, we already have that for controller events. |
But adding the empty methods in 5.2 can also if problematic. Since a signature mismatch with existing methods will create a PHP error. |
The main issue with actual methods and inheritance is that you cannot use the concrete objects as types, only EntityInterface etc |
Yes, hence the chance of signature mismatch, I too often use type the argument using the concrete entity class. |
@ADmad I adjusted my changes so that if a model has a callback method but does not implement a corresponding interface then an exception will be thrown. What do you think about this approach? |
That could be considered for the next major. But I am not in favor of using similar interfaces for callbacks which take an entity as an argument. Typing the argument using |
That I do not understand. Do you suggest to remove "EntityInterface" from the method signature like |
Would a different approach #18008 be better than this? |
Not specifying the type for the $entity argument would be an option then we are back to specifying |
Users could chose. We could in the future also check on the interface for existence of callbacks. So basically this is just a way for users to more quickly add their event callbacks with pre-defined signatures if they want to. I think the framework should provide them as part of the contract. And then people can use to use them. |
I like the |
With the other PR advancing, closing this for now. |
The idea is to explicitly define model callback methods so that in order to use the callbacks table classes would need to implement callback interfaces like BeforeMarshalEventInterface. This way it would be possible to enforce the consistent methods signatures of model callbacks in table classes. For example, if the client code would have
public function beforeMarshal($event, $data, $options): void
method an error would be generated because it does not match the method defined in BeforeMarshalEventInterface.Would this approach be okay? Only one callback interface is added here just to make it easier to explain.