本文整理汇总了PHP中Symfony\Component\Serializer\Serializer::denormalize方法的典型用法代码示例。如果您正苦于以下问题:PHP Serializer::denormalize方法的具体用法?PHP Serializer::denormalize怎么用?PHP Serializer::denormalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Serializer\Serializer
的用法示例。
在下文中一共展示了Serializer::denormalize方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function it_denormalizes_association_with_products(Association $association, Serializer $serializer, ProductInterface $product1, ProductInterface $product2)
{
// Mock product denormalization
$serializer->denormalize('foo', self::PRODUCT_CLASS, self::FORMAT_CSV)->willReturn($product1);
$serializer->denormalize('bar', self::PRODUCT_CLASS, self::FORMAT_CSV)->willReturn($product2);
$association->addProduct($product1)->shouldBeCalled();
$association->addProduct($product2)->shouldBeCalled();
$this->setSerializer($serializer);
$this->denormalize('foo,bar', self::ENTITY_CLASS, self::FORMAT_CSV, ['part' => 'products', 'entity' => $association]);
}
示例2: deserializeForm
/**
* @param $code
* @return array
*/
public function deserializeForm($code) {
$mappings_raw = json_decode($code, TRUE);
$decoded_fillpdf_form = $this->serializer->denormalize($mappings_raw['form'], 'Drupal\fillpdf\Entity\FillPdfForm');
// Denormalization is a pain; we have to iterate over the fields to actually
// recompose the $fields array.
$field_json = $mappings_raw['fields'];
$decoded_fields = [];
foreach ($field_json as $normalized_field) {
$field = $this->serializer->denormalize($normalized_field, 'Drupal\fillpdf\Entity\FillPdfFormField');
$decoded_fields[$field->pdf_key->value] = $field;
}
$return = ['form' => $decoded_fillpdf_form, 'fields' => $decoded_fields];
return $return;
}
示例3: denormalize
/**
* {@inheritdoc}
*/
public function denormalize($data, $type, $format = null)
{
// Use alias namespace ?
if (strrpos($type, ':') !== false) {
list($namespaceAlias, $simpleClassName) = explode(':', $type);
$type = $this->entityManager->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
}
return parent::denormalize($data, $type, $format);
}
示例4: 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;
}
示例5: testDenormalizeWithSupportOnData
public function testDenormalizeWithSupportOnData()
{
$denormalizer1 = $this->getMock('Symfony\\Component\\Serializer\\Normalizer\\DenormalizerInterface');
$denormalizer1->method('supportsDenormalization')->willReturnCallback(function ($data, $type, $format) {
return isset($data['test1']);
});
$denormalizer1->method('denormalize')->willReturn('test1');
$denormalizer2 = $this->getMock('Symfony\\Component\\Serializer\\Normalizer\\DenormalizerInterface');
$denormalizer2->method('supportsDenormalization')->willReturn(true);
$denormalizer2->method('denormalize')->willReturn('test2');
$serializer = new Serializer(array($denormalizer1, $denormalizer2));
$this->assertEquals('test1', $serializer->denormalize(array('test1' => true), 'test'));
$this->assertEquals('test2', $serializer->denormalize(array(), 'test'));
}
示例6: testDenormalizeOnNormalizer
/**
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
*/
public function testDenormalizeOnNormalizer()
{
$serializer = new Serializer(array(new TestNormalizer()), array());
$data = array('title' => 'foo', 'numbers' => array(5, 3));
$this->assertTrue($serializer->denormalize(json_encode($data), 'stdClass', 'json'));
}
示例7: testRejectInvalidKey
/**
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
* @expectedExceptionMessage The type of the key "a" must be "int" ("string" given).
*/
public function testRejectInvalidKey()
{
$extractor = new PropertyInfoExtractor(array(), array(new PhpDocExtractor(), new ReflectionExtractor()));
$normalizer = new ObjectNormalizer(null, null, null, $extractor);
$serializer = new Serializer(array(new ArrayDenormalizer(), new DateTimeNormalizer(), $normalizer));
$serializer->denormalize(array('inners' => array('a' => array('foo' => 1))), ObjectOuter::class);
}
示例8: testRejectInvalidType
/**
* @expectedException UnexpectedValueException
* @expectedExceptionMessage The type of the "date" attribute for class "Symfony\Component\Serializer\Tests\Normalizer\ObjectOuter" must be one of "DateTimeInterface" ("string" given).
*/
public function testRejectInvalidType()
{
$normalizer = new ObjectNormalizer(null, null, null, new ReflectionExtractor());
$serializer = new Serializer(array($normalizer));
$serializer->denormalize(array('date' => 'foo'), ObjectOuter::class);
}
示例9: denormalize
/**
* {@inheritdoc}
*/
public function denormalize($data, $type = null, $format = null, array $context = array())
{
$type = isset($data[TypifiedNormalizer::META_CLASS]) ? $data[TypifiedNormalizer::META_CLASS] : $type;
return parent::denormalize($data, $type, $format, $context);
}
示例10: denormalize
/**
* {@inheritdoc}
*/
public function denormalize($data, $type, $format = null, array $context = [])
{
return parent::denormalize(is_array($data) ? $this->order($data) : $data, $type, $format, $context);
}
示例11: deserialize
public function deserialize(array $serializedObject)
{
return $this->serializer->denormalize($serializedObject['payload'], $serializedObject['class']);
}
示例12: denormalize
/**
* {@inheritdoc}
*/
public function denormalize($data, $type, $format = null, array $context = array())
{
$this->denormalizerCache = array();
// disable internal cache;
return parent::denormalize($data, $type, $format, $context);
}
示例13: testDenormalization
public function testDenormalization()
{
$denormalizeBusService = $this->serializer->denormalize(['description' => 'description', 'id' => 1, 'information' => ['information'], 'lines' => ['navy'], 'name' => '1A', 'operation' => ['status' => 'running']], BusService::class);
$this->assertEquals($this->busService, $denormalizeBusService);
}