本文整理匯總了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'));
}