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


PHP Serializer::deserialize方法代码示例

本文整理汇总了PHP中JMS\Serializer\Serializer::deserialize方法的典型用法代码示例。如果您正苦于以下问题:PHP Serializer::deserialize方法的具体用法?PHP Serializer::deserialize怎么用?PHP Serializer::deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JMS\Serializer\Serializer的用法示例。


在下文中一共展示了Serializer::deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCustomSubscribingHandler

 public function testCustomSubscribingHandler()
 {
     $fixture = file_get_contents(FIXTURE_ROOT . '/Unit/Serializer/JmsSerializer/test_entity_1.json');
     $resultEntity = $this->realJms->deserialize($fixture, 'Elastification\\Client\\Serializer\\JmsSerializer\\SearchResponseEntity', 'json');
     $this->assertInstanceOf('Elastification\\Client\\Serializer\\JmsSerializer\\SearchResponseEntity', $resultEntity);
     /* @var $resultEntity \Elastification\Client\Serializer\JmsSerializer\SearchResponseEntity */
     $this->assertEquals(1, $resultEntity->took);
     $this->assertEquals(false, $resultEntity->timed_out);
     $this->assertInstanceOf('Elastification\\Client\\Serializer\\JmsSerializer\\Shards', $resultEntity->_shards);
     $this->assertEquals(1, $resultEntity->_shards->total);
     $this->assertEquals(1, $resultEntity->_shards->successful);
     $this->assertEquals(0, $resultEntity->_shards->failed);
     $this->assertInstanceOf('Elastification\\Client\\Serializer\\JmsSerializer\\Hits', $resultEntity->hits);
     $this->assertEquals(1, $resultEntity->hits->total);
     $this->assertEquals(0, $resultEntity->hits->maxScore);
     $this->assertCount(1, $resultEntity->hits->hits);
     $hit = $resultEntity->hits->hits[0];
     $this->assertInstanceOf('Elastification\\Client\\Serializer\\JmsSerializer\\Hit', $hit);
     $this->assertEquals('4372-4412104-928-DL', $hit->_id);
     $this->assertEquals('elastification', $hit->_index);
     $this->assertEquals('test', $hit->_type);
     $this->assertEquals(1.993935, $hit->_score);
     $entity = $hit->_source;
     $this->assertInstanceOf('Elastification\\Client\\Tests\\Fixtures\\Unit\\Serializer\\JmsSerializer\\TestEntity', $entity);
     $this->assertEquals(123, $entity->a);
 }
开发者ID:thebennos,项目名称:php-client,代码行数:26,代码来源:JmsSerializerTest.php

