* @author Kyrian Obikwelu */ final class Server { public function __construct( private readonly Protocol $protocol, private readonly LoggerInterface $logger = new NullLogger(), ) { } public static function builder(): Builder { return new Builder(); } /** * @template TResult * * @param TransportInterface $transport * * @return TResult */ public function run(TransportInterface $transport): mixed { $transport->initialize(); $this->protocol->connect($transport); $this->logger->info('Running server...'); try { return $transport->listen(); } finally { $transport->close(); } } }