Skip to content

Commit

Permalink
[JMS] allow v5
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Feb 4, 2024
1 parent dfc42f3 commit ceba3cd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ docs/build
docs/node_modules
docs/.docusaurus
node_modules
cache/
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,14 @@ services:
tags:
- { name: kernel.event_subscriber }

coreshop.jms_serializer.object_constructor:
class: JMS\Serializer\Construction\UnserializeObjectConstructor

CoreShop\Bundle\ResourceBundle\Serialization\VersionObjectConstructor:
decorates: 'jms_serializer.object_constructor'
arguments:
- '@CoreShop\Bundle\ResourceBundle\Serialization\VersionObjectConstructor.inner'
- '@coreshop.jms_serializer.object_constructor'

CoreShop\Component\Resource\Service\FolderCreationServiceInterface: '@CoreShop\Component\Resource\Service\FolderCreationService'
CoreShop\Component\Resource\Service\FolderCreationService:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class VersionObjectConstructor implements ObjectConstructorInterface
{
public function __construct(
private ObjectConstructorInterface $fallbackConstructor,
private ObjectConstructorInterface $fallbacksFallbackConstructor,
private string $fallbackStrategy = DoctrineObjectConstructor::ON_MISSING_FALLBACK,
private ?\JMS\Serializer\Exclusion\ExpressionLanguageExclusionStrategy $expressionLanguageExclusionStrategy = null,
) {
Expand Down Expand Up @@ -97,7 +98,7 @@ public function construct(DeserializationVisitorInterface $visitor, ClassMetadat
}

if (array_key_exists('id', $identifierList) && !$identifierList['id']) {
return $this->fallbackConstructor->construct($visitor, $metadata, $data, $type, $context);
return $this->fallbacksFallbackConstructor->construct($visitor, $metadata, $data, $type, $context);
}

// Entity update, load it from database
Expand All @@ -110,7 +111,7 @@ public function construct(DeserializationVisitorInterface $visitor, ClassMetadat
case DoctrineObjectConstructor::ON_MISSING_EXCEPTION:
throw new ObjectConstructionException(sprintf('Entity %s can not be found', $metadata->name));
case DoctrineObjectConstructor::ON_MISSING_FALLBACK:
return $this->fallbackConstructor->construct($visitor, $metadata, $data, $type, $context);
return $this->fallbacksFallbackConstructor->construct($visitor, $metadata, $data, $type, $context);
default:
throw new InvalidArgumentException('The provided fallback strategy for the object constructor is not valid');
}
Expand Down

0 comments on commit ceba3cd

Please sign in to comment.