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


PHP SerializationContext::setSerializeNull方法代码示例

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


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

示例1: __construct

 /**
  * @param Serializer $serializer
  * @param SqsClient  $sqsClient
  */
 public function __construct(Serializer $serializer, SqsClient $sqsClient)
 {
     $this->serializer = $serializer;
     $this->sqsClient = $sqsClient;
     $this->serializationContext = new SerializationContext();
     $this->serializationContext->setSerializeNull(true);
 }
开发者ID:oriodesign,项目名称:tastd-backend-demo,代码行数:11,代码来源:QueueMessengerListener.php

示例2: __construct

 /**
  * @param SerializerInterface $serializer
  */
 public function __construct(SerializerInterface $serializer = null)
 {
     $this->serializer = $serializer ?: SerializerBuilder::create()->build();
     $this->serializationContext = new SerializationContext();
     $this->serializationContext->setSerializeNull(true);
     $this->deserializationContext = new DeserializationContext();
     $this->deserializationContext->setSerializeNull(true);
 }
开发者ID:cleentfaar,项目名称:windmill,代码行数:11,代码来源:GameSerializer.php

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

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

示例5: serializeObject

 protected function serializeObject($object)
 {
     $serializer = SerializerBuilder::create()->build();
     $serializationContext = new SerializationContext();
     $serializationContext->setSerializeNull(true);
     $objectJson = $serializer->serialize($object, 'json', $serializationContext);
     return json_decode($objectJson);
 }
开发者ID:inwicast,项目名称:claroline-plugin-bundle,代码行数:8,代码来源:Controller.php

示例6: jsonResponse

 protected function jsonResponse($data)
 {
     $context = new SerializationContext();
     $context->setSerializeNull(true);
     $content = $this->serializer->serialize($data, 'json', $context);
     $this->response->setContent($content);
     return $this->response;
 }
开发者ID:rmukras,项目名称:coffee,代码行数:8,代码来源:BaseController.php

示例7: setData

 /**
  * {@inheritdoc}
  */
 public function setData($data = array())
 {
     $this->originalData = $data;
     $context = new SerializationContext();
     $context->setSerializeNull(true);
     $serializer = SerializerBuilder::create()->build();
     $this->data = $serializer->serialize($data, 'json', $context);
     return $this->update();
 }
开发者ID:proyecto404,项目名称:UtilBundle,代码行数:12,代码来源:JsonResponse.php

示例8: createNewContext

 /**
  * Create a new serialization context
  *
  * @param array $groups [optional]
  * @return SerializationContext
  */
 protected function createNewContext(array $groups = null)
 {
     $context = new SerializationContext();
     $context->setSerializeNull($this->serializeNull);
     if (null !== $groups) {
         $context->setGroups($groups);
     }
     return $context;
 }
开发者ID:outeredge,项目名称:edge-zf2,代码行数:15,代码来源:Serializer.php

示例9: testToArrayUseProvidedSerializationContext

 public function testToArrayUseProvidedSerializationContext()
 {
     $contextFactoryMock = $this->getMockForAbstractClass('JMS\\Serializer\\ContextFactory\\SerializationContextFactoryInterface');
     $context = new SerializationContext();
     $context->setSerializeNull(true);
     $contextFactoryMock->expects($this->once())->method('createSerializationContext')->will($this->returnValue($context));
     $this->serializer->setDefaultSerializationContextFactory($contextFactoryMock);
     $result = $this->serializer->toArray(array('value' => null));
     $this->assertEquals(array('value' => null), $result);
 }
开发者ID:alcalyn,项目名称:serializer,代码行数:10,代码来源:SerializationContextFactoryTest.php

示例10: getmailAction

 public function getmailAction()
 {
     try {
         $jsonData = $this->getRequest()->getContent();
         $data = $this->serializer->deserialize($jsonData, "Application\\API\\Canonicals\\Dto\\ThirdPartyEmailTransport", "json");
         $emailRepo = $this->getServiceLocator()->get('EMailSvc');
         $emails = $emailRepo->fetchMail($data->mailapikey);
         $context = new SerializationContext();
         $context->setSerializeNull(true);
         $content = $this->serializer->serialize($emails, 'json', $context);
         $this->response->setContent($content);
         return $this->response;
     } catch (\Exception $ex) {
         error_log($ex->getMessage());
     }
     exit;
 }
开发者ID:rmukras,项目名称:ekda.org,代码行数:17,代码来源:BatchMailController.php

