From 0970cd8d147bdf84aed166a14d0a3a36f9bb90bc Mon Sep 17 00:00:00 2001 From: Yada Clintjens Date: Fri, 9 Feb 2024 07:44:43 +0100 Subject: [PATCH] Improve documentation --- README.md | 28 +++++++++++++++++++--------- examples/lookup.php | 10 +++++----- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f475c26..8e8a901 100644 --- a/README.md +++ b/README.md @@ -34,15 +34,21 @@ as defined in [RFC 6763](https://tools.ietf.org/html/rfc6763). Once [installed](#install), you can use the following code to look up the address of a local domain name: ```php -$factory = new Factory(); +createResolver(); -$resolver->lookup('hostname.local')->then(function ($ip) { - echo 'Found: ' . $ip . PHP_EOL; +$resolver->resolve('hostname.local')->then(function ($ip) { + echo 'Found: ' . $ip . PHP_EOL; +}, function (Exception $e) { + echo 'Error: ' . $e->getMessage() . PHP_EOL; }); ``` -See also the [examples](examples). +See also the [examples](examples/). ## Usage @@ -83,7 +89,7 @@ Sending queries uses a [Promise](https://github.com/reactphp/promise)-based inte (i.e. either successfully resolved or rejected with an error): ```php -$resolver->lookup($hostname)->then( +$resolver->resolve($hostname)->then( function ($ip) { // IP successfully resolved }, @@ -105,12 +111,16 @@ you should look into also using [clue/reactphp-block](https://github.com/clue/re The resulting blocking code could look something like this: ```php +createResolver(); -$promise = $resolver->lookup('me.local'); +$promise = $resolver->resolve('me.local'); try { $ip = Block\await($promise, $loop); @@ -124,8 +134,8 @@ Similarly, you can also process multiple lookups concurrently and await an array ```php $promises = array( - $resolver->lookup('first.local'), - $resolver->lookup('second.local'), + $resolver->resolve('first.local'), + $resolver->resolve('second.local'), ); $ips = Block\awaitAll($promises, $loop); diff --git a/examples/lookup.php b/examples/lookup.php index 0fce64d..e0136f1 100644 --- a/examples/lookup.php +++ b/examples/lookup.php @@ -7,8 +7,8 @@ $factory = new Clue\React\Mdns\Factory(); $mdns = $factory->createResolver(); -$mdns->resolve($name)->then('e', 'e'); - -function e($v) { - echo $v . PHP_EOL; -} +$mdns->resolve($name)->then(function ($ip) { + echo 'Found: ' . $ip . PHP_EOL; +}, function (Exception $e) { + echo 'Error: ' . $e->getMessage() . PHP_EOL; +});