Skip to content

Commit 4a564e4

Browse files
committed
Use Clue\React\Socks PSR-4 namespace under src/
1 parent 8790bb5 commit 4a564e4

10 files changed

Lines changed: 63 additions & 61 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212
],
1313
"autoload": {
14-
"psr-0": {"Socks": ""}
14+
"psr-4": {"Clue\\React\\Socks\\": "src"}
1515
},
1616
"require": {
1717
"react/http-client": "0.3.*",

Socks/Client.php renamed to src/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Socks;
3+
namespace Clue\React\Socks;
44

55
use React\Promise\When;
66
use React\Promise\Deferred;
@@ -10,7 +10,7 @@
1010
use React\EventLoop\LoopInterface;
1111
use React\SocketClient\ConnectorInterface;
1212
use React\SocketClient\SecureConnector;
13-
use Socks\Connector;
13+
use Clue\React\Socks\Connector;
1414
use \Exception;
1515
use \InvalidArgumentException;
1616
use \UnexpectedValueException;
@@ -118,7 +118,7 @@ public function createSecureConnector()
118118
{
119119
return new SecureConnector($this->createConnector(), $this->loop);
120120
}
121-
121+
122122
public function createConnector()
123123
{
124124
return new Connector($this);
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<?php
22

3-
namespace Socks;
3+
namespace Clue\React\Socks;
44

55
use React\SocketClient\ConnectorInterface;
6-
use Socks\Client;
6+
use Clue\React\Socks\Client;
77

88
class Connector implements ConnectorInterface
99
{
1010
private $client;
11-
11+
1212
public function __construct(Client $socksClient)
1313
{
1414
$this->client = $socksClient;
1515
}
16-
16+
1717
public function create($host, $port)
1818
{
1919
return $this->client->getConnection($host, $port);

Socks/Factory.php renamed to src/Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Socks;
3+
namespace Clue\React\Socks;
44

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

Socks/Server.php renamed to src/Server.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Socks;
3+
namespace Clue\React\Socks;
44

55
use Evenement\EventEmitter;
66
use React\Socket\ServerInterface;
@@ -93,17 +93,17 @@ public function onConnection(Connection $connection)
9393
$that->endConnection($connection);
9494
});
9595
}
96-
96+
9797
/**
9898
* gracefully shutdown connection by flushing all remaining data and closing stream
99-
*
99+
*
100100
* @param Stream $stream
101101
*/
102102
public function endConnection(Stream $stream)
103103
{
104104
$tid = true;
105105
$loop = $this->loop;
106-
106+
107107
// cancel below timer in case connection is closed in time
108108
$stream->once('close', function () use (&$tid, $loop) {
109109
// close event called before the timer was set up, so everything is okay
@@ -114,11 +114,11 @@ public function endConnection(Stream $stream)
114114
$loop->cancelTimer($tid);
115115
}
116116
});
117-
117+
118118
// shut down connection by pausing input data, flushing outgoing buffer and then exit
119119
$stream->pause();
120120
$stream->end();
121-
121+
122122
// check if connection is not already closed
123123
if ($tid === true) {
124124
// fall back to forcefully close connection in 3 seconds if buffer can not be flushed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Socks;
3+
namespace Clue\React\Socks;
44

55
use React\Promise\Deferred;
66
use React\Stream\Stream;

tests/ClientApiTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Clue\React\Socks;
4+
35
class ClientApiTest extends TestCase
46
{
57
public function setUp()
@@ -13,7 +15,7 @@ public function setUp()
1315

1416
$this->client = $factory->createClient('127.0.0.1', 9050);
1517
}
16-
18+
1719
/**
1820
* @expectedException InvalidArgumentException
1921
*/
@@ -42,7 +44,7 @@ public function testValidAuthVersion()
4244
$this->client->setAuth('username', 'password');
4345
$this->assertNull($this->client->setProtocolVersion(5));
4446
}
45-
47+
4648
/**
4749
* @expectedException UnexpectedValueException
4850
*/
@@ -51,12 +53,12 @@ public function testInvalidCanNotSetAuthenticationForSocks4()
5153
$this->client->setProtocolVersion(4);
5254
$this->client->setAuth('username', 'password');
5355
}
54-
56+
5557
public function testUnsetAuth()
5658
{
5759
// unset auth even if it's not set is valid
5860
$this->client->unsetAuth();
59-
61+
6062
$this->client->setAuth('username', 'password');
6163
$this->client->unsetAuth();
6264
}
@@ -106,7 +108,7 @@ public function testInvalidResolveRemoteVersion()
106108
$this->client->setResolveLocal(false);
107109
$this->client->setProtocolVersion('4');
108110
}
109-
111+
110112
public function testSetTimeout()
111113
{
112114
$this->client->setTimeout(1);
@@ -118,7 +120,7 @@ public function testCreateHttpClient()
118120
{
119121
$this->assertInstanceOf('\React\HttpClient\Client', $this->client->createHttpClient());
120122
}
121-
123+
122124
public function testCreateConnector()
123125
{
124126
$this->assertInstanceOf('\React\SocketClient\ConnectorInterface', $this->client->createConnector());

tests/FactoryTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
<?php
22

3-
use Socks\Factory;
3+
use Clue\React\Socks\Factory;
44

55
class FactoryTest extends TestCase
66
{
77
/** @var Factory */
88
private $factory;
9-
9+
1010
public function setUp()
1111
{
1212
$this->factory = new Factory($this->createLoop(), $this->createResolver());
1313
}
14-
14+
1515
public function testCreateClient()
1616
{
1717
$client = $this->factory->createClient('localhost', 9050);
1818

19-
$this->assertInstanceOf('Socks\Client', $client);
19+
$this->assertInstanceOf('Clue\React\Socks\Client', $client);
2020
}
21-
21+
2222
public function testCreateServer()
2323
{
2424
$server = $this->factory->createServer($this->createSocket());
25-
26-
$this->assertInstanceOf('Socks\Server', $server);
25+
26+
$this->assertInstanceOf('Clue\React\Socks\Server', $server);
2727
}
28-
28+
2929
private function createLoop()
3030
{
3131
return React\EventLoop\Factory::create();
3232
}
33-
33+
3434
private function createResolver()
3535
{
3636
return $this->getMockBuilder('React\Dns\Resolver\Resolver')
3737
->disableOriginalConstructor()
3838
->getMock();
3939
}
40-
40+
4141
private function createSocket()
4242
{
4343
return $this->getMockBuilder('React\Socket\Server')

tests/PairTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
<?php
22

3-
use Socks\Factory;
3+
use Clue\React\Socks\Factory;
44

55
class PairTest extends TestCase
66
{
77
private $loop;
88
private $factory;
9-
9+
1010
public function setUp()
1111
{
1212
$this->loop = React\EventLoop\Factory::create();
13-
13+
1414
$dnsResolverFactory = new React\Dns\Resolver\Factory();
1515
$dns = $dnsResolverFactory->createCached('8.8.8.8', $this->loop);
16-
16+
1717
$this->factory = new Factory($this->loop, $dns);
1818
}
19-
19+
2020
public function testClientHttpRequest()
2121
{
2222
$socket = $this->createSocketServer();
2323
$port = $socket->getPort();
2424
$this->assertNotEquals(0, $port);
25-
25+
2626
$server = $this->factory->createServer($socket);
27-
27+
2828
$server->on('connection', function () use ($socket) {
2929
// close server socket once first connection has been established
3030
$socket->shutdown();
3131
});
32-
32+
3333
$client = $this->factory->createClient('127.0.0.1', $port);
34-
34+
3535
$http = $client->createHttpClient();
36-
36+
3737
$request = $http->request('GET', 'https://www.google.com/', array('user-agent'=>'none'));
3838
$request->on('response', function (React\HttpClient\Response $response) {
3939
// response received, do not care for the rest of the response body
@@ -47,15 +47,15 @@ public function testClientHttpRequest()
4747
// $that->fail('timeout timer');
4848
// $loop->stop();
4949
// });
50-
50+
5151
$this->loop->run();
5252
}
53-
53+
5454
private function createSocketServer()
5555
{
5656
$socket = new React\Socket\Server($this->loop);
5757
$socket->listen(0);
58-
58+
5959
return $socket;
6060
}
6161
}

0 commit comments

Comments
 (0)