• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Serializer\Serializer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Serializer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: create

 /**
  * @param array      $data
  * @param Serializer $serializer
  * @return LegalEntity
  * @throws \Exception
  */
 public static function create(array $data, Serializer $serializer)
 {
     $caseType = null;
     $data['caseType'] = isset($data['caseType']) ? $data['caseType'] : 'Lpa';
     if (!empty($data['caseType'])) {
         switch ($data['caseType']) {
             case "Epa":
                 $caseType = "Opg\\Core\\Model\\Entity\\CaseItem\\PowerOfAttorney\\Epa";
                 break;
             case "Order":
                 $caseType = "Opg\\Core\\Model\\Entity\\CaseItem\\Deputyship\\Order";
                 break;
             default:
                 $caseType = "Opg\\Core\\Model\\Entity\\CaseItem\\PowerOfAttorney\\Lpa";
                 break;
         }
     } else {
         throw new \Exception('Cannot build unknown case type.');
     }
     try {
         /** @var CaseItem $case */
         $case = $serializer->deserialize(json_encode($data), $caseType, 'json');
     } catch (\Exception $e) {
         throw $e;
     }
     return $case;
 }
开发者ID:ministryofjustice,项目名称:opg-core-public-domain-model,代码行数:33,代码来源:CaseItemFactory.php


示例3: setUp

 protected function setUp()
 {
     $this->channel = $this->prophesize(AMQPChannel::class);
     $this->serializer = $this->prophesize(Serializer::class);
     $this->eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
     $this->parser = $this->prophesize(Parser::class);
     $this->manager = new ConsumerManager($this->channel->reveal(), self::EXCHANGE_NAME, $this->serializer->reveal(), $this->parser->reveal());
     $this->manager->setEventDispatcher($this->eventDispatcher->reveal());
 }
开发者ID:rebuy-de,项目名称:amqp-php-consumer,代码行数:9,代码来源:ManagerTest.php


示例4: 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


示例5: serializeResponse

 /**
  * @param GetResponseForControllerResultEvent $event
  */
 public function serializeResponse(GetResponseForControllerResultEvent $event)
 {
     if ($this->doSerialize) {
         $data = $event->getControllerResult();
         $apiResponse = new ApiResponse(200, $data);
         $data = array_merge($apiResponse->toArray(), $this->data->all());
         $data = array_filter($data);
         if (!isset($data['data'])) {
             $data['data'] = [];
         }
         $context = new SerializationContext();
         $context->setSerializeNull(true);
         if (method_exists($context, 'enableMaxDepthChecks')) {
             $context->enableMaxDepthChecks();
         }
         if ($action = $this->getAction($event)) {
             $context->setGroups($action->getSerializationGroups());
         }
         if ($fields = $event->getRequest()->query->get('fields')) {
             $context->addExclusionStrategy(new FieldsListExclusionStrategy($fields));
         }
         $json = $this->serializer->serialize($data, 'json', $context);
         $response = new Response($json, 200, ['Content-Type' => 'application/json']);
         $event->setResponse($response);
         $event->stopPropagation();
     }
 }
开发者ID:bitecodes,项目名称:rest-api-generator-bundle,代码行数:30,代码来源:SerializationSubscriber.php


示例6: put

 public function put($resource, $body, $type, $options = [])
 {
     $options['body'] = $this->serializer->serialize($body, 'json');
     $options['headers'] = ['Content-Type' => 'application/json'];
     $content = $this->client->put($resource, $options)->getBody()->getContents();
     return $this->deserialize($content, $type);
 }
开发者ID:italolelis,项目名称:wunderlist,代码行数:7,代码来源:GuzzleAdapter.php


示例7: unmapObject

 /**
  * @param mixed $object
  * @return array
  */
 public function unmapObject($object)
 {
     if (is_array($object)) {
         return $object;
     }
     return $this->serializer->toArray($object);
 }
开发者ID:raphhh,项目名称:balloon,代码行数:11,代码来源:DataMapper.php


示例8: 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


示例9: 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


示例10: render

 /**
  * Render the view into a string and return for output
  *
  * @param mixed $input
  * @return string
  * @throws \Exception
  */
 public function render($input = null)
 {
     $context = new SerializationContext();
     $context->setSerializeNull(true);
     $context->enableMaxDepthChecks();
     FrontController::getInstance()->getResponse()->headers->set('Content-Type', 'application/json');
     return $this->serializer->serialize($input, $this->format, $context);
 }
开发者ID:epoplive,项目名称:pillow,代码行数:15,代码来源:DoctrineAnnotationTemplateView.php


示例11: 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


示例12: json

 public function json($data, $groups = null)
 {
     if ($groups) {
         $this->context->setGroups($groups);
     }
     $serializedData = $this->serializer->serialize($data, 'json', $this->context);
     return $serializedData;
 }
开发者ID:bakgat,项目名称:notos,代码行数:8,代码来源:Controller.php


示例13: 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


示例14: 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


示例15: 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


示例16: getResponse

 /**
  * @inheritDoc
  */
 public function getResponse($responseType, $view, $templateName, $params, $status = 200, $headers = [], $groups = ['Default'])
 {
     if ($responseType === 'html') {
         $response = $this->getHtml($view, $templateName, $params);
     } else {
         $response = $this->serializer->serialize($params, $responseType, SerializationContext::create()->setGroups($groups));
     }
     return new Response($response, $status, $headers);
 }
开发者ID:auamarto,项目名称:crud-bundle,代码行数:12,代码来源:ResponseHandler.php


示例17: 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


示例18: 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


示例19: put

 public function put($resource, $body, $type, $options = [])
 {
     $options['future'] = true;
     $options['body'] = $this->serializer->serialize($body, 'json');
     $options['headers'] = ['Content-Type' => 'application/json'];
     return $this->client->put($resource, $options)->then(function (Response $reponse) {
         return $reponse->getBody()->getContents();
     })->then(function ($content) use($type) {
         return $this->deserialize($content, $type);
     });
 }
开发者ID:italolelis,项目名称:wunderlist,代码行数:11,代码来源:AsyncGuzzleAdapter.php


示例20: serialize

 /**
  * @param array|object $data
  * @param string $dtoClassName
  * @param string $outputFormat
  * @return array
  */
 public function serialize($data, $dtoClassName, $outputFormat = 'json')
 {
     // TODO: check if $data is object or array
     $itemArray = [];
     foreach ($data as $item) {
         $dto = $this->shifter->toDto($item, new $dtoClassName());
         $serializedData = $this->serializer->serialize($dto, $outputFormat);
         $itemArray[] = (array) json_decode($serializedData);
     }
     return $itemArray;
 }
开发者ID:rud-felix,项目名称:tweet,代码行数:17,代码来源:DataTransferPrepare.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Serializer\SerializerBuilder类代码示例发布时间:2022-05-23
下一篇:
PHP Serializer\SerializationContext类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap