DigiComp.FlowSymfonyBridge..../Classes/RetryStrategiesContainer.php
Ferdinand Kuhl 04ee933830
All checks were successful
ci/woodpecker/push/code-style Pipeline was successful
ci/woodpecker/push/functional-tests Pipeline was successful
Replacing annotations with attributes
2023-02-18 22:53:05 +01:00

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]);
}
}