53 lines
1.7 KiB
PHP
53 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace DigiComp\FlowSymfonyBridge\Messenger;
|
|
|
|
use Neos\Flow\Annotations as Flow;
|
|
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
|
|
use Psr\Container\ContainerInterface;
|
|
use Symfony\Component\Messenger\Retry\MultiplierRetryStrategy;
|
|
use Symfony\Component\Messenger\Retry\RetryStrategyInterface;
|
|
|
|
#[Flow\Scope('singleton')]
|
|
class RetryStrategiesContainer implements ContainerInterface
|
|
{
|
|
#[Flow\InjectConfiguration]
|
|
protected array $configuration;
|
|
|
|
#[Flow\Inject]
|
|
protected ObjectManagerInterface $objectManager;
|
|
|
|
/**
|
|
* @var RetryStrategyInterface[]
|
|
*/
|
|
protected array $retryStrategies;
|
|
|
|
public function get(string $id)
|
|
{
|
|
if (! isset($this->configuration['transports'][$id])) {
|
|
throw new \InvalidArgumentException('Unknown transport name: ' . $id);
|
|
}
|
|
if (! isset($this->retryStrategies[$id])) {
|
|
$strategyDefinition = \array_merge(
|
|
$this->configuration['defaultRetryStrategyOptions'],
|
|
$this->configuration['transports'][$id]['retryStrategy'] ?? []
|
|
);
|
|
if ($strategyDefinition['service']) {
|
|
$this->retryStrategies[$id] = $this->objectManager->get($strategyDefinition['service']);
|
|
} else {
|
|
$this->retryStrategies[$id] = new MultiplierRetryStrategy(
|
|
$strategyDefinition['maxRetries'],
|
|
$strategyDefinition['delay'],
|
|
$strategyDefinition['multiplier'],
|
|
$strategyDefinition['maxDelay']
|
|
);
|
|
}
|
|
}
|
|
return $this->retryStrategies[$id];
|
|
}
|
|
|
|
public function has(string $id): bool
|
|
{
|
|
return isset($this->configuration['transports'][$id]);
|
|
}
|
|
}
|