示例11: processForm

 public function processForm(WebsiteOptions $options, array $parameters, $method = 'PUT')
 {
     $form = $this->formFactory->create(new WebsiteOptionsType(), $options, array('method' => $method));
     $form->submit($parameters, 'PATCH' !== $method);
     if ($form->isValid()) {
         $options = $form->getData();
         $this->om->persist($options);
         $this->om->flush();
         $serializationContext = new SerializationContext();
         $serializationContext->setSerializeNull(true);
         return json_decode($this->serializer->serialize($options, 'json', $serializationContext));
     }
     /*else {
           return $this->getErrorMessages($form);
       }*/
     throw new \InvalidArgumentException();
 }
开发者ID:claroline,项目名称:distribution,代码行数:17,代码来源:WebsiteOptionsManager.php

示例12: testAbc

 public function testAbc()
 {
     $client = new Entity\Client();
     $location = new Entity\Location();
     $orders = new Collections\ArrayCollection();
     $orders->add(new Entity\Order('Order 001'));
     $orders->add(new Entity\Order('Order 002'));
     $orders->add(new Entity\Order('Order 003'));
     $session = new Entity\Session('981be8ae41ba4a148f20a04508ab1ab');
     $request = new Request\SaveOrder($session, $orders);
     $context = new SerializationContext();
     $context->setSerializeNull(true);
     $serializer = SerializerBuilder::create()->build();
     // serialize
     $xml = $serializer->serialize($request, 'xml', $context);
     //var_dump($xml);
     // deserialize
     $object = $serializer->deserialize($xml, Request\SaveOrder::class, 'xml');
     var_dump($object);
 }
开发者ID:vasildakov,项目名称:maxoptra,代码行数:20,代码来源:SaveOrderTest.php

示例13: cgetAction

 public function cgetAction(Request $request)
 {
     $adminCode = $request->get('_sonata_admin');
     if (!$adminCode) {
         throw new \RuntimeException(sprintf('There is no `_sonata_admin` defined for the controller `%s` and the current route `%s`', get_class($this), $request->get('_route')));
     }
     $admin = $this->get('sonata.admin.pool')->getAdminByAdminCode($adminCode);
     if (false === $admin->isGranted('LIST')) {
         throw new AccessDeniedException();
     }
     /** @var MenuItemRepository $menuRepository */
     $menuRepository = $this->get('doctrine.orm.entity_manager')->getRepository('GravityMenuBundle:MenuItem');
     $menus = $menuRepository->findBy(['parent' => null], null, 20, 0);
     $view = new View($menus);
     $context = new SerializationContext();
     $context->setSerializeNull(true);
     $context->setGroups(['gravity_api_read']);
     $view->setSerializationContext($context);
     return $this->get('fos_rest.view_handler')->handle($view);
 }
开发者ID:gravity-cms,项目名称:menu-bundle,代码行数:20,代码来源:MenuController.php

示例14: buildMultiObjectResponse

 /**
  * @param PaginationInterface $pagination
  * @param Request             $request
  * @param Router              $router
  * @param array               $serializationGroups
  *
  * @return mixed
  */
 public function buildMultiObjectResponse(PaginationInterface $pagination, Request $request, Router $router, array $serializationGroups = array())
 {
     if (empty($pagination->getItems())) {
         return $this->handle(View::create(null, Response::HTTP_NO_CONTENT));
     }
     $paginationData = $pagination->getPaginationData();
     $link = $this->buildPaginationLink($paginationData, $request, $router);
     $headers = [];
     if (!empty($link)) {
         $headers['Link'] = $link;
     }
     if (isset($paginationData['totalCount'])) {
         $headers['X-Total-Count'] = $paginationData['totalCount'];
     }
     $view = View::create($pagination->getItems(), Response::HTTP_OK, $headers);
     $context = new SerializationContext();
     $context->setSerializeNull(true);
     if (!empty($serializationGroups)) {
         $context->setGroups($serializationGroups);
     }
     $view->setSerializationContext($context);
     return $this->handle($view);
 }
开发者ID:jpierront,项目名称:parabola-bundle,代码行数:31,代码来源:SuccessResponseBuilder.php

示例15: createSerializationContext

 /**
  * Create serialization context with settings taken from the controller's annotation
  *
  * @param MappingInterface $mapping
  * @return SerializationContext
  */
 protected function createSerializationContext(MappingInterface $mapping)
 {
     $context = new SerializationContext();
     if ($mapping->getAnnotation()->getSerializerEnableMaxDepthChecks()) {
         $context->enableMaxDepthChecks();
     }
     if ($mapping->getAnnotation()->getSerializerGroups()) {
         $context->setGroups($mapping->getAnnotation()->getSerializerGroups());
     }
     if ($mapping->getAnnotation()->getSerializerSerializeNull()) {
         $context->setSerializeNull(true);
     }
     return $context;
 }
开发者ID:TNAJanssen,项目名称:ThruwayBundle,代码行数:20,代码来源:WampKernel.php


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