Skip to content

Commit 91f5d70

Browse files
committed
wip
1 parent 7ddbdea commit 91f5d70

File tree

9 files changed

+360
-136
lines changed

9 files changed

+360
-136
lines changed

Readme.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,52 @@
1616

1717
# Syndesi's Cypher Data Structures
1818

19-
This library provides data structures for Cypher data types.
20-
21-
Links:
19+
This library provides basic data classes, so that working with Cypher based graph databases becomes easy.
2220

2321
- [Documentation](https://neo4j-php.github.io/cypher-data-structures)
2422
- [Packagist](https://packagist.org/packages/syndesi/cypher-data-structures)
25-
- [Neo4j PHP Community](https://github.com/neo4j-php)
23+
24+
## Installation
25+
26+
To install this library, run the following code:
27+
28+
```bash
29+
composer require syndesi/cypher-data-structures
30+
```
31+
32+
This is all, now you can use the library :D
33+
34+
## Using the library
35+
36+
```php
37+
use Syndesi\CypherDataStructures\Type\Node;
38+
use Syndesi\CypherDataStructures\Type\Relation;
39+
40+
$node = new Node();
41+
$node
42+
->addLabel('NodeLabel')
43+
->addIdentifier('id', 123)
44+
->addProperty('someProperty', 'someValue')
45+
->addIdentifier('id');
46+
47+
$otherNode = new Node();
48+
$otherNode
49+
->addLabel('OtherNodeLabel')
50+
->addIdentifier('id', 234)
51+
->addProperty('hello', 'world :D')
52+
->addIdentifier('id');
53+
54+
$relation = new Relation();
55+
$relation
56+
->setStartNode($node)
57+
->setEndNode($node)
58+
->setType('SOME_RELATION');
59+
```
60+
61+
## Advanced integration
62+
63+
This library itself does not provide advanced features like validation. Those are separated into their own projects:
64+
65+
- Validation: Work in progress, not yet released.
66+
- [Entity Manager](https://github.com/neo4j-php/cypher-entity-manager): Automatically creates and runs Cypher statements
67+
from data objects of this library for you.

docs/README.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,52 @@
1616

1717
# Syndesi's Cypher Data Structures
1818

19-
This library provides data structures for Cypher data types.
20-
21-
Links:
19+
This library provides basic data classes, so that working with Cypher based graph databases becomes easy.
2220

2321
- [Documentation](https://neo4j-php.github.io/cypher-data-structures)
2422
- [Packagist](https://packagist.org/packages/syndesi/cypher-data-structures)
25-
- [Neo4j PHP Community](https://github.com/neo4j-php)
23+
24+
## Installation
25+
26+
To install this library, run the following code:
27+
28+
```bash
29+
composer require syndesi/cypher-data-structures
30+
```
31+
32+
This is all, now you can use the library :D
33+
34+
## Using the library
35+
36+
```php
37+
use Syndesi\CypherDataStructures\Type\Node;
38+
use Syndesi\CypherDataStructures\Type\Relation;
39+
40+
$node = new Node();
41+
$node
42+
->addLabel('NodeLabel')
43+
->addIdentifier('id', 123)
44+
->addProperty('someProperty', 'someValue')
45+
->addIdentifier('id');
46+
47+
$otherNode = new Node();
48+
$otherNode
49+
->addLabel('OtherNodeLabel')
50+
->addIdentifier('id', 234)
51+
->addProperty('hello', 'world :D')
52+
->addIdentifier('id');
53+
54+
$relation = new Relation();
55+
$relation
56+
->setStartNode($node)
57+
->setEndNode($node)
58+
->setType('SOME_RELATION');
59+
```
60+
61+
## Advanced integration
62+
63+
This library itself does not provide advanced features like validation. Those are separated into their own projects:
64+
65+
- Validation: Work in progress, not yet released.
66+
- [Entity Manager](https://github.com/neo4j-php/cypher-entity-manager): Automatically creates and runs Cypher statements
67+
from data objects of this library for you.

docs/_sidebar.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
- [Home](/)
2-
- [Getting Started](/getting_started.md)
32
- Types
4-
- [Property](/property.md)
53
- [Node](/node.md)
64
- [Relation](/relation.md)
75
- [Index](/type.index.md)

docs/getting_started.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

docs/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
3232
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-bash.min.js"></script>
3333
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-php.min.js"></script>
34+
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-cypher.min.js"></script>
3435
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-yaml.min.js"></script>
3536
</body>
3637
</html>

docs/node.md

Lines changed: 135 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,143 @@
11
# Node
22

3-
Nodes are entities which contain the following attributes:
4-
5-
- **NodeLabels**: Zero or more node labels, usually one. They are basically strings with validation. They must be
6-
CamelCase as per [Neo4j's documentation](https://neo4j.com/docs/cypher-manual/current/syntax/naming/#_recommendations)
7-
.
8-
Node labels can start with a single underscore, although this is reserved for internal logic.
9-
You can overwrite the validation part by creating your own implementation of
10-
`Syndesi\CypherDataStructures\Contract\NodeLabelInterface`.
11-
12-
- **Properties**: Zero or more properties, which are composed of one `PropertyName` for the key and a mixed property value.
13-
Within the node they are stored as an array-like storage. For more information see [property](property.md).
14-
15-
- **Identifiers**: The names of zero or more properties which uniquely identify the node. The referenced properties must
16-
contain a value.
17-
When removing identifying properties without removing the identifier first, an exception is triggered.
18-
19-
- **Relations**: A list of relations which either start or end at the node.
20-
The default implementation stores relations in [weak references](https://www.php.net/manual/en/class.weakreference.php)
21-
so when a relation is unset, the node's relation will become `null`. This is done to remove the possibility of cyclic
22-
references.
23-
Relations must contain the node itself as either the start or end node.
24-
25-
!> **Note**: Make sure that identifying elements (node labels, relation type, identifying properties) are set before
26-
referencing nodes to relations and vice versa.
27-
Changing those elements later does not update the existing references.
28-
29-
## Examples
3+
Nodes are the most basic data elements within a graph database.
4+
They can be created as following:
305

316
```php
32-
use Syndesi\CypherDataStructures\Type\NodeLabel;
337
use Syndesi\CypherDataStructures\Type\Node;
34-
use Syndesi\CypherDataStructures\Type\PropertyName;
358

369
$node = new Node();
37-
$node
38-
->addNodeLabel(new NodeLabel("SomeNode"))
39-
->addProperty(new PropertyName("id"), 1234)
40-
->addIdentifier(new PropertyName("id"));
10+
```
11+
12+
## Labels
13+
14+
Labels identify the node's type, e.g. a label called `User` would identify a node as a user and `Document` would
15+
identify it as a document.
16+
Nodes can have zero, one or more labels, although one label is the default.
17+
Labels [should be written in CamelCase](https://neo4j.com/docs/cypher-manual/current/syntax/naming/#_recommendations).
18+
19+
```php
20+
// add a single label to a node:
21+
$node->addLabel('FirstLabel');
22+
23+
// add multiple labels to a node:
24+
$node->addLabels(['SecondLabel', 'ThirdLabel']);
25+
26+
// check if a node has a label:
27+
$node->hasLabel('FirstLabel');
28+
29+
// get all labels from a node:
30+
$node->getLabels();
31+
32+
// remove a label from a node:
33+
$node->removeLabel('ThirdLabel');
34+
35+
// remove all labels from a node:
36+
$node->removeLabels();
37+
```
38+
39+
## Properties
40+
41+
Properties are key-value-pairs which can store data within a node.
42+
The keys must be unique and [should be written in camelCase](https://neo4j.com/docs/cypher-manual/current/styleguide/#cypher-styleguide-casing).
43+
44+
!> **Note**: While this library supports arrays and objects as property values, Neo4j has limited support for those types.
45+
Be sure that those types are correctly handled.
46+
47+
```php
48+
// add property to a node:
49+
$node->addProperty('propertyName', 'property value');
50+
51+
// add multiple properties to a node:
52+
$node->addProperties([
53+
'id' => 123,
54+
'hello' => 'world :D'
55+
]);
56+
57+
// check if a node has a specific property:
58+
$node->hasProperty('id');
59+
60+
// get the value of a specific property:
61+
$node->getProperty('id');
62+
63+
// get all properties from a node:
64+
$node->getProperties();
65+
66+
// remove a specific property from a node:
67+
$node->removeProperty('hello');
68+
69+
// remove all properties from a node:
70+
$node->removeProperties();
71+
```
72+
73+
### Identifying Properties
74+
75+
Identifying properties are just normal properties which are marked to identify the node uniquely within the database.
76+
77+
!> **Note**: Identifying properties are not part of the OpenCypher specification.
78+
79+
!> **Important**: Only existing properties can be marked as "identifying". Also, identifying properties can not be removed
80+
from the node as long as the identifying-mark is not removed.
81+
82+
```php
83+
// add identifying property to a node:
84+
$node->addProperty('id', 123);
85+
$node->addIdentifier('id');
86+
87+
// add multiple identifying properties to a node:
88+
$node->addProperties([
89+
'id2' => '234',
90+
'id3' => '345'
91+
]);
92+
$node->addIdentifiers(['id2', 'id3']);
93+
94+
// check if node has a specific identifying property:
95+
$node->hasIdentifier('id');
96+
97+
// get the value of a specific identifying property:
98+
$node->getIdentifier('id');
99+
100+
// get all identifying properties:
101+
$node->getIdentifiers();
102+
103+
// remove a specific identifying property mark without removing the property itself:
104+
$node->removeIdentifier('id');
105+
106+
// remove all identifying property marks without removing the properties themselves:
107+
$node->removeProperties();
108+
```
109+
110+
## Relations
111+
112+
Nodes can relate to other nodes and are connected to them via [relations](relation.md). Those must either start or end
113+
at the current node.
114+
115+
```php
116+
$node = new \Syndesi\CypherDataStructures\Type\Node();
117+
use Syndesi\CypherDataStructures\Type\Relation;
118+
119+
$relation = new Relation();
120+
$relation->setStartNode($node); // important: Relations must either start or end at the node itself
121+
$relation->setType('RELATION');
122+
123+
// add relation to node:
124+
$node->addRelation($relation);
125+
126+
// add relations to node:
127+
$node->addRelations([
128+
$relation,
129+
clone $relation
130+
]);
131+
132+
// check if a node has a specific relation
133+
$node->hasRelation($relation);
134+
135+
// get all relations from a node
136+
$node->getRelations();
137+
138+
// remove a specific relation from a node:
139+
$node->removeRelation($relation);
140+
141+
// remove all relations from a node:
142+
$node->removeRelations();
41143
```

docs/property.md

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)