File tree Expand file tree Collapse file tree 4 files changed +87
-2
lines changed Expand file tree Collapse file tree 4 files changed +87
-2
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace WikibaseSolutions \CypherDSL \Patterns ;
4
+
5
+ use WikibaseSolutions \CypherDSL \Traits \PathTrait ;
6
+ use WikibaseSolutions \CypherDSL \Types \StructuralTypes \PathType ;
7
+ use WikibaseSolutions \CypherDSL \Types \StructuralTypes \StructuralType ;
8
+
9
+ class Path implements PathType
10
+ {
11
+ use PathTrait;
12
+
13
+ /** @var Relationship[] */
14
+ private array $ relationships = [];
15
+
16
+ public function __construct ()
17
+ {
18
+ }
19
+
20
+ public function toQuery (): string
21
+ {
22
+ $ cql = '' ;
23
+ if ($ this ->getVariable () !== null ) {
24
+ $ cql = $ this ->getName ()->toQuery () . ' = ' ;
25
+ }
26
+
27
+ foreach ($ this ->relationships as $ relationship ) {
28
+ $ cql .= $ relationship ->getLeft ()->toQuery ();
29
+ $ cql .= $ relationship ->toRelationshipQuery ();
30
+ }
31
+
32
+ if (isset ($ relationship )) {
33
+ $ cql .= $ relationship ->getRight ()->toQuery ();
34
+ }
35
+
36
+ return $ cql ;
37
+ }
38
+
39
+ public function relationshipTo (StructuralType $ pattern ): Path
40
+ {
41
+ $ this ->relationships [] = $ this ->getLatestNode ()->relationshipUni ($ pattern );
42
+
43
+ return $ this ;
44
+ }
45
+
46
+ public function relationshipFrom (StructuralType $ pattern ): Path
47
+ {
48
+ $ this ->relationships [] = $ this ->getLatestNode ()->relationshipUni ($ pattern );
49
+
50
+ return $ this ;
51
+ }
52
+
53
+ public function relationshipUni (StructuralType $ pattern ): Path
54
+ {
55
+ $ this ->relationships [] = $ this ->getLatestNode ()->relationshipUni ($ pattern );
56
+
57
+ return $ this ;
58
+ }
59
+
60
+ private function getLatestNode (): StructuralType
61
+ {
62
+ return $ this ->relationships [count ($ this ->relationships ) - 1 ]->getRight ();
63
+ }
64
+ }
Original file line number Diff line number Diff line change 24
24
use DomainException ;
25
25
use InvalidArgumentException ;
26
26
use LogicException ;
27
+ use WikibaseSolutions \CypherDSL \Property ;
27
28
use WikibaseSolutions \CypherDSL \Traits \EscapeTrait ;
28
29
use WikibaseSolutions \CypherDSL \Traits \RelationshipTrait ;
29
30
use WikibaseSolutions \CypherDSL \Types \StructuralTypes \RelationshipType ;
@@ -201,7 +202,7 @@ public function toQuery(): string
201
202
$ a = $ this ->left ->toQuery ();
202
203
$ b = $ this ->right ->toQuery ();
203
204
204
- return $ a . $ this ->direction [ 0 ] . $ this -> conditionToString () . $ this -> direction [ 1 ] . $ b ;
205
+ return $ a . $ this ->toRelationshipQuery () . $ b ;
205
206
}
206
207
207
208
/**
@@ -327,4 +328,14 @@ public function property(string $property): Property
327
328
{
328
329
return new Property ($ this ->getName (), $ property );
329
330
}
331
+
332
+ /**
333
+ * Returns the relationship part of the pattern without the nodes.
334
+ *
335
+ * @return string
336
+ */
337
+ public function toRelationshipQuery (): string
338
+ {
339
+ return $ this ->direction [0 ] . $ this ->conditionToString () . $ this ->direction [1 ];
340
+ }
330
341
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace WikibaseSolutions \CypherDSL \Traits ;
4
+
5
+ trait PathTrait
6
+ {
7
+ use HasVariableTrait;
8
+ }
Original file line number Diff line number Diff line change 21
21
22
22
namespace WikibaseSolutions \CypherDSL \Types \StructuralTypes ;
23
23
24
+ use WikibaseSolutions \CypherDSL \Types \AnyType ;
25
+
24
26
/**
25
27
* Represents the type "node".
26
28
*/
27
- interface PathType extends StructuralType
29
+ interface PathType extends AnyType
28
30
{
29
31
}
You can’t perform that action at this time.
0 commit comments