forked from neo4j-php/neo4j-symfony
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SymfonyTransaction.php
76 lines (63 loc) · 2.06 KB
/
SymfonyTransaction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace Neo4j\Neo4jBundle;
use Laudis\Neo4j\Contracts\UnmanagedTransactionInterface;
use Laudis\Neo4j\Databags\Statement;
use Laudis\Neo4j\Databags\SummarizedResult;
use Laudis\Neo4j\Types\CypherList;
use Laudis\Neo4j\Types\CypherMap;
/**
* @implements UnmanagedTransactionInterface<SummarizedResult<CypherList<CypherMap<mixed>>>|null>
*/
class SymfonyTransaction implements UnmanagedTransactionInterface
{
/** @var UnmanagedTransactionInterface<SummarizedResult<CypherList<CypherMap<mixed>>>> */
private UnmanagedTransactionInterface $tsx;
private EventHandler $handler;
/**
* @param UnmanagedTransactionInterface<SummarizedResult<CypherList<CypherMap<mixed>>>> $tsx
*/
public function __construct(UnmanagedTransactionInterface $tsx, EventHandler $handler)
{
$this->tsx = $tsx;
$this->handler = $handler;
}
public function run(string $statement, iterable $parameters = []): ?SummarizedResult
{
return $this->runStatement(new Statement($statement, $parameters));
}
public function runStatement(Statement $statement): ?SummarizedResult
{
$result = $this->runStatements([$statement]);
return $result->isEmpty() ? null : $result->first();
}
/**
* @psalm-suppress InvalidReturnStatement
*/
public function runStatements(iterable $statements): CypherList
{
return $this->handler->handle(fn () => $this->tsx->runStatements($statements), $statements);
}
/**
* @psalm-suppress InvalidReturnStatement
*/
public function commit(iterable $statements = []): CypherList
{
return $this->handler->handle(fn () => $this->tsx->commit($statements), $statements);
}
public function rollback(): void
{
$this->tsx->rollback();
}
public function isRolledBack(): bool
{
return $this->tsx->isRolledBack();
}
public function isCommitted(): bool
{
return $this->tsx->isCommitted();
}
public function isFinished(): bool
{
return $this->tsx->isFinished();
}
}