当前位置: 首页>>代码示例>>PHP>>正文


PHP Serializer::denormalize方法代码示例

本文整理汇总了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]);
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:10,代码来源:AssociationDenormalizerSpec.php

示例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;
  }
开发者ID:AshishNaik021,项目名称:iimisac-d8,代码行数:21,代码来源:Serializer.php

示例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);
 }
开发者ID:nervo,项目名称:DoctrineEntitySerializer,代码行数:12,代码来源:DoctrineEntitySerializer.php

示例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;
 }
开发者ID:mihai-stancu,项目名称:serializer,代码行数:32,代码来源:ParamsDenormalizer.php

示例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'));
 }
开发者ID:ayoah,项目名称:symfony,代码行数:14,代码来源:SerializerTest.php

示例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'));
 }
开发者ID:ABaldwinHunter,项目名称:symfony-clone,代码行数:9,代码来源:SerializerTest.php

示例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);
 }
开发者ID:yceruto,项目名称:symfony,代码行数:11,代码来源:ObjectNormalizerTest.php

示例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);
 }
开发者ID:MisatoTremor,项目名称:symfony,代码行数:10,代码来源:ObjectNormalizerTest.php

示例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);
 }
开发者ID:evangelion1204,项目名称:typified-serializer,代码行数:8,代码来源:TypifiedSerializer.php

示例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);
 }
开发者ID:N3m1s,项目名称:ElasticsearchBundle,代码行数:7,代码来源:OrderedSerializer.php

示例11: deserialize

 public function deserialize(array $serializedObject)
 {
     return $this->serializer->denormalize($serializedObject['payload'], $serializedObject['class']);
 }
开发者ID:simgroep,项目名称:broadway-simple-serializer,代码行数:4,代码来源:SimpleSerializer.php

示例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);
 }
开发者ID:Maksold,项目名称:platform,代码行数:9,代码来源:ProcessDataSerializer.php

示例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);
 }
开发者ID:wearebase,项目名称:base-transport,代码行数:5,代码来源:BusServiceNormalizerTest.php


注:本文中的Symfony\Component\Serializer\Serializer::denormalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。