Skip to content

Commit 00d950e

Browse files
committed
WIP
1 parent 7492476 commit 00d950e

28 files changed

+169
-992
lines changed

README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -308,21 +308,16 @@ composer require nyholm/psr7 nyholm/psr7-server kriswallsmith/buzz
308308

309309
## Result formats/hydration
310310

311-
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.
311+
In order to make the results of the bolt protocol and the http uniform, the driver provides a summarizes the results.
312312

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

315-
The driver provides three formatters by default, which are all found in the Formatter namespace:
316-
- `\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.
317-
- `\Laudis\Neo4j\Formatter\OGMFormatter` which maps the cypher types to php types as explained [here](#accessing-the-results).
318-
- `\Laudis\Neo4j\Formatter\SummarizedResultFormatter` which decorates any formatter and adds an extensive result summary.
315+
`\Laudis\Neo4j\Formatter\SummarizedResultFormatter` adds an extensive result summary.
319316

320317
The client builder provides an easy way to change the formatter:
321318

322319
```php
323-
$client = \Laudis\Neo4j\ClientBuilder::create()
324-
->withFormatter(\Laudis\Neo4j\Formatter\SummarizedResultFormatter::create())
325-
->build();
320+
$client = \Laudis\Neo4j\ClientBuilder::create()->build();
326321

327322
/**
328323
* The client will now return a result, decorated with a summary.
@@ -339,8 +334,6 @@ $summary = $summarisedResult->getSummary();
339334
$result = $summarisedResult->getResult();
340335
```
341336

342-
In order to use a custom formatter, implement the `Laudis\Neo4j\Contracts\FormatterInterface` and provide it when using the client builder.
343-
344337
## Concepts
345338

346339
The driver API described [here](https://neo4j.com/docs/driver-manual/current/) is the main target of the driver. Because of this, the client is nothing more than a driver manager. The driver creates sessions. A session runs queries through a transaction.

src/Basic/UnmanagedTransaction.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,12 @@ public function __construct(
3333

3434
/**
3535
* @param iterable<string, mixed> $parameters
36-
*
37-
* @return SummarizedResult<CypherMap>
3836
*/
3937
public function run(string $statement, iterable $parameters = []): SummarizedResult
4038
{
4139
return $this->tsx->run($statement, $parameters);
4240
}
4341

