‪TYPO3CMS  ‪main
MessageListener.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Log\LoggerInterface;
21 use Symfony\Component\Messenger\MessageBusInterface;
23 
33 {
34  public function ‪__construct(
35  protected readonly MessageBusInterface $bus,
36  protected readonly ‪WebhookMessageFactory $messageFactory,
37  protected readonly LoggerInterface $logger,
38  ) {}
39 
40  public function ‪__invoke(mixed $object): void
41  {
42  $message = $this->messageFactory->createMessageFromEvent($object);
43  if ($message === null) {
44  return;
45  }
46  try {
47  $this->bus->dispatch($message);
48  } catch (\Throwable $e) {
49  // At the moment we ignore every exception here, but we log them.
50  // An exception here means that an error happens while sending the webhook,
51  // and we should not block the execution of other configured webhooks.
52  // This can happen if no transport is configured, and the message is handled directly.
53  $this->logger->error(get_class($message) . ': ' . $e->getMessage());
54  }
55  }
56 }
‪TYPO3\CMS\Webhooks\Listener\MessageListener\__invoke
‪__invoke(mixed $object)
Definition: MessageListener.php:40
‪TYPO3\CMS\Webhooks\Listener
Definition: MessageListener.php:18
‪TYPO3\CMS\Webhooks\Listener\MessageListener
Definition: MessageListener.php:33
‪TYPO3\CMS\Webhooks\Listener\MessageListener\__construct
‪__construct(protected readonly MessageBusInterface $bus, protected readonly WebhookMessageFactory $messageFactory, protected readonly LoggerInterface $logger,)
Definition: MessageListener.php:34
‪TYPO3\CMS\Webhooks\Message\WebhookMessageFactory
Definition: WebhookMessageFactory.php:26