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