Skip to content

Commit 74190c4

Browse files
committed
Update SocketClient to v0.7
1 parent 17a9471 commit 74190c4

3 files changed

Lines changed: 11 additions & 20 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"php": ">=5.3",
1515
"evenement/evenement": "~1.0|~2.0",
1616
"react/promise": "~1.0|~2.0",
17-
"react/socket-client": "^0.6",
17+
"react/socket-client": "^0.7",
1818
"react/event-loop": "0.3.*|0.4.*"
1919
},
2020
"require-dev": {

src/Factory.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,39 @@
44

55
use React\EventLoop\LoopInterface;
66
use React\SocketClient\ConnectionInterface;
7-
use React\SocketClient\ConnectorInterface;
87
use React\SocketClient\Connector;
9-
use React\SocketClient\SecureConnector;
10-
use React\Dns\Resolver\Factory as ResolverFactory;
8+
use React\SocketClient\ConnectorInterface;
119
use InvalidArgumentException;
1210

1311
class Factory
1412
{
1513
private $loop;
1614
private $connector;
17-
private $secureConnector;
1815

19-
public function __construct(LoopInterface $loop, ConnectorInterface $connector = null, ConnectorInterface $secureConnector = null)
16+
public function __construct(LoopInterface $loop, ConnectorInterface $connector = null)
2017
{
2118
if ($connector === null) {
22-
$resolverFactory = new ResolverFactory();
23-
$connector = new Connector($loop, $resolverFactory->create('8.8.8.8', $loop));
24-
}
25-
if ($secureConnector === null) {
26-
$secureConnector = new SecureConnector($connector, $loop);
19+
$connector = new Connector($loop);
2720
}
2821

2922
$this->loop = $loop;
3023
$this->connector = $connector;
31-
$this->secureConnector = $secureConnector;
3224
}
3325

3426
public function createClient($address = null)
3527
{
3628
$parts = $this->parseUrl($address);
3729

38-
$secure = (isset($parts['scheme']) && $parts['scheme'] !== 'tcp');
39-
$connector = $secure ? $this->secureConnector : $this->connector;
30+
if (isset($parts['scheme']) && $parts['scheme'] !== 'tcp') {
31+
$parts['host'] = 'tls://' . $parts['host'];
32+
}
4033

41-
$promise = $connector->connect($parts['host'] . ':' . $parts['port'])->then(function (ConnectionInterface $stream) {
34+
$promise = $this->connector->connect($parts['host'] . ':' . $parts['port'])->then(function (ConnectionInterface $stream) {
4235
return new Client($stream);
4336
});
4437

4538
if (isset($parts['user'])) {
46-
$promise = $promise->then(function (Client $client) use ($parts, $secure) {
39+
$promise = $promise->then(function (Client $client) use ($parts) {
4740
$sender = new ActionSender($client);
4841

4942
return $sender->login($parts['user'], $parts['pass'])->then(

tests/FactoryTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ class FactoryTest extends TestCase
66
{
77
private $loop;
88
private $tcp;
9-
private $tls;
109
private $factory;
1110

1211
public function setUp()
1312
{
1413
$this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
1514
$this->tcp = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
16-
$this->tls = $this->getMockBuilder('React\SocketClient\ConnectorInterface')->getMock();
1715

18-
$this->factory = new Factory($this->loop, $this->tcp, $this->tls);
16+
$this->factory = new Factory($this->loop, $this->tcp);
1917
}
2018

2119
public function testDefaultCtor()
@@ -42,7 +40,7 @@ public function testCreateClientUsesTcpConnectorWithLocalhostLocation()
4240
public function testCreateClientUsesTlsConnectorWithTlsLocation()
4341
{
4442
$promise = new Promise(function () { });
45-
$this->tls->expects($this->once())->method('connect')->with('ami.local:1234')->willReturn($promise);
43+
$this->tcp->expects($this->once())->method('connect')->with('tls://ami.local:1234')->willReturn($promise);
4644

4745
$this->factory->createClient('tls://ami.local:1234');
4846
}

0 commit comments

Comments
 (0)