示例2: postPersist

 /**
  * @param \Doctrine\ORM\Event\LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     $layoutBlock = $args->getEntity();
     if ($layoutBlock instanceof LayoutBlock) {
         if ($contentObject = $layoutBlock->getSnapshotContent()) {
             $contentObject = $this->serializer->deserialize($contentObject, $layoutBlock->getClassType(), 'json');
             $em = $args->getEntityManager();
             try {
                 $em->persist($contentObject);
                 $contentObject = $em->merge($contentObject);
                 $reflection = new \ReflectionClass($contentObject);
                 foreach ($reflection->getProperties() as $property) {
                     $method = sprintf('get%s', ucfirst($property->getName()));
                     if ($reflection->hasMethod($method) && ($var = $contentObject->{$method}())) {
                         if ($var instanceof ArrayCollection) {
                             foreach ($var as $v) {
                                 $em->merge($v);
                             }
                         }
                     }
                 }
             } catch (EntityNotFoundException $e) {
                 $em->detach($contentObject);
                 $classType = $layoutBlock->getClassType();
                 $contentObject = new $classType();
                 $em->persist($contentObject);
             }
             $em->flush($contentObject);
             $layoutBlock->setObjectId($contentObject->getId());
             $em->persist($layoutBlock);
             $em->flush($layoutBlock);
         }
     }
 }
开发者ID:lzdv,项目名称:init-cms-bundle,代码行数:37,代码来源:LayoutBlockListener.php

示例3: execute

 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return bool
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     foreach ($this->sources as $name => $class) {
         $result = $this->serializer->deserialize(file_get_contents(getcwd() . '/tests/Common/Api/test_cases/protocols/output/fixtures/' . $name . '.xml'), $class, 'xml');
         file_put_contents(getcwd() . '/tests/Common/Api/test_cases/protocols/output/fixtures/' . $name . '.serialized', serialize($result->getBody()));
         $output->writeln('Processed ' . $name . ' serialized file.');
     }
 }
开发者ID:danielcosta,项目名称:sellercenter-sdk,代码行数:14,代码来源:UpdateSerializedFixturesFromXmlCommand.php

示例4: deserialize

 public function deserialize($data, $type)
 {
     $result = $this->serializer->deserialize($data, $type, 'json');
     if (preg_match('/ArrayCollection/', $type)) {
         $result = new ArrayList($result);
     }
     return $result;
 }
开发者ID:italolelis,项目名称:wunderlist,代码行数:8,代码来源:AsyncGuzzleAdapter.php

示例5: testDeserializeJson

 public function testDeserializeJson()
 {
     $json = '{"foo":"bar","baz":[1,2,3]}';
     /** @var Metadata $metadata */
     $metadata = $this->serializer->deserialize($json, Metadata::class, 'json');
     $this->assertInstanceOf(Metadata::class, $metadata);
     $this->assertEquals(['baz' => [1, 2, 3], 'foo' => 'bar'], $metadata->toArray());
 }
开发者ID:pauci,项目名称:cqrs,代码行数:8,代码来源:MetadataHandlerTest.php

示例6: deserialize

 /**
  * @param AbstractJsonEvent $event
  * 
  * @return AbstractJsonEvent
  */
 public function deserialize(AbstractJsonEvent $event)
 {
     $deSerialized = $this->serializer->deserialize($event->getJson(), get_class($event), self::JSON_FORMAT);
     $deSerialized->type = $event->type;
     $deSerialized->content = $event->content;
     $deSerialized->setName($event->getName());
     return $deSerialized;
 }
开发者ID:smart-gamma,项目名称:pushpin-bundle,代码行数:13,代码来源:EventSerializer.php

示例7: onResponseEvent

 /**
  * @param ServiceEvent $event
  */
 public function onResponseEvent(ServiceEvent $event)
 {
     $service = $event->getService();
     if ($service instanceof ServiceConfigurableInterface && null !== $service->getOption('response_type')) {
         /** @var Service $service */
         $service->getResponse()->setDeserializedContent($this->serializer->deserialize($service->getResponse()->getContent(), $service->getOption('response_type'), $service->getOption('response_format')));
     }
 }
开发者ID:itkg,项目名称:consumer,代码行数:11,代码来源:DeserializerListener.php

示例8: testDiscriminatorIsInferredForGenericBaseClass

 public function testDiscriminatorIsInferredForGenericBaseClass()
 {
     $student = new Student();
     $json = $this->serializer->serialize($student, 'json');
     $this->assertEquals('{"type":"student"}', $json);
     $deserialized = $this->serializer->deserialize($json, Person::class, 'json');
     $this->assertEquals($student, $deserialized);
 }
开发者ID:baardbaard,项目名称:bb-twitterfeed,代码行数:8,代码来源:IntegrationTest.php

