Skip to content

Commit d02a78d

Browse files
applied new changes to v3.1.3
1 parent b8014bd commit d02a78d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+763
-226
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ cert/
55
/vendor/
66
*.lock
77
*.cache
8+
phpunit.dev.xml

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ We like to keep the code unified and clean as possible.
2323
- Set methods return type
2424
- Add descriptive method annotations if needed
2525
- Don't use @deprecated annotation
26-
- Follow Bolt specification by [official documentation](https://7687.org/)
26+
- Follow Bolt specification by [official documentation](https://www.neo4j.com/docs/bolt/current/)
2727

2828
\
2929
PHP Bolt library is a volunteer effort. We are thankful for your interest or contribution.

README.md

Lines changed: 96 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,129 @@
1-
![Logo](https://repository-images.githubusercontent.com/198229221/c0edf6c1-8699-481d-85f7-17b6ea0ffb26)
1+
![Logo](https://repository-images.githubusercontent.com/198229221/fcf334aa-ef6b-4fe9-89ad-d03e4c7d89e3)
22

33
# Bolt
4-
Bolt protocol library over TCP socket. Bolt protocol is created and in use for communication with [Neo4j](https://neo4j.com/) Graph database. The Bolt 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.
4+
PHP library for communication with [Neo4j](https://neo4j.com/) graph database over TCP socket with Bolt protocol specification. The Bolt documentation is available at [https://www.neo4j.com/](https://www.neo4j.com/docs/bolt/current/). This library is aimed to be low level, support all available versions and keep up with protocol messages architecture and specifications.
55

6-
![DB Tests](https://github.com/neo4j-php/Bolt/actions/workflows/db-tests.yml/badge.svg?branch=master)
7-
![No DB Tests PHP7](https://github.com/neo4j-php/Bolt/actions/workflows/no-db-test-php-7.yml/badge.svg?branch=master)
8-
![No DB Tests PHP8](https://github.com/neo4j-php/Bolt/actions/workflows/no-db-test-php-8.yml/badge.svg?branch=master)
6+
![DB Tests PHP7](https://github.com/neo4j-php/Bolt/actions/workflows/db-test-php-7.yml/badge.svg?branch=master)
7+
![DB Tests PHP8](https://github.com/neo4j-php/Bolt/actions/workflows/db-test-php-8.yml/badge.svg?branch=master)
8+
![No DB Tests PHP7](https://github.com/neo4j-php/Bolt/actions/workflows/no-db-test-php-7.yml/badge.svg?branch=master)
9+
![No DB Tests PHP8](https://github.com/neo4j-php/Bolt/actions/workflows/no-db-test-php-8.yml/badge.svg?branch=master)
910

10-
![](https://img.shields.io/github/stars/stefanak-michal/Bolt)
11-
![](https://img.shields.io/packagist/dt/stefanak-michal/bolt)
12-
![](https://img.shields.io/github/v/release/stefanak-michal/bolt)
13-
![](https://img.shields.io/github/commits-since/stefanak-michal/bolt/latest)
11+
[![](https://img.shields.io/github/stars/stefanak-michal/Bolt)](https://github.com/neo4j-php/Bolt/stargazers)
12+
[![](https://img.shields.io/packagist/dt/stefanak-michal/bolt)](https://packagist.org/packages/stefanak-michal/bolt/stats)
13+
[![](https://img.shields.io/github/v/release/stefanak-michal/bolt)](https://github.com/neo4j-php/Bolt/releases)
14+
[![](https://img.shields.io/github/commits-since/stefanak-michal/bolt/latest)](https://github.com/neo4j-php/Bolt/releases/latest)
1415

1516
## Version support
1617

17-
We are trying to keep up and this library supports **Neo4j <= 4.4**.
18+
We are trying to keep up and this library supports **Neo4j <= 4.4** with **Bolt <= 4.4**.
1819

19-
[More info](https://github.com/neo4j-php/Bolt/wiki/Version-support)
20+
https://www.neo4j.com/docs/bolt/current/bolt-compatibility/
2021

2122
## Requirements
2223

23-
It's hard to live without all new features which means we keep at **PHP >= 7.1**.
24+
Keep up with [PHP supported versions](https://www.php.net/supported-versions.php) means we are at **PHP >= 7.4**.
2425

25-
[More info](https://github.com/neo4j-php/Bolt/wiki/Requirements)
26+
_If you need support for PHP < 7.4 you can use latest v3.x release. Not all new features are implement backwards._
27+
28+
### Extensions
29+
30+
- mbstring https://www.php.net/manual/en/book.mbstring.php
31+
- sockets https://www.php.net/manual/en/book.sockets.php (optional) - Required when you use Socket connection class
32+
- openssl https://www.php.net/manual/en/book.openssl.php (optional) - Required when you use StreamSocket connection class with enabled SSL
33+
- phpunit >= 9 https://phpunit.de/ (development)
2634

2735
## Installation
2836

29-
You can use composer or download this repository.
37+
You can use composer or download this repository from github and manually implement it.
38+
39+
### Composer
40+
41+
Run the following command in your project to install the latest applicable version of the package:
3042

3143
`composer require stefanak-michal/bolt`
3244

33-
[More info](https://github.com/neo4j-php/Bolt/wiki/Installation)
45+
[Packagist](https://packagist.org/packages/stefanak-michal/bolt)
46+
47+
### Manual
48+
49+
1. Download [latest release](https://github.com/neo4j-php/Bolt/releases/latest) or [master](https://github.com/neo4j-php/Bolt)
50+
2. Unpack
51+
3. Copy content of `src` directory to your project
3452

3553
## Usage
3654

37-
Concept of usage is based on Bolt messages and mostly you need just these.
55+
Concept of usage is based on Bolt messages. Available protocol methods depends on Bolt version.
56+
57+
https://www.neo4j.com/docs/bolt/current/bolt/message/
3858

3959
```php
40-
<?php
41-
$bolt = new \Bolt\Bolt(new \Bolt\connection\Socket());
60+
// Create connection class and specify target host and port
61+
$conn = new \Bolt\connection\Socket();
62+
// Create new Bolt instance and provide connection object
63+
$bolt = new \Bolt\Bolt($conn);
64+
// Build and get protocol version instance which creates connection and executes handshake
4265
$protocol = $bolt->build();
66+
// Login to database with credentials
4367
$protocol->hello(\Bolt\helpers\Auth::basic('neo4j', 'neo4j'));
44-
$stats = $protocol->run('RETURN 1 AS num, 2 AS cnt');
68+
// Execute query with parameters
69+
$stats = $protocol->run('RETURN $a AS num, $b AS str', ['a' => 123, 'b' => 'text']);
70+
// Pull records from last executed query
4571
$rows = $protocol->pull();
4672
```
4773

74+
Response from database (`$rows`) always contains n+1 rows because last entry are meta informations.
75+
4876
[More info](https://github.com/neo4j-php/Bolt/wiki/Usage)
4977

78+
### Transactions
79+
80+
Bolt from version 3 supports transactions and protocol contains these methods:
81+
82+
- begin
83+
- commit
84+
- rollback
85+
86+
_`run` executes query in auto-commit transaction if explicit transaction was not open._
87+
88+
### Cypher query parameters
89+
90+
| Neo4j | PHP |
91+
| --- | --- |
92+
| Null | null |
93+
| Boolean | boolean |
94+
| Integer | integer |
95+
| Float | float |
96+
| Bytes | [Bytes class](https://github.com/neo4j-php/Bolt/blob/master/src/structures/Bytes.php) |
97+
| String | string |
98+
| List | array with consecutive numeric keys from 0 |
99+
| Dictionary | object or array which is not considered as list |
100+
| Structure | [directory with structures](https://github.com/neo4j-php/Bolt/tree/master/src/structures) |
101+
102+
List or dictionary can be also provided as instance of class implementing `Bolt\PackStream\IPackListGenerator` or `Bolt\PackStream\IPackDictionaryGenerator`. This approach helps with memory management while working with big amount of data. To learn more you can check [performance test](https://github.com/neo4j-php/Bolt/blob/master/tests/PerformanceTest.php) or [packer test](https://github.com/neo4j-php/Bolt/blob/master/tests/PackStream/v1/PackerTest.php).
103+
104+
### Neo4j Aura
105+
106+
Connecting to Aura requires encryption which is provided with SSL. To connect to Aura you have to use StreamSocket connection class and enable SSL.
107+
108+
```php
109+
// url without neo4j+s protocol
110+
$conn = new \Bolt\connection\StreamSocket('helloworld.databases.neo4j.io');
111+
// enable SSL
112+
$conn->setSslContextOptions([
113+
'verify_peer' => true
114+
]);
115+
$bolt = new \Bolt\Bolt($conn);
116+
```
117+
118+
https://www.php.net/manual/en/context.ssl.php
119+
50120
## Another solutions
51121

52122
https://neo4j.com/developer/php/
123+
124+
125+
## Support the driver
126+
127+
This project is made as opensource but every support in form of donations are highly appreciated.
128+
129+
<a href='https://ko-fi.com/Z8Z5ABMLW' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi1.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
},
1717
"support": {
1818
"issues": "https://github.com/neo4j-php/Bolt/issues",
19-
"source": "https://github.com/neo4j-php/Bolt"
19+
"source": "https://github.com/neo4j-php/Bolt",
20+
"docs": "https://www.neo4j.com/docs/bolt/current/"
2021
},
2122
"funding": [
2223
{

phpunit.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
<directory>./tests/PackStream</directory>
99
</testsuite>
1010
<testsuite name="NoDatabase">
11-
<directory>./tests/error</directory>
12-
<directory>./tests/PackStream</directory>
1311
<directory>./tests/protocol</directory>
1412
</testsuite>
1513
</testsuites>

src/Bolt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function setPackStreamVersion(int $version = 1): Bolt
108108
}
109109

110110
/**
111-
* @link https://7687.org/bolt/bolt-protocol-handshake-specification.html
111+
* @link https://www.neo4j.com/docs/bolt/current/bolt/handshake/
112112
* @return string
113113
* @throws Exception
114114
*/
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Bolt\PackStream;
4+
5+
/**
6+
* Class PackDictionaryGenerator
7+
* @author Michal Stefanak
8+
* @link https://github.com/neo4j-php/Bolt
9+
* @package Bolt\PackStream
10+
*/
11+
interface IPackDictionaryGenerator extends \Countable, \Iterator
12+
{
13+
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Bolt\PackStream;
4+
5+
/**
6+
* Class PackListGenerator
7+
* @author Michal Stefanak
8+
* @link https://github.com/neo4j-php/Bolt
9+
* @package Bolt\PackStream
10+
*/
11+
interface IPackListGenerator extends \Iterator, \Countable
12+
{
13+
14+
}

src/PackStream/IPacker.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Bolt\PackStream;
44

5-
use Generator;
6-
75
/**
86
* Interface IPacker
97
*
@@ -16,7 +14,7 @@ interface IPacker
1614
/**
1715
* @param $signature
1816
* @param mixed ...$params
19-
* @return Generator
17+
* @return iterable
2018
*/
21-
public function pack($signature, ...$params): Generator;
19+
public function pack($signature, ...$params): iterable;
2220
}

0 commit comments

Comments
 (0)