Skip to content

Commit 72510d6

Browse files
committed
Partial DBAL 4.x support
1 parent ee91783 commit 72510d6

File tree

24 files changed

+190
-74
lines changed

24 files changed

+190
-74
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"require-dev": {
5555
"doctrine/annotations": "^1.13 || ^2.0",
5656
"doctrine/cache": "^1.11 || ^2.0",
57-
"doctrine/dbal": "^3.2",
57+
"doctrine/dbal": "^3.7 || ^4.0",
5858
"doctrine/doctrine-bundle": "^2.3",
5959
"doctrine/mongodb-odm": "^2.3",
6060
"doctrine/orm": "^2.14.0 || ^3.0",
@@ -73,7 +73,7 @@
7373
},
7474
"conflict": {
7575
"doctrine/annotations": "<1.13 || >=3.0",
76-
"doctrine/dbal": "<3.2 || >=4.0",
76+
"doctrine/dbal": "<3.7 || >=5.0",
7777
"doctrine/mongodb-odm": "<2.3 || >=3.0",
7878
"doctrine/orm": "<2.14.0 || 2.16.0 || 2.16.1 || >=4.0"
7979
},

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ parameters:
1010
count: 3
1111
path: src/AbstractTrackingListener.php
1212

13-
-
14-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getConnection\\(\\)\\.$#"
15-
count: 1
16-
path: src/AbstractTrackingListener.php
17-
1813
-
1914
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getUnitOfWork\\(\\)\\.$#"
2015
count: 3

phpstan.neon.dist

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ parameters:
2020
- '#^Result of static method Gedmo\\Uploadable\\Mapping\\Validator::validateConfiguration\(\) \(void\) is used\.$#'
2121
- '#^Result of method Gedmo\\Mapping\\Driver::readExtendedMetadata\(\) \(void\) is used\.$#'
2222
excludePaths:
23+
# Deprecated and unused class, interface does not exist as of 4.0
24+
- src/Tool/Logging/DBAL/QueryAnalyzer.php
2325
# Generates non-ignorable errors like " Parameter #1 $method (string) of method Gedmo\Tree\Entity\Repository\NestedTreeRepository::__call() is not contravariant with parameter #1 $method (mixed) of method Doctrine\ORM\EntityRepository::__call()."
2426
- src/Tool/ORM/Repository/EntityRepositoryCompat.php
25-
# Compat file for ORM 2, causes analysis errors with ORM 3
26-
- src/Tool/ORM/Walker/orm-2.php
2727
# Uses a tracking policy that was removed in ORM 3, PHPStan crashes on this file
2828
- tests/Gedmo/Sortable/Fixture/NotifyNode.php
29+
# Generates non-ignorable errors regarding covariance due to the internal compat layer
30+
- tests/Gedmo/Translatable/Fixture/Type/Custom.php

src/AbstractTrackingListener.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Doctrine\DBAL\Types\Type;
1414
use Doctrine\ODM\MongoDB\DocumentManager;
1515
use Doctrine\ODM\MongoDB\Types\Type as TypeODM;
16+
use Doctrine\ORM\EntityManagerInterface;
1617
use Doctrine\ORM\UnitOfWork;
1718
use Doctrine\Persistence\Event\LifecycleEventArgs;
1819
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;
@@ -267,9 +268,13 @@ private function getPhpValues($values, ?string $type, ObjectManager $om): ?array
267268
} else {
268269
$values[$i] = $value;
269270
}
270-
} elseif (Type::hasType($type)) {
271-
$values[$i] = Type::getType($type)
272-
->convertToPHPValue($value, $om->getConnection()->getDatabasePlatform());
271+
} elseif ($om instanceof EntityManagerInterface) {
272+
if (Type::hasType($type)) {
273+
$values[$i] = $om->getConnection()
274+
->convertToPHPValue($value, $type);
275+
} else {
276+
$values[$i] = $value;
277+
}
273278
}
274279
}
275280
}

src/Loggable/Entity/MappedSuperclass/AbstractLogEntry.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ abstract class AbstractLogEntry implements LogEntryInterface
8484
* @var array<string, mixed>|null
8585
*
8686
* @ORM\Column(type="array", nullable=true)
87+
*
88+
* @note The attribute uses the "array" name directly instead of the constant since it was removed in DBAL 4.0.
8789
*/
88-
#[ORM\Column(type: Types::ARRAY, nullable: true)]
90+
#[ORM\Column(type: 'array', nullable: true)]
8991
protected $data;
9092

