Skip to content

Commit 9f482df

Browse files
Merge remote-tracking branch 'origin/master'
2 parents ceb8a01 + 7324def commit 9f482df

File tree

4 files changed

+17
-34
lines changed

4 files changed

+17
-34
lines changed

README.md

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,16 @@
11
# Bolt
2-
Bolt protocol library over TCP socket. Bolt protocol is primary used for communication with [Neo4j](https://neo4j.com/) Graph database. The documentation is available at [https://7687.org/](https://7687.org/).
2+
Bolt protocol library over TCP socket. Bolt protocol is created and in use for communication with [Neo4j](https://neo4j.com/) Graph database. The documentation is available at [https://7687.org/](https://7687.org/). This library is aimed to be low level and keep up with protocol messages architecture and specifications.
33

44
![](https://img.shields.io/badge/phpunit-passed-success) ![](https://img.shields.io/badge/coverage-86%25-green) ![](https://img.shields.io/github/stars/stefanak-michal/Bolt) ![](https://img.shields.io/packagist/dt/stefanak-michal/bolt) ![](https://img.shields.io/github/v/release/stefanak-michal/bolt) ![](https://img.shields.io/github/commits-since/stefanak-michal/bolt/latest)
55

6-
## Version support
7-
Bolt <= 4.1
8-
9-
| Neo4j Version | Bolt 1 | Bolt 2 | Bolt 3 | Bolt 4.0 | Bolt 4.1 |
10-
|:-------------:|:------:|:------:|:------:|:--------:|:--------:|
11-
| 3.0 | x | | | | |
12-
| 3.1 | x | | | | |
13-
| 3.2 | x | | | | |
14-
| 3.3 | x | | | | |
15-
| 3.4 | (x) | x | | | |
16-
| 3.5 | | (x) | x | | |
17-
| 4.0 | | | (x) | x | |
18-
| 4.1 | | | (x) | (x) | x |
19-
| 4.2 | | | (x) | (x) | (x) |
20-
21-
<sup>The (x) denotes that support could be removed in next version of Neo4j.</sup>
22-
6+
## [Version support](https://github.com/stefanak-michal/Bolt/wiki/Version-support)
237
## [Requirements](https://github.com/stefanak-michal/Bolt/wiki/Requirements)
248
## [Installation](https://github.com/stefanak-michal/Bolt/wiki/Installation)
259
## [Usage](https://github.com/stefanak-michal/Bolt/wiki/Usage)
2610
## [Errors](https://github.com/stefanak-michal/Bolt/wiki/Errors)
2711

2812
## Author note
29-
I really like Neo4j and I wanted to use it with PHP. But after I looked on official php library, I was really disappointed. Too much dependencies. I don't like if I have to install 10 things because of one. First I decided to use HTTP API for communication, but it wasn't fast enough. I went through bolt protocol documentation and I said to myself, why not to create own simpler library?
30-
31-
[Speed comparison](https://github.com/stefanak-michal/Bolt/wiki/Speed-comparison)
13+
Bolt protocol is created by Neo4j and I heard about it first time at 2012 (maybe 2013). I was looking for a opportunity to use their database and that opportunity came after few years. From that moment I love this database. But there was small catch, they had low support for combination Bolt protocol and PHP. Official existing library for this language is outdated and repository is archived. Of course Neo4j has API access, but I feel the cURL in PHP is slower then direct socket connection. I've decided to make my own library for their Bolt protocol.
3214

3315
## Another solutions
3416
https://neo4j.com/developer/php/

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"authors": [
2929
{
3030
"name": "Michal Stefanak",
31-
"role": "Developer"
31+
"role": "Developer",
32+
"homepage": "https://www.linkedin.com/in/michalstefanak/"
3233
}
3334
],
3435
"autoload": {

src/connection/Socket.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class Socket extends AConnection
1616
{
1717

1818
/**
19-
* @var resource
19+
* @var resource|object|bool
2020
*/
21-
private $socket;
21+
private $socket = false;
2222

2323
/**
2424
* Create socket connection
@@ -32,7 +32,7 @@ public function connect(): bool
3232
}
3333

3434
$this->socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
35-
if (!is_resource($this->socket)) {
35+
if ($this->socket === false) {
3636
throw new ConnectException('Cannot create socket');
3737
}
3838

@@ -61,7 +61,7 @@ public function connect(): bool
6161
*/
6262
public function write(string $buffer)
6363
{
64-
if (!is_resource($this->socket)) {
64+
if ($this->socket === false) {
6565
throw new ConnectException('Not initialized socket');
6666
}
6767

@@ -93,7 +93,7 @@ public function read(int $length = 2048): string
9393
{
9494
$output = '';
9595

96-
if (!is_resource($this->socket)) {
96+
if ($this->socket === false) {
9797
throw new ConnectException('Not initialized socket');
9898
}
9999

@@ -117,7 +117,7 @@ public function read(int $length = 2048): string
117117
*/
118118
public function disconnect()
119119
{
120-
if (is_resource($this->socket)) {
120+
if ($this->socket !== false) {
121121
@socket_shutdown($this->socket);
122122
@socket_close($this->socket);
123123
}

tests/ATest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Bolt\tests;
44

55
use PHPUnit\Framework\TestCase;
6-
use Bolt\connection\IConnection;
6+
use Bolt\connection\AConnection;
77

88
/**
99
* Class ATest
@@ -33,15 +33,15 @@ abstract class ATest extends TestCase
3333

3434
/**
3535
* Mock Socket class with "write" and "read" methods
36-
* @return IConnection
36+
* @return AConnection
3737
*/
3838
protected function mockConnection()
3939
{
4040
$mockBuilder = $this
41-
->getMockBuilder(IConnection::class)
41+
->getMockBuilder(AConnection::class)
4242
->disableOriginalConstructor();
4343
call_user_func([$mockBuilder, method_exists($mockBuilder, 'onlyMethods') ? 'onlyMethods' : 'setMethods'], ['__construct', 'write', 'read', 'connect', 'disconnect']);
44-
/** @var IConnection $connection */
44+
/** @var AConnection $connection */
4545
$connection = $mockBuilder->getMock();
4646

4747
$connection
@@ -98,9 +98,9 @@ public function readCallback(): string
9898
}
9999

100100
/**
101-
* Reset mockup IConnetion variables
101+
* Reset mockup AConnetion variables
102102
*/
103-
protected function setUp()
103+
protected function setUp(): void
104104
{
105105
self::$readIndex = 0;
106106
self::$readArray = [];

0 commit comments

Comments
 (0)