Skip to content

Commit 6008eb2

Browse files
authored
Merge pull request #23 from clue-labs/dns-config
Update DNS dependency and load system default DNS config on all supported platforms
2 parents fd735dd + dfc89a4 commit 6008eb2

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Once [installed](#install), you can use the following code to connect to an UDP
1111

1212
```php
1313
$loop = React\EventLoop\Factory::create();
14-
1514
$factory = new React\Datagram\Factory($loop);
1615

1716
$factory->createClient('localhost:1234')->then(function (React\Datagram\Socket $client) {

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"php": ">=5.3",
1818
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
1919
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
20-
"react/dns": "^0.4.11",
20+
"react/dns": "^0.4.13",
2121
"react/promise": "~2.1|~1.2"
2222
},
2323
"require-dev": {

examples/client.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
require_once __DIR__.'/../vendor/autoload.php';
44

55
$loop = React\EventLoop\Factory::create();
6-
7-
$factory = new React\Dns\Resolver\Factory();
8-
$resolver = $factory->createCached('8.8.8.8', $loop);
9-
10-
$factory = new React\Datagram\Factory($loop, $resolver);
6+
$factory = new React\Datagram\Factory($loop);
117

128
$factory->createClient('localhost:1234')->then(function (React\Datagram\Socket $client) use ($loop) {
139
$client->send('first');

examples/server.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require_once __DIR__.'/../vendor/autoload.php';
44

55
$loop = React\EventLoop\Factory::create();
6-
76
$factory = new React\Datagram\Factory($loop);
87

98
$factory->createServer('localhost:1234')->then(function (React\Datagram\Socket $server) {

src/Factory.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace React\Datagram;
44

55
use React\Datagram\Socket;
6+
use React\Dns\Config\Config;
67
use React\Dns\Resolver\Factory as DnsFactory;
78
use React\Dns\Resolver\Resolver;
89
use React\EventLoop\LoopInterface;
@@ -19,13 +20,18 @@ class Factory
1920
*
2021
* @param LoopInterface $loop
2122
* @param Resolver|null $resolver Resolver instance to use. Will otherwise
22-
* default to using Google's public DNS 8.8.8.8
23+
* try to load the system default DNS config or fall back to using
24+
* Google's public DNS 8.8.8.8
2325
*/
2426
public function __construct(LoopInterface $loop, Resolver $resolver = null)
2527
{
2628
if ($resolver === null) {
29+
// try to load nameservers from system config or default to Google's public DNS
30+
$config = Config::loadSystemConfigBlocking();
31+
$server = $config->nameservers ? reset($config->nameservers) : '8.8.8.8';
32+
2733
$factory = new DnsFactory();
28-
$resolver = $factory->create('8.8.8.8', $loop);
34+
$resolver = $factory->create($server, $loop);
2935
}
3036

3137
$this->loop = $loop;

0 commit comments

Comments
 (0)