1
0
mirror of https://github.com/danog/dns.git synced 2024-12-13 01:47:21 +01:00
dns/lib/Addr/ResolverFactory.php

53 lines
1.3 KiB
PHP
Raw Normal View History

2014-06-13 19:17:49 +02:00
<?php
namespace Addr;
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
* @param string $serverAddr
* @param int $serverPort
* @param int $requestTimeout
* @param Cache $cache
* @param string $hostsFilePath
2014-06-13 19:17:49 +02:00
* @return Resolver
*/
public function createResolver(
Reactor $reactor,
$serverAddr = null,
$serverPort = null,
$requestTimeout = null,
Cache $cache = null,
$hostsFilePath = null
) {
$nameValidator = new NameValidator;
$cache = $cache ?: new Cache\MemoryCache;
$client = new Client(
$reactor,
new RequestBuilder(
new MessageFactory,
new QuestionFactory,
(new EncoderFactory)->create()
),
new ResponseInterpreter(
(new DecoderFactory)->create()
),
2014-06-16 19:30:28 +02:00
$cache, $serverAddr, $serverPort, $requestTimeout
);
$hostsFile = new HostsFile($nameValidator, $hostsFilePath);
2014-06-16 19:30:28 +02:00
return new Resolver($reactor, $nameValidator, $client, $hostsFile);
2014-06-13 19:17:49 +02:00
}
}