From 21ddbf345881ffecbbc537af453f8b3ab9f27878 Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Wed, 11 Jun 2014 08:29:05 +0545 Subject: [PATCH] DNS resolver is optional --- src/Connector.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Connector.php b/src/Connector.php index 7dd5b10..b479640 100644 --- a/src/Connector.php +++ b/src/Connector.php @@ -13,12 +13,26 @@ class Connector implements ConnectorInterface private $loop; private $resolver; - public function __construct(LoopInterface $loop, Resolver $resolver) + public function __construct(LoopInterface $loop, Resolver $resolver = null) { $this->loop = $loop; $this->resolver = $resolver; } + public function setDnsResolver(Resolver $resolver) + { + $this->resolver = $resolver; + } + + public function getDnsResolver() + { + if (!$this->resolver instanceof Resolver) { + throw new \RuntimeException('DNS Resolver is not set.'); + } + + return $this->resolver; + } + public function create($host, $port) { return $this @@ -97,6 +111,6 @@ protected function resolveHostname($host) return Promise\resolve($host); } - return $this->resolver->resolve($host); + return $this->getDnsResolver()->resolve($host); } }