Review main Merged

61303[FEATURE] Introduce PSR-14-based EventDispatcher as alternative for hooks

Benni Mack CR +2 V +2 Expert +1134 −27 updated 07/16/19, 13:50

Commit message

The new PSR-14 standard for dispatching Events (that is: to extend
a Framework without having to modify a frameworks' code) adds
a EventDispatcher object that can dispatch Event objects to
EventListeners.

In PSR-14 every dispatched event is an object. It uses PHP class names as
identifiers for events. Class hierarchies may be used to group events.

A ListenerProvider object collects available listeners from an extension
and allows to listen and/or modify data provided by the Event object.

The current implementation relies on a custom TYPO3-specific
ListenerProvider that is configured using Symfony's Dependency Injection
tags.

As an example the Mailer-postProcInitialization signal/slot is
replaced by an Event.

This first patch introduces the feature, and does not deprecate
anything yet. The most important part is that new Events
can use this API instead of Hooks in TYPO3 v10.

Short-Term goal is to deprecate SignalSlot dispatcher in TYPO3 v10,
and migrate all signals to the EventDispatcher.

Review

  • Code review CR +2 Done
    • Benjamin Franzke +2
    • Georg Ringer +1
    • Andreas Kienast +1
    • Benni Mack +1
  • Verified V +2 Done
    • Benjamin Franzke +2
    • Georg Ringer +1

Issues 1

Files 22

Show 2 more files

Review log 3146

Show 1321 earlier messages
  1. Benni Mack uploaded patch set 1 07/15/19, 18:31

  2. TYPO3com voted on patch set 1 V +1 07/15/19, 18:44 Completed build in 12m 06s on Mon, 15 Jul, 08:44 PM Test Summary: 46998 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35054

  3. Benjamin Franzke uploaded patch set 2 07/15/19, 19:26

  4. TYPO3com voted on patch set 2 V -1 07/15/19, 19:26 Completed build in 11s on Mon, 15 Jul, 09:26 PM Test Summary: No tests found Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35056

  5. Benni Mack uploaded patch set 3 07/15/19, 19:40

  6. TYPO3com voted on patch set 3 V -1 07/15/19, 19:54 Completed build in 14m 04s on Mon, 15 Jul, 09:54 PM Test Summary: 1 of 47361 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35057

  7. Benjamin Franzke uploaded patch set 4 07/15/19, 20:10

  8. Benjamin Franzke uploaded patch set 5 07/15/19, 20:20

  9. TYPO3com voted on patch set 4 V +1 07/15/19, 20:33 Completed build in 17m 33s on Mon, 15 Jul, 10:33 PM Test Summary: 46998 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35062

  10. TYPO3com voted on patch set 5 V +1 07/15/19, 20:37 Completed build in 16m 17s on Mon, 15 Jul, 10:37 PM Test Summary: 46998 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35063

  11. Benni Mack uploaded patch set 6 07/15/19, 20:40

  12. TYPO3com voted on patch set 6 V +1 07/15/19, 20:52 Completed build in 11m 23s on Mon, 15 Jul, 10:52 PM Test Summary: 46998 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35065

  13. Benjamin Franzke uploaded patch set 7 07/15/19, 22:22

  14. TYPO3com voted on patch set 7 V +1 07/15/19, 22:32 Completed build in 09m 40s on Tue, 16 Jul, 12:32 AM Test Summary: 46998 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35066

  15. Benjamin Franzke uploaded patch set 8 07/16/19, 04:30

  16. Benjamin Franzke commented on patch set 7 07/16/19, 04:30

    EventDispatcher.php:51

    As we're php 7 only, we can drop call_user_func here: https://trowski.com/2015/06/20/php-callable-paradox/

    EventDispatcher.php:53

    From https://www.php-fig.org/psr/psr-14/: > An Exception or Error thrown by a Listener MUST be allowed to propagate back up to the Emitter If we want to log here, we should `throw $e`.
  17. Benjamin Franzke commented on patch set 8 V +1 CR +1 07/16/19, 04:30

    EventDispatcher.php:51 Reply

    Done

    EventDispatcher.php:53 Reply

    Done
  18. TYPO3com voted on patch set 8 V +1 07/16/19, 04:46 Completed build in 12m 04s on Tue, 16 Jul, 06:46 AM Test Summary: 46998 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35069

  19. Georg Ringer commented on patch set 8 07/16/19, 06:33

    object

    EventDispatcher.php:53

    should we add a todo?

    Feature-88770-PSR-14BasedEventDispatcher.rst:122

    is this really true? don't we might have special edge cases where we hook into core on your own and don't want others to reuse that code? maybe add something like "unless commented with @internal"?
  20. Andreas Kienast commented on patch set 8 CR -1 07/16/19, 06:55

    Feature-88770-PSR-14BasedEventDispatcher.rst:37

    information

    Feature-88770-PSR-14BasedEventDispatcher.rst:44

    configuration
  21. Andreas Kienast uploaded patch set 9 07/16/19, 06:55

  1. Mathias Brodala commented on patch set 8 07/16/19, 06:56

    Feature-88770-PSR-14BasedEventDispatcher.rst:22

    Should be "An"

    Feature-88770-PSR-14BasedEventDispatcher.rst:24

    Here we should add the implied ... thus it is possible to extend/replace the event dispatcher with any implementation.

    Feature-88770-PSR-14BasedEventDispatcher.rst:36

    "... of other event listeners"

    Feature-88770-PSR-14BasedEventDispatcher.rst:37

    information

    Feature-88770-PSR-14BasedEventDispatcher.rst:42

    "... are usually associated ..." It's up to the listener provider to fetch listeners for an event which does not have to happen based on the event object class/hierarchy.

    Feature-88770-PSR-14BasedEventDispatcher.rst:74

    I'd prefer the non-inline notation here for readability.

    Feature-88770-PSR-14BasedEventDispatcher.rst:105

    "... event, this listeners is called automatically."

    Feature-88770-PSR-14BasedEventDispatcher.rst:111

    What does this mean?

    Feature-88770-PSR-14BasedEventDispatcher.rst:118

    "... as ...", less Denglish. ;-)
  2. TYPO3com voted on patch set 9 V +1 07/16/19, 07:06 Completed build in 10m 58s on Tue, 16 Jul, 09:06 AM Test Summary: 46997 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35071

  3. Benjamin Franzke uploaded patch set 10 07/16/19, 08:26

  4. Benjamin Franzke commented on patch set 10 07/16/19, 08:29

    Feature-88770-PSR-14BasedEventDispatcher.rst:22 Reply

    Done

    Feature-88770-PSR-14BasedEventDispatcher.rst:24 Reply

    Done

    Feature-88770-PSR-14BasedEventDispatcher.rst:36 Reply

    Done

    Feature-88770-PSR-14BasedEventDispatcher.rst:37 Reply

    Done

    Feature-88770-PSR-14BasedEventDispatcher.rst:37 Reply

    Done

    Feature-88770-PSR-14BasedEventDispatcher.rst:42 Reply

    Ack

    Feature-88770-PSR-14BasedEventDispatcher.rst:44 Reply

    Done

    Feature-88770-PSR-14BasedEventDispatcher.rst:74 Reply

    Ack

    Feature-88770-PSR-14BasedEventDispatcher.rst:105 Reply

    Done

    Feature-88770-PSR-14BasedEventDispatcher.rst:111 Reply

    He meant it's easier to read/understand when… My\Namespace\Signal\Foo::class …is used (due to being an invokable class) instead of sth like: My\Namespace\Signal\Foo::class . '::onFoobarEvent'. That syntax was used in the first patchset. Now we still have the optional "method" attribute (which should be avoided for the sake of __invoke() as well). I have therefore rephrased to: When configuring Listeners, it is recommended to add one Listener class per Event type, and have it called via `__invoke()`.

    Feature-88770-PSR-14BasedEventDispatcher.rst:118 Reply

    Ack

    Feature-88770-PSR-14BasedEventDispatcher.rst:122 Reply

    I personally agree with the statement as written in the rst. We should only add events that are worth being marked stable, and are generally useful. I think this limitation is quite good. If we've got a 1:1 relationship between two extensions in core and want these to be private but decoupled, we should rather use an interface and implementations overrides (in Services.yaml) instead of the event mechansim – which is really intended for being multiplexed.
  5. TYPO3com voted on patch set 10 V +1 07/16/19, 08:41 Completed build in 14m 41s on Tue, 16 Jul, 10:41 AM Test Summary: 46998 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35073

  6. Benjamin Franzke uploaded patch set 11 07/16/19, 09:49

  7. TYPO3com voted on patch set 11 V +1 07/16/19, 10:00 Completed build in 10m 50s on Tue, 16 Jul, 12:00 PM Test Summary: 47106 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35082

  8. Benjamin Franzke uploaded patch set 12 07/16/19, 12:55

  9. Benjamin Franzke commented on patch set 12 V +1 CR +1 07/16/19, 12:55

    Reply

    Done

    EventDispatcher.php:53 Reply

    I would leave it as is for now. I'd assume this is rather a "if we want, we could add logging here" than a real todo.
  10. Benni Mack commented on patch set 13 07/16/19, 12:58

    Published edit on patch set 12.
  11. TYPO3com voted on patch set 12 V +1 07/16/19, 13:09 Completed build in 14m 26s on Tue, 16 Jul, 03:09 PM Test Summary: 47118 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35089

  12. Benni Mack commented on patch set 13 07/16/19, 13:11

    EventDispatcher.php:53 Reply

    PSR-14 states that something could be logged here. that's the purpose of catching it. but we don't have to. So we could also remove the try() catch block.
  13. TYPO3com voted on patch set 13 V +1 07/16/19, 13:12 Completed build in 14m 26s on Tue, 16 Jul, 03:12 PM Test Summary: 47118 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35090

  14. Benjamin Franzke uploaded patch set 14 07/16/19, 13:25

  15. Benjamin Franzke voted on patch set 14 V +1 CR +1 07/16/19, 13:26

  16. Benjamin Franzke commented on patch set 14 07/16/19, 13:27

    EventDispatcher.php:53 Reply

    Ack, we should remove it for now. Did so.

    Feature-88770-PSR-14BasedEventDispatcher.rst:122 Reply

    Done
  17. Benni Mack voted on patch set 14 CR +1 07/16/19, 13:35

  18. Benni Mack commented on patch set 15 07/16/19, 13:38

    Published edit on patch set 14.
  19. Benni Mack voted on patch set 15 CR +1 07/16/19, 13:39

  20. Georg Ringer voted on patch set 15 V +1 CR +1 07/16/19, 13:39

  21. TYPO3com voted on patch set 14 V +1 07/16/19, 13:41 Completed build in 13m 34s on Tue, 16 Jul, 03:41 PM Test Summary: 47118 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35095

  22. Andreas Kienast voted on patch set 15 CR +1 07/16/19, 13:45

  23. Benjamin Franzke voted on patch set 15 V +2 CR +2 07/16/19, 13:48

  24. Benjamin Franzke merged patch set 16 07/16/19, 13:48

  25. TYPO3com voted on patch set 15 V +1 07/16/19, 13:50 Completed build in 11m 16s on Tue, 16 Jul, 03:50 PM Test Summary: 47118 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-35096