2021-04-18 22:24:02 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace DigiComp\FlowSymfonyBridge\Messenger;
|
|
|
|
|
|
|
|
use DigiComp\FlowSymfonyBridge\Messenger\ObjectManagement\RewindableGenerator;
|
|
|
|
use Neos\Flow\Annotations as Flow;
|
|
|
|
use Psr\Container\ContainerInterface;
|
|
|
|
use Symfony\Component\Messenger\MessageBus;
|
|
|
|
|
2023-02-18 22:53:05 +01:00
|
|
|
#[Flow\Scope('singleton')]
|
2021-04-18 22:24:02 +02:00
|
|
|
class MessageBusContainer implements ContainerInterface
|
|
|
|
{
|
2023-02-18 22:53:05 +01:00
|
|
|
#[Flow\InjectConfiguration(path: 'buses')]
|
|
|
|
protected array $configuration;
|
2021-04-18 22:24:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var MessageBus[]
|
|
|
|
*/
|
|
|
|
protected array $buses = [];
|
|
|
|
|
|
|
|
public function get(string $id)
|
|
|
|
{
|
|
|
|
if (! isset($this->buses[$id])) {
|
|
|
|
$middlewares = new RewindableGenerator($this->configuration[$id]['middleware']);
|
|
|
|
$this->buses[$id] = new MessageBus($middlewares);
|
|
|
|
}
|
|
|
|
return $this->buses[$id];
|
|
|
|
}
|
|
|
|
|
2023-02-18 22:53:05 +01:00
|
|
|
public function has(string $id): bool
|
2021-04-18 22:24:02 +02:00
|
|
|
{
|
|
|
|
return isset($this->configuration[$id]);
|
|
|
|
}
|
|
|
|
}
|