本文整理匯總了PHP中Symfony\Component\Serializer\SerializerInterface::supportsDenormalization方法的典型用法代碼示例。如果您正苦於以下問題:PHP SerializerInterface::supportsDenormalization方法的具體用法?PHP SerializerInterface::supportsDenormalization怎麽用?PHP SerializerInterface::supportsDenormalization使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Serializer\SerializerInterface
的用法示例。
在下文中一共展示了SerializerInterface::supportsDenormalization方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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);
}
示例2: supportsDenormalization
/**
* {@inheritdoc}
*/
public function supportsDenormalization($data, $type, $format = null)
{
return substr($type, -2) === '[]' && $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format);
}