33
33
use function is_string ;
34
34
35
35
use Laudis \Neo4j \Contracts \BoltConvertibleInterface ;
36
+ use Laudis \Neo4j \Enum \ConnectionProtocol ;
36
37
use Laudis \Neo4j \Types \CypherList ;
37
38
use Laudis \Neo4j \Types \CypherMap ;
38
39
use stdClass ;
@@ -80,13 +81,13 @@ public static function asMap(iterable $iterable): CypherMap
80
81
*/
81
82
public static function asParameter (
82
83
mixed $ value ,
83
- bool $ boltDriver = false
84
+ ConnectionProtocol $ protocol
84
85
): iterable |int |float |bool |string |stdClass |IStructure |null {
85
86
return self ::cypherMapToStdClass ($ value ) ??
86
87
self ::emptySequenceToArray ($ value ) ??
87
- self ::convertBoltConvertibles ($ value , $ boltDriver ) ??
88
- self ::convertTemporalTypes ($ value , $ boltDriver ) ??
89
- self ::filledIterableToArray ($ value , $ boltDriver ) ??
88
+ self ::convertBoltConvertibles ($ value , $ protocol ) ??
89
+ self ::convertTemporalTypes ($ value , $ protocol ) ??
90
+ self ::filledIterableToArray ($ value , $ protocol ) ??
90
91
self ::stringAbleToString ($ value ) ??
91
92
self ::filterInvalidType ($ value );
92
93
}
@@ -148,10 +149,10 @@ private static function cypherMapToStdClass(mixed $value): ?stdClass
148
149
return null ;
149
150
}
150
151
151
- private static function filledIterableToArray (mixed $ value , bool $ boltDriver ): ?array
152
+ private static function filledIterableToArray (mixed $ value , ConnectionProtocol $ protocol ): ?array
152
153
{
153
154
if (is_iterable ($ value )) {
154
- return self ::iterableToArray ($ value , $ boltDriver );
155
+ return self ::iterableToArray ($ value , $ protocol );
155
156
}
156
157
157
158
return null ;
@@ -162,7 +163,7 @@ private static function filledIterableToArray(mixed $value, bool $boltDriver): ?
162
163
*
163
164
* @return CypherMap<iterable|scalar|stdClass|null>
164
165
*/
165
- public static function formatParameters (iterable $ parameters , bool $ boltDriver = false ): CypherMap
166
+ public static function formatParameters (iterable $ parameters , ConnectionProtocol $ connection ): CypherMap
166
167
{
167
168
/** @var array<string, iterable|scalar|stdClass|null> $tbr */
168
169
$ tbr = [];
@@ -175,13 +176,13 @@ public static function formatParameters(iterable $parameters, bool $boltDriver =
175
176
$ msg = 'The parameters must have an integer or string as key values, ' .gettype ($ key ).' received. ' ;
176
177
throw new InvalidArgumentException ($ msg );
177
178
}
178
- $ tbr [(string ) $ key ] = self ::asParameter ($ value , $ boltDriver );
179
+ $ tbr [(string ) $ key ] = self ::asParameter ($ value , $ connection );
179
180
}
180
181
181
182
return new CypherMap ($ tbr );
182
183
}
183
184
184
- private static function iterableToArray (iterable $ value , bool $ boltDriver ): array
185
+ private static function iterableToArray (iterable $ value , ConnectionProtocol $ protocol ): array
185
186
{
186
187
$ tbr = [];
187
188
/**
@@ -190,7 +191,7 @@ private static function iterableToArray(iterable $value, bool $boltDriver): arra
190
191
*/
191
192
foreach ($ value as $ key => $ val ) {
192
193
if (is_int ($ key ) || is_string ($ key )) {
193
- $ tbr [$ key ] = self ::asParameter ($ val , $ boltDriver );
194
+ $ tbr [$ key ] = self ::asParameter ($ val , $ protocol );
194
195
} else {
195
196
$ msg = 'Iterable parameters must have an integer or string as key values, ' .gettype ($ key ).' received. ' ;
196
197
throw new InvalidArgumentException ($ msg );
@@ -200,19 +201,27 @@ private static function iterableToArray(iterable $value, bool $boltDriver): arra
200
201
return $ tbr ;
201
202
}
202
203
203
- private static function convertBoltConvertibles (mixed $ value , bool $ boltDriver ): ?IStructure
204
+ private static function convertBoltConvertibles (mixed $ value , ConnectionProtocol $ protocol ): ?IStructure
204
205
{
205
- if ($ boltDriver && $ value instanceof BoltConvertibleInterface) {
206
+ if ($ protocol -> isBolt () && $ value instanceof BoltConvertibleInterface) {
206
207
return $ value ->convertToBolt ();
207
208
}
208
209
209
210
return null ;
210
211
}
211
212
212
- private static function convertTemporalTypes (mixed $ value , bool $ boltDriver ): ?IStructure
213
+ private static function convertTemporalTypes (mixed $ value , ConnectionProtocol $ protocol ): ?IStructure
213
214
{
214
- if ($ boltDriver ) {
215
+ if ($ protocol -> isBolt () ) {
215
216
if ($ value instanceof DateTimeInterface) {
217
+ if ($ protocol ->compare (ConnectionProtocol::BOLT_V44 ()) > 0 ) {
218
+ return new \Bolt \protocol \v5 \structures \DateTimeZoneId (
219
+ $ value ->getTimestamp (),
220
+ ((int ) $ value ->format ('u ' )) * 1000 ,
221
+ $ value ->getTimezone ()->getName ()
222
+ );
223
+ }
224
+
216
225
return new DateTimeZoneId (
217
226
$ value ->getTimestamp (),
218
227
((int ) $ value ->format ('u ' )) * 1000 ,
0 commit comments