ApiPlatform\Core\Serializer\AbstractItemNormalizer::denormalizeCollection PHP Method

denormalizeCollection() private method

Denormalizes a collection of objects.
private denormalizeCollection ( string $attribute, PropertyMetadata $propertyMetadata, Symfony\Component\PropertyInfo\Type $type, string $className, mixed $value, string $format = null, array $context ) : array
$attribute string
$propertyMetadata ApiPlatform\Core\Metadata\Property\PropertyMetadata
$type Symfony\Component\PropertyInfo\Type
$className string
$value mixed
$format string
$context array
return array
    private function denormalizeCollection(string $attribute, PropertyMetadata $propertyMetadata, Type $type, string $className, $value, string $format = null, array $context) : array
    {
        if (!is_array($value)) {
            throw new InvalidArgumentException(sprintf('The type of the "%s" attribute must be "array", "%s" given.', $attribute, gettype($value)));
        }
        $collectionKeyType = $type->getCollectionKeyType();
        $collectionKeyBuiltinType = null === $collectionKeyType ? null : $collectionKeyType->getBuiltinType();
        $values = [];
        foreach ($value as $index => $obj) {
            if (null !== $collectionKeyBuiltinType && !call_user_func('is_' . $collectionKeyBuiltinType, $index)) {
                throw new InvalidArgumentException(sprintf('The type of the key "%s" must be "%s", "%s" given.', $index, $collectionKeyBuiltinType, gettype($index)));
            }
            $values[$index] = $this->denormalizeRelation($attribute, $propertyMetadata, $className, $obj, $format, $context);
        }
        return $values;
    }