Skip to content

Commit

Permalink
applied new changes to v3.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanak-michal committed Jul 13, 2022
1 parent b8014bd commit d02a78d
Show file tree
Hide file tree
Showing 47 changed files with 763 additions and 226 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ cert/
/vendor/
*.lock
*.cache
phpunit.dev.xml
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ We like to keep the code unified and clean as possible.
- Set methods return type
- Add descriptive method annotations if needed
- Don't use @deprecated annotation
- Follow Bolt specification by [official documentation](https://7687.org/)
- Follow Bolt specification by [official documentation](https://www.neo4j.com/docs/bolt/current/)

\
PHP Bolt library is a volunteer effort. We are thankful for your interest or contribution.
115 changes: 96 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,129 @@
![Logo](https://repository-images.githubusercontent.com/198229221/c0edf6c1-8699-481d-85f7-17b6ea0ffb26)
![Logo](https://repository-images.githubusercontent.com/198229221/fcf334aa-ef6b-4fe9-89ad-d03e4c7d89e3)

# Bolt
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.
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.

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

![](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)
[![](https://img.shields.io/github/stars/stefanak-michal/Bolt)](https://github.com/neo4j-php/Bolt/stargazers)
[![](https://img.shields.io/packagist/dt/stefanak-michal/bolt)](https://packagist.org/packages/stefanak-michal/bolt/stats)
[![](https://img.shields.io/github/v/release/stefanak-michal/bolt)](https://github.com/neo4j-php/Bolt/releases)
[![](https://img.shields.io/github/commits-since/stefanak-michal/bolt/latest)](https://github.com/neo4j-php/Bolt/releases/latest)

## Version support

We are trying to keep up and this library supports **Neo4j <= 4.4**.
We are trying to keep up and this library supports **Neo4j <= 4.4** with **Bolt <= 4.4**.

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

## Requirements

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

[More info](https://github.com/neo4j-php/Bolt/wiki/Requirements)
_If you need support for PHP < 7.4 you can use latest v3.x release. Not all new features are implement backwards._

### Extensions

- mbstring https://www.php.net/manual/en/book.mbstring.php
- sockets https://www.php.net/manual/en/book.sockets.php (optional) - Required when you use Socket connection class
- openssl https://www.php.net/manual/en/book.openssl.php (optional) - Required when you use StreamSocket connection class with enabled SSL
- phpunit >= 9 https://phpunit.de/ (development)

## Installation

You can use composer or download this repository.
You can use composer or download this repository from github and manually implement it.

### Composer

Run the following command in your project to install the latest applicable version of the package:

`composer require stefanak-michal/bolt`

[More info](https://github.com/neo4j-php/Bolt/wiki/Installation)
[Packagist](https://packagist.org/packages/stefanak-michal/bolt)

### Manual

1. Download [latest release](https://github.com/neo4j-php/Bolt/releases/latest) or [master](https://github.com/neo4j-php/Bolt)
2. Unpack
3. Copy content of `src` directory to your project

## Usage

Concept of usage is based on Bolt messages and mostly you need just these.
Concept of usage is based on Bolt messages. Available protocol methods depends on Bolt version.

https://www.neo4j.com/docs/bolt/current/bolt/message/

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

Response from database (`$rows`) always contains n+1 rows because last entry are meta informations.

[More info](https://github.com/neo4j-php/Bolt/wiki/Usage)

### Transactions

Bolt from version 3 supports transactions and protocol contains these methods:

- begin
- commit
- rollback

_`run` executes query in auto-commit transaction if explicit transaction was not open._

### Cypher query parameters

| Neo4j | PHP |
| --- | --- |
| Null | null |
| Boolean | boolean |
| Integer | integer |
| Float | float |
| Bytes | [Bytes class](https://github.com/neo4j-php/Bolt/blob/master/src/structures/Bytes.php) |
| String | string |
| List | array with consecutive numeric keys from 0 |
| Dictionary | object or array which is not considered as list |
| Structure | [directory with structures](https://github.com/neo4j-php/Bolt/tree/master/src/structures) |

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).

### Neo4j Aura

Connecting to Aura requires encryption which is provided with SSL. To connect to Aura you have to use StreamSocket connection class and enable SSL.

```php
// url without neo4j+s protocol
$conn = new \Bolt\connection\StreamSocket('helloworld.databases.neo4j.io');
// enable SSL
$conn->setSslContextOptions([
'verify_peer' => true
]);
$bolt = new \Bolt\Bolt($conn);
```

https://www.php.net/manual/en/context.ssl.php

## Another solutions

https://neo4j.com/developer/php/


## Support the driver

This project is made as opensource but every support in form of donations are highly appreciated.

<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>
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
},
"support": {
"issues": "https://github.com/neo4j-php/Bolt/issues",
"source": "https://github.com/neo4j-php/Bolt"
"source": "https://github.com/neo4j-php/Bolt",
"docs": "https://www.neo4j.com/docs/bolt/current/"
},
"funding": [
{
Expand Down
2 changes: 0 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<directory>./tests/PackStream</directory>
</testsuite>
<testsuite name="NoDatabase">
<directory>./tests/error</directory>
<directory>./tests/PackStream</directory>
<directory>./tests/protocol</directory>
</testsuite>
</testsuites>
Expand Down
2 changes: 1 addition & 1 deletion src/Bolt.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function setPackStreamVersion(int $version = 1): Bolt
}

/**
* @link https://7687.org/bolt/bolt-protocol-handshake-specification.html
* @link https://www.neo4j.com/docs/bolt/current/bolt/handshake/
* @return string
* @throws Exception
*/
Expand Down
14 changes: 14 additions & 0 deletions src/PackStream/IPackDictionaryGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Bolt\PackStream;

/**
* Class PackDictionaryGenerator
* @author Michal Stefanak
* @link https://github.com/neo4j-php/Bolt
* @package Bolt\PackStream
*/
interface IPackDictionaryGenerator extends \Countable, \Iterator
{

}
14 changes: 14 additions & 0 deletions src/PackStream/IPackListGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Bolt\PackStream;

/**
* Class PackListGenerator
* @author Michal Stefanak
* @link https://github.com/neo4j-php/Bolt
* @package Bolt\PackStream
*/
interface IPackListGenerator extends \Iterator, \Countable
{

}
6 changes: 2 additions & 4 deletions src/PackStream/IPacker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Bolt\PackStream;

use Generator;

/**
* Interface IPacker
*
Expand All @@ -16,7 +14,7 @@ interface IPacker
/**
* @param $signature
* @param mixed ...$params
* @return Generator
* @return iterable
*/
public function pack($signature, ...$params): Generator;
public function pack($signature, ...$params): iterable;
}
Loading

0 comments on commit d02a78d

Please sign in to comment.