|
26 | 26 | use Bolt\protocol\v1\structures\Relationship as BoltRelationship; |
27 | 27 | use Bolt\protocol\v1\structures\Time as BoltTime; |
28 | 28 | use Bolt\protocol\v1\structures\UnboundRelationship as BoltUnboundRelationship; |
| 29 | +use Bolt\protocol\v6\structures\Vector as BoltVector; |
| 30 | +use Laudis\Neo4j\Enum\VectorTypeMarker; |
29 | 31 | use Laudis\Neo4j\Formatter\SummarizedResultFormatter; |
30 | 32 | use Laudis\Neo4j\Types\Abstract3DPoint; |
31 | 33 | use Laudis\Neo4j\Types\AbstractPoint; |
|
44 | 46 | use Laudis\Neo4j\Types\Relationship; |
45 | 47 | use Laudis\Neo4j\Types\Time; |
46 | 48 | use Laudis\Neo4j\Types\UnboundRelationship; |
| 49 | +use Laudis\Neo4j\Types\Vector; |
47 | 50 | use Laudis\Neo4j\Types\WGS843DPoint; |
48 | 51 | use Laudis\Neo4j\Types\WGS84Point; |
49 | 52 | use UnexpectedValueException; |
@@ -81,6 +84,7 @@ public function __construct() |
81 | 84 | BoltPoint2D::class => $this->makeFromBoltPoint2D(...), |
82 | 85 | BoltPoint3D::class => $this->makeFromBoltPoint3D(...), |
83 | 86 | BoltDateTimeZoneId::class => $this->makeBoltTimezoneIdentifier(...), |
| 87 | + BoltVector::class => $this->makeFromBoltVector(...), |
84 | 88 | 'array' => $this->mapArray(...), |
85 | 89 | 'int' => static fn (int $x): int => $x, |
86 | 90 | 'null' => static fn (): ?object => null, |
@@ -268,6 +272,18 @@ private function makeFromBoltPoint3D(BoltPoint3D $x): Abstract3DPoint |
268 | 272 | throw new UnexpectedValueException('An srid of '.$x->srid.' has been returned, which has not been implemented.'); |
269 | 273 | } |
270 | 274 |
|
| 275 | + private function makeFromBoltVector(BoltVector $value): Vector |
| 276 | + { |
| 277 | + /** @psalm-suppress ImpureMethodCall Vector::decode() only reads protocol data but Psalm treats Bolt structures as potentially stateful */ |
| 278 | + $decoded = $value->decode(); |
| 279 | + // Cast to string then read first byte to avoid Bytes::offsetGet (ImpureMethodCall) and to satisfy Psalm that ord() never receives null |
| 280 | + $bytesStr = (string) $value->type_marker; |
| 281 | + $markerByte = $bytesStr !== '' ? ord($bytesStr[0]) : null; |
| 282 | + $typeMarker = $markerByte !== null ? VectorTypeMarker::tryFrom($markerByte) : null; |
| 283 | + |
| 284 | + return new Vector(array_values($decoded), $typeMarker); |
| 285 | + } |
| 286 | + |
271 | 287 | private function makeFromBoltPath(BoltPath $path): Path |
272 | 288 | { |
273 | 289 | $nodes = []; |
|
0 commit comments