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

setAttributeValue() protected method

protected setAttributeValue ( $object, $attribute, $value, $format = null, array $context = [] )
$context array
    protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = [])
    {
        $propertyMetadata = $this->propertyMetadataFactory->create($context['resource_class'], $attribute, $this->getFactoryOptions($context));
        $type = $propertyMetadata->getType();
        if (null === $type) {
            // No type provided, blindly set the value
            $this->setValue($object, $attribute, $value);
            return;
        }
        if (null === $value && $type->isNullable()) {
            $this->setValue($object, $attribute, $value);
            return;
        }
        if ($type->isCollection() && null !== ($collectionValueType = $type->getCollectionValueType()) && null !== ($className = $collectionValueType->getClassName())) {
            $this->setValue($object, $attribute, $this->denormalizeCollection($attribute, $propertyMetadata, $type, $className, $value, $format, $context));
            return;
        }
        if (null !== ($className = $type->getClassName())) {
            $this->setValue($object, $attribute, $this->denormalizeRelation($attribute, $propertyMetadata, $className, $value, $format, $context));
            return;
        }
        $this->validateType($attribute, $type, $value, $format);
        $this->setValue($object, $attribute, $value);
    }