Skip to content

Commit 71320e0

Browse files
authored
Merge pull request #24 from flow-control/patch-1
Allow for custom Connector / DNS Resolver
2 parents f0ada36 + e6b544b commit 71320e0

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Connection.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
namespace React\MySQL;
44

55
use React\EventLoop\LoopInterface;
6-
use React\Socket\Connector;
76
use React\Socket\ConnectionInterface as SocketConnectionInterface;
7+
use React\Socket\Connector;
8+
use React\Socket\ConnectorInterface;
89
use React\MySQL\Commands\AuthenticateCommand;
910
use React\MySQL\Commands\PingCommand;
1011
use React\MySQL\Commands\QueryCommand;
@@ -67,14 +68,19 @@ class Connection extends EventEmitter implements ConnectionInterface
6768
/**
6869
* Connection constructor.
6970
*
70-
* @param LoopInterface $loop ReactPHP event loop instance.
71-
* @param array $connectOptions MySQL connection options.
71+
* @param LoopInterface $loop ReactPHP event loop instance.
72+
* @param array $connectOptions MySQL connection options.
73+
* @param ConnectorInterface $connector (optional) socket sonnector instance.
7274
*/
73-
public function __construct(LoopInterface $loop, array $connectOptions = array())
75+
public function __construct(LoopInterface $loop, array $connectOptions = array(), ConnectorInterface $connector = null)
7476
{
7577
$this->loop = $loop;
76-
$resolver = (new \React\Dns\Resolver\Factory())->createCached('8.8.8.8', $loop);
77-
$this->connector = new Connector($loop, ['dns' => $resolver]);
78+
if (!$connector) {
79+
$connector = new Connector($loop, [
80+
'dns' => (new \React\Dns\Resolver\Factory())->createCached('8.8.8.8', $loop)
81+
]);
82+
}
83+
$this->connector = $connector;
7884
$this->executor = new Executor($this);
7985
$this->options = $connectOptions + $this->options;
8086
}

0 commit comments

Comments
 (0)