Permalink
Browse files

Provide default implementation of ConnectionFactory

  • Loading branch information...
1 parent ad55b45 commit 41ca9c577f4485c076be9b11ccaaea5500f448d2 @igorw igorw committed Nov 7, 2012
Showing with 23 additions and 5 deletions.
  1. +1 −5 examples/query.php
  2. +22 −0 src/React/Whois/ConnectionFactory.php
View
@@ -5,11 +5,7 @@
$loop = React\EventLoop\Factory::create();
$factory = new React\Dns\Resolver\Factory();
$resolver = $factory->create('8.8.8.8', $loop);
-
-$connFactory = function ($ip) use ($loop) {
- $fd = stream_socket_client("tcp://$ip:43");
- return new React\Socket\Connection($fd, $loop);
-};
+$connFactory = new React\Whois\ConnectionFactory($loop);
$domain = 'igor.io';
@@ -0,0 +1,22 @@
+<?php
+
+namespace React\Whois;
+
+use React\EventLoop\LoopInterface;
+use React\Socket\Connection;
+
+class ConnectionFactory
+{
+ private $loop;
+
+ public function __construct(LoopInterface $loop)
+ {
+ $this->loop = $loop;
+ }
+
+ public function __invoke($ip)
+ {
+ $fd = stream_socket_client("tcp://$ip:43");
+ return new Connection($fd, $this->loop);
+ }
+}

0 comments on commit 41ca9c5

Please sign in to comment.