Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DNS dependency and load system default DNS config on all supported platforms #23

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Once [installed](#install), you can use the following code to connect to an UDP

```php
$loop = React\EventLoop\Factory::create();

$factory = new React\Datagram\Factory($loop);

$factory->createClient('localhost:1234')->then(function (React\Datagram\Socket $client) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"php": ">=5.3",
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
"react/dns": "^0.4.11",
"react/dns": "^0.4.13",
"react/promise": "~2.1|~1.2"
},
"require-dev": {
Expand Down
6 changes: 1 addition & 5 deletions examples/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
require_once __DIR__.'/../vendor/autoload.php';

$loop = React\EventLoop\Factory::create();

$factory = new React\Dns\Resolver\Factory();
$resolver = $factory->createCached('8.8.8.8', $loop);

$factory = new React\Datagram\Factory($loop, $resolver);
$factory = new React\Datagram\Factory($loop);

$factory->createClient('localhost:1234')->then(function (React\Datagram\Socket $client) use ($loop) {
$client->send('first');
Expand Down
1 change: 0 additions & 1 deletion examples/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require_once __DIR__.'/../vendor/autoload.php';

$loop = React\EventLoop\Factory::create();

$factory = new React\Datagram\Factory($loop);

$factory->createServer('localhost:1234')->then(function (React\Datagram\Socket $server) {
Expand Down
10 changes: 8 additions & 2 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace React\Datagram;

use React\Datagram\Socket;
use React\Dns\Config\Config;
use React\Dns\Resolver\Factory as DnsFactory;
use React\Dns\Resolver\Resolver;
use React\EventLoop\LoopInterface;
Expand All @@ -19,13 +20,18 @@ class Factory
*
* @param LoopInterface $loop
* @param Resolver|null $resolver Resolver instance to use. Will otherwise
* default to using Google's public DNS 8.8.8.8
* try to load the system default DNS config or fall back to using
* Google's public DNS 8.8.8.8
*/
public function __construct(LoopInterface $loop, Resolver $resolver = null)
{
if ($resolver === null) {
// try to load nameservers from system config or default to Google's public DNS
$config = Config::loadSystemConfigBlocking();
$server = $config->nameservers ? reset($config->nameservers) : '8.8.8.8';

$factory = new DnsFactory();
$resolver = $factory->create('8.8.8.8', $loop);
$resolver = $factory->create($server, $loop);
}

$this->loop = $loop;
Expand Down