Skip to content

Commit e483a52

Browse files
Merge pull request #170 from stefanak-michal/ssl_context_array
slight change how setSslContextOptions can be called.
2 parents bd59d95 + ce9e58b commit e483a52

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,20 @@ This class extends StreamSocket and adds support for persistent connections. Upo
231231

232232
## :lock: SSL
233233

234+
Connection secured with SSL is available only with connection classes `StreamSocket` and `PStreamSocket`.
235+
234236
### Neo4j Aura
235237

236-
Connecting to Aura requires encryption which is provided with SSL. To connect to Aura you have to use `StreamSocket` connection class and enable SSL.
238+
Connecting to Aura requires encrypted connection by default. To connect to Aura you have to use connection class with SSL support and enable SSL.
237239

238240
```php
239241
$conn = new \Bolt\connection\StreamSocket('helloworld.databases.neo4j.io');
240242
// enable SSL
241-
$conn->setSslContextOptions([
242-
'verify_peer' => true
243-
]);
243+
$conn->setSslContextOptions();
244244
$bolt = new \Bolt\Bolt($conn);
245245
```
246246

247-
https://www.php.net/manual/en/context.ssl.php
247+
_For more informations about what argument can be passed to `setSslContextOptions` check out [php.net](https://www.php.net/manual/en/context.ssl.php) _
248248

249249
### Example on localhost database with self-signed certificate:
250250

src/connection/StreamSocket.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
class StreamSocket extends AConnection
1818
{
19-
protected array $sslContextOptions = [];
19+
protected ?array $sslContextOptions = null;
2020

2121
/**
2222
* @var resource
@@ -27,9 +27,11 @@ class StreamSocket extends AConnection
2727

2828
/**
2929
* Set SSL Context options
30+
* Just by calling this method without any argument, SSL will be enabled with default configuration
31+
* @param ?array $options By passing null, SSL will be disabled
3032
* @link https://www.php.net/manual/en/context.ssl.php
3133
*/
32-
public function setSslContextOptions(array $options): void
34+
public function setSslContextOptions(?array $options = []): void
3335
{
3436
$this->sslContextOptions = $options;
3537
}
@@ -40,7 +42,7 @@ public function connect(): bool
4042
'socket' => [
4143
'tcp_nodelay' => true,
4244
],
43-
'ssl' => $this->sslContextOptions
45+
'ssl' => (array)$this->sslContextOptions
4446
]);
4547

4648
$this->stream = @stream_socket_client('tcp://' . $this->ip . ':' . $this->port, $errno, $errstr, $this->timeout, $this->connectionFlags, $context);
@@ -53,7 +55,7 @@ public function connect(): bool
5355
throw new ConnectException('Cannot set socket into blocking mode');
5456
}
5557

56-
if (!empty($this->sslContextOptions)) {
58+
if ($this->sslContextOptions !== null) {
5759
if (stream_socket_enable_crypto($this->stream, true, STREAM_CRYPTO_METHOD_ANY_CLIENT) !== true) {
5860
throw new ConnectException('Enable encryption error');
5961
}

0 commit comments

Comments
 (0)