9193
/**

src/SoftDeleteable/Mapping/Event/Adapter/ORM.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace Gedmo\SoftDeleteable\Mapping\Event\Adapter;
1111

12-
use Doctrine\DBAL\Types\Type;
1312
use Doctrine\DBAL\Types\Types;
1413
use Doctrine\ORM\Mapping\ClassMetadata;
1514
use Doctrine\ORM\Mapping\FieldMapping;
@@ -42,10 +41,11 @@ public function setClock(ClockInterface $clock): void
4241
public function getDateValue($meta, $field)
4342
{
4443
$mapping = $meta->getFieldMapping($field);
45-
$converter = Type::getType($mapping['type'] ?? Types::DATETIME_MUTABLE);
46-
$platform = $this->getObjectManager()->getConnection()->getDriver()->getDatabasePlatform();
4744

48-
return $converter->convertToPHPValue($this->getRawDateValue($mapping), $platform);
45+
return $this->getObjectManager()->getConnection()->convertToPHPValue(
46+
$this->getRawDateValue($mapping),
47+
$mapping instanceof FieldMapping ? $mapping->type : ($mapping['type'] ?? Types::DATETIME_MUTABLE)
48+
);
4949
}
5050

5151
/**

src/Timestampable/Mapping/Event/Adapter/ORM.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace Gedmo\Timestampable\Mapping\Event\Adapter;
1111

12-
use Doctrine\DBAL\Types\Type;
1312
use Doctrine\DBAL\Types\Types;
1413
use Doctrine\ORM\Mapping\ClassMetadata;
1514
use Doctrine\ORM\Mapping\FieldMapping;
@@ -42,10 +41,11 @@ public function setClock(ClockInterface $clock): void
4241
public function getDateValue($meta, $field)
4342
{
4443
$mapping = $meta->getFieldMapping($field);
45-
$converter = Type::getType($mapping['type'] ?? Types::DATETIME_MUTABLE);
46-
$platform = $this->getObjectManager()->getConnection()->getDriver()->getDatabasePlatform();
4744

48-
return $converter->convertToPHPValue($this->getRawDateValue($mapping), $platform);
45+
return $this->getObjectManager()->getConnection()->convertToPHPValue(
46+
$this->getRawDateValue($mapping),
47+
$mapping instanceof FieldMapping ? $mapping->type : ($mapping['type'] ?? Types::DATETIME_MUTABLE)
48+
);
4949
}
5050

5151
/**

src/Translatable/Entity/Repository/TranslationRepository.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace Gedmo\Translatable\Entity\Repository;
1111

12-
use Doctrine\DBAL\Types\Type;
1312
use Doctrine\ORM\EntityManagerInterface;
1413
use Doctrine\ORM\EntityRepository;
1514
use Doctrine\ORM\Mapping\ClassMetadata;
@@ -99,8 +98,7 @@ public function translate($entity, $field, $locale, $value)
9998
$listener->setTranslationInDefaultLocale(spl_object_id($entity), $field, $trans);
10099
$needsPersist = $listener->getPersistDefaultLocaleTranslation();
101100
}
102-
$type = Type::getType($meta->getTypeOfField($field));
103-
$transformed = $type->convertToDatabaseValue($value, $this->getEntityManager()->getConnection()->getDatabasePlatform());
101+
$transformed = $this->getEntityManager()->getConnection()->convertToDatabaseValue($value, $meta->getTypeOfField($field));
104102
$transMeta->getReflectionProperty('content')->setValue($trans, $transformed);
105103
if ($needsPersist) {
106104
if ($this->getEntityManager()->getUnitOfWork()->isInIdentityMap($entity)) {

src/Translatable/Mapping/Event/Adapter/ORM.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,26 +211,25 @@ public function getTranslationValue($object, $field, $value = false)
211211
$em = $this->getObjectManager();
212212
$wrapped = AbstractWrapper::wrap($object, $em);
213213
$meta = $wrapped->getMetadata();
214-
$type = Type::getType($meta->getTypeOfField($field));
214+
215215
if (false === $value) {
216216
$value = $wrapped->getPropertyValue($field);
217217
}
218218

219-
return $type->convertToDatabaseValue($value, $em->getConnection()->getDatabasePlatform());
219+
return $em->getConnection()->convertToDatabaseValue($value, $meta->getTypeOfField($field));
220220
}
221221

222222
public function setTranslationValue($object, $field, $value)
223223
{
224224
$em = $this->getObjectManager();
225225
$wrapped = AbstractWrapper::wrap($object, $em);
226226
$meta = $wrapped->getMetadata();
227-
$type = Type::getType($meta->getTypeOfField($field));
228-
$value = $type->convertToPHPValue($value, $em->getConnection()->getDatabasePlatform());
227+
$value = $em->getConnection()->convertToPHPValue($value, $meta->getTypeOfField($field));
229228
$wrapped->setPropertyValue($field, $value);
230229
}
231230

232231
/**
233-
* Transforms foreing key of translation to appropriate PHP value
232+
* Transforms foreign key of translation to appropriate PHP value
234233
* to prevent database level cast
235234
*
236235
* @param mixed $key foreign key value
@@ -245,7 +244,8 @@ private function foreignKey($key, string $className)
245244
$em = $this->getObjectManager();
246245
$meta = $em->getClassMetadata($className);
247246
$type = Type::getType($meta->getTypeOfField('foreignKey'));
248-
switch ($type->getName()) {
247+
248+
switch (Type::lookupName($type)) {
249249
case Types::BIGINT:
250250
case Types::INTEGER:
251251
case Types::SMALLINT:

src/Translatable/Query/TreeWalker/TranslationWalker.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,8 @@ class TranslationWalker extends SqlWalker
9090

9191
/**
9292
* DBAL database platform
93-
*
94-
* @var AbstractPlatform
9593
*/
96-
private $platform;
94+
private AbstractPlatform $platform;
9795

9896
/**
9997
* DBAL database connection

0 commit comments

Comments
 (0)