Skip to content

Commit 0126cda

Browse files
added new helper class to simplify use. update url.
1 parent a283bd2 commit 0126cda

108 files changed

Lines changed: 636 additions & 101 deletions

File tree

Some content is hidden

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

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,35 @@ foreach ($protocol->getResponses() as $response) {
208208
Directory `src` contains autoload file which accepts only Bolt library namespaces. Main Bolt namespace points to this
209209
directory. If you have installed this project with composer, you have to load `vendor/autoload.php`.
210210

211+
### Client helper class
212+
213+
Library contains helper class `\Bolt\helpers\Client` for simplified interaction with a graph database. It wraps common operations (authentication, queries, transactions) into static methods so you don't have to manage protocol messages and responses manually.
214+
215+
```php
216+
$conn = new \Bolt\connection\Socket('127.0.0.1', 7687);
217+
$bolt = new \Bolt\Bolt($conn);
218+
$protocol = $bolt->build();
219+
220+
// If no error handler is set, exception is thrown.
221+
\Bolt\helpers\Client::setErrorHandler(function (Exception $e) {
222+
error_log($e->getMessage());
223+
});
224+
225+
\Bolt\helpers\Client::setProtocol($protocol, [
226+
'scheme' => 'basic',
227+
'principal' => 'neo4j',
228+
'credentials' => 'neo4j'
229+
]);
230+
231+
// Query example
232+
$rows = \Bolt\helpers\Client::query('MATCH (n:Person) RETURN n.name AS name, n.age AS age');
233+
// $rows = [['name' => 'Alice', 'age' => 30], ['name' => 'Bob', 'age' => 25]]
234+
```
235+
236+
By using method `setProtocol` you can switch between multiple connections you have opened. If you have only one you need to call this method once.
237+
238+
Authentication is handled automatically inside `setProtocol()` based on the Bolt version. Already authenticated protocol instances are tracked and won't be re-authenticated.
239+
211240
## :chains: Connection
212241

213242
Bolt class constructor accepts connection argument. This argument has to be instance of class which implements IConnection interface. Library offers few options.

phpunit.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88
<directory>./tests/packstream</directory>
99
<directory>./tests/structures</directory>
1010
<file>./tests/PerformanceTest.php</file>
11+
<file>./tests/helpers/ClientTest.php</file>
1112
</testsuite>
1213
<testsuite name="NoDatabase">
1314
<directory>./tests/protocol</directory>
1415
<file>./tests/helpers/FileCacheTest.php</file>
1516
</testsuite>
1617
<testsuite name="Memgraph">
1718
<file>./tests/MemgraphTest.php</file>
19+
<file>./tests/helpers/ClientTest.php</file>
1820
</testsuite>
1921
<testsuite name="NornicDB">
2022
<file>./tests/NornicDBTest.php</file>
23+
<file>./tests/helpers/ClientTest.php</file>
2124
</testsuite>
2225
</testsuites>
2326
<php>

src/Bolt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Acts as factory which provides protocol class by requested version
1616
*
1717
* @author Michal Stefanak
18-
* @link https://github.com/neo4j-php/Bolt
18+
* @link https://github.com/stefanak-michal/php-bolt-driver
1919
* @package Bolt
2020
*/
2121
final class Bolt

src/connection/AConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Class AConnection
77
*
88
* @author Michal Stefanak
9-
* @link https://github.com/neo4j-php/Bolt
9+
* @link https://github.com/stefanak-michal/php-bolt-driver
1010
* @package Bolt\connection
1111
*/
1212
abstract class AConnection implements IConnection

src/connection/IConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Interface IConnection
99
*
1010
* @author Michal Stefanak
11-
* @link https://github.com/neo4j-php/Bolt
11+
* @link https://github.com/stefanak-michal/php-bolt-driver
1212
* @package Bolt\connection
1313
*/
1414
interface IConnection

src/connection/PStreamSocket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* your attemt to connect will end with ConnectionTimeoutException.
1717
*
1818
* @author Michal Stefanak
19-
* @link https://github.com/neo4j-php/Bolt
19+
* @link https://github.com/stefanak-michal/php-bolt-driver
2020
* @package Bolt\connection
2121
*/
2222
class PStreamSocket extends StreamSocket

src/connection/Socket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Socket class
1111
*
1212
* @author Michal Stefanak
13-
* @link https://github.com/neo4j-php/Bolt
13+
* @link https://github.com/stefanak-michal/php-bolt-driver
1414
* @package Bolt\connection
1515
*/
1616
class Socket extends AConnection

src/connection/StreamSocket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Stream socket class
1212
*
1313
* @author Michal Stefanak
14-
* @link https://github.com/neo4j-php/Bolt
14+
* @link https://github.com/stefanak-michal/php-bolt-driver
1515
* @package Bolt\connection
1616
*/
1717
class StreamSocket extends AConnection

src/enum/Message.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Enum Message
77
* @author Michal Stefanak
8-
* @link https://github.com/neo4j-php/Bolt
8+
* @link https://github.com/stefanak-michal/php-bolt-driver
99
* @package Bolt\enum
1010
*/
1111
enum Message

src/enum/ServerState.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Enum ServerState
77
* @author Michal Stefanak
8-
* @link https://github.com/neo4j-php/Bolt
8+
* @link https://github.com/stefanak-michal/php-bolt-driver
99
* @package Bolt\enum
1010
*/
1111
enum ServerState

0 commit comments

Comments
 (0)