Skip to content

Commit

Permalink
Add legacy Connector as BC layer
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Sep 23, 2015
1 parent d84193a commit 4a29eec
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ $dnsConnector->create('www.google.com', 80)->then(function (React\Stream\Stream
$loop->run();
```

The legacy `Connector` class can be used for backwards-compatiblity reasons.
It works very much like the newer `DnsConnector` but instead has to be
set up like this:

```php
$connector = new React\SocketClient\Connector($loop, $dns);

$connector->create('www.google.com', 80)->then($callback);
```

### Async SSL/TLS connections

The `SecureConnector` class decorates a given `Connector` instance by enabling
Expand Down
24 changes: 24 additions & 0 deletions src/Connector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace React\SocketClient;

use React\EventLoop\LoopInterface;
use React\Dns\Resolver\Resolver;

/**
* @deprecated Exists for BC only, consider using the newer DnsConnector instead
*/
class Connector implements ConnectorInterface
{
private $connector;

public function __construct(LoopInterface $loop, Resolver $resolver)
{
$this->connector = new DnsConnector(new TcpConnector($loop), $resolver);
}

public function create($host, $port)
{
return $this->connector->create($host, $port);
}
}
10 changes: 2 additions & 8 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use React\SocketClient\Connector;
use React\SocketClient\SecureConnector;
use React\Stream\BufferedSink;
use React\SocketClient\TcpConnector;
use React\SocketClient\DnsConnector;

class IntegrationTest extends TestCase
{
Expand All @@ -18,11 +16,9 @@ public function gettingStuffFromGoogleShouldWork()
{
$loop = new StreamSelectLoop();

$connector = new TcpConnector($loop);

$factory = new Factory();
$dns = $factory->create('8.8.8.8', $loop);
$connector = new DnsConnector($connector, $dns);
$connector = new Connector($loop, $dns);

$connected = false;
$response = null;
Expand All @@ -48,16 +44,14 @@ public function gettingEncryptedStuffFromGoogleShouldWork()
{
$loop = new StreamSelectLoop();

$connector = new TcpConnector($loop);

$factory = new Factory();
$dns = $factory->create('8.8.8.8', $loop);

$connected = false;
$response = null;

$secureConnector = new SecureConnector(
new DnsConnector($connector, $dns),
new Connector($loop, $dns),
$loop
);
$secureConnector->create('google.com', 443)
Expand Down

0 comments on commit 4a29eec

Please sign in to comment.