Skip to content

Commit 26a2df1

Browse files
committed
fixed configuration order when creating driver
1 parent 7d9f8a2 commit 26a2df1

File tree

2 files changed

+54
-30
lines changed

2 files changed

+54
-30
lines changed

README.md

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -232,27 +232,6 @@ Cypher values and types map to these php types and classes:
232232

233233
(*) A point can be one of four types implementing PointInterface: `\Laudis\Neo4j\Types\CartesianPoint` `\Laudis\Neo4j\Types\Cartesian3DPoint` `\Laudis\Neo4j\Types\WGS84Point` `\Laudis\Neo4j\Types\WGS843DPoint`
234234

235-
If you want the results to be just a set of rows, columns, arrays and scalar types, you can use a BasicFormatter:
236-
237-
```php
238-
use Laudis\Neo4j\ClientBuilder;
239-
use Laudis\Neo4j\Formatter\BasicFormatter;
240-
241-
$client = ClientBuilder::create()->withFormatter(new BasicFormatter())->build();
242-
243-
// Results are a CypherList
244-
$results = $client->run('MATCH (node:Node) RETURN node, node.id AS id');
245-
246-
// A row is a CypherMap
247-
foreach ($results as $result) {
248-
// Returns an array of attributes instead of a Node.
249-
$node = $result->get('node');
250-
251-
echo $node['id'];
252-
echo $result->get('id');
253-
}
254-
```
255-
256235
## Diving Deeper
257236

258237
### Differentiating between parameter type
@@ -264,12 +243,11 @@ The `ParameterHelper` class is the ideal companion for this:
264243
```php
265244
use Laudis\Neo4j\ParameterHelper;
266245

267-
$client->run('MATCH (x) WHERE x.slug in $listOrMap RETURN x', ['listOrMap' => ParameterHelper::asList([])]); // will return an empty vector
246+
$client->run('MATCH (x) WHERE x.slug in $listOrMap RETURN x', ['listOrMap' => ParameterHelper::asList([])]); // will return an empty CypherList
268247
$client->run('MATCH (x) WHERE x.slug in $listOrMap RETURN x', ['listOrMap' => ParameterHelper::asMap([])]); // will error
269-
$client->run('MATCH (x) WHERE x.slug in $listOrMap RETURN x', ['listOrMap' => []]); // will retrun an empty vector
248+
$client->run('MATCH (x) WHERE x.slug in $listOrMap RETURN x', ['listOrMap' => []]); // will return an empty CypherList
270249
```
271250

272-
273251
### Neo4j Version Support
274252

275253
| **Version** | **Tested** |
@@ -313,8 +291,8 @@ In order to make the results of the bolt protocol and the http uniform, the driv
313291

314292
The default formatter is the `\Laudis\Neo4j\Formatters\OGMFormatter`, which is explained extensively in [the result format section](#accessing-the-results).
315293

316-
The driver also provides three formatters by default, which are all found in the Formatter namespace:
317-
- `\Laudis\Neo4j\Formatter\BasicFormatter` which erases all the Cypher types and simply returns every value in the resulting map as a scalar, null or array value.
294+
The driver provides three formatters by default, which are all found in the Formatter namespace:
295+
- `\Laudis\Neo4j\Formatter\BasicFormatter` which erases all the Cypher types and simply returns every value in the resulting map as a [scalar](https://www.php.net/manual/en/function.is-scalar.php), null or array value.
318296
- `\Laudis\Neo4j\Formatter\OGMFormatter` which maps the cypher types to php types as explained [here](#accessing-the-results).
319297
- `\Laudis\Neo4j\Formatter\SummarizedResultFormatter` which decorates any formatter and adds an extensive result summary.
320298

@@ -373,7 +351,7 @@ A **client** manages **drivers** and routes the queries to the correct drivers b
373351

374352
### Driver
375353

376-
The ** driver** object is the thread-safe backbone that gives access to Neo4j. It owns a connection pool and can spawn **sessions** for carrying out work.
354+
The **driver** object is the thread-safe backbone that gives access to Neo4j. It owns a connection pool and can spawn **sessions** for carrying out work.
377355

378356
### Session
379357

@@ -417,3 +395,47 @@ This library supports three drivers: bolt, HTTP and neo4j. The scheme part of th
417395
| neo4j | neo4j | neo4j+s | neo4j+ssc | Client side routing over bolt |
418396
| bolt | bolt | bolt+s | bolt+ssc | Single server over bolt |
419397
| http | http | https | configured through PSR Client implementation | Single server over HTTP |
398+
399+
### Configuration objects
400+
401+
A driver, session and transaction can be configured using configuration objects. An overview of the configuration options can be found here:
402+
403+
| name | concept | description | class |
404+
|------|---------|-------------|-------|
405+
| user agent | driver | The user agent used to identify the client to the neo4j server. | `DriverConfiguration` |
406+
| Http PSR Bindings | driver | The relevant PSR implementation used by the driver when using the HTTP protocol. | `DriverConfiguration` |
407+
| database | session | The database to connect to. | `SessionConfiguration` |
408+
| fetch size | session | The amount of rows to fetch at once. (experimental) | `SessionConfiguration` |
409+
| access mode | session | The default mode when accessing the server. | `SessionConfiguration` |
410+
| bookmarks | session | The bookmarks used in the session. (experimental) | `SessionConfiguration` |
411+
| metadata | transaction | The metadata used during the transaction. (experimental) | `TransactionConfiguration` |
412+
| timeout | transaction | The maximum amount of time before timing out. | `TransactionConfiguration` |
413+
414+
Code Example:
415+
416+
```php
417+
use \Laudis\Neo4j\Databags\DriverConfiguration;
418+
use Laudis\Neo4j\Databags\SessionConfiguration;
419+
use Laudis\Neo4j\Databags\TransactionConfiguration;
420+
421+
$client = \Laudis\Neo4j\ClientBuilder::create()
422+
->withDefaultDriverConfiguration(DriverConfiguration::default()->withUserAgent('MyApp/1.0.0'))
423+
->withDefaultSessionConfiguration(SessionConfiguration::default()->withDatabase('app-database'))
424+
->withDefaultTransactionConfiguration(TransactionConfiguration::default()->withTimeout(5.0))
425+
->build();
426+
427+
// The client will run the query on a driver with the provided config,
428+
// which spawns a session with the provided session config
429+
// and runs the query in a transaction with he provided transaction config
430+
$client->run('MATCH (x) RETURN count(x) AS count');
431+
432+
// More granular control can be achieved by requesting the concepts yourself:
433+
434+
$tsx = $client->getDriver('default')
435+
->createSession(SessionConfiguration::default()->withDatabase('management-database'))
436+
->beginTransaction(null, TransactionConfiguration::default()->withTimeout(200));
437+
438+
$tsx->run('SOME REALLY LONG MANAGEMENT QUERY');
439+
440+
$tsx->commit();
441+
```

src/Bolt/BoltDriver.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ public static function create($uri, ?DriverConfiguration $configuration = null,
118118
*/
119119
public function createSession(?SessionConfiguration $config = null): SessionInterface
120120
{
121-
$config ??= SessionConfiguration::default();
122-
$config = $config->merge(SessionConfiguration::fromUri($this->parsedUrl));
121+
$sessionConfig = SessionConfiguration::fromUri($this->parsedUrl);
122+
if ($config !== null) {
123+
$sessionConfig = $sessionConfig->merge($config);
124+
}
123125

124126
return new Session(
125-
$config,
127+
$sessionConfig,
126128
$this->pool,
127129
$this->formatter,
128130
$this->config->getUserAgent(),

0 commit comments

Comments
 (0)