denormalizeParameter example

$allowed = false === $allowedAttributes || \in_array($paramName$allowedAttributes);
                $ignored = !$this->isAllowedAttribute($class$paramName$format$context);
                if ($constructorParameter->isVariadic()) {
                    if ($allowed && !$ignored && (isset($data[$key]) || \array_key_exists($key$data))) {
                        if (!\is_array($data[$key])) {
                            throw new RuntimeException(sprintf('Cannot create an instance of "%s" from serialized data because the variadic parameter "%s" can only accept an array.', $class$constructorParameter->name));
                        }

                        $variadicParameters = [];
                        foreach ($data[$key] as $parameterKey => $parameterData) {
                            $variadicParameters[$parameterKey] = $this->denormalizeParameter($reflectionClass$constructorParameter$paramName$parameterData$attributeContext$format);
                        }

                        $params = array_merge($params$variadicParameters);
                        unset($data[$key]);
                    }
                } elseif ($allowed && !$ignored && (isset($data[$key]) || \array_key_exists($key$data))) {
                    $parameterData = $data[$key];
                    if (null === $parameterData && $constructorParameter->allowsNull()) {
                        $params[] = null;
                        // Don't run set for a parameter passed to the constructor                         unset($data[$key]);
                        
$allowed = false === $allowedAttributes || \in_array($paramName$allowedAttributes);
                $ignored = !$this->isAllowedAttribute($class$paramName$format$context);
                if ($constructorParameter->isVariadic()) {
                    if ($allowed && !$ignored && (isset($data[$key]) || \array_key_exists($key$data))) {
                        if (!\is_array($data[$key])) {
                            throw new RuntimeException(sprintf('Cannot create an instance of "%s" from serialized data because the variadic parameter "%s" can only accept an array.', $class$constructorParameter->name));
                        }

                        $variadicParameters = [];
                        foreach ($data[$key] as $parameterKey => $parameterData) {
                            $variadicParameters[$parameterKey] = $this->denormalizeParameter($reflectionClass$constructorParameter$paramName$parameterData$attributeContext$format);
                        }

                        $params = array_merge($params$variadicParameters);
                        unset($data[$key]);
                    }
                } elseif ($allowed && !$ignored && (isset($data[$key]) || \array_key_exists($key$data))) {
                    $parameterData = $data[$key];
                    if (null === $parameterData && $constructorParameter->allowsNull()) {
                        $params[] = null;
                        // Don't run set for a parameter passed to the constructor                         unset($data[$key]);
                        


        throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" attribute for class "%s" must be one of "%s" ("%s" given).', $attribute$currentClassimplode('", "', array_keys($expectedTypes))get_debug_type($data))$dataarray_keys($expectedTypes)$context['deserialization_path'] ?? $attribute);
    }

    /** * @internal */
    protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, string $parameterName, mixed $parameterData, array $context, string $format = null): mixed
    {
        if ($parameter->isVariadic() || null === $this->propertyTypeExtractor || null === $types = $this->getTypes($class->getName()$parameterName)) {
            return parent::denormalizeParameter($class$parameter$parameterName$parameterData$context$format);
        }

        $parameterData = $this->validateAndDenormalize($types$class->getName()$parameterName$parameterData$format$context);

        return $this->applyCallbacks($parameterData$class->getName()$parameterName$format$context);
    }

    /** * @return Type[]|null */
    private function getTypes(string $currentClass, string $attribute): ?array
    {


        throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" attribute for class "%s" must be one of "%s" ("%s" given).', $attribute$currentClassimplode('", "', array_keys($expectedTypes))get_debug_type($data))$dataarray_keys($expectedTypes)$context['deserialization_path'] ?? $attribute);
    }

    /** * @internal */
    protected function denormalizeParameter(\ReflectionClass $class, \ReflectionParameter $parameter, string $parameterName, mixed $parameterData, array $context, string $format = null): mixed
    {
        if ($parameter->isVariadic() || null === $this->propertyTypeExtractor || null === $types = $this->getTypes($class->getName()$parameterName)) {
            return parent::denormalizeParameter($class$parameter$parameterName$parameterData$context$format);
        }

        $parameterData = $this->validateAndDenormalize($types$class->getName()$parameterName$parameterData$format$context);

        return $this->applyCallbacks($parameterData$class->getName()$parameterName$format$context);
    }

    /** * @return Type[]|null */
    private function getTypes(string $currentClass, string $attribute): ?array
    {
Home | Imprint | This part of the site doesn't use cookies.