當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。