Skip to content

Commit 69cf6a2

Browse files
committed
made the entire summarisedresult json serialisable
1 parent 725b58e commit 69cf6a2

File tree

7 files changed

+73
-7
lines changed

7 files changed

+73
-7
lines changed

src/Basic/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
final class Driver implements DriverInterface
2828
{
29-
/** @var DriverInterface DriverInterface<SummarizedResult<CypherMap>> */
29+
/** @var DriverInterface<SummarizedResult<CypherMap>> */
3030
private DriverInterface $driver;
3131

3232
/**

src/Databags/DatabaseInfo.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313

1414
namespace Laudis\Neo4j\Databags;
1515

16+
use Laudis\Neo4j\Types\AbstractCypherObject;
17+
1618
/**
1719
* Stores relevant information of a database.
1820
*
1921
* @psalm-immutable
2022
*/
21-
final class DatabaseInfo
23+
final class DatabaseInfo extends AbstractCypherObject
2224
{
2325
private string $name;
2426

@@ -34,4 +36,9 @@ public function getName(): string
3436
{
3537
return $this->name;
3638
}
39+
40+
public function toArray(): array
41+
{
42+
return ['name' => $this->name];
43+
}
3744
}

src/Databags/Plan.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Laudis\Neo4j\Databags;
1515

16+
use Laudis\Neo4j\Types\AbstractCypherObject;
1617
use Laudis\Neo4j\Types\CypherList;
1718
use Laudis\Neo4j\Types\CypherMap;
1819

@@ -23,7 +24,7 @@
2324
*
2425
* @psalm-immutable
2526
*/
26-
final class Plan
27+
final class Plan extends AbstractCypherObject
2728
{
2829
/** @var CypherMap<mixed> */
2930
private CypherMap $arguments;
@@ -87,4 +88,14 @@ public function getOperator(): string
8788
{
8889
return $this->operator;
8990
}
91+
92+
public function toArray(): array
93+
{
94+
return [
95+
'arguments' => $this->arguments,
96+
'list' => $this->list,
97+
'identifiers' => $this->identifiers,
98+
'operator' => $this->operator,
99+
];
100+
}
90101
}

src/Databags/ProfiledPlan.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Laudis\Neo4j\Databags;
1515

16+
use Laudis\Neo4j\Types\AbstractCypherObject;
1617
use Laudis\Neo4j\Types\CypherList;
1718

1819
/**
@@ -22,7 +23,7 @@
2223
*
2324
* @psalm-immutable
2425
*/
25-
final class ProfiledPlan
26+
final class ProfiledPlan extends AbstractCypherObject
2627
{
2728
/** @var CypherList<ProfiledPlan> */
2829
private CypherList $children;
@@ -120,4 +121,18 @@ public function getTime(): int
120121
{
121122
return $this->time;
122123
}
124+
125+
public function toArray(): array
126+
{
127+
return [
128+
'children' => $this->children,
129+
'dbHits' => $this->dbHits,
130+
'hasPageCacheStats' => $this->hasPageCacheStats,
131+
'pageCacheHitRatio' => $this->pageCacheHitRatio,
132+
'pageCacheHits' => $this->pageCacheHits,
133+
'pageCacheMisses' => $this->pageCacheMisses,
134+
'records' => $this->records,
135+
'time' => $this->time,
136+
];
137+
}
123138
}

src/Databags/ResultSummary.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace Laudis\Neo4j\Databags;
1515

1616
use Laudis\Neo4j\Enum\QueryTypeEnum;
17+
use Laudis\Neo4j\Types\AbstractCypherObject;
1718
use Laudis\Neo4j\Types\CypherList;
1819

1920
/**
@@ -28,7 +29,7 @@
2829
*
2930
* @psalm-immutable
3031
*/
31-
final class ResultSummary
32+
final class ResultSummary extends AbstractCypherObject
3233
{
3334
private SummaryCounters $counters;
3435
private DatabaseInfo $databaseInfo;
@@ -150,4 +151,20 @@ public function getServerInfo(): ServerInfo
150151
{
151152
return $this->serverInfo;
152153
}
154+
155+
public function toArray(): array
156+
{
157+
return [
158+
'counters' => $this->counters,
159+
'databaseInfo' => $this->databaseInfo,
160+
'notifications' => $this->notifications,
161+
'plan' => $this->plan,
162+
'profiledPlan' => $this->profiledPlan,
163+
'statement' => $this->statement,
164+
'queryType' => $this->queryType,
165+
'resultAvailableAfter' => $this->resultAvailableAfter,
166+
'resultConsumedAfter' => $this->resultConsumedAfter,
167+
'serverInfo' => $this->serverInfo,
168+
];
169+
}
153170
}

src/Databags/ServerInfo.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
namespace Laudis\Neo4j\Databags;
1515

1616
use Laudis\Neo4j\Enum\ConnectionProtocol;
17+
use Laudis\Neo4j\Types\AbstractCypherObject;
1718
use Psr\Http\Message\UriInterface;
1819

1920
/**
2021
* Provides some basic information of the server where the result is obtained from.
2122
*
2223
* @psalm-immutable
2324
*/
24-
final class ServerInfo
25+
final class ServerInfo extends AbstractCypherObject
2526
{
2627
private UriInterface $address;
2728
private ConnectionProtocol $protocol;
@@ -57,4 +58,13 @@ public function getAgent(): string
5758
{
5859
return $this->agent;
5960
}
61+
62+
public function toArray(): array
63+
{
64+
return [
65+
'address' => $this->address,
66+
'protocol' => $this->protocol,
67+
'agent' => $this->agent,
68+
];
69+
}
6070
}

src/Enum/ConnectionProtocol.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace Laudis\Neo4j\Enum;
1515

1616
use Bolt\Bolt;
17+
use JsonSerializable;
1718
use Laudis\TypedEnum\TypedEnum;
1819

1920
/**
@@ -32,7 +33,7 @@
3233
*
3334
* @psalm-suppress MutableDependency
3435
*/
35-
final class ConnectionProtocol extends TypedEnum
36+
final class ConnectionProtocol extends TypedEnum implements JsonSerializable
3637
{
3738
private const BOLT_V3 = 'bolt-v3';
3839
private const BOLT_V40 = 'bolt-v40';
@@ -88,4 +89,9 @@ public function compare(ConnectionProtocol $protocol): int
8889

8990
return $x - $y;
9091
}
92+
93+
public function jsonSerialize(): string
94+
{
95+
return $this->getValue();
96+
}
9197
}

0 commit comments

Comments
 (0)