<?php
declare(strict_types=1);
namespace App\System\Infrastructure\Implementation\Logger;
use App\Infrastructure\Interfaces\Logger\MessageDirectorInterface;
use App\Infrastructure\Interfaces\Logger\NetworkLoggerInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Messenger\MessageBusInterface;
class NetworkLogger implements NetworkLoggerInterface
{
private const TEST_ENV = 'test';
public function __construct(
private readonly KernelInterface $kernel,
private readonly MessageBusInterface $bus,
) {
}
public function publish(MessageDirectorInterface $director): void
{
if ($this->kernel->getEnvironment() === self::TEST_ENV) {
return;
}
$message = $director->make();
$this->bus->dispatch($message);
}
}