Skip to content

Commit 900d142

Browse files
authored
fix(doctrine): avoid deprecated ArrayAccess on FieldMapping in DoctrineORMListener (#506)
* Enhance DoctrineORMListener for compatibility with Doctrine ORM 3.x - Updated field mapping logic to support both legacy array mapping and the new FieldMapping object introduced in Doctrine ORM 3.x. - Ensured backward compatibility with existing implementations while preparing for future ORM 4.0 changes. * Refactor field mapping logic in DoctrineORMListener for improved compatibility - Adjusted the handling of field mappings to ensure proper support for the FieldMapping object in Doctrine ORM 3.x. - Removed deprecated ArrayAccess usage to prepare for future ORM 4.0 changes, enhancing code maintainability.
1 parent db9d7c2 commit 900d142

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

Storage/Listener/DoctrineORMListener.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,19 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
2525
foreach ($metadata->getFieldNames() as $name) {
2626
$fieldMapping = $metadata->getFieldMapping($name);
2727

28-
if (isset($fieldMapping['type']) && 'string' === $fieldMapping['type']) {
29-
$fieldMapping['length'] = 191;
28+
if (\is_array($fieldMapping)) {
29+
// Doctrine ORM 2.x / legacy array mapping
30+
if (isset($fieldMapping['type']) && 'string' === $fieldMapping['type']) {
31+
$fieldMapping['length'] = 191;
32+
$metadata->fieldMappings[$name] = $fieldMapping;
33+
}
34+
35+
continue;
36+
}
37+
38+
// Doctrine ORM 3+: FieldMapping object — avoid deprecated ArrayAccess (removed in ORM 4.0)
39+
if ('string' === $fieldMapping->type) {
40+
$fieldMapping->length = 191;
3041
$metadata->fieldMappings[$name] = $fieldMapping;
3142
}
3243
}

0 commit comments

Comments
 (0)