Skip to content

Commit

Permalink
Reduce deprecations due to FieldMapping array access
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean85 committed Oct 18, 2024
1 parent ee63c20 commit 627676d
Show file tree
Hide file tree
Showing 32 changed files with 89 additions and 87 deletions.
2 changes: 1 addition & 1 deletion doc/mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Blameable/Mapping/Driver/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions src/Blameable/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/IpTraceable/Mapping/Driver/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions src/IpTraceable/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
}
8 changes: 4 additions & 4 deletions src/Loggable/Document/Repository/LogEntryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion src/Loggable/Entity/Repository/LogEntryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/Loggable/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand All @@ -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)) {
Expand All @@ -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)) {
Expand All @@ -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)) {
Expand All @@ -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)) {
Expand All @@ -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)) {
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/Driver/AbstractAnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/ReferenceIntegrity/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ 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()));
}

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'][$property]['mappedBy']] =
$config['referenceIntegrity'][$property][($mapping->fields ?? $mapping['fields'])[$property]['mappedBy']] =
$fieldMapping['gedmo']['referenceIntegrity'];
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/References/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
30 changes: 15 additions & 15 deletions src/References/ReferencesListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
);
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sluggable/Mapping/Driver/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Sluggable/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Sluggable/Mapping/Event/Adapter/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading

0 comments on commit 627676d

Please sign in to comment.