示例9: getLockFile

 /**
  * @return \App\Satis\Model\ConfigLock|array|\JMS\Serializer\scalar|mixed|object
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 protected function getLockFile()
 {
     if ($this->filesystem->exists($this->lockFilename)) {
         $configLock = $this->serializer->deserialize($this->filesystem->get($this->lockFilename), 'App\\Satis\\Model\\ConfigLock', 'json');
     } else {
         $configLock = new ConfigLock();
     }
     return $configLock;
 }
开发者ID:realshadow,项目名称:satis-control-panel,代码行数:13,代码来源:ConfigPersister.php

示例10: deserialize

 /**
  * Deserializes request content.
  *
  * @param ResponseInterface $response
  * @param string            $type
  * @param string            $format
  *
  * @return mixed
  *
  * @throws \Exception
  */
 protected function deserialize(ResponseInterface $response, $type, $format = 'json')
 {
     try {
         return $this->serializer->deserialize((string) $response->getBody(), $type, $format);
     } catch (\Exception $exception) {
         $this->logger->error('[WebServiceClient] Deserialization problem on webservice call.', array('response' => (string) $response->getBody(), 'exception' => $exception));
         throw $exception;
     }
 }
开发者ID:nicolasdewez,项目名称:webhome-common,代码行数:20,代码来源:AbstractClient.php

示例11: testDeserializeJson

 public function testDeserializeJson()
 {
     $json = '{"uuid":"ed34c88e-78b0-11e3-9ade-406c8f20ad00"}';
     /** @var ObjectWithUuid $object */
     $object = $this->serializer->deserialize($json, ObjectWithUuid::class, 'json');
     $uuid = $object->getUuid();
     $this->assertInstanceOf(UuidInterface::class, $uuid);
     $this->assertEquals('ed34c88e-78b0-11e3-9ade-406c8f20ad00', (string) $uuid);
 }
开发者ID:pauci,项目名称:cqrs,代码行数:9,代码来源:RamseyUuidHandlerTest.php

示例12: it_can_be_deserialized

 /**
  * @test
  */
 public function it_can_be_deserialized()
 {
     $modelData = $this->getModelData();
     $modelClass = $this->getModelClass();
     /** @var AbstractModel $model */
     $model = $this->serializer->deserialize(json_encode($modelData), $modelClass, 'json');
     $this->assertInstanceOf($modelClass, $model);
     $this->assertInstanceOf('CL\\Slack\\Model\\AbstractModel', $model);
     $this->assertModel($modelData, $model);
 }
开发者ID:wogsland,项目名称:slack,代码行数:13,代码来源:AbstractModelTest.php

示例13: test_CreateAnimal_success

 public function test_CreateAnimal_success()
 {
     $this->testUtils->createUser()->toEleveur();
     $this->client->request('POST', '/animal');
     $this->assertEquals(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());
     /** @var PageAnimal $pageAnimal */
     $pageAnimal = $this->serializer->deserialize($this->client->getResponse()->getContent(), PageAnimal::class, 'json');
     $this->client->request('GET', '/animal/' . $pageAnimal->getId());
     $this->assertEquals(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());
 }
开发者ID:apflieger,项目名称:zigotoo,代码行数:10,代码来源:PageAnimalControllerTest.php

示例14: hydrateEntity

 /**
  * @param $data
  * @param $entityName
  * @return mixed
  */
 public function hydrateEntity($data, $entityName)
 {
     if (empty($data)) {
         $data = array();
     }
     if (is_string($data)) {
         $data = json_decode($data, true);
     }
     return $this->serializer->deserialize(json_encode($this->transformer->transformHydrateData($data)), $entityName, 'json');
 }
开发者ID:nikonm,项目名称:silex-rest-service-providers,代码行数:15,代码来源:HydratorService.php

示例15: reverseTransform

 /**
  * {@inheritdoc}
  */
 public function reverseTransform($data)
 {
     if ($data === null) {
         return null;
     }
     try {
         return $this->serializer->deserialize($data, $this->class, $this->format);
     } catch (JMSException $e) {
         throw new StorageException('The JMS serializer failed deserializing the data: ' . $e->getMessage(), 0, $e);
     }
 }
开发者ID:mnapoli,项目名称:blackbox,代码行数:14,代码来源:JmsSerializer.php


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