Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
strategy:
matrix:
php:
- 8.4
- 8.3
- 8.2
- 8.1
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
],
"require": {
"php": ">=5.3",
"react/promise": "^3 || ^2.1 || ^1.2",
"react/socket": "^1.12"
"react/promise": "^3.2 || ^2.1 || ^1.2",
"react/socket": "^1.16"
},
"require-dev": {
"clue/connection-manager-extra": "^1.3",
"phpunit/phpunit": "^9.6 || ^8.5 || ^5.7 || ^4.8.36",
"react/async": "^4 || ^3 || ^2",
"react/async": "^4.3 || ^3 || ^2",
"react/event-loop": "^1.2",
"react/http": "^1.6"
"react/http": "^1.11"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 5 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ final class Client implements ConnectorInterface
public function __construct(
#[\SensitiveParameter]
$socksUri,
ConnectorInterface $connector = null
$connector = null
) {
if ($connector !== null && !$connector instanceof ConnectorInterface) { // manual type check to support legacy PHP < 7.1
throw new InvalidArgumentException('Argument #2 ($connector) expected null|React\Socket\ConnectorInterface');
}

// support `sockss://` scheme for SOCKS over TLS
// support `socks+unix://` scheme for Unix domain socket (UDS) paths
if (preg_match('/^(socks(?:5|4)?)(s|\+unix):\/\/(.*?@)?(.+?)$/', $socksUri, $match)) {
Expand Down
11 changes: 9 additions & 2 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,18 @@ final class Server
* @param null|array|callable $auth
*/
public function __construct(
LoopInterface $loop = null,
ConnectorInterface $connector = null,
$loop = null,
$connector = null,
#[\SensitiveParameter]
$auth = null
) {
if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
throw new \InvalidArgumentException('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
}
if ($connector !== null && !$connector instanceof ConnectorInterface) { // manual type check to support legacy PHP < 7.1
throw new \InvalidArgumentException('Argument #2 ($connector) expected null|React\Socket\ConnectorInterface');
}

if (\is_array($auth)) {
// wrap authentication array in authentication callback
$this->auth = function (
Expand Down
6 changes: 6 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ public function testInvalidProtocolVersion()
$this->client = new Client('socks3://127.0.0.1:9050', $this->connector);
}

public function testCtorThrowsForInvalidConnector()
{
$this->setExpectedException('InvalidArgumentException', 'Argument #2 ($connector) expected null|React\Socket\ConnectorInterface');
new Client('127.0.0.1:1080', 'connector');
}

public function testCreateWillConnectToProxy()
{
$promise = new Promise(function () { });
Expand Down
12 changes: 12 additions & 0 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ public function testConstructorWithStaticAuthArray()
));
}

public function testConstructorThrowsForInvalidLoop()
{
$this->setExpectedException('InvalidArgumentException', 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
new Server('loop');
}

public function testConstructorThrowsForInvalidConnector()
{
$this->setExpectedException('InvalidArgumentException', 'Argument #2 ($connector) expected null|React\Socket\ConnectorInterface');
new Server(null, 'connector');
}

public function testConstructorWithInvalidAuthenticatorThrows()
{
$this->setExpectedException("InvalidArgumentException");
Expand Down
Loading