|
3 | 3 | namespace React\MySQL; |
4 | 4 |
|
5 | 5 | use React\EventLoop\LoopInterface; |
6 | | -use React\Socket\Connector; |
7 | 6 | use React\Socket\ConnectionInterface as SocketConnectionInterface; |
| 7 | +use React\Socket\Connector; |
| 8 | +use React\Socket\ConnectorInterface; |
8 | 9 | use React\MySQL\Commands\AuthenticateCommand; |
9 | 10 | use React\MySQL\Commands\PingCommand; |
10 | 11 | use React\MySQL\Commands\QueryCommand; |
@@ -67,14 +68,19 @@ class Connection extends EventEmitter implements ConnectionInterface |
67 | 68 | /** |
68 | 69 | * Connection constructor. |
69 | 70 | * |
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. |
72 | 74 | */ |
73 | | - public function __construct(LoopInterface $loop, array $connectOptions = array()) |
| 75 | + public function __construct(LoopInterface $loop, array $connectOptions = array(), ConnectorInterface $connector = null) |
74 | 76 | { |
75 | 77 | $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; |
78 | 84 | $this->executor = new Executor($this); |
79 | 85 | $this->options = $connectOptions + $this->options; |
80 | 86 | } |
|
0 commit comments