From df96939b61718a3dc00c6ed8c5941b697d57ed1d Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Sat, 19 Oct 2024 00:01:44 +0200 Subject: [PATCH 1/9] Reduce deprecations due to FieldMapping array access (for properties named $mapping) --- doc/mapping.md | 2 +- src/Blameable/Mapping/Driver/Xml.php | 2 +- src/Blameable/Mapping/Driver/Yaml.php | 6 ++-- src/IpTraceable/Mapping/Driver/Xml.php | 2 +- src/IpTraceable/Mapping/Driver/Yaml.php | 6 ++-- .../Repository/LogEntryRepository.php | 8 ++--- .../Entity/Repository/LogEntryRepository.php | 2 +- src/Loggable/Mapping/Driver/Yaml.php | 14 ++++----- .../Driver/AbstractAnnotationDriver.php | 2 +- .../Mapping/Driver/Yaml.php | 6 ++-- src/References/Mapping/Driver/Yaml.php | 4 +-- src/References/ReferencesListener.php | 30 +++++++++---------- src/Sluggable/Mapping/Driver/Xml.php | 2 +- src/Sluggable/Mapping/Driver/Yaml.php | 6 ++-- src/Sluggable/Mapping/Event/Adapter/ORM.php | 4 +-- src/Sluggable/SluggableListener.php | 10 +++---- src/SoftDeleteable/Mapping/Driver/Yaml.php | 2 +- .../Mapping/Event/Adapter/ODM.php | 2 +- .../Mapping/Event/Adapter/ORM.php | 4 +-- src/Sortable/Mapping/Driver/Xml.php | 2 +- src/Sortable/Mapping/Driver/Yaml.php | 10 +++---- src/Timestampable/Mapping/Driver/Xml.php | 2 +- src/Timestampable/Mapping/Driver/Yaml.php | 4 +-- .../Mapping/Event/Adapter/ODM.php | 2 +- .../Mapping/Event/Adapter/ORM.php | 4 +-- .../Repository/TranslationRepository.php | 2 +- src/Translatable/Mapping/Driver/Yaml.php | 6 ++-- src/Tree/Mapping/Driver/Yaml.php | 8 ++--- src/Tree/Mapping/Validator.php | 12 ++++---- src/Tree/Strategy/ORM/Closure.php | 4 ++- src/Uploadable/Mapping/Driver/Yaml.php | 4 +-- .../Encoder/Mapping/Driver/Attribute.php | 2 +- 32 files changed, 89 insertions(+), 87 deletions(-) diff --git a/doc/mapping.md b/doc/mapping.md index fe90e2c0dd..5cb48cc378 100644 --- a/doc/mapping.md +++ b/doc/mapping.md @@ -149,7 +149,7 @@ class Annotation implements Driver } // validate encoding type $mapping = $meta->getFieldMapping($field); - if ($mapping['type'] != 'string') { + if (($mapping->type ?? $mapping['type']) != 'string') { throw new \Exception("Only strings can be encoded"); } // store the metadata diff --git a/src/Blameable/Mapping/Driver/Xml.php b/src/Blameable/Mapping/Driver/Xml.php index 42861f8e17..703a5c19a5 100644 --- a/src/Blameable/Mapping/Driver/Xml.php +++ b/src/Blameable/Mapping/Driver/Xml.php @@ -128,6 +128,6 @@ protected function isValidField($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping['type'], self::VALID_TYPES, true); + return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true); } } diff --git a/src/Blameable/Mapping/Driver/Yaml.php b/src/Blameable/Mapping/Driver/Yaml.php index e72b334890..1abe79e9d4 100644 --- a/src/Blameable/Mapping/Driver/Yaml.php +++ b/src/Blameable/Mapping/Driver/Yaml.php @@ -53,7 +53,7 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['fields'])) { - foreach ($mapping['fields'] as $field => $fieldMapping) { + foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo']['blameable'])) { $mappingProperty = $fieldMapping['gedmo']['blameable']; if (!$this->isValidField($meta, $field)) { @@ -84,7 +84,7 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['manyToOne'])) { - foreach ($mapping['manyToOne'] as $field => $fieldMapping) { + foreach (($mapping->manyToOne ?? $mapping['manyToOne']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo']['blameable'])) { $mappingProperty = $fieldMapping['gedmo']['blameable']; if (!$meta->isSingleValuedAssociation($field)) { @@ -134,6 +134,6 @@ protected function isValidField($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping['type'], self::VALID_TYPES, true); + return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true); } } diff --git a/src/IpTraceable/Mapping/Driver/Xml.php b/src/IpTraceable/Mapping/Driver/Xml.php index 9e64a9efd2..c8759f5c31 100644 --- a/src/IpTraceable/Mapping/Driver/Xml.php +++ b/src/IpTraceable/Mapping/Driver/Xml.php @@ -130,6 +130,6 @@ protected function isValidField($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping['type'], self::VALID_TYPES, true); + return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true); } } diff --git a/src/IpTraceable/Mapping/Driver/Yaml.php b/src/IpTraceable/Mapping/Driver/Yaml.php index 590969ea8d..45976a7892 100644 --- a/src/IpTraceable/Mapping/Driver/Yaml.php +++ b/src/IpTraceable/Mapping/Driver/Yaml.php @@ -49,7 +49,7 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['fields'])) { - foreach ($mapping['fields'] as $field => $fieldMapping) { + foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo']['ipTraceable'])) { $mappingProperty = $fieldMapping['gedmo']['ipTraceable']; if (!$this->isValidField($meta, $field)) { @@ -80,7 +80,7 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['manyToOne'])) { - foreach ($mapping['manyToOne'] as $field => $fieldMapping) { + foreach (($mapping->manyToOne ?? $mapping['manyToOne']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo']['ipTraceable'])) { $mappingProperty = $fieldMapping['gedmo']['ipTraceable']; if (!$meta->isSingleValuedAssociation($field)) { @@ -130,6 +130,6 @@ protected function isValidField($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping['type'], self::VALID_TYPES, true); + return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true); } } diff --git a/src/Loggable/Document/Repository/LogEntryRepository.php b/src/Loggable/Document/Repository/LogEntryRepository.php index 1c0a2d52c0..74eb6fb4fe 100644 --- a/src/Loggable/Document/Repository/LogEntryRepository.php +++ b/src/Loggable/Document/Repository/LogEntryRepository.php @@ -130,17 +130,17 @@ protected function fillDocument($document, array $data) // Fill the embedded document if ($wrapped->isEmbeddedAssociation($field)) { if (!empty($value)) { - assert(class_exists($mapping['targetDocument'])); + assert(class_exists($mapping->targetDocument ?? $mapping['targetDocument'])); - $embeddedMetadata = $this->dm->getClassMetadata($mapping['targetDocument']); + $embeddedMetadata = $this->dm->getClassMetadata($mapping->targetDocument ?? $mapping['targetDocument']); $document = $embeddedMetadata->newInstance(); $this->fillDocument($document, $value); $value = $document; } } elseif ($objectMeta->isSingleValuedAssociation($field)) { - assert(class_exists($mapping['targetDocument'])); + assert(class_exists($mapping->targetDocument ?? $mapping['targetDocument'])); - $value = $value ? $this->dm->getReference($mapping['targetDocument'], $value) : null; + $value = $value ? $this->dm->getReference($mapping->targetDocument ?? $mapping['targetDocument'], $value) : null; } $wrapped->setPropertyValue($field, $value); unset($fields[$field]); diff --git a/src/Loggable/Entity/Repository/LogEntryRepository.php b/src/Loggable/Entity/Repository/LogEntryRepository.php index 9e3274f80c..2769cbe6d3 100644 --- a/src/Loggable/Entity/Repository/LogEntryRepository.php +++ b/src/Loggable/Entity/Repository/LogEntryRepository.php @@ -165,7 +165,7 @@ protected function mapValue(ClassMetadata $objectMeta, $field, &$value) } $mapping = $objectMeta->getAssociationMapping($field); - $value = $value ? $this->getEntityManager()->getReference($mapping['targetEntity'], $value) : null; + $value = $value ? $this->getEntityManager()->getReference($mapping->targetEntity ?? $mapping['targetEntity'], $value) : null; } /** diff --git a/src/Loggable/Mapping/Driver/Yaml.php b/src/Loggable/Mapping/Driver/Yaml.php index 9c4e556c90..95562d725b 100644 --- a/src/Loggable/Mapping/Driver/Yaml.php +++ b/src/Loggable/Mapping/Driver/Yaml.php @@ -41,7 +41,7 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['gedmo'])) { - $classMapping = $mapping['gedmo']; + $classMapping = ($mapping->gedmo ?? $mapping['gedmo']); if (isset($classMapping['loggable'])) { $config['loggable'] = true; if (isset($classMapping['loggable']['logEntryClass'])) { @@ -54,7 +54,7 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['fields'])) { - foreach ($mapping['fields'] as $field => $fieldMapping) { + foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { if (in_array('versioned', $fieldMapping['gedmo'], true)) { if ($meta->isCollectionValuedAssociation($field)) { @@ -68,7 +68,7 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['attributeOverride'])) { - foreach ($mapping['attributeOverride'] as $field => $fieldMapping) { + foreach (($mapping->attributeOverride ?? $mapping['attributeOverride']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { if (in_array('versioned', $fieldMapping['gedmo'], true)) { if ($meta->isCollectionValuedAssociation($field)) { @@ -82,7 +82,7 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['manyToOne'])) { - foreach ($mapping['manyToOne'] as $field => $fieldMapping) { + foreach (($mapping->manyToOne ?? $mapping['manyToOne']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { if (in_array('versioned', $fieldMapping['gedmo'], true)) { if ($meta->isCollectionValuedAssociation($field)) { @@ -96,7 +96,7 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['oneToOne'])) { - foreach ($mapping['oneToOne'] as $field => $fieldMapping) { + foreach (($mapping->oneToOne ?? $mapping['oneToOne']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { if (in_array('versioned', $fieldMapping['gedmo'], true)) { if ($meta->isCollectionValuedAssociation($field)) { @@ -110,7 +110,7 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['embedded'])) { - foreach ($mapping['embedded'] as $field => $fieldMapping) { + foreach (($mapping->embedded ?? $mapping['embedded']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { if (in_array('versioned', $fieldMapping['gedmo'], true)) { if ($meta->isCollectionValuedAssociation($field)) { @@ -150,7 +150,7 @@ protected function _loadMappingFile($file) private function inspectEmbeddedForVersioned(string $field, array $mapping, array $config): array { if (isset($mapping['fields'])) { - foreach ($mapping['fields'] as $property => $fieldMapping) { + foreach (($mapping->fields ?? $mapping['fields']) as $property => $fieldMapping) { $config['versioned'][] = $field.'.'.$property; } } diff --git a/src/Mapping/Driver/AbstractAnnotationDriver.php b/src/Mapping/Driver/AbstractAnnotationDriver.php index 43c92deae3..fb170f3663 100644 --- a/src/Mapping/Driver/AbstractAnnotationDriver.php +++ b/src/Mapping/Driver/AbstractAnnotationDriver.php @@ -131,7 +131,7 @@ protected function isValidField($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping['type'], $this->validTypes, true); + return $mapping && in_array($mapping->type ?? $mapping['type'], $this->validTypes, true); } /** diff --git a/src/ReferenceIntegrity/Mapping/Driver/Yaml.php b/src/ReferenceIntegrity/Mapping/Driver/Yaml.php index 4c0bd33fc8..86b67d1608 100644 --- a/src/ReferenceIntegrity/Mapping/Driver/Yaml.php +++ b/src/ReferenceIntegrity/Mapping/Driver/Yaml.php @@ -41,13 +41,13 @@ public function readExtendedMetadata($meta, array &$config) $validator = new Validator(); if (isset($mapping['fields'])) { - foreach ($mapping['fields'] as $property => $fieldMapping) { + foreach (($mapping->fields ?? $mapping['fields']) as $property => $fieldMapping) { if (isset($fieldMapping['gedmo']['referenceIntegrity'])) { if (!$meta->hasField($property)) { throw new InvalidMappingException(sprintf('Unable to find reference integrity [%s] as mapped property in entity - %s', $property, $meta->getName())); } - if (empty($mapping['fields'][$property]['mappedBy'])) { + if (empty(($mapping->fields ?? $mapping['fields'])[$property]['mappedBy'])) { throw new InvalidMappingException(sprintf("'mappedBy' should be set on '%s' in '%s'", $property, $meta->getName())); } @@ -55,7 +55,7 @@ public function readExtendedMetadata($meta, array &$config) throw new InvalidMappingException(sprintf('Field - [%s] does not have a valid integrity option, [%s] in class - %s', $property, implode(', ', $validator->getIntegrityActions()), $meta->getName())); } - $config['referenceIntegrity'][$property][$mapping['fields'][$property]['mappedBy']] = + $config['referenceIntegrity'][$property][($mapping->fields ?? $mapping['fields'])[$property]['mappedBy']] = $fieldMapping['gedmo']['referenceIntegrity']; } } diff --git a/src/References/Mapping/Driver/Yaml.php b/src/References/Mapping/Driver/Yaml.php index 48a8b4bb10..9fbbcd2cdf 100644 --- a/src/References/Mapping/Driver/Yaml.php +++ b/src/References/Mapping/Driver/Yaml.php @@ -42,8 +42,8 @@ public function readExtendedMetadata($meta, array &$config) { $mapping = $this->_getMapping($meta->getName()); - if (isset($mapping['gedmo'], $mapping['gedmo']['reference'])) { - foreach ($mapping['gedmo']['reference'] as $field => $fieldMapping) { + if (isset($mapping['gedmo'], ($mapping->gedmo ?? $mapping['gedmo'])['reference'])) { + foreach (($mapping->gedmo ?? $mapping['gedmo'])['reference'] as $field => $fieldMapping) { $reference = $fieldMapping['reference']; if (!in_array($reference, array_keys($this->validReferences), true)) { diff --git a/src/References/ReferencesListener.php b/src/References/ReferencesListener.php index 6f9c7c85e4..d2821d0ab8 100644 --- a/src/References/ReferencesListener.php +++ b/src/References/ReferencesListener.php @@ -92,16 +92,16 @@ public function postLoad(EventArgs $eventArgs) if (isset($config['referenceOne'])) { foreach ($config['referenceOne'] as $mapping) { - $property = $meta->reflClass->getProperty($mapping['field']); + $property = $meta->reflClass->getProperty($mapping->field ?? $mapping['field']); $property->setAccessible(true); if (isset($mapping['identifier'])) { - $referencedObjectId = $meta->getFieldValue($object, $mapping['identifier']); + $referencedObjectId = $meta->getFieldValue($object, ($mapping->identifier ?? $mapping['identifier'])); if (null !== $referencedObjectId) { $property->setValue( $object, $ea->getSingleReference( - $this->getManager($mapping['type']), - $mapping['class'], + $this->getManager($mapping->type ?? $mapping['type']), + ($mapping->class ?? $mapping['class']), $referencedObjectId ) ); @@ -112,16 +112,16 @@ public function postLoad(EventArgs $eventArgs) if (isset($config['referenceMany'])) { foreach ($config['referenceMany'] as $mapping) { - $property = $meta->reflClass->getProperty($mapping['field']); + $property = $meta->reflClass->getProperty($mapping->field ?? $mapping['field']); $property->setAccessible(true); if (isset($mapping['mappedBy'])) { $id = $ea->extractIdentifier($om, $object); - $manager = $this->getManager($mapping['type']); - $class = $mapping['class']; + $manager = $this->getManager($mapping->type ?? $mapping['type']); + $class = ($mapping->class ?? $mapping['class']); $refMeta = $manager->getClassMetadata($class); $refConfig = $this->getConfiguration($manager, $refMeta->getName()); - if (isset($refConfig['referenceOne'][$mapping['mappedBy']])) { - $refMapping = $refConfig['referenceOne'][$mapping['mappedBy']]; + if (isset($refConfig['referenceOne'][($mapping->mappedBy ?? $mapping['mappedBy'])])) { + $refMapping = $refConfig['referenceOne'][($mapping->mappedBy ?? $mapping['mappedBy'])]; $identifier = $refMapping['identifier']; $property->setValue( $object, @@ -220,18 +220,18 @@ public function updateManyEmbedReferences(EventArgs $eventArgs) if (isset($config['referenceManyEmbed'])) { foreach ($config['referenceManyEmbed'] as $mapping) { - $property = $meta->reflClass->getProperty($mapping['field']); + $property = $meta->reflClass->getProperty($mapping->field ?? $mapping['field']); $property->setAccessible(true); $id = $ea->extractIdentifier($om, $object); $manager = $this->getManager('document'); - $class = $mapping['class']; + $class = ($mapping->class ?? $mapping['class']); $refMeta = $manager->getClassMetadata($class); // Trigger the loading of the configuration to validate the mapping $this->getConfiguration($manager, $refMeta->getName()); - $identifier = $mapping['identifier']; + $identifier = ($mapping->identifier ?? $mapping['identifier']); $property->setValue( $object, new LazyCollection( @@ -271,17 +271,17 @@ private function updateReferences(EventArgs $eventArgs): void if (isset($config['referenceOne'])) { foreach ($config['referenceOne'] as $mapping) { if (isset($mapping['identifier'])) { - $property = $meta->reflClass->getProperty($mapping['field']); + $property = $meta->reflClass->getProperty($mapping->field ?? $mapping['field']); $property->setAccessible(true); $referencedObject = $property->getValue($object); if (is_object($referencedObject)) { - $manager = $this->getManager($mapping['type']); + $manager = $this->getManager($mapping->type ?? $mapping['type']); $identifier = $ea->getIdentifier($manager, $referencedObject); $meta->setFieldValue( $object, - $mapping['identifier'], + ($mapping->identifier ?? $mapping['identifier']), $identifier ); } diff --git a/src/Sluggable/Mapping/Driver/Xml.php b/src/Sluggable/Mapping/Driver/Xml.php index a54976b85d..89f8d454d7 100644 --- a/src/Sluggable/Mapping/Driver/Xml.php +++ b/src/Sluggable/Mapping/Driver/Xml.php @@ -76,7 +76,7 @@ protected function isValidField($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping['type'], self::VALID_TYPES, true); + return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true); } /** diff --git a/src/Sluggable/Mapping/Driver/Yaml.php b/src/Sluggable/Mapping/Driver/Yaml.php index eddc7c9c5f..cb74de749e 100644 --- a/src/Sluggable/Mapping/Driver/Yaml.php +++ b/src/Sluggable/Mapping/Driver/Yaml.php @@ -54,13 +54,13 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['fields'])) { - foreach ($mapping['fields'] as $field => $fieldMapping) { + foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { $config = $this->buildFieldConfiguration($field, $fieldMapping, $meta, $config); } } if (isset($mapping['attributeOverride'])) { - foreach ($mapping['attributeOverride'] as $field => $overrideMapping) { + foreach (($mapping->attributeOverride ?? $mapping['attributeOverride']) as $field => $overrideMapping) { $config = $this->buildFieldConfiguration($field, $overrideMapping, $meta, $config); } } @@ -85,7 +85,7 @@ protected function isValidField($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping['type'], self::VALID_TYPES, true); + return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true); } /** diff --git a/src/Sluggable/Mapping/Event/Adapter/ORM.php b/src/Sluggable/Mapping/Event/Adapter/ORM.php index 62a65f2dab..d6c84a208f 100644 --- a/src/Sluggable/Mapping/Event/Adapter/ORM.php +++ b/src/Sluggable/Mapping/Event/Adapter/ORM.php @@ -55,13 +55,13 @@ public function getSimilarSlugs($object, $meta, array $config, $slug) if (($ubase || 0 === $ubase) && !$mapping) { $qb->andWhere('rec.'.$config['unique_base'].' = :unique_base'); $qb->setParameter(':unique_base', $ubase); - } elseif ($ubase && $mapping && in_array($mapping['type'], [EntityClassMetadata::ONE_TO_ONE, EntityClassMetadata::MANY_TO_ONE], true)) { + } elseif ($ubase && $mapping && in_array($mapping->type ?? $mapping['type'], [EntityClassMetadata::ONE_TO_ONE, EntityClassMetadata::MANY_TO_ONE], true)) { $mappedAlias = 'mapped_'.$config['unique_base']; $wrappedUbase = AbstractWrapper::wrap($ubase, $em); $metadata = $wrappedUbase->getMetadata(); assert($metadata instanceof EntityClassMetadata || $metadata instanceof LegacyEntityClassMetadata); $qb->innerJoin('rec.'.$config['unique_base'], $mappedAlias); - foreach (array_keys($mapping['targetToSourceKeyColumns']) as $i => $mappedKey) { + foreach (array_keys($mapping->targetToSourceKeyColumns ?? $mapping['targetToSourceKeyColumns']) as $i => $mappedKey) { $mappedProp = $metadata->getFieldName($mappedKey); $qb->andWhere($qb->expr()->eq($mappedAlias.'.'.$mappedProp, ':assoc'.$i)); $qb->setParameter(':assoc'.$i, $wrappedUbase->getPropertyValue($mappedProp)); diff --git a/src/Sluggable/SluggableListener.php b/src/Sluggable/SluggableListener.php index 2b519fe955..f89d304060 100644 --- a/src/Sluggable/SluggableListener.php +++ b/src/Sluggable/SluggableListener.php @@ -440,11 +440,11 @@ private function generateSlug(SluggableAdapter $ea, object $object): void } // cut slug if exceeded in length - if (isset($mapping['length']) && strlen($slug) > $mapping['length']) { - $slug = substr($slug, 0, $mapping['length']); + if (isset($mapping['length']) && strlen($slug) > ($mapping->length ?? $mapping['length'])) { + $slug = substr($slug, 0, ($mapping->length ?? $mapping['length'])); } - if (isset($mapping['nullable']) && $mapping['nullable'] && 0 === strlen($slug)) { + if (isset($mapping['nullable']) && ($mapping->nullable ?? $mapping['nullable']) && 0 === strlen($slug)) { $slug = null; } @@ -546,11 +546,11 @@ private function makeUniqueSlug(SluggableAdapter $ea, object $object, string $pr } $mapping = $meta->getFieldMapping($config['slug']); - if (isset($mapping['length']) && strlen($generatedSlug) > $mapping['length']) { + if (isset($mapping['length']) && strlen($generatedSlug) > ($mapping->length ?? $mapping['length'])) { $generatedSlug = substr( $generatedSlug, 0, - $mapping['length'] - (strlen($uniqueSuffix) + strlen($config['separator'])) + ($mapping->length ?? $mapping['length']) - (strlen($uniqueSuffix) + strlen($config['separator'])) ); $this->exponent = strlen($uniqueSuffix) - 1; if (substr($generatedSlug, -strlen($config['separator'])) == $config['separator']) { diff --git a/src/SoftDeleteable/Mapping/Driver/Yaml.php b/src/SoftDeleteable/Mapping/Driver/Yaml.php index e2790b1b66..63d7107bee 100644 --- a/src/SoftDeleteable/Mapping/Driver/Yaml.php +++ b/src/SoftDeleteable/Mapping/Driver/Yaml.php @@ -41,7 +41,7 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['gedmo'])) { - $classMapping = $mapping['gedmo']; + $classMapping = ($mapping->gedmo ?? $mapping['gedmo']); if (isset($classMapping['soft_deleteable'])) { $config['softDeleteable'] = true; diff --git a/src/SoftDeleteable/Mapping/Event/Adapter/ODM.php b/src/SoftDeleteable/Mapping/Event/Adapter/ODM.php index 1640e853da..fc47e0be13 100644 --- a/src/SoftDeleteable/Mapping/Event/Adapter/ODM.php +++ b/src/SoftDeleteable/Mapping/Event/Adapter/ODM.php @@ -40,7 +40,7 @@ public function getDateValue($meta, $field) { $datetime = $this->clock instanceof ClockInterface ? $this->clock->now() : new \DateTimeImmutable(); $mapping = $meta->getFieldMapping($field); - $type = $mapping['type'] ?? null; + $type = $mapping->type ?? $mapping['type'] ?? null; if ('timestamp' === $type) { return (int) $datetime->format('U'); diff --git a/src/SoftDeleteable/Mapping/Event/Adapter/ORM.php b/src/SoftDeleteable/Mapping/Event/Adapter/ORM.php index 46d31be7e7..9cb72c6eeb 100644 --- a/src/SoftDeleteable/Mapping/Event/Adapter/ORM.php +++ b/src/SoftDeleteable/Mapping/Event/Adapter/ORM.php @@ -44,7 +44,7 @@ public function getDateValue($meta, $field) return $this->getObjectManager()->getConnection()->convertToPHPValue( $this->getRawDateValue($mapping), - $mapping instanceof FieldMapping ? $mapping->type : ($mapping['type'] ?? Types::DATETIME_MUTABLE) + $mapping instanceof FieldMapping ? $mapping->type : ($mapping->type ?? $mapping['type'] ?? Types::DATETIME_MUTABLE) ); } @@ -58,7 +58,7 @@ public function getDateValue($meta, $field) private function getRawDateValue($mapping) { $datetime = $this->clock instanceof ClockInterface ? $this->clock->now() : new \DateTimeImmutable(); - $type = $mapping instanceof FieldMapping ? $mapping->type : ($mapping['type'] ?? ''); + $type = $mapping instanceof FieldMapping ? $mapping->type : ($mapping->type ?? $mapping['type'] ?? ''); if ('integer' === $type) { return (int) $datetime->format('U'); diff --git a/src/Sortable/Mapping/Driver/Xml.php b/src/Sortable/Mapping/Driver/Xml.php index 658e692c36..e02b81ca18 100644 --- a/src/Sortable/Mapping/Driver/Xml.php +++ b/src/Sortable/Mapping/Driver/Xml.php @@ -90,7 +90,7 @@ protected function isValidField($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping['type'], self::VALID_TYPES, true); + return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true); } /** diff --git a/src/Sortable/Mapping/Driver/Yaml.php b/src/Sortable/Mapping/Driver/Yaml.php index d09d815ab7..87736da406 100644 --- a/src/Sortable/Mapping/Driver/Yaml.php +++ b/src/Sortable/Mapping/Driver/Yaml.php @@ -52,7 +52,7 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['fields'])) { - foreach ($mapping['fields'] as $field => $fieldMapping) { + foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { if (in_array('sortablePosition', $fieldMapping['gedmo'], true)) { if (!$this->isValidField($meta, $field)) { @@ -62,13 +62,13 @@ public function readExtendedMetadata($meta, array &$config) } } } - $config = $this->readSortableGroups($mapping['fields'], $config); + $config = $this->readSortableGroups($mapping->fields ?? $mapping['fields'], $config); } if (isset($mapping['manyToOne'])) { - $config = $this->readSortableGroups($mapping['manyToOne'], $config); + $config = $this->readSortableGroups($mapping->manyToOne ?? $mapping['manyToOne'], $config); } if (isset($mapping['manyToMany'])) { - $config = $this->readSortableGroups($mapping['manyToMany'], $config); + $config = $this->readSortableGroups($mapping->manyToMany ?? $mapping['manyToMany'], $config); } if (!$meta->isMappedSuperclass && $config) { @@ -97,7 +97,7 @@ protected function isValidField($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping['type'], self::VALID_TYPES, true); + return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true); } /** diff --git a/src/Timestampable/Mapping/Driver/Xml.php b/src/Timestampable/Mapping/Driver/Xml.php index e94415ab42..e217168063 100644 --- a/src/Timestampable/Mapping/Driver/Xml.php +++ b/src/Timestampable/Mapping/Driver/Xml.php @@ -105,6 +105,6 @@ protected function isValidField($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping['type'], self::VALID_TYPES, true); + return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true); } } diff --git a/src/Timestampable/Mapping/Driver/Yaml.php b/src/Timestampable/Mapping/Driver/Yaml.php index 3c1600f734..bf3744bb8b 100644 --- a/src/Timestampable/Mapping/Driver/Yaml.php +++ b/src/Timestampable/Mapping/Driver/Yaml.php @@ -59,7 +59,7 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['fields'])) { - foreach ($mapping['fields'] as $field => $fieldMapping) { + foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo']['timestampable'])) { $mappingProperty = $fieldMapping['gedmo']['timestampable']; if (!$this->isValidField($meta, $field)) { @@ -109,6 +109,6 @@ protected function isValidField($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping['type'], self::VALID_TYPES, true); + return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true); } } diff --git a/src/Timestampable/Mapping/Event/Adapter/ODM.php b/src/Timestampable/Mapping/Event/Adapter/ODM.php index 8b9f5b9b2c..ee7cb77a10 100644 --- a/src/Timestampable/Mapping/Event/Adapter/ODM.php +++ b/src/Timestampable/Mapping/Event/Adapter/ODM.php @@ -40,7 +40,7 @@ public function getDateValue($meta, $field) { $datetime = $this->clock instanceof ClockInterface ? $this->clock->now() : new \DateTimeImmutable(); $mapping = $meta->getFieldMapping($field); - $type = $mapping['type'] ?? null; + $type = $mapping->type ?? $mapping['type'] ?? null; if ('timestamp' === $type) { return (int) $datetime->format('U'); diff --git a/src/Timestampable/Mapping/Event/Adapter/ORM.php b/src/Timestampable/Mapping/Event/Adapter/ORM.php index 4325127a44..2fb2f16673 100644 --- a/src/Timestampable/Mapping/Event/Adapter/ORM.php +++ b/src/Timestampable/Mapping/Event/Adapter/ORM.php @@ -44,7 +44,7 @@ public function getDateValue($meta, $field) return $this->getObjectManager()->getConnection()->convertToPHPValue( $this->getRawDateValue($mapping), - $mapping instanceof FieldMapping ? $mapping->type : ($mapping['type'] ?? Types::DATETIME_MUTABLE) + $mapping instanceof FieldMapping ? $mapping->type : ($mapping->type ?? $mapping['type'] ?? Types::DATETIME_MUTABLE) ); } @@ -58,7 +58,7 @@ public function getDateValue($meta, $field) private function getRawDateValue($mapping) { $datetime = $this->clock instanceof ClockInterface ? $this->clock->now() : new \DateTimeImmutable(); - $type = $mapping instanceof FieldMapping ? $mapping->type : ($mapping['type'] ?? ''); + $type = $mapping instanceof FieldMapping ? $mapping->type : ($mapping->type ?? $mapping['type'] ?? ''); if ('integer' === $type) { return (int) $datetime->format('U'); diff --git a/src/Translatable/Document/Repository/TranslationRepository.php b/src/Translatable/Document/Repository/TranslationRepository.php index a372d029a8..74c7962c3f 100644 --- a/src/Translatable/Document/Repository/TranslationRepository.php +++ b/src/Translatable/Document/Repository/TranslationRepository.php @@ -95,7 +95,7 @@ public function translate($document, $field, $locale, $value) $transMeta->getReflectionProperty('locale')->setValue($trans, $locale); } $mapping = $meta->getFieldMapping($field); - $type = $this->getType($mapping['type']); + $type = $this->getType($mapping->type ?? $mapping['type']); $transformed = $type->convertToDatabaseValue($value); $transMeta->getReflectionProperty('content')->setValue($trans, $transformed); if ($this->dm->getUnitOfWork()->isInIdentityMap($document)) { diff --git a/src/Translatable/Mapping/Driver/Yaml.php b/src/Translatable/Mapping/Driver/Yaml.php index dea0516339..bc7e25da23 100644 --- a/src/Translatable/Mapping/Driver/Yaml.php +++ b/src/Translatable/Mapping/Driver/Yaml.php @@ -39,7 +39,7 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['gedmo'])) { - $classMapping = $mapping['gedmo']; + $classMapping = ($mapping->gedmo ?? $mapping['gedmo']); if (isset($classMapping['translation']['entity'])) { $translationEntity = $classMapping['translation']['entity']; if (!$cl = $this->getRelatedClassName($meta, $translationEntity)) { @@ -55,13 +55,13 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['fields'])) { - foreach ($mapping['fields'] as $field => $fieldMapping) { + foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { $config = $this->buildFieldConfiguration($field, $fieldMapping, $config); } } if (isset($mapping['attributeOverride'])) { - foreach ($mapping['attributeOverride'] as $field => $overrideMapping) { + foreach (($mapping->attributeOverride ?? $mapping['attributeOverride']) as $field => $overrideMapping) { $config = $this->buildFieldConfiguration($field, $overrideMapping, $config); } } diff --git a/src/Tree/Mapping/Driver/Yaml.php b/src/Tree/Mapping/Driver/Yaml.php index d7cfe555cd..c4c4b2661a 100644 --- a/src/Tree/Mapping/Driver/Yaml.php +++ b/src/Tree/Mapping/Driver/Yaml.php @@ -52,7 +52,7 @@ public function readExtendedMetadata($meta, array &$config) $validator = new Validator(); if (isset($mapping['gedmo'])) { - $classMapping = $mapping['gedmo']; + $classMapping = ($mapping->gedmo ?? $mapping['gedmo']); if (isset($classMapping['tree']['type'])) { $strategy = $classMapping['tree']['type']; if (!in_array($strategy, $this->strategies, true)) { @@ -76,7 +76,7 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['id'])) { - foreach ($mapping['id'] as $field => $fieldMapping) { + foreach (($mapping->id ?? $mapping['id']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { if (in_array('treePathSource', $fieldMapping['gedmo'], true)) { if (!$validator->isValidFieldForPathSource($meta, $field)) { @@ -89,7 +89,7 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['fields'])) { - foreach ($mapping['fields'] as $field => $fieldMapping) { + foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { if (in_array('treeLeft', $fieldMapping['gedmo'], true)) { if (!$validator->isValidField($meta, $field)) { @@ -182,7 +182,7 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['manyToOne'])) { - foreach ($mapping['manyToOne'] as $field => $relationMapping) { + foreach (($mapping->manyToOne ?? $mapping['manyToOne']) as $field => $relationMapping) { if (isset($relationMapping['gedmo'])) { if (in_array('treeParent', $relationMapping['gedmo'], true)) { if (!$this->getRelatedClassName($meta, $relationMapping['targetEntity'])) { diff --git a/src/Tree/Mapping/Validator.php b/src/Tree/Mapping/Validator.php index f2d0fcd9fa..c17071ce3f 100644 --- a/src/Tree/Mapping/Validator.php +++ b/src/Tree/Mapping/Validator.php @@ -97,7 +97,7 @@ public function isValidField($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping['type'], self::VALID_TYPES, true); + return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true); } /** @@ -112,7 +112,7 @@ public function isValidFieldForPath($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping['type'], $this->validPathTypes, true); + return $mapping && in_array($mapping->type ?? $mapping['type'], $this->validPathTypes, true); } /** @@ -127,7 +127,7 @@ public function isValidFieldForPathSource($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping['type'], $this->validPathSourceTypes, true); + return $mapping && in_array($mapping->type ?? $mapping['type'], $this->validPathSourceTypes, true); } /** @@ -142,7 +142,7 @@ public function isValidFieldForPathHash($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping['type'], $this->validPathHashTypes, true); + return $mapping && in_array($mapping->type ?? $mapping['type'], $this->validPathHashTypes, true); } /** @@ -157,7 +157,7 @@ public function isValidFieldForLockTime($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && ('date' === $mapping['type'] || 'datetime' === $mapping['type'] || 'timestamp' === $mapping['type']); + return $mapping && ('date' === ($mapping->type ?? $mapping['type']) || 'datetime' === ($mapping->type ?? $mapping['type']) || 'timestamp' === ($mapping->type ?? $mapping['type'])); } /** @@ -172,7 +172,7 @@ public function isValidFieldForRoot($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping['type'], $this->validRootTypes, true); + return $mapping && in_array($mapping->type ?? $mapping['type'], $this->validRootTypes, true); } /** diff --git a/src/Tree/Strategy/ORM/Closure.php b/src/Tree/Strategy/ORM/Closure.php index 3e68f6b3d5..b6ca7873c4 100644 --- a/src/Tree/Strategy/ORM/Closure.php +++ b/src/Tree/Strategy/ORM/Closure.php @@ -524,7 +524,9 @@ protected function setLevelFieldOnPendingNodes(ObjectManager $em) } // Avoid type conversion performance penalty - $type = 'integer' === $mapping['type'] ? ArrayParameterType::INTEGER : ArrayParameterType::STRING; + $type = 'integer' === ($mapping->type ?? $mapping['type']) + ? ArrayParameterType::INTEGER + : ArrayParameterType::STRING; // We calculate levels for all nodes $sql = 'SELECT c.descendant, MAX(c.depth) + 1 AS levelNum '; diff --git a/src/Uploadable/Mapping/Driver/Yaml.php b/src/Uploadable/Mapping/Driver/Yaml.php index 540389aa92..cb63585d8b 100644 --- a/src/Uploadable/Mapping/Driver/Yaml.php +++ b/src/Uploadable/Mapping/Driver/Yaml.php @@ -40,7 +40,7 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['gedmo'])) { - $classMapping = $mapping['gedmo']; + $classMapping = ($mapping->gedmo ?? $mapping['gedmo']); if (isset($classMapping['uploadable'])) { $uploadable = $classMapping['uploadable']; @@ -65,7 +65,7 @@ public function readExtendedMetadata($meta, array &$config) $config['disallowedTypes'] = $uploadable['disallowedTypes'] ?? ''; if (isset($mapping['fields'])) { - foreach ($mapping['fields'] as $field => $info) { + foreach (($mapping->fields ?? $mapping['fields']) as $field => $info) { if (isset($info['gedmo']) && array_key_exists(0, $info['gedmo'])) { if ('uploadableFileMimeType' === $info['gedmo'][0]) { $config['fileMimeTypeField'] = $field; diff --git a/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Driver/Attribute.php b/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Driver/Attribute.php index eeaf0619a5..2794af8934 100644 --- a/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Driver/Attribute.php +++ b/tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Driver/Attribute.php @@ -49,7 +49,7 @@ public function readExtendedMetadata($meta, array &$config) // validate encoding type $mapping = $meta->getFieldMapping($field); - if ('string' !== $mapping['type']) { + if ('string' !== ($mapping->type ?? $mapping['type'])) { throw new \Exception('Only strings can be encoded'); } From 4347cff1934ed0eb07313cf95b69be962eb03e39 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Sat, 19 Oct 2024 00:24:15 +0200 Subject: [PATCH 2/9] Reduce deprecations due to FieldMapping array access (for properties named $fieldMapping) --- src/Blameable/Mapping/Driver/Yaml.php | 4 +-- src/IpTraceable/Mapping/Driver/Yaml.php | 4 +-- src/Loggable/Mapping/Driver/Yaml.php | 12 ++++---- .../Mapping/Driver/Yaml.php | 4 +-- .../ReferenceIntegrityListener.php | 28 +++++++++---------- src/References/Mapping/Driver/Yaml.php | 12 ++++---- src/Sluggable/Mapping/Driver/Yaml.php | 2 +- src/SoftDeleteable/Mapping/Validator.php | 4 +-- src/Sortable/Mapping/Driver/Yaml.php | 4 +-- src/Timestampable/Mapping/Driver/Yaml.php | 2 +- src/Translatable/Mapping/Driver/Yaml.php | 4 +-- .../Query/TreeWalker/TranslationWalker.php | 6 ++-- src/Tree/Mapping/Driver/Yaml.php | 24 ++++++++-------- .../Strategy/AbstractMaterializedPath.php | 2 +- src/Uploadable/Mapping/Validator.php | 2 +- 15 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/Blameable/Mapping/Driver/Yaml.php b/src/Blameable/Mapping/Driver/Yaml.php index 1abe79e9d4..2a923e29f3 100644 --- a/src/Blameable/Mapping/Driver/Yaml.php +++ b/src/Blameable/Mapping/Driver/Yaml.php @@ -55,7 +55,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['fields'])) { foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo']['blameable'])) { - $mappingProperty = $fieldMapping['gedmo']['blameable']; + $mappingProperty = $fieldMapping->gedmo->blameable ?? $fieldMapping['gedmo']['blameable']; if (!$this->isValidField($meta, $field)) { throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'string' or a reference in class - {$meta->getName()}"); } @@ -86,7 +86,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['manyToOne'])) { foreach (($mapping->manyToOne ?? $mapping['manyToOne']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo']['blameable'])) { - $mappingProperty = $fieldMapping['gedmo']['blameable']; + $mappingProperty = $fieldMapping->gedmo->blameable ?? $fieldMapping['gedmo']['blameable']; if (!$meta->isSingleValuedAssociation($field)) { throw new InvalidMappingException("Association - [{$field}] is not valid, it must be a one-to-many relation or a string field - {$meta->getName()}"); } diff --git a/src/IpTraceable/Mapping/Driver/Yaml.php b/src/IpTraceable/Mapping/Driver/Yaml.php index 45976a7892..992409be1c 100644 --- a/src/IpTraceable/Mapping/Driver/Yaml.php +++ b/src/IpTraceable/Mapping/Driver/Yaml.php @@ -51,7 +51,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['fields'])) { foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo']['ipTraceable'])) { - $mappingProperty = $fieldMapping['gedmo']['ipTraceable']; + $mappingProperty = $fieldMapping->gedmo->ipTraceable ?? $fieldMapping['gedmo']['ipTraceable']; if (!$this->isValidField($meta, $field)) { throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'string' in class - {$meta->getName()}"); } @@ -82,7 +82,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['manyToOne'])) { foreach (($mapping->manyToOne ?? $mapping['manyToOne']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo']['ipTraceable'])) { - $mappingProperty = $fieldMapping['gedmo']['ipTraceable']; + $mappingProperty = ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['ipTraceable']; if (!$meta->isSingleValuedAssociation($field)) { throw new InvalidMappingException("Association - [{$field}] is not valid, it must be a one-to-many relation or a string field - {$meta->getName()}"); } diff --git a/src/Loggable/Mapping/Driver/Yaml.php b/src/Loggable/Mapping/Driver/Yaml.php index 95562d725b..3fd3a0c8ec 100644 --- a/src/Loggable/Mapping/Driver/Yaml.php +++ b/src/Loggable/Mapping/Driver/Yaml.php @@ -56,7 +56,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['fields'])) { foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('versioned', $fieldMapping['gedmo'], true)) { + if (in_array('versioned', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { if ($meta->isCollectionValuedAssociation($field)) { throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}"); } @@ -70,7 +70,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['attributeOverride'])) { foreach (($mapping->attributeOverride ?? $mapping['attributeOverride']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('versioned', $fieldMapping['gedmo'], true)) { + if (in_array('versioned', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { if ($meta->isCollectionValuedAssociation($field)) { throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}"); } @@ -84,7 +84,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['manyToOne'])) { foreach (($mapping->manyToOne ?? $mapping['manyToOne']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('versioned', $fieldMapping['gedmo'], true)) { + if (in_array('versioned', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { if ($meta->isCollectionValuedAssociation($field)) { throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}"); } @@ -98,7 +98,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['oneToOne'])) { foreach (($mapping->oneToOne ?? $mapping['oneToOne']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('versioned', $fieldMapping['gedmo'], true)) { + if (in_array('versioned', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { if ($meta->isCollectionValuedAssociation($field)) { throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}"); } @@ -112,12 +112,12 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['embedded'])) { foreach (($mapping->embedded ?? $mapping['embedded']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('versioned', $fieldMapping['gedmo'], true)) { + if (in_array('versioned', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { if ($meta->isCollectionValuedAssociation($field)) { throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}"); } // fields cannot be overrided and throws mapping exception - $mapping = $this->_getMapping($fieldMapping['class']); + $mapping = $this->_getMapping($fieldMapping->class ?? $fieldMapping['class']); $config = $this->inspectEmbeddedForVersioned($field, $mapping, $config); } } diff --git a/src/ReferenceIntegrity/Mapping/Driver/Yaml.php b/src/ReferenceIntegrity/Mapping/Driver/Yaml.php index 86b67d1608..9bb5abf38e 100644 --- a/src/ReferenceIntegrity/Mapping/Driver/Yaml.php +++ b/src/ReferenceIntegrity/Mapping/Driver/Yaml.php @@ -51,12 +51,12 @@ public function readExtendedMetadata($meta, array &$config) throw new InvalidMappingException(sprintf("'mappedBy' should be set on '%s' in '%s'", $property, $meta->getName())); } - if (!in_array($fieldMapping['gedmo']['referenceIntegrity'], $validator->getIntegrityActions(), true)) { + if (!in_array(($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['referenceIntegrity'], $validator->getIntegrityActions(), true)) { throw new InvalidMappingException(sprintf('Field - [%s] does not have a valid integrity option, [%s] in class - %s', $property, implode(', ', $validator->getIntegrityActions()), $meta->getName())); } $config['referenceIntegrity'][$property][($mapping->fields ?? $mapping['fields'])[$property]['mappedBy']] = - $fieldMapping['gedmo']['referenceIntegrity']; + ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['referenceIntegrity']; } } } diff --git a/src/ReferenceIntegrity/ReferenceIntegrityListener.php b/src/ReferenceIntegrity/ReferenceIntegrityListener.php index 901c18dc76..9e6343472d 100644 --- a/src/ReferenceIntegrity/ReferenceIntegrityListener.php +++ b/src/ReferenceIntegrity/ReferenceIntegrityListener.php @@ -86,15 +86,15 @@ public function preRemove(EventArgs $args) throw new InvalidMappingException(sprintf("Reference '%s' on '%s' should have 'mappedBy' option defined", $property, $meta->getName())); } - assert(class_exists($fieldMapping['targetDocument'])); + assert(class_exists($fieldMapping->targetDocument ?? $fieldMapping['targetDocument'])); - $subMeta = $om->getClassMetadata($fieldMapping['targetDocument']); + $subMeta = $om->getClassMetadata($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']); - if (!$subMeta->hasField($fieldMapping['mappedBy'])) { - throw new InvalidMappingException(sprintf('Unable to find reference integrity [%s] as mapped property in entity - %s', $fieldMapping['mappedBy'], $fieldMapping['targetDocument'])); + if (!$subMeta->hasField($fieldMapping->mappedBy ?? $fieldMapping['mappedBy'])) { + throw new InvalidMappingException(sprintf('Unable to find reference integrity [%s] as mapped property in entity - %s', ($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']), ($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']))); } - $refReflProp = $subMeta->getReflectionProperty($fieldMapping['mappedBy']); + $refReflProp = $subMeta->getReflectionProperty($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']); if ($meta->isCollectionValuedReference($property)) { foreach ($refDoc as $refObj) { @@ -112,19 +112,19 @@ public function preRemove(EventArgs $args) throw new InvalidMappingException(sprintf("Reference '%s' on '%s' should have 'mappedBy' option defined", $property, $meta->getName())); } - assert(class_exists($fieldMapping['targetDocument'])); + assert(class_exists($fieldMapping->targetDocument ?? $fieldMapping['targetDocument'])); - $subMeta = $om->getClassMetadata($fieldMapping['targetDocument']); + $subMeta = $om->getClassMetadata($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']); - if (!$subMeta->hasField($fieldMapping['mappedBy'])) { - throw new InvalidMappingException(sprintf('Unable to find reference integrity [%s] as mapped property in entity - %s', $fieldMapping['mappedBy'], $fieldMapping['targetDocument'])); + if (!$subMeta->hasField($fieldMapping->mappedBy ?? $fieldMapping['mappedBy'])) { + throw new InvalidMappingException(sprintf('Unable to find reference integrity [%s] as mapped property in entity - %s', ($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']), ($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']))); } - if (!$subMeta->isCollectionValuedReference($fieldMapping['mappedBy'])) { - throw new InvalidMappingException(sprintf('Reference integrity [%s] mapped property in entity - %s should be a Reference Many', $fieldMapping['mappedBy'], $fieldMapping['targetDocument'])); + if (!$subMeta->isCollectionValuedReference($fieldMapping->mappedBy ?? $fieldMapping['mappedBy'])) { + throw new InvalidMappingException(sprintf('Reference integrity [%s] mapped property in entity - %s should be a Reference Many', ($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']), ($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']))); } - $refReflProp = $subMeta->getReflectionProperty($fieldMapping['mappedBy']); + $refReflProp = $subMeta->getReflectionProperty($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']); if ($meta->isCollectionValuedReference($property)) { foreach ($refDoc as $refObj) { @@ -143,10 +143,10 @@ public function preRemove(EventArgs $args) break; case Validator::RESTRICT: if ($meta->isCollectionValuedReference($property) && $refDoc->count() > 0) { - throw new ReferenceIntegrityStrictException(sprintf("The reference integrity for the '%s' collection is restricted", $fieldMapping['targetDocument'])); + throw new ReferenceIntegrityStrictException(sprintf("The reference integrity for the '%s' collection is restricted", ($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']))); } if ($meta->isSingleValuedReference($property) && null !== $refDoc) { - throw new ReferenceIntegrityStrictException(sprintf("The reference integrity for the '%s' document is restricted", $fieldMapping['targetDocument'])); + throw new ReferenceIntegrityStrictException(sprintf("The reference integrity for the '%s' document is restricted", ($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']))); } break; diff --git a/src/References/Mapping/Driver/Yaml.php b/src/References/Mapping/Driver/Yaml.php index 9fbbcd2cdf..e18a42bf72 100644 --- a/src/References/Mapping/Driver/Yaml.php +++ b/src/References/Mapping/Driver/Yaml.php @@ -44,7 +44,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['gedmo'], ($mapping->gedmo ?? $mapping['gedmo'])['reference'])) { foreach (($mapping->gedmo ?? $mapping['gedmo'])['reference'] as $field => $fieldMapping) { - $reference = $fieldMapping['reference']; + $reference = ($fieldMapping->reference ?? $fieldMapping['reference']); if (!in_array($reference, array_keys($this->validReferences), true)) { throw new InvalidMappingException($reference.' is not a valid reference, valid references are: '.implode(', ', array_keys($this->validReferences))); @@ -52,20 +52,20 @@ public function readExtendedMetadata($meta, array &$config) $config[$reference][$field] = [ 'field' => $field, - 'type' => $fieldMapping['type'], - 'class' => $fieldMapping['class'], + 'type' => $fieldMapping->type ?? $fieldMapping['type'], + 'class' => $fieldMapping->class ?? $fieldMapping['class'], ]; if (array_key_exists('mappedBy', $fieldMapping)) { - $config[$reference][$field]['mappedBy'] = $fieldMapping['mappedBy']; + $config[$reference][$field]['mappedBy'] = ($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']); } if (array_key_exists('identifier', $fieldMapping)) { - $config[$reference][$field]['identifier'] = $fieldMapping['identifier']; + $config[$reference][$field]['identifier'] = ($fieldMapping->identifier ?? $fieldMapping['identifier']); } if (array_key_exists('inversedBy', $fieldMapping)) { - $config[$reference][$field]['inversedBy'] = $fieldMapping['inversedBy']; + $config[$reference][$field]['inversedBy'] = ($fieldMapping->inversedBy ?? $fieldMapping['inversedBy']); } } } diff --git a/src/Sluggable/Mapping/Driver/Yaml.php b/src/Sluggable/Mapping/Driver/Yaml.php index cb74de749e..f455257758 100644 --- a/src/Sluggable/Mapping/Driver/Yaml.php +++ b/src/Sluggable/Mapping/Driver/Yaml.php @@ -98,7 +98,7 @@ private function buildFieldConfiguration(string $field, array $fieldMapping, Cla { if (isset($fieldMapping['gedmo'])) { if (isset($fieldMapping['gedmo']['slug'])) { - $slug = $fieldMapping['gedmo']['slug']; + $slug = ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['slug']; if (!$this->isValidField($meta, $field)) { throw new InvalidMappingException("Cannot use field - [{$field}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->getName()}"); } diff --git a/src/SoftDeleteable/Mapping/Validator.php b/src/SoftDeleteable/Mapping/Validator.php index 0f138e2504..54b9ed0bcf 100644 --- a/src/SoftDeleteable/Mapping/Validator.php +++ b/src/SoftDeleteable/Mapping/Validator.php @@ -52,8 +52,8 @@ public static function validateField(ClassMetadata $meta, $field) $fieldMapping = $meta->getFieldMapping($field); - if (!in_array($fieldMapping['type'], self::$validTypes, true)) { - throw new InvalidMappingException(sprintf('Field "%s" (type "%s") must be of one of the following types: "%s" in entity %s', $field, $fieldMapping['type'], implode(', ', self::$validTypes), $meta->getName())); + if (!in_array(($fieldMapping->type ?? $fieldMapping['type']), self::$validTypes, true)) { + throw new InvalidMappingException(sprintf('Field "%s" (type "%s") must be of one of the following types: "%s" in entity %s', $field, ($fieldMapping->type ?? $fieldMapping['type']), implode(', ', self::$validTypes), $meta->getName())); } } } diff --git a/src/Sortable/Mapping/Driver/Yaml.php b/src/Sortable/Mapping/Driver/Yaml.php index 87736da406..5472b31b6e 100644 --- a/src/Sortable/Mapping/Driver/Yaml.php +++ b/src/Sortable/Mapping/Driver/Yaml.php @@ -54,7 +54,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['fields'])) { foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('sortablePosition', $fieldMapping['gedmo'], true)) { + if (in_array('sortablePosition', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { if (!$this->isValidField($meta, $field)) { throw new InvalidMappingException("Sortable position field - [{$field}] type is not valid and must be 'integer' in class - {$meta->getName()}"); } @@ -110,7 +110,7 @@ private function readSortableGroups(iterable $mapping, array $config): array { foreach ($mapping as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('sortableGroup', $fieldMapping['gedmo'], true)) { + if (in_array('sortableGroup', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { if (!isset($config['groups'])) { $config['groups'] = []; } diff --git a/src/Timestampable/Mapping/Driver/Yaml.php b/src/Timestampable/Mapping/Driver/Yaml.php index bf3744bb8b..da678057df 100644 --- a/src/Timestampable/Mapping/Driver/Yaml.php +++ b/src/Timestampable/Mapping/Driver/Yaml.php @@ -61,7 +61,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['fields'])) { foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo']['timestampable'])) { - $mappingProperty = $fieldMapping['gedmo']['timestampable']; + $mappingProperty = ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['timestampable']; if (!$this->isValidField($meta, $field)) { throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'date', 'datetime' or 'time' in class - {$meta->getName()}"); } diff --git a/src/Translatable/Mapping/Driver/Yaml.php b/src/Translatable/Mapping/Driver/Yaml.php index bc7e25da23..ae7ba07c4e 100644 --- a/src/Translatable/Mapping/Driver/Yaml.php +++ b/src/Translatable/Mapping/Driver/Yaml.php @@ -89,11 +89,11 @@ protected function _loadMappingFile($file) private function buildFieldConfiguration(string $field, array $fieldMapping, array $config): array { if (isset($fieldMapping['gedmo'])) { - if (in_array('translatable', $fieldMapping['gedmo'], true) || isset($fieldMapping['gedmo']['translatable'])) { + if (in_array('translatable', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true) || isset($fieldMapping['gedmo']['translatable'])) { // fields cannot be overrided and throws mapping exception $config['fields'][] = $field; if (isset($fieldMapping['gedmo']['translatable']['fallback'])) { - $config['fallback'][$field] = $fieldMapping['gedmo']['translatable']['fallback']; + $config['fallback'][$field] = ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['translatable']['fallback']; } } } diff --git a/src/Translatable/Query/TreeWalker/TranslationWalker.php b/src/Translatable/Query/TreeWalker/TranslationWalker.php index 4801ad4d16..b1c0a08b18 100644 --- a/src/Translatable/Query/TreeWalker/TranslationWalker.php +++ b/src/Translatable/Query/TreeWalker/TranslationWalker.php @@ -309,10 +309,10 @@ private function prepareTranslatedComponents(): void // Treat translation as original field type $fieldMapping = $meta->getFieldMapping($field); if ((($this->platform instanceof AbstractMySQLPlatform) - && in_array($fieldMapping['type'], ['decimal'], true)) + && in_array(($fieldMapping->type ?? $fieldMapping['type']), ['decimal'], true)) || (!($this->platform instanceof AbstractMySQLPlatform) - && !in_array($fieldMapping['type'], ['datetime', 'datetimetz', 'date', 'time'], true))) { - $type = Type::getType($fieldMapping['type']); + && !in_array(($fieldMapping->type ?? $fieldMapping['type']), ['datetime', 'datetimetz', 'date', 'time'], true))) { + $type = Type::getType($fieldMapping->type ?? $fieldMapping['type']); // In ORM 2.x, $fieldMapping is an array. In ORM 3.x, it's a data object. Always cast to an array for compatibility across versions. $substituteField = 'CAST('.$substituteField.' AS '.$type->getSQLDeclaration((array) $fieldMapping, $this->platform).')'; diff --git a/src/Tree/Mapping/Driver/Yaml.php b/src/Tree/Mapping/Driver/Yaml.php index c4c4b2661a..39e65855e3 100644 --- a/src/Tree/Mapping/Driver/Yaml.php +++ b/src/Tree/Mapping/Driver/Yaml.php @@ -78,7 +78,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['id'])) { foreach (($mapping->id ?? $mapping['id']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('treePathSource', $fieldMapping['gedmo'], true)) { + if (in_array('treePathSource', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { if (!$validator->isValidFieldForPathSource($meta, $field)) { throw new InvalidMappingException("Tree PathSource field - [{$field}] type is not valid. It can be any of the integer variants, double, float or string in class - {$meta->getName()}"); } @@ -91,34 +91,34 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['fields'])) { foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('treeLeft', $fieldMapping['gedmo'], true)) { + if (in_array('treeLeft', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { if (!$validator->isValidField($meta, $field)) { throw new InvalidMappingException("Tree left field - [{$field}] type is not valid and must be 'integer' in class - {$meta->getName()}"); } $config['left'] = $field; - } elseif (in_array('treeRight', $fieldMapping['gedmo'], true)) { + } elseif (in_array('treeRight', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { if (!$validator->isValidField($meta, $field)) { throw new InvalidMappingException("Tree right field - [{$field}] type is not valid and must be 'integer' in class - {$meta->getName()}"); } $config['right'] = $field; - } elseif (in_array('treeLevel', $fieldMapping['gedmo'], true)) { + } elseif (in_array('treeLevel', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { if (!$validator->isValidField($meta, $field)) { throw new InvalidMappingException("Tree level field - [{$field}] type is not valid and must be 'integer' in class - {$meta->getName()}"); } $config['level'] = $field; - } elseif (in_array('treeRoot', $fieldMapping['gedmo'], true)) { + } elseif (in_array('treeRoot', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { if (!$validator->isValidFieldForRoot($meta, $field)) { throw new InvalidMappingException("Tree root field - [{$field}] type is not valid and must be any of the 'integer' types or 'string' in class - {$meta->getName()}"); } $config['root'] = $field; - } elseif (in_array('treePath', $fieldMapping['gedmo'], true) || isset($fieldMapping['gedmo']['treePath'])) { + } elseif (in_array('treePath', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true) || isset($fieldMapping['gedmo']['treePath'])) { if (!$validator->isValidFieldForPath($meta, $field)) { throw new InvalidMappingException("Tree Path field - [{$field}] type is not valid. It must be string or text in class - {$meta->getName()}"); } - $treePathInfo = $fieldMapping['gedmo']['treePath'] ?? $fieldMapping['gedmo'][array_search( + $treePathInfo = ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['treePath'] ?? ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])[array_search( 'treePath', - $fieldMapping['gedmo'], + ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true )]; @@ -155,22 +155,22 @@ public function readExtendedMetadata($meta, array &$config) $config['path_append_id'] = $appendId; $config['path_starts_with_separator'] = $startsWithSeparator; $config['path_ends_with_separator'] = $endsWithSeparator; - } elseif (in_array('treePathSource', $fieldMapping['gedmo'], true)) { + } elseif (in_array('treePathSource', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { if (!$validator->isValidFieldForPathSource($meta, $field)) { throw new InvalidMappingException("Tree PathSource field - [{$field}] type is not valid. It can be any of the integer variants, double, float or string in class - {$meta->getName()}"); } $config['path_source'] = $field; - } elseif (in_array('treePathHash', $fieldMapping['gedmo'], true)) { + } elseif (in_array('treePathHash', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { if (!$validator->isValidFieldForPathSource($meta, $field)) { throw new InvalidMappingException("Tree PathHash field - [{$field}] type is not valid and must be 'string' in class - {$meta->getName()}"); } $config['path_hash'] = $field; - } elseif (in_array('treeLockTime', $fieldMapping['gedmo'], true)) { + } elseif (in_array('treeLockTime', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { if (!$validator->isValidFieldForLocktime($meta, $field)) { throw new InvalidMappingException("Tree LockTime field - [{$field}] type is not valid. It must be \"date\" in class - {$meta->getName()}"); } $config['lock_time'] = $field; - } elseif (in_array('treeParent', $fieldMapping['gedmo'], true)) { + } elseif (in_array('treeParent', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { $config['parent'] = $field; } } diff --git a/src/Tree/Strategy/AbstractMaterializedPath.php b/src/Tree/Strategy/AbstractMaterializedPath.php index 0f4cc8372f..c1eef0df63 100644 --- a/src/Tree/Strategy/AbstractMaterializedPath.php +++ b/src/Tree/Strategy/AbstractMaterializedPath.php @@ -225,7 +225,7 @@ public function updateNode(ObjectManager $om, $node, AdapterInterface $ea) // default behavior: if PathSource field is a string, we append the ID to the path // path_append_id is true: always append id // path_append_id is false: never append id - if (true === $config['path_append_id'] || ('string' === $fieldMapping['type'] && false !== $config['path_append_id'])) { + if (true === $config['path_append_id'] || ('string' === ($fieldMapping->type ?? $fieldMapping['type']) && false !== $config['path_append_id'])) { if (method_exists($meta, 'getIdentifierValue')) { $identifier = $meta->getIdentifierValue($node); } else { diff --git a/src/Uploadable/Mapping/Validator.php b/src/Uploadable/Mapping/Validator.php index 4dfce4c1b3..f009c54b90 100644 --- a/src/Uploadable/Mapping/Validator.php +++ b/src/Uploadable/Mapping/Validator.php @@ -150,7 +150,7 @@ public static function validateField($meta, $field, $uploadableField, $validFiel $fieldMapping = $meta->getFieldMapping($field); - if (!in_array($fieldMapping['type'], $validFieldTypes, true)) { + if (!in_array(($fieldMapping->type ?? $fieldMapping['type']), $validFieldTypes, true)) { $msg = 'Field "%s" to work as an "%s" field must be of one of the following types: "%s".'; throw new InvalidMappingException(sprintf($msg, $field, $uploadableField, implode(', ', $validFieldTypes))); From 4ef25b721813dadf85f3bfe5cfaf4b64131ea7f9 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Sat, 19 Oct 2024 00:32:18 +0200 Subject: [PATCH 3/9] Manually fix more deprecations by reviewing usages of \Doctrine\ORM\Mapping\ClassMetadata::getFieldMapping() --- src/Timestampable/Mapping/Event/Adapter/ORM.php | 2 +- src/Translatable/Query/TreeWalker/TranslationWalker.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Timestampable/Mapping/Event/Adapter/ORM.php b/src/Timestampable/Mapping/Event/Adapter/ORM.php index 2fb2f16673..0738e4bfc0 100644 --- a/src/Timestampable/Mapping/Event/Adapter/ORM.php +++ b/src/Timestampable/Mapping/Event/Adapter/ORM.php @@ -44,7 +44,7 @@ public function getDateValue($meta, $field) return $this->getObjectManager()->getConnection()->convertToPHPValue( $this->getRawDateValue($mapping), - $mapping instanceof FieldMapping ? $mapping->type : ($mapping->type ?? $mapping['type'] ?? Types::DATETIME_MUTABLE) + $mapping instanceof FieldMapping ? $mapping->type : $mapping['type'] ?? Types::DATETIME_MUTABLE ); } diff --git a/src/Translatable/Query/TreeWalker/TranslationWalker.php b/src/Translatable/Query/TreeWalker/TranslationWalker.php index b1c0a08b18..359ba6e845 100644 --- a/src/Translatable/Query/TreeWalker/TranslationWalker.php +++ b/src/Translatable/Query/TreeWalker/TranslationWalker.php @@ -297,7 +297,7 @@ private function prepareTranslatedComponents(): void $mappingFK = $transMeta->getFieldMapping('foreignKey'); $mappingPK = $meta->getFieldMapping($identifier); - $fkColName = $this->getCastedForeignKey($compTblAlias.'.'.$idColName, $mappingFK['type'], $mappingPK['type']); + $fkColName = $this->getCastedForeignKey($compTblAlias.'.'.$idColName, $mappingFK->type ?? $mappingFK['type'], $mappingPK->type ?? $mappingPK['type']); $sql .= ' AND '.$tblAlias.'.'.$quoteStrategy->getColumnName('foreignKey', $transMeta, $this->platform) .' = '.$fkColName; } From 753511a474d175d8e9597a8c7d70bdc33acbec45 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Sat, 19 Oct 2024 00:34:32 +0200 Subject: [PATCH 4/9] Fix CS & manually fix more deprecations by reviewing usages of \Doctrine\ORM\Mapping\ClassMetadata::getFieldMapping() --- src/Loggable/Mapping/Driver/Yaml.php | 10 ++++----- .../ReferenceIntegrityListener.php | 10 ++++----- src/References/ReferencesListener.php | 10 ++++----- src/Sluggable/SluggableListener.php | 2 +- src/SoftDeleteable/Mapping/Validator.php | 4 ++-- src/Sortable/Mapping/Driver/Yaml.php | 4 ++-- src/Translatable/Mapping/Driver/Yaml.php | 2 +- .../Query/TreeWalker/TranslationWalker.php | 4 ++-- src/Tree/Mapping/Driver/Yaml.php | 22 +++++++++---------- src/Tree/Strategy/ORM/Closure.php | 4 ++-- src/Uploadable/Mapping/Validator.php | 2 +- 11 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/Loggable/Mapping/Driver/Yaml.php b/src/Loggable/Mapping/Driver/Yaml.php index 3fd3a0c8ec..ef94e70ec6 100644 --- a/src/Loggable/Mapping/Driver/Yaml.php +++ b/src/Loggable/Mapping/Driver/Yaml.php @@ -56,7 +56,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['fields'])) { foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('versioned', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { + if (in_array('versioned', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { if ($meta->isCollectionValuedAssociation($field)) { throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}"); } @@ -70,7 +70,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['attributeOverride'])) { foreach (($mapping->attributeOverride ?? $mapping['attributeOverride']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('versioned', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { + if (in_array('versioned', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { if ($meta->isCollectionValuedAssociation($field)) { throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}"); } @@ -84,7 +84,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['manyToOne'])) { foreach (($mapping->manyToOne ?? $mapping['manyToOne']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('versioned', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { + if (in_array('versioned', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { if ($meta->isCollectionValuedAssociation($field)) { throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}"); } @@ -98,7 +98,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['oneToOne'])) { foreach (($mapping->oneToOne ?? $mapping['oneToOne']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('versioned', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { + if (in_array('versioned', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { if ($meta->isCollectionValuedAssociation($field)) { throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}"); } @@ -112,7 +112,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['embedded'])) { foreach (($mapping->embedded ?? $mapping['embedded']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('versioned', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { + if (in_array('versioned', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { if ($meta->isCollectionValuedAssociation($field)) { throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}"); } diff --git a/src/ReferenceIntegrity/ReferenceIntegrityListener.php b/src/ReferenceIntegrity/ReferenceIntegrityListener.php index 9e6343472d..c6113ee60d 100644 --- a/src/ReferenceIntegrity/ReferenceIntegrityListener.php +++ b/src/ReferenceIntegrity/ReferenceIntegrityListener.php @@ -91,7 +91,7 @@ public function preRemove(EventArgs $args) $subMeta = $om->getClassMetadata($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']); if (!$subMeta->hasField($fieldMapping->mappedBy ?? $fieldMapping['mappedBy'])) { - throw new InvalidMappingException(sprintf('Unable to find reference integrity [%s] as mapped property in entity - %s', ($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']), ($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']))); + throw new InvalidMappingException(sprintf('Unable to find reference integrity [%s] as mapped property in entity - %s', $fieldMapping->mappedBy ?? $fieldMapping['mappedBy'], $fieldMapping->targetDocument ?? $fieldMapping['targetDocument'])); } $refReflProp = $subMeta->getReflectionProperty($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']); @@ -117,11 +117,11 @@ public function preRemove(EventArgs $args) $subMeta = $om->getClassMetadata($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']); if (!$subMeta->hasField($fieldMapping->mappedBy ?? $fieldMapping['mappedBy'])) { - throw new InvalidMappingException(sprintf('Unable to find reference integrity [%s] as mapped property in entity - %s', ($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']), ($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']))); + throw new InvalidMappingException(sprintf('Unable to find reference integrity [%s] as mapped property in entity - %s', $fieldMapping->mappedBy ?? $fieldMapping['mappedBy'], $fieldMapping->targetDocument ?? $fieldMapping['targetDocument'])); } if (!$subMeta->isCollectionValuedReference($fieldMapping->mappedBy ?? $fieldMapping['mappedBy'])) { - throw new InvalidMappingException(sprintf('Reference integrity [%s] mapped property in entity - %s should be a Reference Many', ($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']), ($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']))); + throw new InvalidMappingException(sprintf('Reference integrity [%s] mapped property in entity - %s should be a Reference Many', $fieldMapping->mappedBy ?? $fieldMapping['mappedBy'], $fieldMapping->targetDocument ?? $fieldMapping['targetDocument'])); } $refReflProp = $subMeta->getReflectionProperty($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']); @@ -143,10 +143,10 @@ public function preRemove(EventArgs $args) break; case Validator::RESTRICT: if ($meta->isCollectionValuedReference($property) && $refDoc->count() > 0) { - throw new ReferenceIntegrityStrictException(sprintf("The reference integrity for the '%s' collection is restricted", ($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']))); + throw new ReferenceIntegrityStrictException(sprintf("The reference integrity for the '%s' collection is restricted", $fieldMapping->targetDocument ?? $fieldMapping['targetDocument'])); } if ($meta->isSingleValuedReference($property) && null !== $refDoc) { - throw new ReferenceIntegrityStrictException(sprintf("The reference integrity for the '%s' document is restricted", ($fieldMapping->targetDocument ?? $fieldMapping['targetDocument']))); + throw new ReferenceIntegrityStrictException(sprintf("The reference integrity for the '%s' document is restricted", $fieldMapping->targetDocument ?? $fieldMapping['targetDocument'])); } break; diff --git a/src/References/ReferencesListener.php b/src/References/ReferencesListener.php index d2821d0ab8..c0df3e7fac 100644 --- a/src/References/ReferencesListener.php +++ b/src/References/ReferencesListener.php @@ -95,13 +95,13 @@ public function postLoad(EventArgs $eventArgs) $property = $meta->reflClass->getProperty($mapping->field ?? $mapping['field']); $property->setAccessible(true); if (isset($mapping['identifier'])) { - $referencedObjectId = $meta->getFieldValue($object, ($mapping->identifier ?? $mapping['identifier'])); + $referencedObjectId = $meta->getFieldValue($object, $mapping->identifier ?? $mapping['identifier']); if (null !== $referencedObjectId) { $property->setValue( $object, $ea->getSingleReference( $this->getManager($mapping->type ?? $mapping['type']), - ($mapping->class ?? $mapping['class']), + $mapping->class ?? $mapping['class'], $referencedObjectId ) ); @@ -120,8 +120,8 @@ public function postLoad(EventArgs $eventArgs) $class = ($mapping->class ?? $mapping['class']); $refMeta = $manager->getClassMetadata($class); $refConfig = $this->getConfiguration($manager, $refMeta->getName()); - if (isset($refConfig['referenceOne'][($mapping->mappedBy ?? $mapping['mappedBy'])])) { - $refMapping = $refConfig['referenceOne'][($mapping->mappedBy ?? $mapping['mappedBy'])]; + if (isset($refConfig['referenceOne'][$mapping->mappedBy ?? $mapping['mappedBy']])) { + $refMapping = $refConfig['referenceOne'][$mapping->mappedBy ?? $mapping['mappedBy']]; $identifier = $refMapping['identifier']; $property->setValue( $object, @@ -281,7 +281,7 @@ private function updateReferences(EventArgs $eventArgs): void $meta->setFieldValue( $object, - ($mapping->identifier ?? $mapping['identifier']), + $mapping->identifier ?? $mapping['identifier'], $identifier ); } diff --git a/src/Sluggable/SluggableListener.php b/src/Sluggable/SluggableListener.php index f89d304060..284400552e 100644 --- a/src/Sluggable/SluggableListener.php +++ b/src/Sluggable/SluggableListener.php @@ -441,7 +441,7 @@ private function generateSlug(SluggableAdapter $ea, object $object): void // cut slug if exceeded in length if (isset($mapping['length']) && strlen($slug) > ($mapping->length ?? $mapping['length'])) { - $slug = substr($slug, 0, ($mapping->length ?? $mapping['length'])); + $slug = substr($slug, 0, $mapping->length ?? $mapping['length']); } if (isset($mapping['nullable']) && ($mapping->nullable ?? $mapping['nullable']) && 0 === strlen($slug)) { diff --git a/src/SoftDeleteable/Mapping/Validator.php b/src/SoftDeleteable/Mapping/Validator.php index 54b9ed0bcf..2e9d52bd38 100644 --- a/src/SoftDeleteable/Mapping/Validator.php +++ b/src/SoftDeleteable/Mapping/Validator.php @@ -52,8 +52,8 @@ public static function validateField(ClassMetadata $meta, $field) $fieldMapping = $meta->getFieldMapping($field); - if (!in_array(($fieldMapping->type ?? $fieldMapping['type']), self::$validTypes, true)) { - throw new InvalidMappingException(sprintf('Field "%s" (type "%s") must be of one of the following types: "%s" in entity %s', $field, ($fieldMapping->type ?? $fieldMapping['type']), implode(', ', self::$validTypes), $meta->getName())); + if (!in_array($fieldMapping->type ?? $fieldMapping['type'], self::$validTypes, true)) { + throw new InvalidMappingException(sprintf('Field "%s" (type "%s") must be of one of the following types: "%s" in entity %s', $field, $fieldMapping->type ?? $fieldMapping['type'], implode(', ', self::$validTypes), $meta->getName())); } } } diff --git a/src/Sortable/Mapping/Driver/Yaml.php b/src/Sortable/Mapping/Driver/Yaml.php index 5472b31b6e..f34cf283d4 100644 --- a/src/Sortable/Mapping/Driver/Yaml.php +++ b/src/Sortable/Mapping/Driver/Yaml.php @@ -54,7 +54,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['fields'])) { foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('sortablePosition', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { + if (in_array('sortablePosition', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { if (!$this->isValidField($meta, $field)) { throw new InvalidMappingException("Sortable position field - [{$field}] type is not valid and must be 'integer' in class - {$meta->getName()}"); } @@ -110,7 +110,7 @@ private function readSortableGroups(iterable $mapping, array $config): array { foreach ($mapping as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('sortableGroup', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { + if (in_array('sortableGroup', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { if (!isset($config['groups'])) { $config['groups'] = []; } diff --git a/src/Translatable/Mapping/Driver/Yaml.php b/src/Translatable/Mapping/Driver/Yaml.php index ae7ba07c4e..6c6185b52c 100644 --- a/src/Translatable/Mapping/Driver/Yaml.php +++ b/src/Translatable/Mapping/Driver/Yaml.php @@ -89,7 +89,7 @@ protected function _loadMappingFile($file) private function buildFieldConfiguration(string $field, array $fieldMapping, array $config): array { if (isset($fieldMapping['gedmo'])) { - if (in_array('translatable', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true) || isset($fieldMapping['gedmo']['translatable'])) { + if (in_array('translatable', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true) || isset($fieldMapping['gedmo']['translatable'])) { // fields cannot be overrided and throws mapping exception $config['fields'][] = $field; if (isset($fieldMapping['gedmo']['translatable']['fallback'])) { diff --git a/src/Translatable/Query/TreeWalker/TranslationWalker.php b/src/Translatable/Query/TreeWalker/TranslationWalker.php index 359ba6e845..7fad4792b3 100644 --- a/src/Translatable/Query/TreeWalker/TranslationWalker.php +++ b/src/Translatable/Query/TreeWalker/TranslationWalker.php @@ -309,9 +309,9 @@ private function prepareTranslatedComponents(): void // Treat translation as original field type $fieldMapping = $meta->getFieldMapping($field); if ((($this->platform instanceof AbstractMySQLPlatform) - && in_array(($fieldMapping->type ?? $fieldMapping['type']), ['decimal'], true)) + && in_array($fieldMapping->type ?? $fieldMapping['type'], ['decimal'], true)) || (!($this->platform instanceof AbstractMySQLPlatform) - && !in_array(($fieldMapping->type ?? $fieldMapping['type']), ['datetime', 'datetimetz', 'date', 'time'], true))) { + && !in_array($fieldMapping->type ?? $fieldMapping['type'], ['datetime', 'datetimetz', 'date', 'time'], true))) { $type = Type::getType($fieldMapping->type ?? $fieldMapping['type']); // In ORM 2.x, $fieldMapping is an array. In ORM 3.x, it's a data object. Always cast to an array for compatibility across versions. diff --git a/src/Tree/Mapping/Driver/Yaml.php b/src/Tree/Mapping/Driver/Yaml.php index 39e65855e3..e6da60705a 100644 --- a/src/Tree/Mapping/Driver/Yaml.php +++ b/src/Tree/Mapping/Driver/Yaml.php @@ -78,7 +78,7 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['id'])) { foreach (($mapping->id ?? $mapping['id']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('treePathSource', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { + if (in_array('treePathSource', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { if (!$validator->isValidFieldForPathSource($meta, $field)) { throw new InvalidMappingException("Tree PathSource field - [{$field}] type is not valid. It can be any of the integer variants, double, float or string in class - {$meta->getName()}"); } @@ -91,34 +91,34 @@ public function readExtendedMetadata($meta, array &$config) if (isset($mapping['fields'])) { foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('treeLeft', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { + if (in_array('treeLeft', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { if (!$validator->isValidField($meta, $field)) { throw new InvalidMappingException("Tree left field - [{$field}] type is not valid and must be 'integer' in class - {$meta->getName()}"); } $config['left'] = $field; - } elseif (in_array('treeRight', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { + } elseif (in_array('treeRight', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { if (!$validator->isValidField($meta, $field)) { throw new InvalidMappingException("Tree right field - [{$field}] type is not valid and must be 'integer' in class - {$meta->getName()}"); } $config['right'] = $field; - } elseif (in_array('treeLevel', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { + } elseif (in_array('treeLevel', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { if (!$validator->isValidField($meta, $field)) { throw new InvalidMappingException("Tree level field - [{$field}] type is not valid and must be 'integer' in class - {$meta->getName()}"); } $config['level'] = $field; - } elseif (in_array('treeRoot', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { + } elseif (in_array('treeRoot', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { if (!$validator->isValidFieldForRoot($meta, $field)) { throw new InvalidMappingException("Tree root field - [{$field}] type is not valid and must be any of the 'integer' types or 'string' in class - {$meta->getName()}"); } $config['root'] = $field; - } elseif (in_array('treePath', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true) || isset($fieldMapping['gedmo']['treePath'])) { + } elseif (in_array('treePath', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true) || isset($fieldMapping['gedmo']['treePath'])) { if (!$validator->isValidFieldForPath($meta, $field)) { throw new InvalidMappingException("Tree Path field - [{$field}] type is not valid. It must be string or text in class - {$meta->getName()}"); } $treePathInfo = ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['treePath'] ?? ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])[array_search( 'treePath', - ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), + $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true )]; @@ -155,22 +155,22 @@ public function readExtendedMetadata($meta, array &$config) $config['path_append_id'] = $appendId; $config['path_starts_with_separator'] = $startsWithSeparator; $config['path_ends_with_separator'] = $endsWithSeparator; - } elseif (in_array('treePathSource', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { + } elseif (in_array('treePathSource', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { if (!$validator->isValidFieldForPathSource($meta, $field)) { throw new InvalidMappingException("Tree PathSource field - [{$field}] type is not valid. It can be any of the integer variants, double, float or string in class - {$meta->getName()}"); } $config['path_source'] = $field; - } elseif (in_array('treePathHash', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { + } elseif (in_array('treePathHash', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { if (!$validator->isValidFieldForPathSource($meta, $field)) { throw new InvalidMappingException("Tree PathHash field - [{$field}] type is not valid and must be 'string' in class - {$meta->getName()}"); } $config['path_hash'] = $field; - } elseif (in_array('treeLockTime', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { + } elseif (in_array('treeLockTime', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { if (!$validator->isValidFieldForLocktime($meta, $field)) { throw new InvalidMappingException("Tree LockTime field - [{$field}] type is not valid. It must be \"date\" in class - {$meta->getName()}"); } $config['lock_time'] = $field; - } elseif (in_array('treeParent', ($fieldMapping->gedmo ?? $fieldMapping['gedmo']), true)) { + } elseif (in_array('treeParent', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { $config['parent'] = $field; } } diff --git a/src/Tree/Strategy/ORM/Closure.php b/src/Tree/Strategy/ORM/Closure.php index b6ca7873c4..9d80e51a45 100644 --- a/src/Tree/Strategy/ORM/Closure.php +++ b/src/Tree/Strategy/ORM/Closure.php @@ -524,8 +524,8 @@ protected function setLevelFieldOnPendingNodes(ObjectManager $em) } // Avoid type conversion performance penalty - $type = 'integer' === ($mapping->type ?? $mapping['type']) - ? ArrayParameterType::INTEGER + $type = 'integer' === ($mapping->type ?? $mapping['type']) + ? ArrayParameterType::INTEGER : ArrayParameterType::STRING; // We calculate levels for all nodes diff --git a/src/Uploadable/Mapping/Validator.php b/src/Uploadable/Mapping/Validator.php index f009c54b90..73571800bd 100644 --- a/src/Uploadable/Mapping/Validator.php +++ b/src/Uploadable/Mapping/Validator.php @@ -150,7 +150,7 @@ public static function validateField($meta, $field, $uploadableField, $validFiel $fieldMapping = $meta->getFieldMapping($field); - if (!in_array(($fieldMapping->type ?? $fieldMapping['type']), $validFieldTypes, true)) { + if (!in_array($fieldMapping->type ?? $fieldMapping['type'], $validFieldTypes, true)) { $msg = 'Field "%s" to work as an "%s" field must be of one of the following types: "%s".'; throw new InvalidMappingException(sprintf($msg, $field, $uploadableField, implode(', ', $validFieldTypes))); From 04d6530a63b4b4924847ba22e963830a4cd64e4d Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Sat, 19 Oct 2024 22:57:41 +0200 Subject: [PATCH 5/9] Revert more they changes related to ODM, since there's no deprecation there --- src/Loggable/Document/Repository/LogEntryRepository.php | 8 ++++---- src/SoftDeleteable/Mapping/Event/Adapter/ODM.php | 2 +- src/Timestampable/Mapping/Event/Adapter/ODM.php | 2 +- .../Document/Repository/TranslationRepository.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Loggable/Document/Repository/LogEntryRepository.php b/src/Loggable/Document/Repository/LogEntryRepository.php index 74eb6fb4fe..1c0a2d52c0 100644 --- a/src/Loggable/Document/Repository/LogEntryRepository.php +++ b/src/Loggable/Document/Repository/LogEntryRepository.php @@ -130,17 +130,17 @@ protected function fillDocument($document, array $data) // Fill the embedded document if ($wrapped->isEmbeddedAssociation($field)) { if (!empty($value)) { - assert(class_exists($mapping->targetDocument ?? $mapping['targetDocument'])); + assert(class_exists($mapping['targetDocument'])); - $embeddedMetadata = $this->dm->getClassMetadata($mapping->targetDocument ?? $mapping['targetDocument']); + $embeddedMetadata = $this->dm->getClassMetadata($mapping['targetDocument']); $document = $embeddedMetadata->newInstance(); $this->fillDocument($document, $value); $value = $document; } } elseif ($objectMeta->isSingleValuedAssociation($field)) { - assert(class_exists($mapping->targetDocument ?? $mapping['targetDocument'])); + assert(class_exists($mapping['targetDocument'])); - $value = $value ? $this->dm->getReference($mapping->targetDocument ?? $mapping['targetDocument'], $value) : null; + $value = $value ? $this->dm->getReference($mapping['targetDocument'], $value) : null; } $wrapped->setPropertyValue($field, $value); unset($fields[$field]); diff --git a/src/SoftDeleteable/Mapping/Event/Adapter/ODM.php b/src/SoftDeleteable/Mapping/Event/Adapter/ODM.php index fc47e0be13..1640e853da 100644 --- a/src/SoftDeleteable/Mapping/Event/Adapter/ODM.php +++ b/src/SoftDeleteable/Mapping/Event/Adapter/ODM.php @@ -40,7 +40,7 @@ public function getDateValue($meta, $field) { $datetime = $this->clock instanceof ClockInterface ? $this->clock->now() : new \DateTimeImmutable(); $mapping = $meta->getFieldMapping($field); - $type = $mapping->type ?? $mapping['type'] ?? null; + $type = $mapping['type'] ?? null; if ('timestamp' === $type) { return (int) $datetime->format('U'); diff --git a/src/Timestampable/Mapping/Event/Adapter/ODM.php b/src/Timestampable/Mapping/Event/Adapter/ODM.php index ee7cb77a10..8b9f5b9b2c 100644 --- a/src/Timestampable/Mapping/Event/Adapter/ODM.php +++ b/src/Timestampable/Mapping/Event/Adapter/ODM.php @@ -40,7 +40,7 @@ public function getDateValue($meta, $field) { $datetime = $this->clock instanceof ClockInterface ? $this->clock->now() : new \DateTimeImmutable(); $mapping = $meta->getFieldMapping($field); - $type = $mapping->type ?? $mapping['type'] ?? null; + $type = $mapping['type'] ?? null; if ('timestamp' === $type) { return (int) $datetime->format('U'); diff --git a/src/Translatable/Document/Repository/TranslationRepository.php b/src/Translatable/Document/Repository/TranslationRepository.php index 74c7962c3f..a372d029a8 100644 --- a/src/Translatable/Document/Repository/TranslationRepository.php +++ b/src/Translatable/Document/Repository/TranslationRepository.php @@ -95,7 +95,7 @@ public function translate($document, $field, $locale, $value) $transMeta->getReflectionProperty('locale')->setValue($trans, $locale); } $mapping = $meta->getFieldMapping($field); - $type = $this->getType($mapping->type ?? $mapping['type']); + $type = $this->getType($mapping['type']); $transformed = $type->convertToDatabaseValue($value); $transMeta->getReflectionProperty('content')->setValue($trans, $transformed); if ($this->dm->getUnitOfWork()->isInIdentityMap($document)) { From 6e78ff3597c2d94e8058850676ef9754c70b03f0 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Sat, 19 Oct 2024 23:11:30 +0200 Subject: [PATCH 6/9] Revert more unneeded changes related to YAML drivers, since they deal with plain arrays --- src/Blameable/Mapping/Driver/Yaml.php | 8 ++--- src/IpTraceable/Mapping/Driver/Yaml.php | 8 ++--- src/Loggable/Mapping/Driver/Yaml.php | 26 +++++++-------- .../Mapping/Driver/Yaml.php | 10 +++--- src/References/Mapping/Driver/Yaml.php | 16 +++++----- src/Sluggable/Mapping/Driver/Yaml.php | 6 ++-- src/Sluggable/Mapping/Event/Adapter/ORM.php | 4 +-- src/SoftDeleteable/Mapping/Driver/Yaml.php | 2 +- src/Sortable/Mapping/Driver/Yaml.php | 12 +++---- src/Translatable/Mapping/Driver/Yaml.php | 10 +++--- src/Tree/Mapping/Driver/Yaml.php | 32 +++++++++---------- src/Uploadable/Mapping/Driver/Yaml.php | 4 +-- 12 files changed, 69 insertions(+), 69 deletions(-) diff --git a/src/Blameable/Mapping/Driver/Yaml.php b/src/Blameable/Mapping/Driver/Yaml.php index 2a923e29f3..02010462ff 100644 --- a/src/Blameable/Mapping/Driver/Yaml.php +++ b/src/Blameable/Mapping/Driver/Yaml.php @@ -53,9 +53,9 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['fields'])) { - foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { + foreach ($mapping['fields'] as $field => $fieldMapping) { if (isset($fieldMapping['gedmo']['blameable'])) { - $mappingProperty = $fieldMapping->gedmo->blameable ?? $fieldMapping['gedmo']['blameable']; + $mappingProperty = $fieldMapping['gedmo']['blameable']; if (!$this->isValidField($meta, $field)) { throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'string' or a reference in class - {$meta->getName()}"); } @@ -84,9 +84,9 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['manyToOne'])) { - foreach (($mapping->manyToOne ?? $mapping['manyToOne']) as $field => $fieldMapping) { + foreach ($mapping['manyToOne'] as $field => $fieldMapping) { if (isset($fieldMapping['gedmo']['blameable'])) { - $mappingProperty = $fieldMapping->gedmo->blameable ?? $fieldMapping['gedmo']['blameable']; + $mappingProperty = $fieldMapping['gedmo']['blameable']; if (!$meta->isSingleValuedAssociation($field)) { throw new InvalidMappingException("Association - [{$field}] is not valid, it must be a one-to-many relation or a string field - {$meta->getName()}"); } diff --git a/src/IpTraceable/Mapping/Driver/Yaml.php b/src/IpTraceable/Mapping/Driver/Yaml.php index 992409be1c..66c2509d28 100644 --- a/src/IpTraceable/Mapping/Driver/Yaml.php +++ b/src/IpTraceable/Mapping/Driver/Yaml.php @@ -49,9 +49,9 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['fields'])) { - foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { + foreach ($mapping['fields'] as $field => $fieldMapping) { if (isset($fieldMapping['gedmo']['ipTraceable'])) { - $mappingProperty = $fieldMapping->gedmo->ipTraceable ?? $fieldMapping['gedmo']['ipTraceable']; + $mappingProperty = $fieldMapping['gedmo']['ipTraceable']; if (!$this->isValidField($meta, $field)) { throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'string' in class - {$meta->getName()}"); } @@ -80,9 +80,9 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['manyToOne'])) { - foreach (($mapping->manyToOne ?? $mapping['manyToOne']) as $field => $fieldMapping) { + foreach ($mapping['manyToOne'] as $field => $fieldMapping) { if (isset($fieldMapping['gedmo']['ipTraceable'])) { - $mappingProperty = ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['ipTraceable']; + $mappingProperty = $fieldMapping['gedmo']['ipTraceable']; if (!$meta->isSingleValuedAssociation($field)) { throw new InvalidMappingException("Association - [{$field}] is not valid, it must be a one-to-many relation or a string field - {$meta->getName()}"); } diff --git a/src/Loggable/Mapping/Driver/Yaml.php b/src/Loggable/Mapping/Driver/Yaml.php index ef94e70ec6..9c4e556c90 100644 --- a/src/Loggable/Mapping/Driver/Yaml.php +++ b/src/Loggable/Mapping/Driver/Yaml.php @@ -41,7 +41,7 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['gedmo'])) { - $classMapping = ($mapping->gedmo ?? $mapping['gedmo']); + $classMapping = $mapping['gedmo']; if (isset($classMapping['loggable'])) { $config['loggable'] = true; if (isset($classMapping['loggable']['logEntryClass'])) { @@ -54,9 +54,9 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['fields'])) { - foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { + foreach ($mapping['fields'] as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('versioned', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { + if (in_array('versioned', $fieldMapping['gedmo'], true)) { if ($meta->isCollectionValuedAssociation($field)) { throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}"); } @@ -68,9 +68,9 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['attributeOverride'])) { - foreach (($mapping->attributeOverride ?? $mapping['attributeOverride']) as $field => $fieldMapping) { + foreach ($mapping['attributeOverride'] as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('versioned', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { + if (in_array('versioned', $fieldMapping['gedmo'], true)) { if ($meta->isCollectionValuedAssociation($field)) { throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}"); } @@ -82,9 +82,9 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['manyToOne'])) { - foreach (($mapping->manyToOne ?? $mapping['manyToOne']) as $field => $fieldMapping) { + foreach ($mapping['manyToOne'] as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('versioned', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { + if (in_array('versioned', $fieldMapping['gedmo'], true)) { if ($meta->isCollectionValuedAssociation($field)) { throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}"); } @@ -96,9 +96,9 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['oneToOne'])) { - foreach (($mapping->oneToOne ?? $mapping['oneToOne']) as $field => $fieldMapping) { + foreach ($mapping['oneToOne'] as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('versioned', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { + if (in_array('versioned', $fieldMapping['gedmo'], true)) { if ($meta->isCollectionValuedAssociation($field)) { throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}"); } @@ -110,14 +110,14 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['embedded'])) { - foreach (($mapping->embedded ?? $mapping['embedded']) as $field => $fieldMapping) { + foreach ($mapping['embedded'] as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('versioned', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { + if (in_array('versioned', $fieldMapping['gedmo'], true)) { if ($meta->isCollectionValuedAssociation($field)) { throw new InvalidMappingException("Cannot apply versioning to field [{$field}] as it is collection in object - {$meta->getName()}"); } // fields cannot be overrided and throws mapping exception - $mapping = $this->_getMapping($fieldMapping->class ?? $fieldMapping['class']); + $mapping = $this->_getMapping($fieldMapping['class']); $config = $this->inspectEmbeddedForVersioned($field, $mapping, $config); } } @@ -150,7 +150,7 @@ protected function _loadMappingFile($file) private function inspectEmbeddedForVersioned(string $field, array $mapping, array $config): array { if (isset($mapping['fields'])) { - foreach (($mapping->fields ?? $mapping['fields']) as $property => $fieldMapping) { + foreach ($mapping['fields'] as $property => $fieldMapping) { $config['versioned'][] = $field.'.'.$property; } } diff --git a/src/ReferenceIntegrity/Mapping/Driver/Yaml.php b/src/ReferenceIntegrity/Mapping/Driver/Yaml.php index 9bb5abf38e..4c0bd33fc8 100644 --- a/src/ReferenceIntegrity/Mapping/Driver/Yaml.php +++ b/src/ReferenceIntegrity/Mapping/Driver/Yaml.php @@ -41,22 +41,22 @@ public function readExtendedMetadata($meta, array &$config) $validator = new Validator(); if (isset($mapping['fields'])) { - foreach (($mapping->fields ?? $mapping['fields']) as $property => $fieldMapping) { + foreach ($mapping['fields'] as $property => $fieldMapping) { if (isset($fieldMapping['gedmo']['referenceIntegrity'])) { if (!$meta->hasField($property)) { throw new InvalidMappingException(sprintf('Unable to find reference integrity [%s] as mapped property in entity - %s', $property, $meta->getName())); } - if (empty(($mapping->fields ?? $mapping['fields'])[$property]['mappedBy'])) { + if (empty($mapping['fields'][$property]['mappedBy'])) { throw new InvalidMappingException(sprintf("'mappedBy' should be set on '%s' in '%s'", $property, $meta->getName())); } - if (!in_array(($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['referenceIntegrity'], $validator->getIntegrityActions(), true)) { + if (!in_array($fieldMapping['gedmo']['referenceIntegrity'], $validator->getIntegrityActions(), true)) { throw new InvalidMappingException(sprintf('Field - [%s] does not have a valid integrity option, [%s] in class - %s', $property, implode(', ', $validator->getIntegrityActions()), $meta->getName())); } - $config['referenceIntegrity'][$property][($mapping->fields ?? $mapping['fields'])[$property]['mappedBy']] = - ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['referenceIntegrity']; + $config['referenceIntegrity'][$property][$mapping['fields'][$property]['mappedBy']] = + $fieldMapping['gedmo']['referenceIntegrity']; } } } diff --git a/src/References/Mapping/Driver/Yaml.php b/src/References/Mapping/Driver/Yaml.php index e18a42bf72..48a8b4bb10 100644 --- a/src/References/Mapping/Driver/Yaml.php +++ b/src/References/Mapping/Driver/Yaml.php @@ -42,9 +42,9 @@ public function readExtendedMetadata($meta, array &$config) { $mapping = $this->_getMapping($meta->getName()); - if (isset($mapping['gedmo'], ($mapping->gedmo ?? $mapping['gedmo'])['reference'])) { - foreach (($mapping->gedmo ?? $mapping['gedmo'])['reference'] as $field => $fieldMapping) { - $reference = ($fieldMapping->reference ?? $fieldMapping['reference']); + if (isset($mapping['gedmo'], $mapping['gedmo']['reference'])) { + foreach ($mapping['gedmo']['reference'] as $field => $fieldMapping) { + $reference = $fieldMapping['reference']; if (!in_array($reference, array_keys($this->validReferences), true)) { throw new InvalidMappingException($reference.' is not a valid reference, valid references are: '.implode(', ', array_keys($this->validReferences))); @@ -52,20 +52,20 @@ public function readExtendedMetadata($meta, array &$config) $config[$reference][$field] = [ 'field' => $field, - 'type' => $fieldMapping->type ?? $fieldMapping['type'], - 'class' => $fieldMapping->class ?? $fieldMapping['class'], + 'type' => $fieldMapping['type'], + 'class' => $fieldMapping['class'], ]; if (array_key_exists('mappedBy', $fieldMapping)) { - $config[$reference][$field]['mappedBy'] = ($fieldMapping->mappedBy ?? $fieldMapping['mappedBy']); + $config[$reference][$field]['mappedBy'] = $fieldMapping['mappedBy']; } if (array_key_exists('identifier', $fieldMapping)) { - $config[$reference][$field]['identifier'] = ($fieldMapping->identifier ?? $fieldMapping['identifier']); + $config[$reference][$field]['identifier'] = $fieldMapping['identifier']; } if (array_key_exists('inversedBy', $fieldMapping)) { - $config[$reference][$field]['inversedBy'] = ($fieldMapping->inversedBy ?? $fieldMapping['inversedBy']); + $config[$reference][$field]['inversedBy'] = $fieldMapping['inversedBy']; } } } diff --git a/src/Sluggable/Mapping/Driver/Yaml.php b/src/Sluggable/Mapping/Driver/Yaml.php index f455257758..167258a22f 100644 --- a/src/Sluggable/Mapping/Driver/Yaml.php +++ b/src/Sluggable/Mapping/Driver/Yaml.php @@ -54,13 +54,13 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['fields'])) { - foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { + foreach ($mapping['fields'] as $field => $fieldMapping) { $config = $this->buildFieldConfiguration($field, $fieldMapping, $meta, $config); } } if (isset($mapping['attributeOverride'])) { - foreach (($mapping->attributeOverride ?? $mapping['attributeOverride']) as $field => $overrideMapping) { + foreach ($mapping['attributeOverride'] as $field => $overrideMapping) { $config = $this->buildFieldConfiguration($field, $overrideMapping, $meta, $config); } } @@ -98,7 +98,7 @@ private function buildFieldConfiguration(string $field, array $fieldMapping, Cla { if (isset($fieldMapping['gedmo'])) { if (isset($fieldMapping['gedmo']['slug'])) { - $slug = ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['slug']; + $slug = $fieldMapping['gedmo']['slug']; if (!$this->isValidField($meta, $field)) { throw new InvalidMappingException("Cannot use field - [{$field}] for slug storage, type is not valid and must be 'string' or 'text' in class - {$meta->getName()}"); } diff --git a/src/Sluggable/Mapping/Event/Adapter/ORM.php b/src/Sluggable/Mapping/Event/Adapter/ORM.php index d6c84a208f..62a65f2dab 100644 --- a/src/Sluggable/Mapping/Event/Adapter/ORM.php +++ b/src/Sluggable/Mapping/Event/Adapter/ORM.php @@ -55,13 +55,13 @@ public function getSimilarSlugs($object, $meta, array $config, $slug) if (($ubase || 0 === $ubase) && !$mapping) { $qb->andWhere('rec.'.$config['unique_base'].' = :unique_base'); $qb->setParameter(':unique_base', $ubase); - } elseif ($ubase && $mapping && in_array($mapping->type ?? $mapping['type'], [EntityClassMetadata::ONE_TO_ONE, EntityClassMetadata::MANY_TO_ONE], true)) { + } elseif ($ubase && $mapping && in_array($mapping['type'], [EntityClassMetadata::ONE_TO_ONE, EntityClassMetadata::MANY_TO_ONE], true)) { $mappedAlias = 'mapped_'.$config['unique_base']; $wrappedUbase = AbstractWrapper::wrap($ubase, $em); $metadata = $wrappedUbase->getMetadata(); assert($metadata instanceof EntityClassMetadata || $metadata instanceof LegacyEntityClassMetadata); $qb->innerJoin('rec.'.$config['unique_base'], $mappedAlias); - foreach (array_keys($mapping->targetToSourceKeyColumns ?? $mapping['targetToSourceKeyColumns']) as $i => $mappedKey) { + foreach (array_keys($mapping['targetToSourceKeyColumns']) as $i => $mappedKey) { $mappedProp = $metadata->getFieldName($mappedKey); $qb->andWhere($qb->expr()->eq($mappedAlias.'.'.$mappedProp, ':assoc'.$i)); $qb->setParameter(':assoc'.$i, $wrappedUbase->getPropertyValue($mappedProp)); diff --git a/src/SoftDeleteable/Mapping/Driver/Yaml.php b/src/SoftDeleteable/Mapping/Driver/Yaml.php index 63d7107bee..e2790b1b66 100644 --- a/src/SoftDeleteable/Mapping/Driver/Yaml.php +++ b/src/SoftDeleteable/Mapping/Driver/Yaml.php @@ -41,7 +41,7 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['gedmo'])) { - $classMapping = ($mapping->gedmo ?? $mapping['gedmo']); + $classMapping = $mapping['gedmo']; if (isset($classMapping['soft_deleteable'])) { $config['softDeleteable'] = true; diff --git a/src/Sortable/Mapping/Driver/Yaml.php b/src/Sortable/Mapping/Driver/Yaml.php index f34cf283d4..500a4e0250 100644 --- a/src/Sortable/Mapping/Driver/Yaml.php +++ b/src/Sortable/Mapping/Driver/Yaml.php @@ -52,9 +52,9 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['fields'])) { - foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { + foreach ($mapping['fields'] as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('sortablePosition', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { + if (in_array('sortablePosition', $fieldMapping['gedmo'], true)) { if (!$this->isValidField($meta, $field)) { throw new InvalidMappingException("Sortable position field - [{$field}] type is not valid and must be 'integer' in class - {$meta->getName()}"); } @@ -62,13 +62,13 @@ public function readExtendedMetadata($meta, array &$config) } } } - $config = $this->readSortableGroups($mapping->fields ?? $mapping['fields'], $config); + $config = $this->readSortableGroups($mapping['fields'], $config); } if (isset($mapping['manyToOne'])) { - $config = $this->readSortableGroups($mapping->manyToOne ?? $mapping['manyToOne'], $config); + $config = $this->readSortableGroups($mapping['manyToOne'], $config); } if (isset($mapping['manyToMany'])) { - $config = $this->readSortableGroups($mapping->manyToMany ?? $mapping['manyToMany'], $config); + $config = $this->readSortableGroups($mapping['manyToMany'], $config); } if (!$meta->isMappedSuperclass && $config) { @@ -110,7 +110,7 @@ private function readSortableGroups(iterable $mapping, array $config): array { foreach ($mapping as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('sortableGroup', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { + if (in_array('sortableGroup', $fieldMapping['gedmo'], true)) { if (!isset($config['groups'])) { $config['groups'] = []; } diff --git a/src/Translatable/Mapping/Driver/Yaml.php b/src/Translatable/Mapping/Driver/Yaml.php index 6c6185b52c..dea0516339 100644 --- a/src/Translatable/Mapping/Driver/Yaml.php +++ b/src/Translatable/Mapping/Driver/Yaml.php @@ -39,7 +39,7 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['gedmo'])) { - $classMapping = ($mapping->gedmo ?? $mapping['gedmo']); + $classMapping = $mapping['gedmo']; if (isset($classMapping['translation']['entity'])) { $translationEntity = $classMapping['translation']['entity']; if (!$cl = $this->getRelatedClassName($meta, $translationEntity)) { @@ -55,13 +55,13 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['fields'])) { - foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { + foreach ($mapping['fields'] as $field => $fieldMapping) { $config = $this->buildFieldConfiguration($field, $fieldMapping, $config); } } if (isset($mapping['attributeOverride'])) { - foreach (($mapping->attributeOverride ?? $mapping['attributeOverride']) as $field => $overrideMapping) { + foreach ($mapping['attributeOverride'] as $field => $overrideMapping) { $config = $this->buildFieldConfiguration($field, $overrideMapping, $config); } } @@ -89,11 +89,11 @@ protected function _loadMappingFile($file) private function buildFieldConfiguration(string $field, array $fieldMapping, array $config): array { if (isset($fieldMapping['gedmo'])) { - if (in_array('translatable', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true) || isset($fieldMapping['gedmo']['translatable'])) { + if (in_array('translatable', $fieldMapping['gedmo'], true) || isset($fieldMapping['gedmo']['translatable'])) { // fields cannot be overrided and throws mapping exception $config['fields'][] = $field; if (isset($fieldMapping['gedmo']['translatable']['fallback'])) { - $config['fallback'][$field] = ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['translatable']['fallback']; + $config['fallback'][$field] = $fieldMapping['gedmo']['translatable']['fallback']; } } } diff --git a/src/Tree/Mapping/Driver/Yaml.php b/src/Tree/Mapping/Driver/Yaml.php index e6da60705a..d7cfe555cd 100644 --- a/src/Tree/Mapping/Driver/Yaml.php +++ b/src/Tree/Mapping/Driver/Yaml.php @@ -52,7 +52,7 @@ public function readExtendedMetadata($meta, array &$config) $validator = new Validator(); if (isset($mapping['gedmo'])) { - $classMapping = ($mapping->gedmo ?? $mapping['gedmo']); + $classMapping = $mapping['gedmo']; if (isset($classMapping['tree']['type'])) { $strategy = $classMapping['tree']['type']; if (!in_array($strategy, $this->strategies, true)) { @@ -76,9 +76,9 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['id'])) { - foreach (($mapping->id ?? $mapping['id']) as $field => $fieldMapping) { + foreach ($mapping['id'] as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('treePathSource', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { + if (in_array('treePathSource', $fieldMapping['gedmo'], true)) { if (!$validator->isValidFieldForPathSource($meta, $field)) { throw new InvalidMappingException("Tree PathSource field - [{$field}] type is not valid. It can be any of the integer variants, double, float or string in class - {$meta->getName()}"); } @@ -89,36 +89,36 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['fields'])) { - foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { + foreach ($mapping['fields'] as $field => $fieldMapping) { if (isset($fieldMapping['gedmo'])) { - if (in_array('treeLeft', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { + if (in_array('treeLeft', $fieldMapping['gedmo'], true)) { if (!$validator->isValidField($meta, $field)) { throw new InvalidMappingException("Tree left field - [{$field}] type is not valid and must be 'integer' in class - {$meta->getName()}"); } $config['left'] = $field; - } elseif (in_array('treeRight', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { + } elseif (in_array('treeRight', $fieldMapping['gedmo'], true)) { if (!$validator->isValidField($meta, $field)) { throw new InvalidMappingException("Tree right field - [{$field}] type is not valid and must be 'integer' in class - {$meta->getName()}"); } $config['right'] = $field; - } elseif (in_array('treeLevel', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { + } elseif (in_array('treeLevel', $fieldMapping['gedmo'], true)) { if (!$validator->isValidField($meta, $field)) { throw new InvalidMappingException("Tree level field - [{$field}] type is not valid and must be 'integer' in class - {$meta->getName()}"); } $config['level'] = $field; - } elseif (in_array('treeRoot', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { + } elseif (in_array('treeRoot', $fieldMapping['gedmo'], true)) { if (!$validator->isValidFieldForRoot($meta, $field)) { throw new InvalidMappingException("Tree root field - [{$field}] type is not valid and must be any of the 'integer' types or 'string' in class - {$meta->getName()}"); } $config['root'] = $field; - } elseif (in_array('treePath', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true) || isset($fieldMapping['gedmo']['treePath'])) { + } elseif (in_array('treePath', $fieldMapping['gedmo'], true) || isset($fieldMapping['gedmo']['treePath'])) { if (!$validator->isValidFieldForPath($meta, $field)) { throw new InvalidMappingException("Tree Path field - [{$field}] type is not valid. It must be string or text in class - {$meta->getName()}"); } - $treePathInfo = ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['treePath'] ?? ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])[array_search( + $treePathInfo = $fieldMapping['gedmo']['treePath'] ?? $fieldMapping['gedmo'][array_search( 'treePath', - $fieldMapping->gedmo ?? $fieldMapping['gedmo'], + $fieldMapping['gedmo'], true )]; @@ -155,22 +155,22 @@ public function readExtendedMetadata($meta, array &$config) $config['path_append_id'] = $appendId; $config['path_starts_with_separator'] = $startsWithSeparator; $config['path_ends_with_separator'] = $endsWithSeparator; - } elseif (in_array('treePathSource', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { + } elseif (in_array('treePathSource', $fieldMapping['gedmo'], true)) { if (!$validator->isValidFieldForPathSource($meta, $field)) { throw new InvalidMappingException("Tree PathSource field - [{$field}] type is not valid. It can be any of the integer variants, double, float or string in class - {$meta->getName()}"); } $config['path_source'] = $field; - } elseif (in_array('treePathHash', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { + } elseif (in_array('treePathHash', $fieldMapping['gedmo'], true)) { if (!$validator->isValidFieldForPathSource($meta, $field)) { throw new InvalidMappingException("Tree PathHash field - [{$field}] type is not valid and must be 'string' in class - {$meta->getName()}"); } $config['path_hash'] = $field; - } elseif (in_array('treeLockTime', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { + } elseif (in_array('treeLockTime', $fieldMapping['gedmo'], true)) { if (!$validator->isValidFieldForLocktime($meta, $field)) { throw new InvalidMappingException("Tree LockTime field - [{$field}] type is not valid. It must be \"date\" in class - {$meta->getName()}"); } $config['lock_time'] = $field; - } elseif (in_array('treeParent', $fieldMapping->gedmo ?? $fieldMapping['gedmo'], true)) { + } elseif (in_array('treeParent', $fieldMapping['gedmo'], true)) { $config['parent'] = $field; } } @@ -182,7 +182,7 @@ public function readExtendedMetadata($meta, array &$config) } if (isset($mapping['manyToOne'])) { - foreach (($mapping->manyToOne ?? $mapping['manyToOne']) as $field => $relationMapping) { + foreach ($mapping['manyToOne'] as $field => $relationMapping) { if (isset($relationMapping['gedmo'])) { if (in_array('treeParent', $relationMapping['gedmo'], true)) { if (!$this->getRelatedClassName($meta, $relationMapping['targetEntity'])) { diff --git a/src/Uploadable/Mapping/Driver/Yaml.php b/src/Uploadable/Mapping/Driver/Yaml.php index cb63585d8b..540389aa92 100644 --- a/src/Uploadable/Mapping/Driver/Yaml.php +++ b/src/Uploadable/Mapping/Driver/Yaml.php @@ -40,7 +40,7 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['gedmo'])) { - $classMapping = ($mapping->gedmo ?? $mapping['gedmo']); + $classMapping = $mapping['gedmo']; if (isset($classMapping['uploadable'])) { $uploadable = $classMapping['uploadable']; @@ -65,7 +65,7 @@ public function readExtendedMetadata($meta, array &$config) $config['disallowedTypes'] = $uploadable['disallowedTypes'] ?? ''; if (isset($mapping['fields'])) { - foreach (($mapping->fields ?? $mapping['fields']) as $field => $info) { + foreach ($mapping['fields'] as $field => $info) { if (isset($info['gedmo']) && array_key_exists(0, $info['gedmo'])) { if ('uploadableFileMimeType' === $info['gedmo'][0]) { $config['fileMimeTypeField'] = $field; From 238471c0961ee075cf41201f4bcb97cd89ec3739 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 23 Oct 2024 09:18:35 +0200 Subject: [PATCH 7/9] Revert more unneeded changes after the review --- src/References/ReferencesListener.php | 30 +++++++++---------- .../Mapping/Event/Adapter/ORM.php | 4 +-- src/Timestampable/Mapping/Driver/Yaml.php | 4 +-- .../Mapping/Event/Adapter/ORM.php | 4 +-- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/References/ReferencesListener.php b/src/References/ReferencesListener.php index c0df3e7fac..6f9c7c85e4 100644 --- a/src/References/ReferencesListener.php +++ b/src/References/ReferencesListener.php @@ -92,16 +92,16 @@ public function postLoad(EventArgs $eventArgs) if (isset($config['referenceOne'])) { foreach ($config['referenceOne'] as $mapping) { - $property = $meta->reflClass->getProperty($mapping->field ?? $mapping['field']); + $property = $meta->reflClass->getProperty($mapping['field']); $property->setAccessible(true); if (isset($mapping['identifier'])) { - $referencedObjectId = $meta->getFieldValue($object, $mapping->identifier ?? $mapping['identifier']); + $referencedObjectId = $meta->getFieldValue($object, $mapping['identifier']); if (null !== $referencedObjectId) { $property->setValue( $object, $ea->getSingleReference( - $this->getManager($mapping->type ?? $mapping['type']), - $mapping->class ?? $mapping['class'], + $this->getManager($mapping['type']), + $mapping['class'], $referencedObjectId ) ); @@ -112,16 +112,16 @@ public function postLoad(EventArgs $eventArgs) if (isset($config['referenceMany'])) { foreach ($config['referenceMany'] as $mapping) { - $property = $meta->reflClass->getProperty($mapping->field ?? $mapping['field']); + $property = $meta->reflClass->getProperty($mapping['field']); $property->setAccessible(true); if (isset($mapping['mappedBy'])) { $id = $ea->extractIdentifier($om, $object); - $manager = $this->getManager($mapping->type ?? $mapping['type']); - $class = ($mapping->class ?? $mapping['class']); + $manager = $this->getManager($mapping['type']); + $class = $mapping['class']; $refMeta = $manager->getClassMetadata($class); $refConfig = $this->getConfiguration($manager, $refMeta->getName()); - if (isset($refConfig['referenceOne'][$mapping->mappedBy ?? $mapping['mappedBy']])) { - $refMapping = $refConfig['referenceOne'][$mapping->mappedBy ?? $mapping['mappedBy']]; + if (isset($refConfig['referenceOne'][$mapping['mappedBy']])) { + $refMapping = $refConfig['referenceOne'][$mapping['mappedBy']]; $identifier = $refMapping['identifier']; $property->setValue( $object, @@ -220,18 +220,18 @@ public function updateManyEmbedReferences(EventArgs $eventArgs) if (isset($config['referenceManyEmbed'])) { foreach ($config['referenceManyEmbed'] as $mapping) { - $property = $meta->reflClass->getProperty($mapping->field ?? $mapping['field']); + $property = $meta->reflClass->getProperty($mapping['field']); $property->setAccessible(true); $id = $ea->extractIdentifier($om, $object); $manager = $this->getManager('document'); - $class = ($mapping->class ?? $mapping['class']); + $class = $mapping['class']; $refMeta = $manager->getClassMetadata($class); // Trigger the loading of the configuration to validate the mapping $this->getConfiguration($manager, $refMeta->getName()); - $identifier = ($mapping->identifier ?? $mapping['identifier']); + $identifier = $mapping['identifier']; $property->setValue( $object, new LazyCollection( @@ -271,17 +271,17 @@ private function updateReferences(EventArgs $eventArgs): void if (isset($config['referenceOne'])) { foreach ($config['referenceOne'] as $mapping) { if (isset($mapping['identifier'])) { - $property = $meta->reflClass->getProperty($mapping->field ?? $mapping['field']); + $property = $meta->reflClass->getProperty($mapping['field']); $property->setAccessible(true); $referencedObject = $property->getValue($object); if (is_object($referencedObject)) { - $manager = $this->getManager($mapping->type ?? $mapping['type']); + $manager = $this->getManager($mapping['type']); $identifier = $ea->getIdentifier($manager, $referencedObject); $meta->setFieldValue( $object, - $mapping->identifier ?? $mapping['identifier'], + $mapping['identifier'], $identifier ); } diff --git a/src/SoftDeleteable/Mapping/Event/Adapter/ORM.php b/src/SoftDeleteable/Mapping/Event/Adapter/ORM.php index 9cb72c6eeb..46d31be7e7 100644 --- a/src/SoftDeleteable/Mapping/Event/Adapter/ORM.php +++ b/src/SoftDeleteable/Mapping/Event/Adapter/ORM.php @@ -44,7 +44,7 @@ public function getDateValue($meta, $field) return $this->getObjectManager()->getConnection()->convertToPHPValue( $this->getRawDateValue($mapping), - $mapping instanceof FieldMapping ? $mapping->type : ($mapping->type ?? $mapping['type'] ?? Types::DATETIME_MUTABLE) + $mapping instanceof FieldMapping ? $mapping->type : ($mapping['type'] ?? Types::DATETIME_MUTABLE) ); } @@ -58,7 +58,7 @@ public function getDateValue($meta, $field) private function getRawDateValue($mapping) { $datetime = $this->clock instanceof ClockInterface ? $this->clock->now() : new \DateTimeImmutable(); - $type = $mapping instanceof FieldMapping ? $mapping->type : ($mapping->type ?? $mapping['type'] ?? ''); + $type = $mapping instanceof FieldMapping ? $mapping->type : ($mapping['type'] ?? ''); if ('integer' === $type) { return (int) $datetime->format('U'); diff --git a/src/Timestampable/Mapping/Driver/Yaml.php b/src/Timestampable/Mapping/Driver/Yaml.php index da678057df..0dee60da71 100644 --- a/src/Timestampable/Mapping/Driver/Yaml.php +++ b/src/Timestampable/Mapping/Driver/Yaml.php @@ -59,9 +59,9 @@ public function readExtendedMetadata($meta, array &$config) $mapping = $this->_getMapping($meta->getName()); if (isset($mapping['fields'])) { - foreach (($mapping->fields ?? $mapping['fields']) as $field => $fieldMapping) { + foreach ($mapping['fields'] as $field => $fieldMapping) { if (isset($fieldMapping['gedmo']['timestampable'])) { - $mappingProperty = ($fieldMapping->gedmo ?? $fieldMapping['gedmo'])['timestampable']; + $mappingProperty = $fieldMapping['gedmo']['timestampable']; if (!$this->isValidField($meta, $field)) { throw new InvalidMappingException("Field - [{$field}] type is not valid and must be 'date', 'datetime' or 'time' in class - {$meta->getName()}"); } diff --git a/src/Timestampable/Mapping/Event/Adapter/ORM.php b/src/Timestampable/Mapping/Event/Adapter/ORM.php index 0738e4bfc0..4325127a44 100644 --- a/src/Timestampable/Mapping/Event/Adapter/ORM.php +++ b/src/Timestampable/Mapping/Event/Adapter/ORM.php @@ -44,7 +44,7 @@ public function getDateValue($meta, $field) return $this->getObjectManager()->getConnection()->convertToPHPValue( $this->getRawDateValue($mapping), - $mapping instanceof FieldMapping ? $mapping->type : $mapping['type'] ?? Types::DATETIME_MUTABLE + $mapping instanceof FieldMapping ? $mapping->type : ($mapping['type'] ?? Types::DATETIME_MUTABLE) ); } @@ -58,7 +58,7 @@ public function getDateValue($meta, $field) private function getRawDateValue($mapping) { $datetime = $this->clock instanceof ClockInterface ? $this->clock->now() : new \DateTimeImmutable(); - $type = $mapping instanceof FieldMapping ? $mapping->type : ($mapping->type ?? $mapping['type'] ?? ''); + $type = $mapping instanceof FieldMapping ? $mapping->type : ($mapping['type'] ?? ''); if ('integer' === $type) { return (int) $datetime->format('U'); From 4a89cd31e00d0f38a9782620928400360d13929e Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 23 Oct 2024 09:19:59 +0200 Subject: [PATCH 8/9] Refactor Validator to avoid repetition --- src/Tree/Mapping/Validator.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Tree/Mapping/Validator.php b/src/Tree/Mapping/Validator.php index c17071ce3f..8c9258eeda 100644 --- a/src/Tree/Mapping/Validator.php +++ b/src/Tree/Mapping/Validator.php @@ -9,6 +9,7 @@ namespace Gedmo\Tree\Mapping; +use Doctrine\ORM\Mapping\FieldMapping; use Doctrine\Persistence\Mapping\ClassMetadata; use Gedmo\Exception\InvalidMappingException; @@ -97,7 +98,7 @@ public function isValidField($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping->type ?? $mapping['type'], self::VALID_TYPES, true); + return $mapping && in_array($this->getMappingType($mapping), self::VALID_TYPES, true); } /** @@ -112,7 +113,7 @@ public function isValidFieldForPath($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping->type ?? $mapping['type'], $this->validPathTypes, true); + return $mapping && in_array($this->getMappingType($mapping), $this->validPathTypes, true); } /** @@ -127,7 +128,7 @@ public function isValidFieldForPathSource($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping->type ?? $mapping['type'], $this->validPathSourceTypes, true); + return $mapping && in_array($this->getMappingType($mapping), $this->validPathSourceTypes, true); } /** @@ -142,7 +143,7 @@ public function isValidFieldForPathHash($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping->type ?? $mapping['type'], $this->validPathHashTypes, true); + return $mapping && in_array($this->getMappingType($mapping), $this->validPathHashTypes, true); } /** @@ -157,7 +158,7 @@ public function isValidFieldForLockTime($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && ('date' === ($mapping->type ?? $mapping['type']) || 'datetime' === ($mapping->type ?? $mapping['type']) || 'timestamp' === ($mapping->type ?? $mapping['type'])); + return $mapping && ('date' === $this->getMappingType($mapping) || 'datetime' === $this->getMappingType($mapping) || 'timestamp' === $this->getMappingType($mapping)); } /** @@ -172,7 +173,7 @@ public function isValidFieldForRoot($meta, $field) { $mapping = $meta->getFieldMapping($field); - return $mapping && in_array($mapping->type ?? $mapping['type'], $this->validRootTypes, true); + return $mapping && in_array($this->getMappingType($mapping), $this->validRootTypes, true); } /** @@ -252,4 +253,16 @@ public function validateMaterializedPathTreeMetadata($meta, array $config) throw new InvalidMappingException('Missing properties: '.implode(', ', $missingFields)." in class - {$meta->getName()}"); } } + + /** + * @param FieldMapping|array $mapping + */ + private function getMappingType($mapping): string + { + if ($mapping instanceof FieldMapping) { + return $mapping->type; + } + + return $mapping['type']; + } } From 3975fa10309ced4c910046ba045ebd9565278a88 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 12 Nov 2024 08:36:40 +0100 Subject: [PATCH 9/9] Simplify by extracting variables --- src/Sluggable/SluggableListener.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Sluggable/SluggableListener.php b/src/Sluggable/SluggableListener.php index 284400552e..485804505a 100644 --- a/src/Sluggable/SluggableListener.php +++ b/src/Sluggable/SluggableListener.php @@ -440,11 +440,12 @@ private function generateSlug(SluggableAdapter $ea, object $object): void } // cut slug if exceeded in length - if (isset($mapping['length']) && strlen($slug) > ($mapping->length ?? $mapping['length'])) { - $slug = substr($slug, 0, $mapping->length ?? $mapping['length']); + $length = $mapping->length ?? $mapping['length'] ?? null; + if (null !== $length && strlen($slug) > $length) { + $slug = substr($slug, 0, $length); } - if (isset($mapping['nullable']) && ($mapping->nullable ?? $mapping['nullable']) && 0 === strlen($slug)) { + if (($mapping->nullable ?? $mapping['nullable'] ?? false) && 0 === strlen($slug)) { $slug = null; } @@ -546,11 +547,12 @@ private function makeUniqueSlug(SluggableAdapter $ea, object $object, string $pr } $mapping = $meta->getFieldMapping($config['slug']); - if (isset($mapping['length']) && strlen($generatedSlug) > ($mapping->length ?? $mapping['length'])) { + $length = $mapping->length ?? $mapping['length'] ?? null; + if (null !== $length && strlen($generatedSlug) > $length) { $generatedSlug = substr( $generatedSlug, 0, - ($mapping->length ?? $mapping['length']) - (strlen($uniqueSuffix) + strlen($config['separator'])) + $length - (strlen($uniqueSuffix) + strlen($config['separator'])) ); $this->exponent = strlen($uniqueSuffix) - 1; if (substr($generatedSlug, -strlen($config['separator'])) == $config['separator']) {