Skip to content

Commit 0d13fdf

Browse files
authored
Merge pull request #14 from WikibaseSolutions/point-and-date-support
Add point and date support
2 parents 0a6e28d + c05904d commit 0d13fdf

34 files changed

+3595
-37
lines changed

src/Functions/Date.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/*
4+
* Cypher DSL
5+
* Copyright (C) 2021 Wikibase Solutions
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License
9+
* as published by the Free Software Foundation; either version 2
10+
* of the License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20+
*/
21+
22+
namespace WikibaseSolutions\CypherDSL\Functions;
23+
24+
use WikibaseSolutions\CypherDSL\Traits\DateTrait;
25+
use WikibaseSolutions\CypherDSL\Types\AnyType;
26+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\DateType;
27+
28+
/**
29+
* This class represents the "date()" function.
30+
*
31+
* @note You most likely do not want to use this function directly. You probably want to use the Literal
32+
* class to construct these objects for you.
33+
*
34+
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-date
35+
*/
36+
class Date extends FunctionCall implements DateType
37+
{
38+
use DateTrait;
39+
40+
/**
41+
* @var AnyType|null The input to the date function, from which to construct the date
42+
*/
43+
private ?AnyType $value;
44+
45+
/**
46+
* Date constructor. The signature of the "date()" function is:
47+
*
48+
* date(input = DEFAULT_TEMPORAL_ARGUMENT :: ANY?) :: (DATE?)
49+
*
50+
* @param AnyType|null $value The input to the date function, from which to construct the date
51+
*/
52+
public function __construct(?AnyType $value = null)
53+
{
54+
$this->value = $value;
55+
}
56+
57+
/**
58+
* @inheritDoc
59+
*/
60+
protected function getSignature(): string
61+
{
62+
return $this->value ? "date(%s)" : "date()";
63+
}
64+
65+
/**
66+
* @inheritDoc
67+
*/
68+
protected function getParameters(): array
69+
{
70+
return $this->value ? [$this->value] : [];
71+
}
72+
}

src/Functions/DateTime.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/*
4+
* Cypher DSL
5+
* Copyright (C) 2021 Wikibase Solutions
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License
9+
* as published by the Free Software Foundation; either version 2
10+
* of the License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20+
*/
21+
22+
namespace WikibaseSolutions\CypherDSL\Functions;
23+
24+
use WikibaseSolutions\CypherDSL\Traits\DateTimeTrait;
25+
use WikibaseSolutions\CypherDSL\Types\AnyType;
26+
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\DateTimeType;
27+
28+
/**
29+
* This class represents the "datetime()" function.
30+
*
31+
* @note You most likely do not want to use this function directly. You probably want to use the Literal
32+
* class to construct these objects for you.
33+
*
34+
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-datetime
35+
*/
36+
class DateTime extends FunctionCall implements DateTimeType
37+
{
38+
use DateTimeTrait;
39+
40+
/**
41+
* @var AnyType|null The input to the datetime function, from which to construct the datetime
42+
*/
43+
private ?AnyType $value;
44+
45+
/**
46+
* DateTime constructor. The signature of the "datetime()" function is:
47+
*
48+
* datetime(input = DEFAULT_TEMPORAL_ARGUMENT :: ANY?) :: (DATETIME?)
49+
*
50+
* @param AnyType|null $value The input to the datetime function, from which to construct the datetime
51+
*/
52+
public function __construct(?AnyType $value = null)
53+
{
54+
$this->value = $value;
55+
}
56+
57+
/**
58+
* @inheritDoc
59+
*/
60+
protected function getSignature(): string
61+
{
62+
return $this->value ? "datetime(%s)" : "datetime()";
63+
}
64+
65+
/**
66+
* @inheritDoc
67+
*/
68+
protected function getParameters(): array
69+
{
70+
return $this->value ? [$this->value] : [];
71+
}
72+
}

src/Functions/FunctionCall.php

