-
Notifications
You must be signed in to change notification settings - Fork 265
Description
Description
The DoctrineORMListener in Lexik Translation Bundle is using ArrayAccess to access Doctrine\ORM\Mapping\FieldMapping properties, which triggers a deprecation warning. This approach will be removed in Doctrine ORM 4.0.
Error Details
Deprecation Message:
User Deprecated: Using ArrayAccess on Doctrine\ORM\Mapping\FieldMapping is deprecated and will not be possible in Doctrine ORM 4.0. Use the corresponding property instead.
Affected File:
Lexik\Bundle\TranslationBundle\Storage\Listener\DoctrineORMListener.php (line 28)
Stack Trace:
/usr/src/app/symfony/vendor/doctrine/deprecations/src/Deprecation.php:208
Doctrine\Deprecations\Deprecation::delegateTriggerToBackend(string $message, array $backtrace, string $link, string $package): void
/usr/src/app/symfony/vendor/doctrine/deprecations/src/Deprecation.php:108
Doctrine\Deprecations\Deprecation::trigger(string $package, string $link, string $message, ...$args): void
/usr/src/app/symfony/vendor/doctrine/orm/src/Mapping/ArrayAccessImplementation.php:18
Doctrine\ORM\Mapping\FieldMapping->offsetExists(mixed $offset): bool
/usr/src/app/symfony/vendor/lexik/translation-bundle/Storage/Listener/DoctrineORMListener.php:28
Lexik\Bundle\TranslationBundle\Storage\Listener\DoctrineORMListener->loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
Steps to Reproduce
- Use Lexik Translation Bundle in a Symfony project with Doctrine ORM 3.x
- Enable deprecation warnings (or have them logged)
- Load any entity metadata that triggers the
DoctrineORMListener::loadClassMetadata()method - The deprecation warning will be triggered
Current Code (Problematic)
In Storage/Listener/DoctrineORMListener.php around line 28:
if (isset($fieldMapping['type']) && 'string' === $fieldMapping['type']) {
$fieldMapping['length'] = 191;
}Proposed Solution
Replace array access with direct property access. The getFieldMapping() method returns a FieldMapping object, so we should access its properties directly.
Simple Fix
Replace:
if (isset($fieldMapping['type']) && 'string' === $fieldMapping['type']) {
$fieldMapping['length'] = 191;
}With:
if (isset($fieldMapping->type) && 'string' === $fieldMapping->type) {
$fieldMapping->length = 191;
}Complete Method Example
Here's how the loadClassMetadata method should look after the fix (assuming the context around line 28):
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void
{
$classMetadata = $eventArgs->getClassMetadata();
// ... existing code ...
foreach ($classMetadata->getFieldNames() as $field) {
$fieldMapping = $classMetadata->getFieldMapping($field);
// Fixed: Use property access instead of ArrayAccess
if (isset($fieldMapping->type) && 'string' === $fieldMapping->type) {
$fieldMapping->length = 191;
}
}
// ... rest of the method ...
}Notes
- The
FieldMappingclass has public properties that can be accessed directly - Using
isset($fieldMapping->type)checks if the property exists - Assigning
$fieldMapping->length = 191directly modifies the object property - This approach is compatible with Doctrine ORM 3.x and will work in 4.0
Expected Behavior
- No deprecation warnings should be triggered
- The functionality should remain the same (setting string field length to 191 for MySQL compatibility)
- The code should be compatible with Doctrine ORM 4.0
Environment
- Lexik Translation Bundle Version: (check your installed version)
- Doctrine ORM Version: 3.x (deprecation present), 4.0 (will break)
- PHP Version: (your PHP version)
- Symfony Version: (your Symfony version)
References
- Doctrine ORM Pull Request: Deprecate array access doctrine/orm#11211
- Related issues in DoctrineExtensions: Similar deprecations have been addressed in other projects
Additional Notes
This deprecation is part of Doctrine ORM's migration away from ArrayAccess implementation on mapping classes. All mapping classes (FieldMapping, AssociationMapping, etc.) should now be accessed as objects with properties rather than arrays.