当前位置: 首页>>代码示例>>PHP>>正文


PHP SerializerInterface::denormalize方法代码示例

本文整理汇总了PHP中Symfony\Component\Serializer\SerializerInterface::denormalize方法的典型用法代码示例。如果您正苦于以下问题:PHP SerializerInterface::denormalize方法的具体用法?PHP SerializerInterface::denormalize怎么用?PHP SerializerInterface::denormalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Serializer\SerializerInterface的用法示例。


在下文中一共展示了SerializerInterface::denormalize方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: denormalize

 /**
  * {@inheritdoc}
  */
 public function denormalize($data, $class, $format = null, array $context = [])
 {
     $result = $this->createObject($class);
     $fields = $this->fieldHelper->getFields($class, true);
     foreach ($fields as $field) {
         $fieldName = $field['name'];
         if (array_key_exists($fieldName, $data)) {
             $value = $data[$fieldName];
             if ($data[$fieldName] !== null && ($this->fieldHelper->isRelation($field) || $this->fieldHelper->isDateTimeField($field))) {
                 if ($this->fieldHelper->isMultipleRelation($field)) {
                     $entityClass = sprintf('ArrayCollection<%s>', $field['related_entity_name']);
                 } elseif ($this->fieldHelper->isSingleRelation($field)) {
                     $entityClass = $field['related_entity_name'];
                 } else {
                     $entityClass = 'DateTime';
                     $context = array_merge($context, ['type' => $field['type']]);
                 }
                 $context = array_merge($context, ['fieldName' => $fieldName]);
                 $value = $this->serializer->denormalize($value, $entityClass, $format, $context);
             }
             $this->fieldHelper->setObjectValue($result, $fieldName, $value);
         }
     }
     return $result;
 }
开发者ID:Maksold,项目名称:platform,代码行数:28,代码来源:ConfigurableEntityNormalizer.php

