mirror of
https://github.com/danog/dns.git
synced 2024-12-02 17:38:05 +01:00
a50369e71e
- Add tests - Configure repo for use with Travis - Add some more Cache implementations
53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Addr;
|
|
|
|
use Alert\Reactor,
|
|
LibDNS\Decoder\DecoderFactory,
|
|
LibDNS\Encoder\EncoderFactory,
|
|
LibDNS\Messages\MessageFactory,
|
|
LibDNS\Records\QuestionFactory;
|
|
|
|
class ResolverFactory
|
|
{
|
|
/**
|
|
* Create a new resolver instance
|
|
*
|
|
* @param Reactor $reactor
|
|
* @param string $serverAddr
|
|
* @param int $serverPort
|
|
* @param int $requestTimeout
|
|
* @param \AddrCache\Cache $cache
|
|
* @param string $hostsFilePath
|
|
* @return Resolver
|
|
*/
|
|
public function createResolver(
|
|
Reactor $reactor,
|
|
$serverAddr = null,
|
|
$serverPort = null,
|
|
$requestTimeout = null,
|
|
\AddrCache\Cache $cache = null,
|
|
$hostsFilePath = null
|
|
) {
|
|
$nameValidator = new NameValidator;
|
|
$cache = $cache ?: new \AddrCache\MemoryCache;
|
|
|
|
$client = new Client(
|
|
$reactor,
|
|
new RequestBuilder(
|
|
new MessageFactory,
|
|
new QuestionFactory,
|
|
(new EncoderFactory)->create()
|
|
),
|
|
new ResponseInterpreter(
|
|
(new DecoderFactory)->create()
|
|
),
|
|
$cache, $serverAddr, $serverPort, $requestTimeout
|
|
);
|
|
|
|
$hostsFile = new HostsFile($nameValidator, $hostsFilePath);
|
|
|
|
return new Resolver($reactor, $nameValidator, $client, $hostsFile);
|
|
}
|
|
}
|