44-
/**
45-
* @return SummarizedResult<CypherMap>
46-
*/
4742
public function runStatement(Statement $statement): SummarizedResult
4843
{
4944
return $this->tsx->runStatement($statement);
@@ -52,7 +47,7 @@ public function runStatement(Statement $statement): SummarizedResult
5247
/**
5348
* @param iterable<Statement> $statements
5449
*
55-
* @return CypherList<SummarizedResult<CypherMap>>
50+
* @return CypherList<SummarizedResult>
5651
*/
5752
public function runStatements(iterable $statements): CypherList
5853
{
@@ -62,7 +57,7 @@ public function runStatements(iterable $statements): CypherList
6257
/**
6358
* @param iterable<Statement> $statements
6459
*
65-
* @return CypherList<SummarizedResult<CypherMap>>
60+
* @return CypherList<SummarizedResult>
6661
*/
6762
public function commit(iterable $statements = []): CypherList
6863
{

src/Bolt/BoltConnection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
use Laudis\Neo4j\Common\Neo4jLogger;
2828
use Laudis\Neo4j\Contracts\AuthenticateInterface;
2929
use Laudis\Neo4j\Contracts\ConnectionInterface;
30-
use Laudis\Neo4j\Contracts\FormatterInterface;
3130
use Laudis\Neo4j\Databags\BookmarkHolder;
3231
use Laudis\Neo4j\Databags\DatabaseInfo;
3332
use Laudis\Neo4j\Databags\Neo4jError;
3433
use Laudis\Neo4j\Enum\AccessMode;
3534
use Laudis\Neo4j\Enum\ConnectionProtocol;
3635
use Laudis\Neo4j\Exception\Neo4jException;
36+
use Laudis\Neo4j\Formatter\SummarizedResultFormatter;
3737
use Laudis\Neo4j\Types\CypherList;
3838
use Psr\Http\Message\UriInterface;
3939
use Psr\Log\LogLevel;
@@ -42,7 +42,7 @@
4242
/**
4343
* @implements ConnectionInterface<array{0: V4_4|V5|V5_1|V5_2|V5_3|V5_4|null, 1: Connection}>
4444
*
45-
* @psalm-import-type BoltMeta from FormatterInterface
45+
* @psalm-import-type BoltMeta from SummarizedResultFormatter
4646
*/
4747
class BoltConnection implements ConnectionInterface
4848
{

src/Bolt/BoltUnmanagedTransaction.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
namespace Laudis\Neo4j\Bolt;
1515

1616
use Bolt\enum\ServerState;
17-
use Laudis\Neo4j\Contracts\FormatterInterface;
1817
use Laudis\Neo4j\Contracts\UnmanagedTransactionInterface;
1918
use Laudis\Neo4j\Databags\BookmarkHolder;
2019
use Laudis\Neo4j\Databags\SessionConfiguration;
2120
use Laudis\Neo4j\Databags\Statement;
2221
use Laudis\Neo4j\Databags\TransactionConfiguration;
2322
use Laudis\Neo4j\Enum\TransactionState;
2423
use Laudis\Neo4j\Exception\ClientException;
24+
use Laudis\Neo4j\Formatter\SummarizedResultFormatter;
2525
use Laudis\Neo4j\ParameterHelper;
2626
use Laudis\Neo4j\Types\AbstractCypherSequence;
2727
use Laudis\Neo4j\Types\CypherList;
@@ -37,22 +37,19 @@
3737
*
3838
* @implements UnmanagedTransactionInterface<T>
3939
*
40-
* @psalm-import-type BoltMeta from FormatterInterface
40+
* @psalm-import-type BoltMeta from SummarizedResultFormatter
4141
*/
4242
final class BoltUnmanagedTransaction implements UnmanagedTransactionInterface
4343
{
4444
private TransactionState $state = TransactionState::ACTIVE;
4545

46-
/**
47-
* @param FormatterInterface<T> $formatter
48-
*/
4946
public function __construct(
5047
/** @psalm-readonly */
5148
private readonly ?string $database,
5249
/**
5350
* @psalm-readonly
5451
*/
55-
private readonly FormatterInterface $formatter,
52+
private readonly SummarizedResultFormatter $formatter,
5653
/** @psalm-readonly */
5754
private readonly BoltConnection $connection,
5855
private readonly SessionConfiguration $config,

src/Bolt/Session.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,24 @@
1818
use Laudis\Neo4j\Common\Neo4jLogger;
1919
use Laudis\Neo4j\Common\TransactionHelper;
2020
use Laudis\Neo4j\Contracts\ConnectionPoolInterface;
21-
use Laudis\Neo4j\Contracts\FormatterInterface;
2221
use Laudis\Neo4j\Contracts\SessionInterface;
2322
use Laudis\Neo4j\Contracts\TransactionInterface;
2423
use Laudis\Neo4j\Contracts\UnmanagedTransactionInterface;
2524
use Laudis\Neo4j\Databags\Bookmark;
2625
use Laudis\Neo4j\Databags\BookmarkHolder;
2726
use Laudis\Neo4j\Databags\SessionConfiguration;
2827
use Laudis\Neo4j\Databags\Statement;
28+
use Laudis\Neo4j\Databags\SummarizedResult;
2929
use Laudis\Neo4j\Databags\TransactionConfiguration;
3030
use Laudis\Neo4j\Enum\AccessMode;
3131
use Laudis\Neo4j\Exception\Neo4jException;
32+
use Laudis\Neo4j\Formatter\SummarizedResultFormatter;
3233
use Laudis\Neo4j\Neo4j\Neo4jConnectionPool;
3334
use Laudis\Neo4j\Types\CypherList;
3435
use Psr\Log\LogLevel;
3536

3637
/**
3738
* A session using bolt connections.
38-
*
39-
* @template ResultFormat
40-
*
41-
* @implements SessionInterface<ResultFormat>
4239
*/
4340
final class Session implements SessionInterface
4441
{
@@ -47,7 +44,6 @@ final class Session implements SessionInterface
4744

4845
/**
4946
* @param ConnectionPool|Neo4jConnectionPool $pool
50-
* @param FormatterInterface<ResultFormat> $formatter
5147
*
5248
* @psalm-mutation-free
5349
*/
@@ -58,7 +54,7 @@ public function __construct(
5854
/**
5955
* @psalm-readonly
6056
*/
61-
private readonly FormatterInterface $formatter
57+
private readonly SummarizedResultFormatter $formatter
6258
) {
6359
$this->bookmarkHolder = new BookmarkHolder(Bookmark::from($config->getBookmarks()));
6460
}
@@ -84,12 +80,12 @@ public function openTransaction(?iterable $statements = null, ?TransactionConfig
8480
return $this->beginTransaction($statements, $this->mergeTsxConfig($config));
8581
}
8682

87-
public function runStatement(Statement $statement, ?TransactionConfiguration $config = null)
83+
public function runStatement(Statement $statement, ?TransactionConfiguration $config = null): SummarizedResult
8884
{
8985
return $this->runStatements([$statement], $config)->first();
9086
}
9187

92-
public function run(string $statement, iterable $parameters = [], ?TransactionConfiguration $config = null)
88+
public function run(string $statement, iterable $parameters = [], ?TransactionConfiguration $config = null): SummarizedResult
9389
{
9490
return $this->runStatement(new Statement($statement, $parameters), $config);
9591
}
@@ -133,7 +129,7 @@ public function beginTransaction(?iterable $statements = null, ?TransactionConfi
133129
}
134130

135131
/**
136-
* @return UnmanagedTransactionInterface<ResultFormat>
132+
* @return UnmanagedTransactionInterface
137133
*/
138134
private function beginInstantTransaction(
139135
SessionConfiguration $config,

src/Common/DriverSetupManager.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
use InvalidArgumentException;
2323
use Laudis\Neo4j\Authentication\Authenticate;
2424
use Laudis\Neo4j\Contracts\DriverInterface;
25-
use Laudis\Neo4j\Contracts\FormatterInterface;
2625
use Laudis\Neo4j\Databags\DriverConfiguration;
2726
use Laudis\Neo4j\Databags\DriverSetup;
2827
use Laudis\Neo4j\Databags\SessionConfiguration;
2928
use Laudis\Neo4j\DriverFactory;
29+
use Laudis\Neo4j\Formatter\SummarizedResultFormatter;
3030

3131
use const PHP_INT_MIN;
3232

@@ -51,11 +51,9 @@ class DriverSetupManager implements Countable
5151

5252
/**
5353
* @psalm-mutation-free
54-
*
55-
* @param FormatterInterface<ResultFormat> $formatter
5654
*/
5755
public function __construct(
58-
private FormatterInterface $formatter,
56+
private SummarizedResultFormatter $formatter,
5957
private DriverConfiguration $configuration
6058
) {}
6159

@@ -193,7 +191,7 @@ public function count(): int
193191
*
194192
* @psalm-mutation-free
195193
*/
196-
public function withFormatter(FormatterInterface $formatter): self
194+
public function withFormatter(SummarizedResultFormatter $formatter): self
197195
{
198196
$tbr = clone $this;
199197
$tbr->formatter = $formatter;

src/Contracts/ClientInterface.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@
1414
namespace Laudis\Neo4j\Contracts;
1515

1616
use Laudis\Neo4j\Databags\Statement;
17+
use Laudis\Neo4j\Databags\SummarizedResult;
1718
use Laudis\Neo4j\Databags\TransactionConfiguration;
1819
use Laudis\Neo4j\Exception\Neo4jException;
1920
use Laudis\Neo4j\Types\CypherList;
2021

21-
/**
22-
* @template ResultFormat
23-
*
24-
* @extends TransactionInterface<ResultFormat>
25-
*/
2622
interface ClientInterface extends TransactionInterface
2723
{
2824
/**
@@ -31,19 +27,15 @@ interface ClientInterface extends TransactionInterface
3127
* @param iterable<string, mixed> $parameters
3228
*
3329
* @throws Neo4jException
34-
*
35-
* @return ResultFormat
3630
*/
37-
public function run(string $statement, iterable $parameters = [], ?string $alias = null);
31+
public function run(string $statement, iterable $parameters = [], ?string $alias = null): SummarizedResult;
3832

3933
/**
4034
* Runs a one off transaction with the provided statement over the connection with the provided alias or the master alias otherwise.
4135
*
4236
* @throws Neo4jException
43-
*
44-
* @return ResultFormat
4537
*/
46-
public function runStatement(Statement $statement, ?string $alias = null);
38+
public function runStatement(Statement $statement, ?string $alias = null): SummarizedResult;
4739

4840
/**
4941
* Runs a one off transaction with the provided statements over the connection with the provided alias or the master alias otherwise.
@@ -52,7 +44,7 @@ public function runStatement(Statement $statement, ?string $alias = null);
5244
*
5345
* @throws Neo4jException
5446
*
55-
* @return CypherList<ResultFormat>
47+
* @return CypherList<mixed>
5648
*/
5749
public function runStatements(iterable $statements, ?string $alias = null): CypherList;
5850

@@ -62,17 +54,13 @@ public function runStatements(iterable $statements, ?string $alias = null): Cyph
6254
* @param iterable<Statement>|null $statements
6355
*
6456
* @throws Neo4jException
65-
*
66-
* @return UnmanagedTransactionInterface<ResultFormat>
6757
*/
6858
public function beginTransaction(?iterable $statements = null, ?string $alias = null, ?TransactionConfiguration $config = null): UnmanagedTransactionInterface;
6959

7060
/**
7161
* Gets the driver with the provided alias. Gets the default driver if no alias is provided.
7262
*
7363
* The driver is guaranteed to have its connectivity verified at least once during its lifetime.
74-
*
75-
* @return DriverInterface<ResultFormat>
7664
*/
7765
public function getDriver(?string $alias): DriverInterface;
7866

@@ -84,7 +72,7 @@ public function hasDriver(string $alias): bool;
8472
/**
8573
* @template U
8674
*
87-
* @param callable(TransactionInterface<ResultFormat>):U $tsxHandler
75+
* @param callable(TransactionInterface):U $tsxHandler
8876
*
8977
* @return U
9078
*/
@@ -93,7 +81,7 @@ public function writeTransaction(callable $tsxHandler, ?string $alias = null, ?T
9381
/**
9482
* @template U
9583
*
96-
* @param callable(TransactionInterface<ResultFormat>):U $tsxHandler
84+
* @param callable(TransactionInterface):U $tsxHandler
9785
*
9886
* @return U
9987
*/
@@ -104,7 +92,7 @@ public function readTransaction(callable $tsxHandler, ?string $alias = null, ?Tr
10492
*
10593
* @template U
10694
*
107-
* @param callable(TransactionInterface<ResultFormat>):U $tsxHandler
95+
* @param callable(TransactionInterface):U $tsxHandler
10896
*
10997
* @return U
11098
*/

0 commit comments

Comments
 (0)