Skip to content

Commit 022699a

Browse files
authored
Merge pull request #36 from neo4j-php/feature/ogm-formatter
OGM Formatter - Graph Data Types Despite a small bug in the CI, everything works perfectly. Great work!
2 parents 83d899c + 32ca84f commit 022699a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3215
-5889
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,10 @@ jobs:
108108
zip \
109109
unzip \
110110
wget \
111+
git \
111112
&& docker-php-ext-install -j$(nproc) gd sockets bcmath \
112-
&& pecl install ds \
113-
&& docker-php-ext-enable ds
113+
&& pecl install ds xdebug \
114+
&& docker-php-ext-enable ds xdebug
114115
- name: Install Composer
115116
run: curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
116117
- name: Install dependencies
@@ -125,7 +126,7 @@ jobs:
125126
&& mv test-reporter-latest-linux-amd64 /usr/bin/cc-test-reporter \
126127
&& chmod +x /usr/bin/cc-test-reporter \
127128
&& cc-test-reporter before-build \
128-
&& vendor/bin/phpunit --config phpunit.coverage.xml.dist -d memory_limit=1024M \
129+
&& XDEBUG_MODE=coverage vendor/bin/phpunit --config phpunit.coverage.xml.dist -d memory_limit=1024M \
129130
&& mkdir -p out/phpunit \
130131
&& cp out/phpunit/clover.xml clover.xml \
131132
&& cc-test-reporter after-build --id ec331dd009edca126a4c27f4921c129de840c8a117643348e3b75ec547661f28 --exit-code 0

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ phpunit.xml
77
clover.xml
88
cc-test-reporter
99
/run-pipeline.sh
10+
composer.lock

.php-cs-fixer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* file that was distributed with this source code.
1212
*/
1313

14+
use PhpCsFixer\Config;
15+
1416
$header = <<<'EOF'
1517
This file is part of the Laudis Neo4j package.
1618
@@ -30,7 +32,7 @@
3032
exit(1);
3133
}
3234

33-
return PhpCsFixer\Config::create()
35+
return (new Config())
3436
->setRules([
3537
'@Symfony' => true,
3638

Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ RUN apt-get update && apt-get install -y \
1010
git \
1111
wget \
1212
&& docker-php-ext-install -j$(nproc) gd sockets bcmath \
13-
&& pecl install ds pcov xdebug \
14-
&& docker-php-ext-enable ds xdebug \
13+
&& pecl install ds pcov \
14+
&& docker-php-ext-enable ds \
1515
&& wget https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 \
1616
&& mv test-reporter-latest-linux-amd64 /usr/bin/cc-test-reporter \
17-
&& chmod +x /usr/bin/cc-test-reporter \
18-
&& echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
19-
&& echo "xdebug.client_host=127.0.0.1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
20-
&& echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
17+
&& chmod +x /usr/bin/cc-test-reporter
18+
19+
RUN pecl install xdebug \
20+
&& docker-php-ext-enable xdebug
2121

2222
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
2323

README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,66 @@ $tsx->commit([Statement::create('MATCH (x) RETURN x LIMIT 100')]);
190190

191191
## Accessing the results
192192

193-
> TODO: Rewrite this as the new standard will be the OGM.
193+
Results are returned in a standard format of rows and columns:
194+
195+
```php
196+
// Results are a CypherList
197+
$results = $client->run('MATCH (node:Node) RETURN node, node.id AS id');
198+
199+
// A row is a CypherMap
200+
foreach ($results as $result) {
201+
// Returns a Node
202+
$node = $result->get('node');
203+
204+
echo $node->getAttribute('id');
205+
echo $result->get('id');
206+
}
207+
```
208+
209+
Cypher values and types are mapped to php types and classes:
210+
211+
|Cypher|Php|
212+
|---|---|
213+
|null|`null`|
214+
|string|`string`|
215+
|integer|`int`|
216+
|float|`float`|
217+
|boolean|`bool`|
218+
|Map|`\Laudis\Neo4j\Types\CypherMap`|
219+
|List|`\Laudis\Neo4j\Types\CypherList`|
220+
|Point|`\Laudis\Neo4j\Contracts\PointInterface` *|
221+
|Date|`\Laudis\Neo4j\Types\Date`|
222+
|Time|`\Laudis\Neo4j\Types\Time`|
223+
|LocalTime|`\Laudis\Neo4j\Types\LocalTime`|
224+
|DateTime|`\Laudis\Neo4j\Types\DateTime`|
225+
|LocalDateTime|`\Laudis\Neo4j\Types\LocalDateTime`|
226+
|Duration|`\Laudis\Neo4j\Types\Duration`|
227+
|Node|`\Laudis\Neo4j\Types\Node`|
228+
|Relationship|`\Laudis\Neo4j\Types\Relationship`|
229+
|Path|`\Laudis\Neo4j\Types\Path`|
230+
231+
(*) A point can be one of four types implementing PointInterface: `\Laudis\Neo4j\Types\CartesianPoint` `\Laudis\Neo4j\Types\Cartesian3DPoint` `\Laudis\Neo4j\Types\WGS84Point` `\Laudis\Neo4j\Types\WGS843DPoint`
232+
233+
If you want the results to be just a set of rows, columns, arrays and scalar types you can use a BasicFormatter:
234+
235+
```php
236+
use Laudis\Neo4j\ClientBuilder;
237+
use Laudis\Neo4j\Formatter\BasicFormatter;
238+
239+
$client = ClientBuilder::create()->withFormatter(BasicFormatter::class)->build();
240+
241+
// Results are a CypherList
242+
$results = $client->run('MATCH (node:Node) RETURN node, node.id AS id');
243+
244+
// A row is a CypherMap
245+
foreach ($results as $result) {
246+
// Returns an array of attributes instead of a Node.
247+
$node = $result->get('node');
248+
249+
echo $node['id'];
250+
echo $result->get('id');
251+
}
252+
```
194253

195254
## Diving Deeper
196255

0 commit comments

Comments
 (0)