fix: Update ErrorAggregationInitializer

Fix DI binding issues for ErrorAggregatorInterface
This commit is contained in:
2025-11-01 00:25:13 +01:00
parent 77b2dc5dd7
commit d2b7fc96fc

View File

@@ -23,6 +23,30 @@ use App\Framework\Mail\TransportInterface;
*/ */
final readonly class ErrorAggregationInitializer final readonly class ErrorAggregationInitializer
{ {
public function __construct(
private Environment $env,
){}
#[Initializer]
public function initErrorAggregator(Container $container): ErrorAggregatorInterface
{
$enabled = $this->env->getBool('ERROR_AGGREGATION_ENABLED', true);
if(!$enabled) {
return new NullErrorAggregator();
}
return new ErrorAggregator(
storage: $container->get(ErrorStorageInterface::class),
cache: $container->get(Cache::class),
clock: $container->get(Clock::class),
alertQueue: $container->get(Queue::class),
logger: $container->get(Logger::class),
batchSize: $this->env->getInt('ERROR_AGGREGATION_BATCH_SIZE', 100),
maxRetentionDays: $this->env->getInt('ERROR_AGGREGATION_MAX_RETENTION_DAYS', 90)
);
}
#[Initializer] #[Initializer]
public function initialize(Container $container): void public function initialize(Container $container): void
{ {
@@ -44,22 +68,22 @@ final readonly class ErrorAggregationInitializer
}); });
// Error Aggregator Interface - bind to concrete or Null implementation // Error Aggregator Interface - bind to concrete or Null implementation
$container->bind(ErrorAggregatorInterface::class, function (Container $container) use ($enabled) { // $container->bind(ErrorAggregatorInterface::class, function (Container $container) use ($enabled) {
if (! $enabled) { // if (! $enabled) {
return new NullErrorAggregator(); // return new NullErrorAggregator();
} // }
//
$env = $container->get(Environment::class); // $env = $container->get(Environment::class);
return new ErrorAggregator( // return new ErrorAggregator(
storage: $container->get(ErrorStorageInterface::class), // storage: $container->get(ErrorStorageInterface::class),
cache: $container->get(Cache::class), // cache: $container->get(Cache::class),
clock: $container->get(Clock::class), // clock: $container->get(Clock::class),
alertQueue: $container->get(Queue::class), // alertQueue: $container->get(Queue::class),
logger: $container->get(Logger::class), // logger: $container->get(Logger::class),
batchSize: $env->getInt('ERROR_AGGREGATION_BATCH_SIZE', 100), // batchSize: $env->getInt('ERROR_AGGREGATION_BATCH_SIZE', 100),
maxRetentionDays: $env->getInt('ERROR_AGGREGATION_MAX_RETENTION_DAYS', 90) // maxRetentionDays: $env->getInt('ERROR_AGGREGATION_MAX_RETENTION_DAYS', 90)
); // );
}); // });
// Error Aggregator (concrete class) - delegate to interface // Error Aggregator (concrete class) - delegate to interface
$container->bind(ErrorAggregator::class, function (Container $container) use ($enabled) { $container->bind(ErrorAggregator::class, function (Container $container) use ($enabled) {