getSerializer example

->method('getSerializer')
            ->willReturn(
                new DateIntervalFieldSerializer(
                    $this->createMock(ValidatorInterface::class),
                    $registry
                )
            );
        $registry->method('getResolver');
        $registry->method('getAccessorBuilder');
        $this->field->compile($registry);

        static::assertInstanceOf(DateIntervalFieldSerializer::class$this->field->getSerializer());
    }
}
$done = [];

            foreach ($mapped as $property => $_) {
                if (\array_key_exists($property$done)) {
                    continue;
                }
                $f = $referencedDefinition->getFields()->get($property);
                if ($f === null) {
                    continue;
                }
                $mapped = $f->getSerializer()->normalize($f$mapped$clonedParams);
                $done[$property] = true;
            }

            foreach ($referencedDefinition->getPrimaryKeys() as $pkField) {
                if (\array_key_exists($pkField->getPropertyName()$done)) {
                    continue;
                }
                $mapped = $pkField->getSerializer()->normalize($pkField$mapped$clonedParams);
                $done[$pkField->getPropertyName()] = true;
            }

            
/** * @param array<mixed> $data * * @return array<mixed> */
    public function normalizeSingle(EntityDefinition $definition, array $data, WriteParameterBag $parameters): array
    {
        $done = [];

        foreach ($definition->getPrimaryKeys() as $pkField) {
            $data = $pkField->getSerializer()->normalize($pkField$data$parameters);
            $done[$pkField->getPropertyName()] = true;
        }

        $normalizedTranslations = false;
        foreach ($data as $property => $_) {
            if (\array_key_exists($property$done)) {
                continue;
            }

            $field = $definition->getFields()->get($property);
            if ($field === null || $field instanceof AssociationField) {
                
sort($primaryKey);

        $decodedPrimaryKey = [];
        foreach ($primaryKey as $fieldValue) {
            /** @var string|false $fieldName */
            $fieldName = array_search($fieldValue$command->getPrimaryKey(), true);
            /** @var Field|null $field */
            $field = null;
            if ($fieldName) {
                $field = $senderIdentification->getFields()->get($fieldName) ?? $senderIdentification->getFields()->getByStorageName($fieldName);
            }
            $decodedPrimaryKey[] = $field ? $field->getSerializer()->decode($field$fieldValue) : $fieldValue;
        }

        $hash = $senderIdentification->getEntityName() . ':' . md5(json_encode($decodedPrimaryKey, \JSON_THROW_ON_ERROR));

        $this->commands[$senderIdentification->getEntityName()][] = $command;

        $this->entityCommands[$hash][] = $command;
        $this->definitions[$senderIdentification->getEntityName()] = $senderIdentification;
    }

    /** * @throws ImpossibleWriteOrderException * * @return list<WriteCommand> */
$pks = array_combine(
                array_keys($existence->getPrimaryKey()),
                array_map(
                    function Dstring $pkFieldStorageName) use ($definition$existence$parameters): mixed {
                        $pkFieldValue = $existence->getPrimaryKey()[$pkFieldStorageName];
                        /** @var Field|null $field */
                        $field = $definition->getFields()->getByStorageName($pkFieldStorageName);
                        if (!$field) {
                            return $pkFieldValue;
                        }

                        return $field->getSerializer()->encode(
                            $field,
                            $existence,
                            new KeyValuePair($field->getPropertyName()$pkFieldValue, true),
                            $parameters,
                        )->current();
                    },
                    array_keys($existence->getPrimaryKey()),
                ),
            );

            $jsonUpdateCommand = new JsonUpdateCommand(
                

    public function decode(string $property, ?string $value)
    {
        $field = $this->getField($property);

        if ($field === null) {
            throw new \RuntimeException(sprintf('Field %s not found', $property));
        }

        return $field->getSerializer()->decode($field$value);
    }

    /** * @return array<string, TranslatedField> */
    public function getTranslatedFields(): array
    {
        return $this->getFields()->getTranslatedFields();
    }

    /** * @return array<string, Field> */
return null;
    }

    private function initLazy(): void
    {
        if ($this->serializer !== null) {
            return;
        }

        \assert($this->registry !== null);

        $this->serializer = $this->registry->getSerializer($this->getSerializerClass());

        $resolverClass = $this->getResolverClass();
        if ($resolverClass !== null) {
            $this->resolver = $this->registry->getResolver($resolverClass);
        }

        $accessorBuilderClass = $this->getAccessorBuilderClass();
        if ($accessorBuilderClass !== null) {
            $this->accessorBuilder = $this->registry->getAccessorBuilder($accessorBuilderClass);
        }
    }
}
/** * {@inheritdoc} */
  protected static function getSerializer() {
    // Allow settings.php to override the YAML serializer.     if (!isset(static::$serializer) &&
      $class = Settings::get('yaml_parser_class')) {

      static::$serializer = $class;
    }
    return parent::getSerializer();
  }

}
$listField->compile($this->definitionRegistry);

        $nestedParameters = $parameters->cloneForSubresource(
            $parameters->getDefinition(),
            $parameters->getPath() . '/' . $field->getPropertyName()
        );

        foreach ($values as $i => $value) {
            try {
                $kvPair = new KeyValuePair((string) $i$value, true);

                $x = $listField->getSerializer()->encode($listField$existence$kvPair$nestedParameters);
                $_x = iterator_to_array($x);
            } catch (WriteFieldException $exception) {
                $parameters->getContext()->getExceptions()->add($exception);
            }
        }
    }
}
$state = $this->getCurrentState($definition$primaryKey$commandQueue);

        $exists = !empty($state);

        $isChild = $this->isChild($definition$data$state$primaryKey$commandQueue);

        $wasChild = $this->wasChild($definition$state);

        $decodedPrimaryKey = [];
        foreach ($primaryKey as $fieldStorageName => $fieldValue) {
            $field = $definition->getFields()->getByStorageName($fieldStorageName);
            $decodedPrimaryKey[$fieldStorageName] = $field ? $field->getSerializer()->decode($field$fieldValue) : $fieldValue;
        }

        return new EntityExistence($definition->getEntityName()$decodedPrimaryKey$exists$isChild$wasChild$state);
    }

    /** * {@inheritdoc} */
    public function execute(array $commands, WriteContext $context): void
    {
        $beforeWriteEvent = EntityWriteEvent::create($context$commands);

        


            $subresources[$fk] = $currentId;

            $clonedParams = $parameters->cloneForSubresource(
                $reference,
                $parameters->getPath() . '/' . $key
            );

            $fkVersionField = $reference->getField($parameters->getDefinition()->getEntityName() . 'VersionId');
            if ($fkVersionField !== null) {
                $subresources = $fkVersionField->getSerializer()->normalize($fkVersionField$subresources$clonedParams);
            }
            $subresources = $this->writeExtractor->normalizeSingle($reference$subresources$clonedParams);

            $value[$keyValue] = $subresources;
        }

        $data[$key] = $value;

        return $data;
    }

    
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;

