‪TYPO3CMS  ‪main
TransportLocator.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 Symfony\Component\DependencyInjection\ServiceLocator;
21 use Symfony\Component\Messenger\Envelope;
22 use Symfony\Component\Messenger\Exception\RuntimeException;
23 use Symfony\Component\Messenger\Handler\HandlersLocator;
24 use Symfony\Component\Messenger\Stamp\TransportNamesStamp;
25 use Symfony\Component\Messenger\Transport\Sender\SendersLocatorInterface;
26 
32 class ‪TransportLocator implements SendersLocatorInterface
33 {
34  public function ‪__construct(private readonly ServiceLocator $sendersLocator) {}
35 
36  public function ‪getSenders(Envelope $envelope): iterable
37  {
38  $sendersMap = ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['messenger']['routing'];
39  if ($envelope->all(TransportNamesStamp::class)) {
40  foreach ($envelope->last(TransportNamesStamp::class)->getTransportNames() as $senderAlias) {
41  yield from $this->‪getSenderFromConfiguration($senderAlias);
42  }
43 
44  return;
45  }
46 
47  $seen = [];
48 
49  foreach (HandlersLocator::listTypes($envelope) as $type) {
50  $transportForMessage = $sendersMap[$type] ?? [];
51  if (is_string($transportForMessage)) {
52  $transportForMessage = [$transportForMessage];
53  }
54  foreach ($transportForMessage as $senderAlias) {
55  if (!\in_array($senderAlias, $seen, true)) {
56  $seen[] = $senderAlias;
57 
58  yield from $this->‪getSenderFromConfiguration($senderAlias);
59  }
60  }
61  }
62  }
63 
64  private function ‪getSenderFromConfiguration(string $senderAlias): iterable
65  {
66  if (!$this->sendersLocator->has($senderAlias)) {
67  throw new RuntimeException(sprintf('Invalid senders configuration: sender "%s" is not registered via messenger.sender tag.', $senderAlias), 1605192311);
68  }
69 
70  yield $senderAlias => $this->sendersLocator->get($senderAlias);
71  }
72 }
‪TYPO3\CMS\Core\Messenger\TransportLocator\getSenderFromConfiguration
‪getSenderFromConfiguration(string $senderAlias)
Definition: TransportLocator.php:64
‪TYPO3\CMS\Core\Messenger\TransportLocator\getSenders
‪getSenders(Envelope $envelope)
Definition: TransportLocator.php:36
‪TYPO3\CMS\Core\Messenger\TransportLocator\__construct
‪__construct(private readonly ServiceLocator $sendersLocator)
Definition: TransportLocator.php:34
‪TYPO3\CMS\Core\Messenger\TransportLocator
Definition: TransportLocator.php:33
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Messenger
Definition: BusFactory.php:18