當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。