fix: Update ErrorAggregationInitializer
Fix DI binding issues for ErrorAggregatorInterface
This commit is contained in:
@@ -23,6 +23,30 @@ use App\Framework\Mail\TransportInterface;
|
||||
*/
|
||||
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]
|
||||
public function initialize(Container $container): void
|
||||
{
|
||||
@@ -44,22 +68,22 @@ final readonly class ErrorAggregationInitializer
|
||||
});
|
||||
|
||||
// Error Aggregator Interface - bind to concrete or Null implementation
|
||||
$container->bind(ErrorAggregatorInterface::class, function (Container $container) use ($enabled) {
|
||||
if (! $enabled) {
|
||||
return new NullErrorAggregator();
|
||||
}
|
||||
|
||||
$env = $container->get(Environment::class);
|
||||
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: $env->getInt('ERROR_AGGREGATION_BATCH_SIZE', 100),
|
||||
maxRetentionDays: $env->getInt('ERROR_AGGREGATION_MAX_RETENTION_DAYS', 90)
|
||||
);
|
||||
});
|
||||
// $container->bind(ErrorAggregatorInterface::class, function (Container $container) use ($enabled) {
|
||||
// if (! $enabled) {
|
||||
// return new NullErrorAggregator();
|
||||
// }
|
||||
//
|
||||
// $env = $container->get(Environment::class);
|
||||
// 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: $env->getInt('ERROR_AGGREGATION_BATCH_SIZE', 100),
|
||||
// maxRetentionDays: $env->getInt('ERROR_AGGREGATION_MAX_RETENTION_DAYS', 90)
|
||||
// );
|
||||
// });
|
||||
|
||||
// Error Aggregator (concrete class) - delegate to interface
|
||||
$container->bind(ErrorAggregator::class, function (Container $container) use ($enabled) {
|
||||
|
||||
Reference in New Issue
Block a user