Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SoftDeletable] Fix ArrayAccess deprecation on FieldMapping #2856

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/SoftDeleteable/Mapping/Event/Adapter/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public function setClock(ClockInterface $clock): void
public function getDateValue($meta, $field)
{
$mapping = $meta->getFieldMapping($field);
$converter = Type::getType($mapping['type'] ?? Types::DATETIME_MUTABLE);
if ($mapping instanceof FieldMapping) {
$converter = Type::getType($mapping->type);
} else {
$converter = Type::getType($mapping['type'] ?? Types::DATETIME_MUTABLE);
}
$platform = $this->getObjectManager()->getConnection()->getDriver()->getDatabasePlatform();

return $converter->convertToPHPValue($this->getRawDateValue($mapping), $platform);
Expand Down
12 changes: 10 additions & 2 deletions src/SoftDeleteable/Mapping/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Gedmo\SoftDeleteable\Mapping;

use Doctrine\ORM\Mapping\FieldMapping;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Gedmo\Exception\InvalidMappingException;

Expand Down Expand Up @@ -44,16 +45,23 @@ class Validator
*
* @return void
*/
public static function validateField(ClassMetadata $meta, $field)
public static function validateField(ClassMetadata $meta, $field): void
{
if ($meta->isMappedSuperclass) {
return;
}

$fieldMapping = $meta->getFieldMapping($field);

if (!in_array($fieldMapping['type'], self::$validTypes, true)) {
if($fieldMapping instanceof FieldMapping) {
$type = $fieldMapping->type;
} else {
$type = $fieldMapping['type'];
}

if (!in_array($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()));
}

}
}