Lines changed: 108 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ abstract class FunctionCall implements QueryConvertable
4141
*
4242
* @param string $functionName The name of the function to call
4343
* @param AnyType[] $parameters The parameters to pass to the function call
44-
* @return FunctionCall
44+
*
45+
* @return RawFunction
4546
*/
46-
public static function raw(string $functionName, array $parameters): FunctionCall
47+
public static function raw(string $functionName, array $parameters): RawFunction
4748
{
4849
return new RawFunction($functionName, $parameters);
4950
}
@@ -56,9 +57,10 @@ public static function raw(string $functionName, array $parameters): FunctionCal
5657
* @param Variable $variable A variable that can be used from within the predicate
5758
* @param ListType $list A list
5859
* @param AnyType $predicate A predicate that is tested against all items in the list
59-
* @return FunctionCall
60+
*
61+
* @return All
6062
*/
61-
public static function all(Variable $variable, ListType $list, AnyType $predicate): FunctionCall
63+
public static function all(Variable $variable, ListType $list, AnyType $predicate): All
6264
{
6365
return new All($variable, $list, $predicate);
6466
}
@@ -72,9 +74,9 @@ public static function all(Variable $variable, ListType $list, AnyType $predicat
7274
* @param ListType $list A list
7375
* @param AnyType $predicate A predicate that is tested against all items in the list
7476
*
75-
* @return FunctionCall
77+
* @return Any
7678
*/
77-
public static function any(Variable $variable, ListType $list, AnyType $predicate): FunctionCall
79+
public static function any(Variable $variable, ListType $list, AnyType $predicate): Any
7880
{
7981
return new Any($variable, $list, $predicate);
8082
}
@@ -85,9 +87,10 @@ public static function any(Variable $variable, ListType $list, AnyType $predicat
8587
* exists(input :: ANY?) :: (BOOLEAN?)
8688
*
8789
* @param AnyType $expression A pattern or property
88-
* @return FunctionCall
90+
*
91+
* @return Exists
8992
*/
90-
public static function exists(AnyType $expression): FunctionCall
93+
public static function exists(AnyType $expression): Exists
9194
{
9295
return new Exists($expression);
9396
}
@@ -100,9 +103,10 @@ public static function exists(AnyType $expression): FunctionCall
100103
* isEmpty(input :: STRING?) :: (BOOLEAN?) - to check whether a string is empty
101104
*
102105
* @param ListType|MapType|StringType $list An expression that returns a list
103-
* @return FunctionCall
106+
*
107+
* @return IsEmpty
104108
*/
105-
public static function isEmpty(AnyType $list): FunctionCall
109+
public static function isEmpty(AnyType $list): IsEmpty
106110
{
107111
return new IsEmpty($list);
108112
}
@@ -116,9 +120,9 @@ public static function isEmpty(AnyType $list): FunctionCall
116120
* @param ListType $list A list
117121
* @param AnyType $predicate A predicate that is tested against all items in the list
118122
*
119-
* @return FunctionCall
123+
* @return None
120124
*/
121-
public static function none(Variable $variable, ListType $list, AnyType $predicate): FunctionCall
125+
public static function none(Variable $variable, ListType $list, AnyType $predicate): None
122126
{
123127
return new None($variable, $list, $predicate);
124128
}
@@ -132,13 +136,103 @@ public static function none(Variable $variable, ListType $list, AnyType $predica
132136
* @param ListType $list A list
133137
* @param AnyType $predicate A predicate that is tested against all items in the list
134138
*
135-
* @return FunctionCall
139+
* @return Single
136140
*/
137-
public static function single(Variable $variable, ListType $list, AnyType $predicate): FunctionCall
141+
public static function single(Variable $variable, ListType $list, AnyType $predicate): Single
138142
{
139143
return new Single($variable, $list, $predicate);
140144
}
141145

146+
/**
147+
* Calls the "point()" function. The signature of the "point()" function is:
148+
*
149+
* point(input :: MAP?) :: (POINT?)
150+
*
151+
* @param MapType $map The map to use for constructing the point
152+
* @note You probably want to use the Literal class instead of this function
153+
*
154+
* @return Point
155+
*/
156+
public static function point(MapType $map): Point
157+
{
158+
return new Point($map);
159+
}
160+
161+
/**
162+
* Calls the "date()" function. The signature of the "date()" function is:
163+
*
164+
* date(input = DEFAULT_TEMPORAL_ARGUMENT :: ANY?) :: (DATE?)
165+
*
166+
* @param AnyType|null $value The input to the date function, from which to construct the date
167+
* @note You probably want to use the Literal class instead of this function
168+
*
169+
* @return Date
170+
*/
171+
public static function date(?AnyType $value = null): Date
172+
{
173+
return new Date($value);
174+
}
175+
176+
/**
177+
* Calls the "datetime()" function. The signature of the "datetime()" function is:
178+
*
179+
* datetime(input = DEFAULT_TEMPORAL_ARGUMENT :: ANY?) :: (DATETIME?)
180+
*
181+
* @param AnyType|null $value The input to the datetime function, from which to construct the datetime
182+
* @note You probably want to use the Literal class instead of this function
183+
*
184+
* @return DateTime
185+
*/
186+
public static function datetime(?AnyType $value = null): DateTime
187+
{
188+
return new DateTime($value);
189+
}
190+
191+
/**
192+
* Calls the "localdatetime()" function. The signature of the "localdatetime()" function is:
193+
*
194+
* datetime(input = DEFAULT_TEMPORAL_ARGUMENT :: ANY?) :: (LOCALDATETIME?)
195+
*
196+
* @param AnyType|null $value The input to the localdatetime function, from which to construct the localdatetime
197+
* @note You probably want to use the Literal class instead of this function
198+
*
199+
* @return LocalDateTime
200+
*/
201+
public static function localdatetime(?AnyType $value = null): LocalDateTime
202+
{
203+
return new LocalDateTime($value);
204+
}
205+
206+
/**
207+
* Calls the "localtime()" function. The signature of the "localtime()" function is:
208+
*
209+
* localtime(input = DEFAULT_TEMPORAL_ARGUMENT :: ANY?) :: (LOCALTIME?)
210+
*
211+
* @param AnyType|null $value The input to the localtime function, from which to construct the localtime
212+
* @note You probably want to use the Literal class instead of this function
213+
*
214+
* @return LocalTime
215+
*/
216+
public static function localtime(?AnyType $value = null): LocalTime
217+
{
218+
return new LocalTime($value);
219+
}
220+
221+
/**
222+
* Calls the "time()" function. The signature of the "time()" function is:
223+
*
224+
* time(input = DEFAULT_TEMPORAL_ARGUMENT :: ANY?) :: (TIME?)
225+
*
226+
* @param AnyType|null $value The input to the localtime function, from which to construct the time
227+
* @note You probably want to use the Literal class instead of this function
228+
*
229+
* @return Time
230+
*/
231+
public static function time(?AnyType $value = null): Time
232+
{
233+
return new Time($value);
234+
}
235+
142236
/**
143237
* @inheritDoc
144238
*/

0 commit comments

Comments
 (0)