2014-06-13 19:17:49 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Addr;
|
|
|
|
|
2014-06-15 01:47:15 +02:00
|
|
|
use Alert\Reactor,
|
|
|
|
LibDNS\Decoder\DecoderFactory,
|
|
|
|
LibDNS\Encoder\EncoderFactory,
|
|
|
|
LibDNS\Messages\MessageFactory,
|
|
|
|
LibDNS\Records\QuestionFactory;
|
2014-06-13 19:17:49 +02:00
|
|
|
|
|
|
|
class ResolverFactory
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Create a new resolver instance
|
|
|
|
*
|
|
|
|
* @param Reactor $reactor
|
2014-06-15 01:47:15 +02:00
|
|
|
* @param string $serverAddr
|
|
|
|
* @param int $serverPort
|
|
|
|
* @param int $requestTimeout
|
|
|
|
* @param string $hostsFilePath
|
2014-06-13 19:17:49 +02:00
|
|
|
* @return Resolver
|
|
|
|
*/
|
2014-06-15 01:47:15 +02:00
|
|
|
public function createResolver(
|
|
|
|
Reactor $reactor,
|
2014-06-15 23:45:33 +02:00
|
|
|
$serverAddr = null,
|
|
|
|
$serverPort = null,
|
|
|
|
$requestTimeout = null,
|
2014-06-15 01:47:15 +02:00
|
|
|
$hostsFilePath = null
|
|
|
|
) {
|
|
|
|
$nameValidator = new NameValidator;
|
|
|
|
|
|
|
|
$client = new Client(
|
|
|
|
$reactor,
|
|
|
|
new RequestBuilder(
|
|
|
|
new MessageFactory,
|
|
|
|
new QuestionFactory,
|
|
|
|
(new EncoderFactory)->create()
|
|
|
|
),
|
|
|
|
new ResponseInterpreter(
|
|
|
|
(new DecoderFactory)->create()
|
|
|
|
),
|
|
|
|
$serverAddr, $serverPort, $requestTimeout
|
|
|
|
);
|
|
|
|
|
2014-06-15 23:52:02 +02:00
|
|
|
$cache = new MemoryCache;
|
2014-06-15 01:47:15 +02:00
|
|
|
$hostsFile = new HostsFile($nameValidator, $hostsFilePath);
|
|
|
|
|
|
|
|
return new Resolver($reactor, $nameValidator, $client, $cache, $hostsFile);
|
2014-06-13 19:17:49 +02:00
|
|
|
}
|
|
|
|
}
|