class MapDenormalizationTest extends TestCase
{
    public function testMapOfStringToNullableObject()
    {
        $normalizedData = $this->getSerializer()->denormalize([
            'map' => [
                'assertDummyMapValue' => [
                    'value' => 'foo',
                ],
                'assertNull' => null,
            ],
        ], DummyMapOfStringToNullableObject::class);

        $this->assertInstanceOf(DummyMapOfStringToNullableObject::class$normalizedData);

        // check nullable map value
$payload = [];
                if (isset($writeResults[$uniqueId])) {
                    $payload = $writeResults[$uniqueId]->getPayload();
                }

                $field = $command->getDefinition()->getFields()->getByStorageName($command->getStorageName());

                if (!$field instanceof Field) {
                    throw new \RuntimeException(sprintf('Field by storage name %s not found', $command->getStorageName()));
                }

                $decodedPayload = $field->getSerializer()->decode(
                    $field,
                    json_encode($command->getPayload(), \JSON_PRESERVE_ZERO_FRACTION | \JSON_THROW_ON_ERROR)
                );
                $mergedPayload = array_merge($payload[$field->getPropertyName() => $decodedPayload]);

                $changeSet = [];
                if ($command instanceof ChangeSetAware) {
                    $changeSet = $command->getChangeSet();
                }

                $writeResults[$uniqueId] = new EntityWriteResult(
                    
use Symfony\Component\HttpFoundation\IpUtils;

/** * @internal */
class RemoteAddressFieldTest extends TestCase
{
    use IntegrationTestBehaviour;

    public function testRemoteAddressSerializerInvalidField(): void
    {
        $serializer = $this->getSerializer();
        $data = new KeyValuePair('remoteAddress', null, false);

        $this->expectException(DataAbstractionLayerException::class);
        $serializer->encode(
            (new IntField('remote_address', 'remoteAddress'))->addFlags(new ApiAware()),
            EntityExistence::createEmpty(),
            $data,
            $this->getWriteParameterBagMock()
        )->current();
    }

    
$registry
            ->method('getSerializer')
            ->willReturn(
                new FlowTemplateConfigFieldSerializer(
                    $this->createMock(ValidatorInterface::class),
                    $registry
                )
            );

        $this->field->compile($registry);

        static::assertInstanceOf(FlowTemplateConfigFieldSerializer::class$this->field->getSerializer());
    }
}
Home | Imprint | This part of the site doesn't use cookies.