1
0
mirror of https://github.com/danog/dns.git synced 2024-12-02 17:38:05 +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;
$client = new Client(
$reactor,
new RequestBuilder(
new MessageFactory,
new QuestionFactory,
(new EncoderFactory)->create()
),
new ResponseInterpreter(
(new DecoderFactory)->create()
),
$serverAddr, $serverPort, $requestTimeout
);
$cache = $cache ?: new MemoryCache;
$hostsFile = new HostsFile($nameValidator, $hostsFilePath);
return new Resolver($reactor, $nameValidator, $client, $cache, $hostsFile);
2014-06-13 19:17:49 +02:00
}
}