Skip to content

Commit 5f9957c

Browse files
committed
Use default port 5039 for secure TLS connections
1 parent c6c2b64 commit 5f9957c

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ $factory = new Factory($loop, $connector);
9999

100100
#### createClient()
101101

102-
The `createClient(string $amiUrl): PromiseInterface<Client>` method can be used to create a new [`Client`](#client).
102+
The `createClient(string $url): PromiseInterface<Client>` method can be used to create a new [`Client`](#client).
103103
It helps with establishing a plain TCP/IP or secure TLS connection to the AMI
104104
and optionally issuing an initial `login` action.
105105

106106
```php
107-
$factory->createClient($amiUrl)->then(
107+
$factory->createClient($url)->then(
108108
function (Client $client) {
109109
// client connected (and authenticated)
110110
},
@@ -118,13 +118,14 @@ The method returns a [Promise](https://github.com/reactphp/promise) that will
118118
resolve with the [`Client`](#client) instance on success or will reject with an
119119
`Exception` if the URL is invalid or the connection or authentication fails.
120120

121-
The `$amiUrl` contains the host and optional port to connect to:
121+
The `$url` parameter contains the host and optional port (which defaults to
122+
`5038` for plain TCP/IP connections) to connect to:
122123

123124
```php
124-
$factory->createClient('127.0.0.1:5038');
125+
$factory->createClient('localhost:5038');
125126
```
126127

127-
The above examples to not pass any authentication details, so you may have to
128+
The above example does not pass any authentication details, so you may have to
128129
call `ActionSender::login()` after connecting or use the recommended shortcut
129130
to pass a username and secret for your AMI login details like this:
130131

@@ -133,10 +134,11 @@ $factory->createClient('user:secret@localhost');
133134
```
134135

135136
The `Factory` defaults to establishing a plaintext TCP connection.
136-
If you want to connect through a secure TLS proxy, you can use the `tls` scheme:
137+
If you want to create a secure TLS connection, you can use the `tls` scheme
138+
(which defaults to port `5039`):
137139

138140
```php
139-
$factory->createClient('tls://user:secret@localhost:12345');
141+
$factory->createClient('tls://user:secret@localhost:5039');
140142
```
141143

142144
### Client

src/Factory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public function createClient($url)
3131
return Promise\reject(new InvalidArgumentException('Given URL "' . $url . '" can not be parsed'));
3232
}
3333

34-
// use default port 5038
34+
// use default port 5039 for `tls://` or 5038 otherwise
3535
if (!isset($parts['port'])) {
36-
$parts['port'] = 5038;
36+
$parts['port'] = $parts['scheme'] === 'tls' ? 5039 : 5038;
3737
}
3838

3939
$promise = $this->connector->connect($parts['scheme'] . '://' . $parts['host'] . ':' . $parts['port'])->then(function (ConnectionInterface $stream) {

tests/FactoryTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ public function testCreateClientUsesDefaultPortForTcpConnection()
3030
$this->factory->createClient('localhost');
3131
}
3232

33+
public function testCreateClientUsesTlsPortForTlsConnection()
34+
{
35+
$promise = new Promise(function () { });
36+
$this->tcp->expects($this->once())->method('connect')->with('tls://localhost:5039')->willReturn($promise);
37+
38+
$this->factory->createClient('tls://localhost');
39+
}
40+
3341
public function testCreateClientUsesTlsConnectorWithTlsLocation()
3442
{
3543
$promise = new Promise(function () { });

0 commit comments

Comments
 (0)