You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Replace hooks and emitter events and listener to use the Symfony ones #29672
Is there a nicer way to achieve the addition of events?
Other than the usual dependency injection, I don't think so.
The key point is who is responsible of creating and sending the events. This responsability needs to be clearly defined in one object (maybe more, depending on the events), but definitely not spread into multiple objects.
The listeners should be registered as part of the initialization of the app that use this. The usual Application class used for the dependency injection can also be used for the event registration.
(in the app.php file)
$app = new Application();
$app->registerListeners();
That should be enough to add unit tests to check if an event is being triggered (probably using the dependency injection, checking if the symfony dispatcher is being called), and also to check the listeners code by triggering the specific event. In both cases, the tests should be pretty isolated.
What I think it's also important is the use custom events. By using custom events you can wrap an object or multiple objects inside an event and provide limited access to the object:
Provide access to specific properties of the wrapped object
Provide read-only access to the wrapped object, in case you don't want the listener to modify any property of the object
Provide limited access to some "write" methods of the object. Maybe you want to allow setting some properties of the object but not others
Provide custom access to some object properties. Maybe you want to conditionally set a property of the object, or set a property only once.
Include custom methods in the event to prevent the event propagation and also prevent further code execution of the method in case of the "beforeSomething" events.
@jvillafanez I think the topic here is about the usage of traits and the wrapping of the event emitter, not the event class itself.
@butonic As far as I remember, the usage of traits was recommended by @DeepDiver1975 when reviewing #29651. Somehow I can't find the commented messages as Github refuses to expand comments from old changes.
@DeepDiver1975 are you ok with reverting the decision about the trait ?
Activity
tomneedham commentedon Jun 27, 2018
The next way of adding
EventEmitterTrait::emittingCallis not so optimal:Is there a nicer way to achieve the addition of events?
butonic commentedon Jun 27, 2018
While I totally agree that we should move forward with moving hooks to events I am very unhappy with the
EventEmitterTrait::emittingCall()added with https://github.com/owncloud/core/pull/29651/files#diff-88dd9ddb262ef3b3df2aa72d7793d462R46 / stable10 https://github.com/owncloud/core/pull/29939/files#diff-88dd9ddb262ef3b3df2aa72d7793d462R46:IMNSHO: stop using that method and get rid of the emitter trait asap.
jvillafanez commentedon Jun 27, 2018
Other than the usual dependency injection, I don't think so.
The key point is who is responsible of creating and sending the events. This responsability needs to be clearly defined in one object (maybe more, depending on the events), but definitely not spread into multiple objects.
The listeners should be registered as part of the initialization of the app that use this. The usual
Applicationclass used for the dependency injection can also be used for the event registration.That should be enough to add unit tests to check if an event is being triggered (probably using the dependency injection, checking if the symfony dispatcher is being called), and also to check the listeners code by triggering the specific event. In both cases, the tests should be pretty isolated.
What I think it's also important is the use custom events. By using custom events you can wrap an object or multiple objects inside an event and provide limited access to the object:
PVince81 commentedon Jun 27, 2018
@jvillafanez I think the topic here is about the usage of traits and the wrapping of the event emitter, not the event class itself.
@butonic As far as I remember, the usage of traits was recommended by @DeepDiver1975 when reviewing #29651. Somehow I can't find the commented messages as Github refuses to expand comments from old changes.
@DeepDiver1975 are you ok with reverting the decision about the trait ?
stale commentedon Sep 21, 2021
This issue has been automatically closed.