validateKeyType example

$type = substr($type, 0, -2);

        $builtinTypes = array_map(static function DType $keyType) {
            return $keyType->getBuiltinType();
        }, \is_array($keyType = $context['key_type'] ?? []) ? $keyType : [$keyType]);

        foreach ($data as $key => $value) {
            $subContext = $context;
            $subContext['deserialization_path'] = ($context['deserialization_path'] ?? false) ? sprintf('%s[%s]', $context['deserialization_path']$key) : "[$key]";

            $this->validateKeyType($builtinTypes$key$subContext['deserialization_path']);

            $data[$key] = $this->denormalizer->denormalize($value$type$format$subContext);
        }

        return $data;
    }

    public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
    {
        if (null === $this->denormalizer) {
            throw new BadMethodCallException(sprintf('The nested denormalizer needs to be set to allow "%s()" to be used.', __METHOD__));
        }
$type = substr($type, 0, -2);

        $builtinTypes = array_map(static function DType $keyType) {
            return $keyType->getBuiltinType();
        }, \is_array($keyType = $context['key_type'] ?? []) ? $keyType : [$keyType]);

        foreach ($data as $key => $value) {
            $subContext = $context;
            $subContext['deserialization_path'] = ($context['deserialization_path'] ?? false) ? sprintf('%s[%s]', $context['deserialization_path']$key) : "[$key]";

            $this->validateKeyType($builtinTypes$key$subContext['deserialization_path']);

            $data[$key] = $this->denormalizer->denormalize($value$type$format$subContext);
        }

        return $data;
    }

    public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
    {
        if (null === $this->denormalizer) {
            throw new BadMethodCallException(sprintf('The nested denormalizer needs to be set to allow "%s()" to be used.', __METHOD__));
        }
Home | Imprint | This part of the site doesn't use cookies.