本文整理汇总了PHP中Symfony\Component\Serializer\Serializer::supportsDenormalization方法的典型用法代码示例。如果您正苦于以下问题:PHP Serializer::supportsDenormalization方法的具体用法?PHP Serializer::supportsDenormalization怎么用?PHP Serializer::supportsDenormalization使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Serializer\Serializer
的用法示例。
在下文中一共展示了Serializer::supportsDenormalization方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: denormalizeParam
/**
* @param array $data
* @param \ReflectionParameter $param
* @param string $format
* @param array $context
*
* @return object
*/
protected function denormalizeParam($data, $param, $format, $context)
{
$name = $param->getName();
$index = $param->getPosition();
if (array_key_exists($name, $data)) {
$value = $data[$name];
} elseif (array_key_exists($index, $data)) {
$value = $data[$index];
} elseif ($param->isDefaultValueAvailable()) {
$value = $param->getDefaultValue();
} else {
$message = sprintf('Missing parameter #%s: %s', $index, $name);
throw new \RuntimeException($message);
}
if ($param->getClass()) {
$class = $param->getClass()->getName();
} elseif ($this->serializer->supportsDenormalization($value, MixedDenormalizer::TYPE, $format)) {
$class = MixedDenormalizer::TYPE;
}
if (isset($class)) {
$value = $this->serializer->denormalize($value, $class, $format, $context);
}
return $value;
}
示例2: testSupportsArrayDeserialization
public function testSupportsArrayDeserialization()
{
$serializer = new Serializer(array(new GetSetMethodNormalizer(), new PropertyNormalizer(), new ObjectNormalizer(), new CustomNormalizer(), new ArrayDenormalizer()), array('json' => new JsonEncoder()));
$this->assertTrue($serializer->supportsDenormalization(array(), __NAMESPACE__ . '\\Model[]', 'json'));
}
示例3: testDeserializeNotSupportedMissing
public function testDeserializeNotSupportedMissing()
{
$serializer = new Serializer(array(), array());
$data = array('title' => 'foo', 'numbers' => array(5, 3));
$this->assertFalse($serializer->supportsDenormalization(json_encode($data), '\\Symfony\\Component\\Serializer\\Tests\\Model', 'json'));
}