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,
|
|
|
|
$serverAddr = '8.8.8.8',
|
|
|
|
$serverPort = 53,
|
|
|
|
$requestTimeout = 2000,
|
|
|
|
$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
|
|
|
|
);
|
|
|
|
|
|
|
|
$cache = new Cache;
|
|
|
|
$hostsFile = new HostsFile($nameValidator, $hostsFilePath);
|
|
|
|
|
|
|
|
return new Resolver($reactor, $nameValidator, $client, $cache, $hostsFile);
|
2014-06-13 19:17:49 +02:00
|
|
|
}
|
|
|
|
}
|