Skip to content

Commit e692e72

Browse files
committed
Added BoltConvertible Implementations
1 parent bb82279 commit e692e72

File tree

8 files changed

+78
-8
lines changed

8 files changed

+78
-8
lines changed
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Laudis Neo4j package.
7+
*
8+
* (c) Laudis technologies <http://laudis.tech>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
314
namespace Laudis\Neo4j\Contracts;
415

16+
use Bolt\structures\IStructure;
17+
518
interface BoltConvertibleInterface
619
{
7-
20+
public function convertToBolt(): IStructure;
821
}

src/Types/Cartesian3DPoint.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
namespace Laudis\Neo4j\Types;
1515

16+
use Bolt\structures\IStructure;
17+
use Bolt\structures\Point3D;
18+
use Laudis\Neo4j\Contracts\BoltConvertibleInterface;
1619
use Laudis\Neo4j\Contracts\PointInterface;
1720

1821
/**
@@ -24,10 +27,15 @@
2427
*
2528
* @psalm-import-type Crs from \Laudis\Neo4j\Contracts\PointInterface
2629
*/
27-
class Cartesian3DPoint extends CartesianPoint implements PointInterface
30+
class Cartesian3DPoint extends CartesianPoint implements PointInterface, BoltConvertibleInterface
2831
{
2932
private float $z;
3033

34+
public function convertToBolt(): IStructure
35+
{
36+
return new Point3D($this->getSrid(), $this->getX(), $this->getY(), $this->getZ());
37+
}
38+
3139
/**
3240
* @param Crs $crs
3341
*/

src/Types/CartesianPoint.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
namespace Laudis\Neo4j\Types;
1515

16+
use Bolt\structures\IStructure;
17+
use Bolt\structures\Point2D;
18+
use Laudis\Neo4j\Contracts\BoltConvertibleInterface;
1619
use Laudis\Neo4j\Contracts\PointInterface;
1720

1821
/**
@@ -24,7 +27,7 @@
2427
*
2528
* @psalm-import-type Crs from \Laudis\Neo4j\Contracts\PointInterface
2629
*/
27-
class CartesianPoint extends AbstractPropertyObject implements PointInterface
30+
class CartesianPoint extends AbstractPropertyObject implements PointInterface, BoltConvertibleInterface
2831
{
2932
private float $x;
3033
private float $y;
@@ -43,6 +46,11 @@ public function __construct(float $x, float $y, string $crs, int $srid)
4346
$this->srid = $srid;
4447
}
4548

49+
public function convertToBolt(): IStructure
50+
{
51+
return new Point2D($this->getSrid(), $this->getX(), $this->getY());
52+
}
53+
4654
public function getX(): float
4755
{
4856
return $this->x;

src/Types/Date.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
namespace Laudis\Neo4j\Types;
1515

16+
use Bolt\structures\IStructure;
1617
use DateTimeImmutable;
1718
use Exception;
19+
use Laudis\Neo4j\Contracts\BoltConvertibleInterface;
1820

1921
/**
2022
* A date represented by days since unix epoch.
@@ -23,7 +25,7 @@
2325
*
2426
* @extends AbstractPropertyObject<int, int>
2527
*/
26-
final class Date extends AbstractPropertyObject
28+
final class Date extends AbstractPropertyObject implements BoltConvertibleInterface
2729
{
2830
private int $days;
2931

@@ -59,4 +61,9 @@ public function toArray(): array
5961
{
6062
return ['days' => $this->days];
6163
}
64+
65+
public function convertToBolt(): IStructure
66+
{
67+
return new \Bolt\structures\Date($this->getDays());
68+
}
6269
}

src/Types/DateTime.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313

1414
namespace Laudis\Neo4j\Types;
1515

16+
use Bolt\structures\IStructure;
1617
use DateTimeImmutable;
1718
use DateTimeZone;
1819
use Exception;
20+
use Laudis\Neo4j\Contracts\BoltConvertibleInterface;
1921
use RuntimeException;
2022
use function sprintf;
2123

@@ -26,7 +28,7 @@
2628
*
2729
* @extends AbstractPropertyObject<int, int>
2830
*/
29-
final class DateTime extends AbstractPropertyObject
31+
final class DateTime extends AbstractPropertyObject implements BoltConvertibleInterface
3032
{
3133
private int $seconds;
3234
private int $nanoseconds;
@@ -100,4 +102,9 @@ public function getProperties(): CypherMap
100102
{
101103
return new CypherMap($this);
102104
}
105+
106+
public function convertToBolt(): IStructure
107+
{
108+
return new \Bolt\structures\DateTime($this->getSeconds(), $this->getNanoseconds(), $this->getTimeZoneOffsetSeconds());
109+
}
103110
}

src/Types/Duration.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
namespace Laudis\Neo4j\Types;
1515

16+
use Bolt\structures\IStructure;
1617
use DateInterval;
1718
use Exception;
19+
use Laudis\Neo4j\Contracts\BoltConvertibleInterface;
1820

1921
/**
2022
* A temporal range represented in months, days, seconds and nanoseconds.
@@ -23,7 +25,7 @@
2325
*
2426
* @extends AbstractPropertyObject<int, int>
2527
*/
26-
final class Duration extends AbstractPropertyObject
28+
final class Duration extends AbstractPropertyObject implements BoltConvertibleInterface
2729
{
2830
private int $months;
2931
private int $days;
@@ -97,4 +99,14 @@ public function getProperties(): CypherMap
9799
{
98100
return new CypherMap($this);
99101
}
102+
103+
public function convertToBolt(): IStructure
104+
{
105+
return new \Bolt\structures\Duration(
106+
$this->getMonths(),
107+
$this->getDays(),
108+
$this->getSeconds(),
109+
$this->getNanoseconds()
110+
);
111+
}
100112
}

src/Types/LocalDateTime.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
namespace Laudis\Neo4j\Types;
1515

16+
use Bolt\structures\IStructure;
1617
use DateTimeImmutable;
1718
use Exception;
19+
use Laudis\Neo4j\Contracts\BoltConvertibleInterface;
1820
use function sprintf;
1921

2022
/**
@@ -24,7 +26,7 @@
2426
*
2527
* @extends AbstractPropertyObject<int, int>
2628
*/
27-
final class LocalDateTime extends AbstractPropertyObject
29+
final class LocalDateTime extends AbstractPropertyObject implements BoltConvertibleInterface
2830
{
2931
private int $seconds;
3032
private int $nanoseconds;
@@ -75,4 +77,9 @@ public function getProperties(): CypherMap
7577
{
7678
return new CypherMap($this);
7779
}
80+
81+
public function convertToBolt(): IStructure
82+
{
83+
return new \Bolt\structures\LocalDateTime($this->getSeconds(), $this->getNanoseconds());
84+
}
7885
}

src/Types/LocalTime.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313

1414
namespace Laudis\Neo4j\Types;
1515

16+
use Bolt\structures\IStructure;
17+
use Laudis\Neo4j\Contracts\BoltConvertibleInterface;
18+
1619
/**
1720
* The time of day represented in nanoseconds.
1821
*
1922
* @psalm-immutable
2023
*
2124
* @extends AbstractPropertyObject<int, int>
2225
*/
23-
final class LocalTime extends AbstractPropertyObject
26+
final class LocalTime extends AbstractPropertyObject implements BoltConvertibleInterface
2427
{
2528
private int $nanoseconds;
2629

@@ -49,4 +52,9 @@ public function getProperties(): CypherMap
4952
{
5053
return new CypherMap($this);
5154
}
55+
56+
public function convertToBolt(): IStructure
57+
{
58+
return new \Bolt\structures\LocalTime($this->getNanoseconds());
59+
}
5260
}

0 commit comments

Comments
 (0)