Skip to content

Commit 970d169

Browse files
committed
added result formatter information to readme
1 parent cfb39fb commit 970d169

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,40 @@ If you plan on using the HTTP drivers, make sure you have [psr-7](https://www.ph
307307
composer require nyholm/psr7 nyholm/psr7-server kriswallsmith/buzz
308308
```
309309

310+
## Result formats/hydration
311+
312+
In order to make the results of the bolt protocol and the http uniform, the driver provides result formatters (aka hydrators). The client is configurable with these formatters. You can even implement your own.
313+
314+
The default formatter is the `\Laudis\Neo4j\Formatters\OGMFormatter`, which is explained extensively in [the result format section](#accessing-the-results).
315+
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.
318+
- `\Laudis\Neo4j\Formatter\OGMFormatter` which maps the cypher types to php types as explained [here](#accessing-the-results).
319+
- `\Laudis\Neo4j\Formatter\SummarizedResultFormatter` which decorates any formatter and adds an extensive result summary.
320+
321+
The client builder provides an easy way to change the formatter:
322+
323+
```php
324+
$client = \Laudis\Neo4j\ClientBuilder::create()
325+
->withFormatter(\Laudis\Neo4j\Formatter\SummarizedResultFormatter::create())
326+
->build();
327+
328+
/**
329+
* The client will now return a result, decorated with a summary.
330+
*
331+
* @var \Laudis\Neo4j\Databags\SummarizedResult $results
332+
*/
333+
$summarisedResult = $client->run('MATCH (x) RETURN x');
334+
335+
// The summary contains extensive information such as counters for changed values in the database,
336+
// information on the database, potential notifications, timing, a (profiled) plan, the type of query
337+
// and information on the server itself.
338+
$summary = $summarisedResult->getSummary();
339+
// The result is exactly the same as the default.
340+
$result = $summarisedResult->getResult();
341+
```
342+
343+
In order to use a custom formatter, implement the `Laudis\Neo4j\Contracts\FormatterInterface` and provide it when using the client builder.
310344

311345
## Concepts
312346

0 commit comments

Comments
 (0)