Skip to content

Commit 4ba86a5

Browse files
authored
Allow DBAL 4.x to be used (#87)
Direct exposure to DBAL is rather limited in this bundle, mostly it's about `TranslatableStringType` as the extra DBAL type having to use a DBAL API.
1 parent 08275d9 commit 4ba86a5

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,5 @@ class represents the values of a single locale only and never contains `Translat
277277
This Bundle was written by webfactory GmbH, Bonn, Germany. We're a software development agency with a focus on PHP (mostly [Symfony](http://github.com/symfony/symfony)). If you're a developer looking for new challenges, we'd like to hear from you!
278278

279279
- <https://www.webfactory.de>
280-
- <https://twitter.com/webfactory>
281280

282-
Copyright 2012-2024 webfactory GmbH, Bonn. Code released under [the MIT license](LICENSE).
281+
Copyright 2012-2025 webfactory GmbH, Bonn. Code released under [the MIT license](LICENSE).

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require": {
2323
"php": ">= 8.1",
2424
"doctrine/collections": "^1.6|^2.0",
25-
"doctrine/dbal": "^2.13|^3.0",
25+
"doctrine/dbal": "^3.0|^4.0",
2626
"doctrine/event-manager": "^1.1|^2.0",
2727
"doctrine/orm": "^2.13|^3.0",
2828
"doctrine/persistence": "^2.4|^3.1|^4.0",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\TranslatableWithObjectData;
4+
5+
use Doctrine\DBAL\Platforms\AbstractPlatform;
6+
use Doctrine\DBAL\Types\JsonType;
7+
use Doctrine\DBAL\Types\Type;
8+
9+
/**
10+
* Custom mapping type to support TranslatableWithObjectDataTest_Object instances in fields of TranslatableWithObjectDataTest_Entity
11+
* and TranslatableWithObjectDataTest_Translation. This is necessary since DBAL 4 removed support for the generic "object" column
12+
* type which was based on PHP serialization (https://github.com/doctrine/dbal/pull/5470).
13+
*/
14+
class ObjectType extends JsonType
15+
{
16+
public const TYPE = 'my_object';
17+
18+
public function convertToPHPValue($value, AbstractPlatform $platform): TranslatableWithObjectDataTest_Object
19+
{
20+
$value = parent::convertToPHPValue($value, $platform);
21+
22+
if (null === $value) {
23+
return null;
24+
}
25+
26+
return new TranslatableWithObjectDataTest_Object($value['text']);
27+
}
28+
}

tests/Fixtures/Entity/TranslatableWithObjectData/TranslatableWithObjectDataTest_Entity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TranslatableWithObjectDataTest_Entity
2323
public Collection $translations;
2424

2525
#[Polyglot\Translatable]
26-
#[ORM\Column(type: 'object')]
26+
#[ORM\Column(type: 'my_object')]
2727
public TranslatableInterface|TranslatableWithObjectDataTest_Object $data;
2828

2929
public function __construct()

tests/Fixtures/Entity/TranslatableWithObjectData/TranslatableWithObjectDataTest_Translation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ class TranslatableWithObjectDataTest_Translation
2020
#[ORM\ManyToOne(inversedBy: 'translations')]
2121
private TranslatableWithObjectDataTest_Entity $entity;
2222

23-
#[ORM\Column(type: 'object')]
23+
#[ORM\Column(type: 'my_object')]
2424
private TranslatableWithObjectDataTest_Object $data;
2525
}

tests/Functional/TranslatableWithObjectDataTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Webfactory\Bundle\PolyglotBundle\Tests\Functional;
44

5+
use Doctrine\DBAL\Types\Type;
56
use Webfactory\Bundle\PolyglotBundle\Doctrine\PersistentTranslatable;
7+
use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\TranslatableWithObjectData\ObjectType;
68
use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\TranslatableWithObjectData\TranslatableWithObjectDataTest_Entity;
79
use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\TranslatableWithObjectData\TranslatableWithObjectDataTest_Object;
810
use Webfactory\Bundle\PolyglotBundle\Tests\Fixtures\Entity\TranslatableWithObjectData\TranslatableWithObjectDataTest_Translation;
@@ -17,6 +19,11 @@ class TranslatableWithObjectDataTest extends DatabaseFunctionalTestCase
1719
protected function setUp(): void
1820
{
1921
parent::setUp();
22+
$typeRegistry = Type::getTypeRegistry();
23+
if (!$typeRegistry->has(ObjectType::TYPE)) {
24+
$typeRegistry->register(ObjectType::TYPE, new ObjectType());
25+
}
26+
2027
self::setupSchema([
2128
TranslatableWithObjectDataTest_Entity::class,
2229
TranslatableWithObjectDataTest_Translation::class,

0 commit comments

Comments
 (0)