本文整理汇总了PHP中Symfony\Component\Serializer\Normalizer\NormalizerInterface::denormalize方法的典型用法代码示例。如果您正苦于以下问题:PHP NormalizerInterface::denormalize方法的具体用法?PHP NormalizerInterface::denormalize怎么用?PHP NormalizerInterface::denormalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Serializer\Normalizer\NormalizerInterface
的用法示例。
在下文中一共展示了NormalizerInterface::denormalize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDenormalizationWithType
public function testDenormalizationWithType()
{
$dummy = $this->getDummy();
$this->normalizer->addType('dummy', TypehintNormalizerClassDummy::class);
$this->normalizer->addType('subdummy', TypehintNormalizerSubclassDummy::class);
$expected = $dummy;
$normalized = $this->normalizer->normalize($dummy);
$this->assertTrue($this->normalizer->supportsDenormalization($normalized, RecursiveNormalizerClassDummy::class));
$actual = $this->normalizer->denormalize($normalized, TypehintNormalizerClassDummy::class);
$this->assertEquals($expected, $actual);
}
示例2: 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;
}
示例3: 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;
}
示例4: denormalize
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = null, array $context = [])
{
if (isset($data['#type'])) {
$type = $data['#type'];
unset($data['#type']);
$data = $this->denormalize($data, $type, $format, $context);
$data = $this->objectNormalizer->denormalize($data, $type, $format, $context);
return $data;
}
if (is_array($data) || $data instanceof \Traversable) {
foreach ($data as $key => $value) {
$data[$key] = $this->serializer->denormalize($value, $class, $format, $context);
}
}
return $data;
}
示例5: 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);
}