loop = LoopFactory::create(); $this->routes = $routes; } public function setHost(string $host) { $this->host = $host; return $this; } public function setPort(string $port) { $this->port = $port; return $this; } public function setLoop(LoopInterface $loop) { $this->loop = $loop; return $this; } public function run() { $server = $this->createServer(); $server->run(); } protected function createServer(): IoServer { $socket = new Reactor("{$this->host}:{$this->port}", $this->loop); $urlMatcher = new UrlMatcher($this->routes, new RequestContext); $router = new Router($urlMatcher); $httpServer = new HttpServer($router); return new IoServer($httpServer, $socket, $this->loop); } }