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


PHP Serializer::serialize方法代码示例

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


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

示例1: testSerializeJson

 public function testSerializeJson()
 {
     $uuid = Uuid::fromString('34ca79b8-6181-4b93-903a-ac658e0c5c35');
     $object = new ObjectWithUuid($uuid);
     $json = $this->serializer->serialize($object, 'json');
     $this->assertEquals('{"uuid":"34ca79b8-6181-4b93-903a-ac658e0c5c35"}', $json);
 }
开发者ID:pauci,项目名称:cqrs,代码行数:7,代码来源:RamseyUuidHandlerTest.php

示例2: xmlSerialization

 /**
  * @test serialized xml has type attribute
  */
 public function xmlSerialization()
 {
     $container = new EventContainer(new SerializableEventStub('event.name', 'some data'));
     $this->namingStrategy->expects($this->once())->method('classToType')->with(get_class($container->getEvent()))->will($this->returnValue('stub'));
     $serialized = $this->serializer->serialize($container, 'xml');
     $this->assertEquals(file_get_contents(__DIR__ . '/Fixtures/container.xml'), $serialized);
 }
开发者ID:event-band,项目名称:band-serializer-jms,代码行数:10,代码来源:EventContainerHandlerTest.php

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

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

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

示例6: dump

 /**
  *
  * @param \CSanquer\FakeryGenerator\Model\Config $config
  * @param string                                 $dir
  * @param string                                 $format
  * @return string filename
  */
 public function dump(Config $config, $dir, $format = 'json')
 {
     $format = in_array($format, ['json', 'xml']) ? $format : 'json';
     $serialized = $this->serializer->serialize($config, $format);
     $filename = $dir . '/' . $config->getClassName(true) . '_fakery_generator_config_' . date('Y-m-d_H-i-s') . '.' . $format;
     file_put_contents($filename, $serialized);
     return $filename;
 }
开发者ID:csanquer,项目名称:fakery-generator,代码行数:15,代码来源:ConfigSerializer.php

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

示例8: transform

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

示例9: serialize

 /**
  * @param mixed $content
  *
  * @return string
  */
 protected function serialize($content)
 {
     if (!empty($content)) {
         if (is_object($content)) {
             $content = $this->serializer->serialize($content, 'json');
         }
     }
     return $content;
 }
开发者ID:nicolasdewez,项目名称:webhome-common,代码行数:14,代码来源:AbstractClient.php

示例10: append

 public function append(EventStream $events)
 {
     foreach ($events as $event) {
         $data = $this->serializer->serialize($event, 'json');
         $event = $this->serializer->serialize(['type' => get_class($event), 'created_on' => (new DateTimeImmutable('now', new DateTimeZone('UTC')))->getTimestamp(), 'data' => $data], 'json');
         $this->predis->rpush('events:' . $events->aggregateId(), $event);
         $this->predis->rpush('published_events', $event);
     }
 }
开发者ID:dddinphp,项目名称:last-wishes-gamify,代码行数:9,代码来源:RedisEventStore.php

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

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

示例13: store

 /**
  * @param object $entidad
  * @param string $contenido
  */
 public function store($entidad, $contenido)
 {
     if (!method_exists($entidad, 'getDetalles')) {
         throw new HttpException(400, "No el objeto no tiene detalles serializables");
     }
     $observacion = new Observacion();
     $observacion->setContenido($contenido);
     $observacion->setRelated($entidad->getId());
     $observacion->setLastState($this->serializer->serialize($entidad->getDetalles(), 'json'));
     $this->manager->persist($observacion);
 }
开发者ID:bixlabs,项目名称:concepto-sises,代码行数:15,代码来源:ObservacionHandler.php

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

示例15: onKernelView

 /**
  * @param GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $result = $event->getControllerResult();
     if ($result instanceof Response) {
         return $result;
     }
     $serialized = $this->serializer->serialize($result, 'json');
     $response = new Response();
     $response->setContent($serialized);
     $response->headers->add(array('Content-type' => 'application/json'));
     $event->setResponse($response);
 }
开发者ID:abdulklarapl,项目名称:presentation-orm,代码行数:15,代码来源:ViewListener.php


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