‪TYPO3CMS  ‪main
HandlersLocatorFactory.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\Container\ContainerInterface;
21 use Symfony\Component\Messenger\Handler\HandlerDescriptor;
22 use Symfony\Component\Messenger\Handler\HandlersLocator;
23 
28 {
29  private array ‪$handlers = [];
30 
31  public function ‪__construct(private readonly ContainerInterface $container) {}
32 
33  public function ‪createHandlersLocator(): HandlersLocator
34  {
35  return new HandlersLocator(
36  $this->handlers
37  );
38  }
39 
43  public function ‪addHandler(string $messageClass, string $handlerService, string $handlerMethod): void
44  {
45  $container = $this->container;
46  $this->handlers[$messageClass][] = new HandlerDescriptor(
47  function (...‪$args) use ($container, $handlerService, $handlerMethod) {
48  if ($handlerMethod === '__invoke') {
49  return $container->get($handlerService)(...‪$args);
50  }
51  return $container->get($handlerService)->{$handlerMethod}(...$args);
52  },
53  [
54  'alias' => $handlerService . '::' . $handlerMethod,
55  ]
56  );
57  }
58 }
‪TYPO3\CMS\Core\Messenger\HandlersLocatorFactory\createHandlersLocator
‪createHandlersLocator()
Definition: HandlersLocatorFactory.php:33
‪TYPO3\CMS\Core\Messenger\HandlersLocatorFactory\__construct
‪__construct(private readonly ContainerInterface $container)
Definition: HandlersLocatorFactory.php:31
‪$args
‪$args
Definition: validateRstFiles.php:259
‪TYPO3\CMS\Core\Messenger\HandlersLocatorFactory\addHandler
‪addHandler(string $messageClass, string $handlerService, string $handlerMethod)
Definition: HandlersLocatorFactory.php:43
‪TYPO3\CMS\Core\Messenger\HandlersLocatorFactory
Definition: HandlersLocatorFactory.php:28
‪TYPO3\CMS\Core\Messenger
Definition: BusFactory.php:18
‪TYPO3\CMS\Core\Messenger\HandlersLocatorFactory\$handlers
‪array $handlers
Definition: HandlersLocatorFactory.php:29