From ba8a8423eb519a90faba5af58a9aedf04d3f542c Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Thu, 22 Jun 2017 18:46:08 -0500 Subject: [PATCH] Use anonymous class --- lib/DefaultResolver.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/DefaultResolver.php b/lib/DefaultResolver.php index fc6d2ed..91a677a 100644 --- a/lib/DefaultResolver.php +++ b/lib/DefaultResolver.php @@ -361,15 +361,27 @@ class DefaultResolver implements Resolver { \stream_set_blocking($socket, false); $id = (int) $socket; - $server = new \StdClass; + + $server = new class { + use Amp\Struct; + public $id; + public $uri; + public $server; + public $socket; + public $buffer = ""; + public $length = INF; + public $pendingRequests = []; + public $watcherId; + public $connect; + }; + $server->id = $id; $server->uri = $uri; $server->socket = $socket; - $server->buffer = ""; - $server->length = INF; $server->pendingRequests = []; $server->watcherId = Loop::onReadable($socket, $this->callableFromInstanceMethod("onReadable")); Loop::disable($server->watcherId); + $this->serverIdMap[$id] = $server; $this->serverUriMap[$uri] = $server; @@ -379,7 +391,7 @@ class DefaultResolver implements Resolver { $watcher = Loop::onWritable($server->socket, static function ($watcher) use ($server, $deferred, &$timer) { Loop::cancel($watcher); Loop::cancel($timer); - unset($server->connect); + $server->connect = null; $deferred->resolve(); }); // TODO: Respect timeout