Skip to content

Commit 5a77694

Browse files
committed
Merge remote-tracking branch 'origin/main' into pratiksha
2 parents 7226193 + 303d029 commit 5a77694

File tree

8 files changed

+435
-32
lines changed

8 files changed

+435
-32
lines changed

composer.lock

Lines changed: 83 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Neo4jQueryAPI.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use GuzzleHttp\Client;
77
use GuzzleHttp\Exception\GuzzleException;
88
use GuzzleHttp\Exception\RequestException;
9+
use Neo4j\QueryAPI\Results\ResultSet;
910
use Neo4j\QueryAPI\Exception\Neo4jException;
1011
use Psr\Http\Client\RequestExceptionInterface;
1112
use RuntimeException;
@@ -40,7 +41,7 @@ public static function login(string $address, string $username, string $password
4041
* @throws Neo4jException
4142
* @throws RequestExceptionInterface
4243
*/
43-
public function run(string $cypher, array $parameters, string $database = 'neo4j'): array
44+
public function run(string $cypher, array $parameters, string $database = 'neo4j'): ResultSet
4445
{
4546
try {
4647
// Prepare the payload for the request
@@ -55,7 +56,10 @@ public function run(string $cypher, array $parameters, string $database = 'neo4j
5556
]);
5657

5758
// Decode the response body
58-
return json_decode($response->getBody()->getContents(), true);
59+
$data = json_decode($response->getBody()->getContents(), true);
60+
$ogm = new OGM();
61+
62+
return new ResultSet($data['data']['fields'], $data['data']['values'], $ogm);
5963
} catch (RequestExceptionInterface $e) {
6064
$response = $e->getResponse();
6165
if ($response !== null) {

src/OGM.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
class OGM
1111
{
12+
/**
13+
* @param array{'$type': string, '_value': mixed} $object
14+
* @return mixed
15+
*/
1216
public function map(array $object): mixed
1317
{
1418
return match ($object['$type']) {

src/Results/ResultRow.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
//namespace Neo4j\QueryAPI\Results;
4+
//
5+
//use Neo4j\QueryAPI\OGM;
6+
//
7+
//class ResultRow
8+
//{
9+
// public function __construct(private array $keys, private array $resultRow, private OGM $ogm)
10+
// {
11+
// $this->values = [];
12+
// foreach ($this->resultRow as $index => $value) {
13+
// $this->values[$this->keys[$index]] = $value['_value'];
14+
// }
15+
// }
16+
//
17+
// public function get(string $column): mixed
18+
// {
19+
// return $this->values[$column] ?? null;
20+
// }
21+
//}
22+
23+
24+
25+
26+
namespace Neo4j\QueryAPI\Results;
27+
28+
29+
use BadMethodCallException;
30+
use Neo4j\QueryAPI\OGM;
31+
use OutOfBoundsException;
32+
use ArrayAccess;
33+
34+
class ResultRow implements ArrayAccess
35+
{
36+
public function __construct(private array $data)
37+
{
38+
}
39+
40+
41+
public function offsetExists($offset): bool
42+
{
43+
return isset($this->data[$offset]);
44+
}
45+
46+
public function offsetGet($offset): mixed
47+
{
48+
if (!$this->offsetExists($offset)) {
49+
throw new OutOfBoundsException("Column {$offset} not found.");
50+
}
51+
return $this->data[$offset];
52+
}
53+
54+
public function offsetSet($offset, $value): void
55+
{
56+
throw new BadMethodCallException("You cant set the value of column {$offset}.");
57+
}
58+
public function offsetUnset($offset): void
59+
{
60+
throw new BadMethodCallException("You cant Unset {$offset}.");
61+
62+
}
63+
64+
65+
public function get(string $row): mixed
66+
{
67+
return $this->offsetGet($row);
68+
}
69+
70+
71+
}
72+
73+

0 commit comments

Comments
 (0)