示例2: denormalize

 /**
  * {@inheritdoc}
  */
 public function denormalize($data, $class, $format = null, array $context = [])
 {
     if (empty($data)) {
         return null;
     }
     $options = new ArrayCollection();
     foreach ($data as $optionCode) {
         $option = $this->serializer->denormalize($optionCode, AttributeTypes::OPTION_SIMPLE_SELECT, $format, $context);
         $options->add($option);
     }
     return $options;
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:15,代码来源:AttributeOptionsDenormalizer.php

示例3: denormalize

 /**
  * {@inheritdoc}
  */
 public function denormalize($data, $class, $format = null, array $context = [])
 {
     if (empty($data)) {
         return null;
     }
     $options = new ArrayCollection();
     foreach ($data as $optionCode) {
         $option = $this->serializer->denormalize($optionCode, 'pim_catalog_simpleselect', $format, $context);
         $options->add($option);
     }
     return $options;
 }
开发者ID:jacko972,项目名称:pim-community-dev,代码行数:15,代码来源:AttributeOptionsDenormalizer.php

示例4: denormalize

 /**
  * @param mixed $data
  * @param string $class
  * @param mixed $format
  * @param array $context
  * @return AbstractTypedAddress
  */
 public function denormalize($data, $class, $format = null, array $context = array())
 {
     /** @var AbstractTypedAddress $result */
     $result = $this->addressNormalizer->denormalize($data, $class, $format, $context);
     if (!empty($data['types']) && is_array($data['types'])) {
         $types = $this->serializer->denormalize($data['types'], static::TYPES_TYPE, $format, $context);
         if ($types) {
             foreach ($types as $type) {
                 $result->addType($type);
             }
         }
     }
     return $result;
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:21,代码来源:TypedAddressNormalizer.php

示例5: denormalize

 /**
  * Returns collection of denormalized data
  *
  * @param mixed $data
  * @param string $class
  * @param mixed $format
  * @param array $context
  * @return ArrayCollection
  */
 public function denormalize($data, $class, $format = null, array $context = array())
 {
     if (!is_array($data)) {
         return new ArrayCollection();
     }
     $itemType = $this->getItemType($class);
     if (!$itemType) {
         return new ArrayCollection($data);
     }
     $result = new ArrayCollection();
     foreach ($data as $item) {
         $result->add($this->serializer->denormalize($item, $itemType, $format, $context));
     }
     return $result;
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:24,代码来源:CollectionNormalizer.php

示例6: denormalize

 /**
  * @param array  $values
  * @param string $class
  * @param string $format
  * @param array  $context
  *
  * @return array|object
  */
 public function denormalize($values, $class, $format = null, array $context = array())
 {
     if (!is_array($values)) {
         return $values;
     }
     $filtered = array_filter($values, function ($value) use($class, $format) {
         return $this->serializer->supportsDenormalization($value, $class, $format);
     });
     if (count($filtered) !== count($values)) {
         throw new \InvalidArgumentException('Not all values within the array can be denormalized.');
     }
     return array_map(function ($value) use($class, $format, $context) {
         return $this->serializer->denormalize($value, $class, $format, $context);
     }, $filtered);
 }
开发者ID:mihai-stancu,项目名称:serializer,代码行数:23,代码来源:MixedDenormalizer.php

示例7: denormalizeObject

 /**
  * @param array  $data
  * @param string $name
  * @param string $type
  * @param mixed  $format
  * @param array  $context
  *
  * @return null|object
  */
 protected function denormalizeObject(array $data, $name, $type, $format = null, $context = array())
 {
     $result = null;
     if (!empty($data[$name])) {
         $result = $this->serializer->denormalize($data[$name], $type, $format, $context);
     }
     return $result;
 }
开发者ID:dairdr,项目名称:crm,代码行数:17,代码来源:AbstractNormalizer.php

示例8: handleUpdateRequest

 /**
  * {@inheritdoc}
  */
 public function handleUpdateRequest(Request $request, $identifier)
 {
     $parameters = $request->request->all();
     $resource = $this->getResourceById($identifier);
     $className = ClassUtils::getRealClass(get_class($resource));
     $resource = $this->serializer->denormalize($parameters, $className, self::RESPONSE_FORMAT, ['resource' => $resource]);
     $data = $this->serializer->serialize($resource, self::RESPONSE_FORMAT, ['group' => $this->getResourceType()]);
     $this->manager->updateResource($resource);
     return new Response($data);
 }
开发者ID:wellcommerce,项目名称:wellcommerce,代码行数:13,代码来源:RequestHandler.php

示例9: denormalize

 /**
  * {@inheritdoc}
  */
 public function denormalize($data, $class, $format = null, array $context = [])
 {
     if (!isset($context['attribute'])) {
         throw new InvalidArgumentException('Attribute must be passed in the context');
     }
     $attribute = $context['attribute'];
     if (!$attribute instanceof AttributeInterface) {
         throw new InvalidArgumentException(sprintf('Attribute must be an instance of %s, %s given', 'Pim\\Bundle\\CatalogBundle\\Model\\AttributeInterface', is_object($attribute) ? get_class($attribute) : gettype($attribute)));
     }
     $data = $data + ['locale' => null, 'scope' => null, 'value' => null];
     $value = new $this->entityClass();
     $value->setAttribute($attribute);
     $value->setLocale($data['locale']);
     $value->setScope($data['scope']);
     $valueData = $this->serializer->denormalize($data['value'], $attribute->getAttributeType(), $format, $context);
     if (null !== $valueData) {
         $value->setData($valueData);
     }
     return $value;
 }
开发者ID:jacko972,项目名称:pim-community-dev,代码行数:23,代码来源:ProductValueDenormalizer.php

示例10: denormalize

 /**
  * @param mixed $data
  * @param string $class
  * @param mixed $format
  * @param array $context
  * @return mixed
  */
 public function denormalize($data, $class, $format = null, array $context = array())
 {
     $fieldRules = $this->getProcessedFieldRules();
     if (!is_array($data)) {
         if ($this->primaryField) {
             $data = array($this->primaryField['normalizeName'] => $data);
         } else {
             return $this->createNewObject();
         }
     }
     $object = $this->createNewObject();
     foreach ($fieldRules as $field) {
         if (!$field['denormalize'] || !array_key_exists($field['normalizeName'], $data)) {
             continue;
         }
         $value = $data[$field['normalizeName']];
         if (isset($field['type']) && $value !== null) {
             $value = $this->serializer->denormalize($data[$field['normalizeName']], $field['type'], $format, array_merge($context, $field['context']));
         }
         $this->getPropertyAccessor()->setValue($object, $field['denormalizeName'], $value);
     }
     return $object;
 }
开发者ID:florinmatthew,项目名称:zoho-integration-bundle,代码行数:30,代码来源:AbstractNormalizer.php


注:本文中的Symfony\Component\Serializer\SerializerInterface::denormalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。