MessageSubscriberInterface.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Messenger\Handler;
  11. /**
  12. * Handlers can implement this interface to handle multiple messages.
  13. *
  14. * @author Samuel Roze <samuel.roze@gmail.com>
  15. */
  16. interface MessageSubscriberInterface extends MessageHandlerInterface
  17. {
  18. /**
  19. * Returns a list of messages to be handled.
  20. *
  21. * It returns a list of messages like in the following example:
  22. *
  23. * yield MyMessage::class;
  24. *
  25. * It can also change the priority per classes.
  26. *
  27. * yield FirstMessage::class => ['priority' => 0];
  28. * yield SecondMessage::class => ['priority' => -10];
  29. *
  30. * It can also specify a method, a priority, a bus and/or a transport per message:
  31. *
  32. * yield FirstMessage::class => ['method' => 'firstMessageMethod'];
  33. * yield SecondMessage::class => [
  34. * 'method' => 'secondMessageMethod',
  35. * 'priority' => 20,
  36. * 'bus' => 'my_bus_name',
  37. * 'from_transport' => 'your_transport_name',
  38. * ];
  39. *
  40. * The benefit of using `yield` instead of returning an array is that you can `yield` multiple times the
  41. * same key and therefore subscribe to the same message multiple times with different options.
  42. *
  43. * The `__invoke` method of the handler will be called as usual with the message to handle.
  44. */
  45. public static function getHandledMessages(): iterable;
  46. }