Skip to content

Commit

Permalink
Upgrade to doctrine/orm v3 & doctrine/dbal v4
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Dec 19, 2024
1 parent 1d22337 commit a515bd0
Show file tree
Hide file tree
Showing 34 changed files with 121 additions and 224 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:

services:
mariadb:
image: "mariadb:10.1"
image: "mariadb:10.11"
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
options: >-
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## [0.4.0](https://github.com/brick/geo-doctrine/releases/tag/0.4.0) - 2024-12-19

💥 **Breaking changes**

- compatibility with `doctrine/orm` `3.x` (`2.x` is no longer supported)
- compatibility with `doctrine/dbal` `4.x` (`2.x` and `3.x` are no longer supported)

🐛 **Bug fixes**

- `GeometryType::convertToDatabaseValue()` now properly throws `ConversionException` as it should

## [0.3.1](https://github.com/brick/geo-doctrine/releases/tag/0.3.1) - 2024-06-07

**Upgrades**
Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
"require": {
"php": "^8.1",
"brick/geo": "~0.10.0 || ~0.11.0",
"doctrine/orm": "^2.8"
"doctrine/dbal": "^4.0",
"doctrine/orm": "^3.0"
},
"require-dev": {
"doctrine/annotations": "^1.0",
"ext-pdo": "*",
"doctrine/cache": "^1.11",
"doctrine/data-fixtures": "^1.0",
"doctrine/data-fixtures": "^1.7",
"guzzlehttp/guzzle": "^7.0",
"phpunit/phpunit": "^10.5",
"php-coveralls/php-coveralls": "^2.7",
"vimeo/psalm": "5.21.1"
"vimeo/psalm": "5.21.1",
"symfony/cache": "^5.0 || ^6.0 || ^7.0"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 5 additions & 5 deletions src/Functions/AbstractFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Brick\Geo\Doctrine\Functions;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\TokenType;

/**
* Base class for Doctrine functions.
Expand Down Expand Up @@ -44,20 +44,20 @@ public function parse(Parser $parser) : void
{
$this->args = [];

$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$parser->match(TokenType::T_IDENTIFIER);
$parser->match(TokenType::T_OPEN_PARENTHESIS);

$parameterCount = $this->getParameterCount();

for ($i = 0; $i < $parameterCount; $i++) {
if ($i !== 0) {
$parser->match(Lexer::T_COMMA);
$parser->match(TokenType::T_COMMA);
}

/** @psalm-suppress InvalidPropertyAssignmentValue */
$this->args[] = $parser->ArithmeticPrimary();
}

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
}
}
2 changes: 1 addition & 1 deletion src/Types/GeometryCollectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class GeometryCollectionType extends GeometryType
{
public function getName() : string
protected function getGeometryName() : string
{
return 'GeometryCollection';
}
Expand Down
33 changes: 15 additions & 18 deletions src/Types/GeometryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

namespace Brick\Geo\Doctrine\Types;

use Brick\DateTime\LocalDateTime;
use Brick\Geo\Geometry;
use Brick\Geo\IO\WKBReader;
use Brick\Geo\Proxy\GeometryProxy;
use Brick\Geo\Proxy\ProxyInterface;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Types\Exception\InvalidType;
use Doctrine\DBAL\Types\Type;

/**
Expand Down Expand Up @@ -50,18 +53,18 @@ protected function hasKnownSubclasses() : bool
return true;
}

public function getName() : string
protected function getGeometryName() : string
{
return 'Geometry';
}

public function getSQLDeclaration(array $column, AbstractPlatform $platform) : string
{
if ($platform instanceof PostgreSQLPlatform) {
return 'GEOMETRY';
return 'Geometry';
}

return strtoupper($this->getName());
return $this->getGeometryName();
}

public function convertToPHPValue($value, AbstractPlatform $platform) : ?Geometry
Expand Down Expand Up @@ -99,10 +102,14 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) : ?st
return $value->asBinary();
}

throw new \UnexpectedValueException(sprintf('Expected %s, got %s.', Geometry::class, get_debug_type($value)));
throw InvalidType::new(
$value,
static::class,
[Geometry::class, 'null'],
);
}

public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform) : string
public function convertToDatabaseValueSQL(string $sqlExpr, AbstractPlatform $platform) : string
{
if ($platform instanceof AbstractMySQLPlatform) {
$sqlExpr = sprintf('BINARY %s', $sqlExpr);
Expand All @@ -111,23 +118,13 @@ public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
return sprintf('ST_GeomFromWKB(%s, %d)', $sqlExpr, self::$srid);
}

public function convertToPHPValueSQL($sqlExpr, $platform) : string
public function convertToPHPValueSQL(string $sqlExpr, AbstractPlatform $platform) : string
{
return sprintf('ST_AsBinary(%s)', $sqlExpr);
}

public function canRequireSQLConversion() : bool
public function getBindingType() : ParameterType
{
return true;
}

public function requiresSQLCommentHint(AbstractPlatform $platform) : bool
{
return true;
}

public function getBindingType() : int
{
return \PDO::PARAM_LOB;
return ParameterType::LARGE_OBJECT;
}
}
2 changes: 1 addition & 1 deletion src/Types/LineStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class LineStringType extends GeometryType
{
public function getName() : string
protected function getGeometryName() : string
{
return 'LineString';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Types/MultiLineStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class MultiLineStringType extends GeometryType
{
public function getName() : string
protected function getGeometryName() : string
{
return 'MultiLineString';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Types/MultiPointType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class MultiPointType extends GeometryType
{
public function getName() : string
protected function getGeometryName() : string
{
return 'MultiPoint';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Types/MultiPolygonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class MultiPolygonType extends GeometryType
{
public function getName() : string
protected function getGeometryName() : string
{
return 'MultiPolygon';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Types/PointType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class PointType extends GeometryType
{
public function getName() : string
protected function getGeometryName() : string
{
return 'Point';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Types/PolygonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class PolygonType extends GeometryType
{
public function getName() : string
protected function getGeometryName() : string
{
return 'Polygon';
}
Expand Down
2 changes: 1 addition & 1 deletion tests/DataFixtures/LoadGeometryData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LoadGeometryData implements FixtureInterface
public function load(ObjectManager $manager): void
{
$point1 = new GeometryEntity();
$point1->setGeometry(Point::xy(1, 2));
$point1->geometry = Point::xy(1, 2);

$manager->persist($point1);
$manager->flush();
Expand Down
2 changes: 1 addition & 1 deletion tests/DataFixtures/LoadLineStringData.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function load(ObjectManager $manager): void
$point3 = Point::xy(1,1);

$lineString1 = new LineStringEntity();
$lineString1->setLineString(LineString::of($point1, $point2, $point3));
$lineString1->lineString = LineString::of($point1, $point2, $point3);

$manager->persist($lineString1);
$manager->flush();
Expand Down
2 changes: 1 addition & 1 deletion tests/DataFixtures/LoadMultiLineStringData.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function load(ObjectManager $manager): void
$lineString2 = LineString::of($point4, $point5, $point6);

$multilineString1 = new MultiLineStringEntity();
$multilineString1->setMultiLineString(MultiLineString::of($lineString1, $lineString2));
$multilineString1->multiLineString = MultiLineString::of($lineString1, $lineString2);

$manager->persist($multilineString1);
$manager->flush();
Expand Down
2 changes: 1 addition & 1 deletion tests/DataFixtures/LoadMultiPointData.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function load(ObjectManager $manager): void
$point3 = Point::xy(1,1);

$multiPoint1 = new MultiPointEntity();
$multiPoint1->setMultiPoint(MultiPoint::of($point1, $point2, $point3));
$multiPoint1->multiPoint = MultiPoint::of($point1, $point2, $point3);

$manager->persist($multiPoint1);
$manager->flush();
Expand Down
2 changes: 1 addition & 1 deletion tests/DataFixtures/LoadMultiPolygonData.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function load(ObjectManager $manager): void
$poly2 = Polygon::of($ring2);

$multiPoly1 = new MultiPolygonEntity();
$multiPoly1->setMultiPolygon(MultiPolygon::of($poly1, $poly2));
$multiPoly1->multiPolygon = MultiPolygon::of($poly1, $poly2);

$manager->persist($multiPoly1);
$manager->flush();
Expand Down
2 changes: 1 addition & 1 deletion tests/DataFixtures/LoadPointData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LoadPointData implements FixtureInterface
public function load(ObjectManager $manager): void
{
$point1 = new PointEntity();
$point1->setPoint(Point::xy(0, 0));
$point1->point = Point::xy(0, 0);

$manager->persist($point1);
$manager->flush();
Expand Down
2 changes: 1 addition & 1 deletion tests/DataFixtures/LoadPolygonData.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function load(ObjectManager $manager): void
$ring = LineString::of($point1, $point2, $point3, $point4, $point5);

$poly1 = new PolygonEntity();
$poly1->setPolygon(Polygon::of($ring));
$poly1->polygon = Polygon::of($ring);

$manager->persist($poly1);
$manager->flush();
Expand Down
32 changes: 8 additions & 24 deletions tests/Fixtures/GeometryEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,16 @@
namespace Brick\Geo\Doctrine\Tests\Fixtures;

use Brick\Geo\Geometry;
use Doctrine\ORM\Mapping as ORM;

/**
* @Entity
* @Table(name="geometries")
*/
#[ORM\Entity]
class GeometryEntity
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
private int $id;
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue]
public int $id;

/**
* @Column(type="Geometry")
*/
private Geometry $geometry;

public function getGeometry() : Geometry
{
return $this->geometry;
}

public function setGeometry(Geometry $geometry) : void
{
$this->geometry = $geometry;
}
#[ORM\Column(type: 'Geometry')]
public Geometry $geometry;
}
32 changes: 8 additions & 24 deletions tests/Fixtures/LineStringEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,16 @@
namespace Brick\Geo\Doctrine\Tests\Fixtures;

use Brick\Geo\LineString;
use Doctrine\ORM\Mapping as ORM;

/**
* @Entity
* @Table(name="linestrings")
*/
#[ORM\Entity]
class LineStringEntity
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
private int $id;
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue]
public int $id;

/**
* @Column(type="LineString")
*/
private LineString $lineString;

public function getLineString() : LineString
{
return $this->lineString;
}

public function setLineString(LineString $lineString) : void
{
$this->lineString = $lineString;
}
#[ORM\Column(type: 'LineString')]
public LineString $lineString;
}
Loading

0 comments on commit a515bd0

Please sign in to comment.