Skip to content

Commit 303d029

Browse files
committed
Merge branch 'workinprogress'
2 parents ec47c7e + 56b176e commit 303d029

File tree

9 files changed

+438
-34
lines changed

9 files changed

+438
-34
lines changed

.phpunit.result.cache

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

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: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use GuzzleHttp\Client;
66
use GuzzleHttp\Exception\GuzzleException;
77
use GuzzleHttp\Exception\RequestException;
8+
use Neo4j\QueryAPI\Results\ResultSet;
89
use RuntimeException;
910
use stdClass;
1011

@@ -36,17 +37,24 @@ public static function login(string $address, string $username, string $password
3637
/**
3738
* @throws GuzzleException
3839
*/
39-
public function run(string $cypher, array $parameters, string $database = 'neo4j'): array
40+
public function run(string $cypher, array $parameters, string $database = 'neo4j'): ResultSet
4041
{
4142
$payload = [
4243
'statement' => $cypher,
43-
'parameters' => $parameters === [] ? new stdClass() : $parameters,
44+
'parameters' => $parameters === [] ? new stdClass() : $parameters,
4445
];
4546

4647
$response = $this->client->post('/db/' . $database . '/query/v2', [
4748
'json' => $payload,
4849
]);
49-
return json_decode($response->getBody()->getContents(), true);
50+
51+
52+
$data = json_decode($response->getBody()->getContents(), true);
53+
54+
55+
$ogm = new OGM();
56+
57+
return new ResultSet($data['data']['fields'], $data['data']['values'], $ogm);
5058
}
5159

5260

src/OGM.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function map(array $object): mixed
1717
'String' => $object['_value'],
1818
'Boolean' => $object['_value'],
1919
'Point' => $this->parseWKT($object['_value']),
20+
default => $object['_value'],
2021
};
2122
}
2223

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)