From 1d8dc615bf7140c87e52156f31c834b0daba2e01 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Thu, 16 Mar 2017 23:01:58 -0500 Subject: [PATCH] Update for async-interop merge and other Amp changes --- composer.json | 1 - lib/DefaultResolver.php | 11 +++++------ lib/Resolver.php | 2 +- lib/functions.php | 6 +++--- test/IntegrationTest.php | 10 +++++----- test/ResolvConfTest.php | 4 ++-- 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index de3e0f1..b7cb93a 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,6 @@ "minimum-stability": "dev", "prefer-stable": true, "require-dev": { - "amphp/loop": "dev-master", "phpunit/phpunit": "^5.2.8", "friendsofphp/php-cs-fixer": "^1.9" }, diff --git a/lib/DefaultResolver.php b/lib/DefaultResolver.php index a5c85e9..d6d0349 100644 --- a/lib/DefaultResolver.php +++ b/lib/DefaultResolver.php @@ -2,11 +2,10 @@ namespace Amp\Dns; -use Amp\{ CallableMaker, Coroutine, Deferred, Failure, MultiReasonException, Success, TimeoutException }; +use Amp\{ CallableMaker, Coroutine, Deferred, Failure, Loop, MultiReasonException, Promise, Success, TimeoutException }; use Amp\Cache\ArrayCache; use Amp\File\FilesystemException; use Amp\WindowsRegistry\{ KeyNotFoundException, WindowsRegistry }; -use AsyncInterop\{ Loop, Promise }; use LibDNS\{ Decoder\DecoderFactory, Encoder\EncoderFactory }; use LibDNS\Messages\{ MessageFactory, MessageTypes }; use LibDNS\Records\QuestionFactory; @@ -92,7 +91,7 @@ class DefaultResolver implements Resolver { // flatten $result while preserving order according to $types (append unspecified types for e.g. Record::ALL queries) private function pipeResult($promise, array $types) { - return \Amp\pipe($promise, function (array $result) use ($types) { + return Promise\pipe($promise, function (array $result) use ($types) { $retval = []; foreach ($types as $type) { if (isset($result[$type])) { @@ -109,7 +108,7 @@ class DefaultResolver implements Resolver { if (!isset($options["hosts"]) || $options["hosts"]) { static $hosts = null; if ($hosts === null || !empty($options["reload_hosts"])) { - return \Amp\pipe(new Coroutine($this->loadHostsFile()), function ($value) use (&$hosts, $name, $types, $options) { + return Promise\pipe(new Coroutine($this->loadHostsFile()), function ($value) use (&$hosts, $name, $types, $options) { unset($options["reload_hosts"]); // avoid recursion $hosts = $value; return $this->recurseWithHosts($name, $types, $options); @@ -160,7 +159,7 @@ class DefaultResolver implements Resolver { $useTCP = \substr($uri, 0, 6) == "tcp://"; if ($useTCP && isset($server->connect)) { - return \Amp\pipe($server->connect, function() use ($uri, $name, $type) { + return Promise\pipe($server->connect, function() use ($uri, $name, $type) { return $this->doRequest($uri, $name, $type); }); } @@ -260,7 +259,7 @@ class DefaultResolver implements Resolver { } try { - list( , $resultArr) = yield \Amp\timeout(\Amp\some($promises), $timeout); + list( , $resultArr) = yield Promise\timeout(Promise\some($promises), $timeout); foreach ($resultArr as $value) { $result += $value; } diff --git a/lib/Resolver.php b/lib/Resolver.php index 68a3933..6ad5dd4 100644 --- a/lib/Resolver.php +++ b/lib/Resolver.php @@ -2,7 +2,7 @@ namespace Amp\Dns; -use AsyncInterop\Promise; +use Amp\Promise; interface Resolver { /** diff --git a/lib/functions.php b/lib/functions.php index 4517eaa..99d3bb8 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -2,7 +2,7 @@ namespace Amp\Dns; -use AsyncInterop\{ Loop, Promise }; +use Amp\{ Loop, Promise }; const LOOP_STATE_IDENTIFIER = Resolver::class; @@ -61,7 +61,7 @@ function driver(): Resolver { * * @param string $name The hostname to resolve * @param array $options - * @return \AsyncInterop\Promise + * @return \Amp\Promise * @TODO add boolean "clear_cache" option flag */ function resolve(string $name, array $options = []): Promise { @@ -73,7 +73,7 @@ function resolve(string $name, array $options = []): Promise { * @param string $name Unlike resolve(), query() allows for requesting _any_ name (as DNS RFC allows for arbitrary strings) * @param int|int[] $type Use constants of Amp\Dns\Record * @param array $options @see resolve documentation - * @return \AsyncInterop\Promise + * @return \Amp\Promise */ function query(string $name, $type, array $options = []): Promise { return resolver()->query($name, $type, $options); diff --git a/test/IntegrationTest.php b/test/IntegrationTest.php index 6a6441f..ad52d40 100644 --- a/test/IntegrationTest.php +++ b/test/IntegrationTest.php @@ -2,7 +2,7 @@ namespace Amp\Dns\Test; -use AsyncInterop\Loop; +use Amp\Loop; class IntegrationTest extends \PHPUnit_Framework_TestCase { /** @@ -10,7 +10,7 @@ class IntegrationTest extends \PHPUnit_Framework_TestCase { * @dataProvider provideHostnames */ public function testResolve($hostname) { - Loop::execute(\Amp\wrap(function () use ($hostname) { + Loop::run(function () use ($hostname) { $result = (yield \Amp\Dns\resolve($hostname)); list($addr, $type, $ttl) = $result[0]; $inAddr = @\inet_pton($addr); @@ -18,7 +18,7 @@ class IntegrationTest extends \PHPUnit_Framework_TestCase { $inAddr, "Server name $hostname did not resolve to a valid IP address" ); - })); + }); } /** @@ -26,7 +26,7 @@ class IntegrationTest extends \PHPUnit_Framework_TestCase { * @dataProvider provideServers */ public function testResolveWithCustomServer($server) { - Loop::execute(\Amp\wrap(function () use ($server) { + Loop::run(function () use ($server) { $result = (yield \Amp\Dns\resolve("google.com", [ "server" => $server ])); @@ -36,7 +36,7 @@ class IntegrationTest extends \PHPUnit_Framework_TestCase { $inAddr, "Server name google.com did not resolve to a valid IP address via $server" ); - })); + }); } public function provideHostnames() { diff --git a/test/ResolvConfTest.php b/test/ResolvConfTest.php index 73bd20d..59901d8 100644 --- a/test/ResolvConfTest.php +++ b/test/ResolvConfTest.php @@ -11,7 +11,7 @@ class ResolvConfTest extends \PHPUnit_Framework_TestCase { $method = $reflector->getMethod("loadResolvConf"); $method->setAccessible(true); - $result = \Amp\wait(new Coroutine($method->invoke(\Amp\Dns\resolver(), __DIR__ . "/data/resolv.conf"))); + $result = \Amp\Promise\wait(new Coroutine($method->invoke(\Amp\Dns\resolver(), __DIR__ . "/data/resolv.conf"))); $this->assertSame([ "nameservers" => [ @@ -28,7 +28,7 @@ class ResolvConfTest extends \PHPUnit_Framework_TestCase { $method = $reflector->getMethod("loadResolvConf"); $method->setAccessible(true); - $result = \Amp\wait(new Coroutine($method->invoke(\Amp\Dns\resolver(), __DIR__ . "/data/invalid.conf"))); + $result = \Amp\Promise\wait(new Coroutine($method->invoke(\Amp\Dns\resolver(), __DIR__ . "/data/invalid.conf"))); $this->assertSame([ "nameservers" => [