Permalink
Browse files

Update to new promise-based dns API in react/dns v0.2.4

  • Loading branch information...
1 parent 0046366 commit 51e6d4458b8b3d24832ddbc49aec88489100143c @igorw igorw committed Nov 18, 2012
Showing with 52 additions and 104 deletions.
  1. +4 −0 CHANGELOG.md
  2. +39 −37 composer.lock
  3. +0 −55 src/React/Whois/BufferedStreamPromise.php
  4. +5 −8 src/React/Whois/Client.php
  5. +4 −4 tests/React/Whois/ClientTest.php
View
@@ -1,6 +1,10 @@
CHANGELOG
=========
+* 0.1.1 (2012-11-18)
+
+ * Use promise-based DNS resolver in react/dns v0.2.4
+
* 0.1.0 (2012-11-08)
* First tagged release
View
@@ -1,5 +1,5 @@
{
- "hash": "1edd7eb3cbc7e76af1041afd0d1b9b66",
+ "hash": "5f7f095d564c748864dd6774182c46b4",
"packages": [
{
"name": "evenement/evenement",
@@ -83,24 +83,25 @@
},
{
"name": "react/dns",
- "version": "v0.2.2",
+ "version": "v0.2.4",
"target-dir": "React/Dns",
"source": {
"type": "git",
"url": "https://github.com/reactphp/dns",
- "reference": "v0.2.2"
+ "reference": "v0.2.4"
},
"dist": {
"type": "zip",
- "url": "https://github.com/reactphp/dns/zipball/v0.2.2",
- "reference": "v0.2.2",
+ "url": "https://github.com/reactphp/dns/archive/v0.2.4.zip",
+ "reference": "v0.2.4",
"shasum": ""
},
"require": {
"php": ">=5.3.2",
- "react/socket": "0.2.*"
+ "react/socket": "0.2.*",
+ "react/promise": "1.0.*"
},
- "time": "2012-10-24 08:04:15",
+ "time": "2012-11-17 16:59:43",
"type": "library",
"installation-source": "dist",
"autoload": {
@@ -119,31 +120,32 @@
},
{
"name": "react/event-loop",
- "version": "v0.2.2",
+ "version": "v0.2.4",
"target-dir": "React/EventLoop",
"source": {
"type": "git",
"url": "https://github.com/reactphp/event-loop",
- "reference": "v0.2.2"
+ "reference": "v0.2.4"
},
"dist": {
"type": "zip",
- "url": "https://github.com/reactphp/event-loop/zipball/v0.2.2",
- "reference": "v0.2.2",
+ "url": "https://github.com/reactphp/event-loop/archive/v0.2.4.zip",
+ "reference": "v0.2.4",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"suggest": {
- "ext-libevent": ">=0.0.5"
+ "ext-libevent": ">=0.0.5",
+ "ext-libev": "*"
},
- "time": "2012-09-10 05:53:22",
+ "time": "2012-11-12 23:00:05",
"type": "library",
"extra": {
- "branch-alias": [
-
- ]
+ "branch-alias": {
+ "dev-master": "0.2-dev"
+ }
},
"installation-source": "dist",
"autoload": {
@@ -161,22 +163,22 @@
},
{
"name": "react/promise",
- "version": "v1.0.0",
+ "version": "v1.0.3",
"source": {
"type": "git",
"url": "https://github.com/reactphp/promise",
- "reference": "v1.0.0"
+ "reference": "v1.0.3"
},
"dist": {
"type": "zip",
- "url": "https://github.com/reactphp/promise/archive/v1.0.0.zip",
- "reference": "v1.0.0",
+ "url": "https://github.com/reactphp/promise/archive/v1.0.3.zip",
+ "reference": "v1.0.3",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
- "time": "2012-11-07 21:24:54",
+ "time": "2012-11-17 21:29:48",
"type": "library",
"extra": {
"branch-alias": {
@@ -204,17 +206,17 @@
},
{
"name": "react/socket",
- "version": "v0.2.2",
+ "version": "v0.2.4",
"target-dir": "React/Socket",
"source": {
"type": "git",
"url": "https://github.com/reactphp/socket",
- "reference": "v0.2.2"
+ "reference": "v0.2.4"
},
"dist": {
"type": "zip",
- "url": "https://github.com/reactphp/socket/zipball/v0.2.2",
- "reference": "v0.2.2",
+ "url": "https://github.com/reactphp/socket/archive/v0.2.4.zip",
+ "reference": "v0.2.4",
"shasum": ""
},
"require": {
@@ -223,12 +225,12 @@
"react/event-loop": "0.2.*",
"react/stream": "0.2.*"
},
- "time": "2012-09-10 05:56:19",
+ "time": "2012-11-05 13:25:35",
"type": "library",
"extra": {
- "branch-alias": [
-
- ]
+ "branch-alias": {
+ "dev-master": "0.2-dev"
+ }
},
"installation-source": "dist",
"autoload": {
@@ -246,17 +248,17 @@
},
{
"name": "react/stream",
- "version": "v0.2.2",
+ "version": "v0.2.4",
"target-dir": "React/Stream",
"source": {
"type": "git",
"url": "https://github.com/reactphp/stream",
- "reference": "v0.2.2"
+ "reference": "v0.2.4"
},
"dist": {
"type": "zip",
- "url": "https://github.com/reactphp/stream/zipball/v0.2.2",
- "reference": "v0.2.2",
+ "url": "https://github.com/reactphp/stream/archive/v0.2.4.zip",
+ "reference": "v0.2.4",
"shasum": ""
},
"require": {
@@ -266,12 +268,12 @@
"suggest": {
"react/event-loop": "0.2.*"
},
- "time": "2012-10-28 03:28:34",
+ "time": "2012-11-18 00:18:39",
"type": "library",
"extra": {
- "branch-alias": [
-
- ]
+ "branch-alias": {
+ "dev-master": "0.2-dev"
+ }
},
"installation-source": "dist",
"autoload": {
@@ -1,55 +0,0 @@
-<?php
-
-namespace React\Whois;
-
-use Evenement\EventEmitter;
-use React\Promise\Deferred;
-use React\Promise\PromiseInterface;
-use React\Stream\WritableStreamInterface;
-
-class BufferedStreamPromise extends EventEmitter implements WritableStreamInterface, PromiseInterface
-{
- private $buffer = '';
- private $closed = false;
- private $deferred;
-
- public function __construct()
- {
- $this->deferred = new Deferred();
- }
-
- public function isWritable()
- {
- return !$this->closed;
- }
-
- public function write($data)
- {
- $this->buffer .= $data;
- }
-
- public function end($data = null)
- {
- if (null !== $data) {
- $this->write($data);
- }
-
- $this->close();
- }
-
- public function close()
- {
- if ($this->closed) {
- return;
- }
-
- $this->closed = true;
- $this->emit('close');
- $this->deferred->resolve($this->buffer);
- }
-
- public function then($fulfilledHandler = null, $errorHandler = null, $progressHandler = null)
- {
- return $this->deferred->then($fulfilledHandler, $errorHandler, $progressHandler);
- }
-}
@@ -6,6 +6,7 @@
use React\Curry\Util as Curry;
use React\Dns\Resolver\Resolver;
use React\Stream\ReadableStreamInterface;
+use React\Stream\BufferedSink;
class Client
{
@@ -27,14 +28,10 @@ public function query($domain)
public function resolveWhoisServer($domain)
{
- $deferred = new Deferred();
-
$tld = substr(strrchr($domain, '.'), 1);
$target = $tld.'.whois-servers.net';
- $this->dns->resolve($target, array($deferred, 'resolve'));
-
- return $deferred->promise();
+ return $this->dns->resolve($target);
}
public function queryWhoisServer($domain, $ip)
@@ -54,9 +51,9 @@ public function normalizeLinefeeds($data)
public function streamGetContents(ReadableStreamInterface $input)
{
- $contents = new BufferedStreamPromise();
- $input->pipe($contents);
+ $sink = new BufferedSink();
+ $input->pipe($sink);
- return $contents;
+ return $sink->promise();
}
}
@@ -2,6 +2,8 @@
namespace React\Whois;
+use React\Promise\FulfilledPromise;
+
class ClientTest extends TestCase
{
/** @test */
@@ -15,17 +17,15 @@ public function clientShouldGetCorrectWhoisServerAndQueryIt()
->method('__invoke')
->with($result);
+ // whois.nic.io => 193.223.78.152
$resolver = $this->getMockBuilder('React\Dns\Resolver\Resolver')
->disableOriginalConstructor()
->getMock();
$resolver
->expects($this->once())
->method('resolve')
->with('io.whois-servers.net')
- ->will($this->returnCallback(function ($domain, $callback) {
- // whois.nic.io
- call_user_func($callback, '193.223.78.152');
- }));
+ ->will($this->returnValue(new FulfilledPromise('193.223.78.152')));
$conn = $this->getMockBuilder('React\Whois\Stub\ConnectionStub')
->setMethods(array(

0 comments on commit 51e6d44

Please sign in to comment.