DigiComp.FlowSymfonyBridge..../Classes/MessageBusContainer.php

35 lines
892 B
PHP
Raw Normal View History

<?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')]
class MessageBusContainer implements ContainerInterface
{
2023-02-18 22:53:05 +01:00
#[Flow\InjectConfiguration(path: 'buses')]
protected array $configuration;
/**
* @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
{
return isset($this->configuration[$id]);
}
}