Revisit how plugin listen / register to events #7241
Labels
c: Platform
For Matomo platform changes that aren't impacting any of our APIs but improve the core itself.
Enhancement
For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Milestone
To register an event one currently has to implement the method
getListHooksRegistered
in the plugin descriptor class. EgSince the wording at some point changed to "Events" we should rename it to
getListEventsRegistered
in a backwards compatible way. Maybe there could be even a better name for this method?Maybe, there would be also another way to listen to events. Eg having an
Events.php
(could be confusing with Events plugin etc). Because of having thisgetListEventsRegistered
in the plugin file we often do have some kind of logic in that class although it shouldn't really contain any logic. Even worse we can't inject anything in tests there which makes it really hard to test this kinda stuff as the plugin instance is created in the background see eg https://github.com/piwik/piwik/blob/2.11.0-b2/plugins/BulkTracking/tests/Framework/TestCase/BulkTrackingTestCase.php#L34-L48.Alternatively or on top maybe we can also check whether it is possible to register an event like this
'API.getSegmentsMetadata' => array('\Any\Other\ClassName', 'getSegmentsMetadata')
. I'm almost sure this is already possible, maybe we should make it the recommended way to move logic out ofpluginname.php
in which it would be ok to register events in that class.Maybe we could also somehow simplify this but I think it is kinda ok this way.
Any ideas welcome
The text was updated successfully, but these errors were encountered: