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


PHP Serializer\SerializationContext类代码示例

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


在下文中一共展示了SerializationContext类的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: serializeEmbeddeds

 /**
  * {@inheritdoc}
  */
 public function serializeEmbeddeds(array $embeddeds, XmlSerializationVisitor $visitor, SerializationContext $context)
 {
     foreach ($embeddeds as $embedded) {
         if ($embedded->getData() instanceof \Traversable || is_array($embedded->getData())) {
             foreach ($embedded->getData() as $data) {
                 $entryNode = $visitor->getDocument()->createElement('resource');
                 $visitor->getCurrentNode()->appendChild($entryNode);
                 $visitor->setCurrentNode($entryNode);
                 $visitor->getCurrentNode()->setAttribute('rel', $embedded->getRel());
                 if (null !== ($node = $context->accept($data))) {
                     $visitor->getCurrentNode()->appendChild($node);
                 }
                 $visitor->revertCurrentNode();
             }
             continue;
         }
         $entryNode = $visitor->getDocument()->createElement('resource');
         $visitor->getCurrentNode()->appendChild($entryNode);
         $visitor->setCurrentNode($entryNode);
         $visitor->getCurrentNode()->setAttribute('rel', $embedded->getRel());
         if (null !== ($node = $context->accept($embedded->getData()))) {
             $visitor->getCurrentNode()->appendChild($node);
         }
         $visitor->revertCurrentNode();
     }
 }
开发者ID:jmcclell,项目名称:Hateoas,代码行数:29,代码来源:XmlHalSerializer.php

示例3: getSerializationContext

 /**
  * @param SerializableInterface $serializable
  * @param SerializationContext  $serializationContext
  *
  * @return SerializationContext
  */
 private function getSerializationContext(SerializableInterface $serializable, SerializationContext $serializationContext)
 {
     if ($serializable instanceof OrderInterface) {
         $serializationContext->setGroups($this->groupsSpecifier->specifyGroups($serializable));
     }
     return $serializationContext;
 }
开发者ID:krzysztof-gzocha,项目名称:payu,代码行数:13,代码来源:Serializer.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: getCountryAction

 /**
  * Информация о стране по id
  *
  * @param Country $country
  *
  * @Rest\Get("countries/{id}", requirements={"id"="\d+"})
  * @ParamConverter("country", class="VifeedGeoBundle:Country")
  * @ApiDoc(
  *     section="Campaign API",
  *     requirements={
  *       {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="id страны"}
  *     },
  *     output={
  *          "class"="Vifeed\GeoBundle\Entity\Country",
  *          "groups"={"default"}
  *     },
  *     statusCodes={
  *         200="Returned when successful",
  *         403="Returned when the user is not authorized to use this method",
  *         404="Returned when campaign not found"
  *     }
  * )
  *
  * @return Response
  */
 public function getCountryAction(Country $country)
 {
     $context = new SerializationContext();
     $context->setGroups(['default']);
     $view = new View($country);
     $view->setSerializationContext($context);
     return $this->handleView($view);
 }
开发者ID:bzis,项目名称:zomba,代码行数:33,代码来源:CountryController.php

示例6: serialize

 /**
  * Serializes data to JSON, optionally filtering on a serialization group.
  *
  * @param mixed  $data
  * @param string $group
  */
 public function serialize($data, $group = null)
 {
     $context = new SerializationContext();
     if ($group) {
         $context->setGroups($group);
     }
     return $this->container->get('serializer')->serialize($data, 'json', $context);
 }
开发者ID:claroline,项目名称:distribution,代码行数:14,代码来源:SerializerExtension.php

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

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

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

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

示例11: serializeEmbedded

 /**
  * {@inheritdoc}
  */
 public function serializeEmbedded(array $embeds, JsonSerializationVisitor $visitor, SerializationContext $context)
 {
     $serializedEmbeds = array();
     foreach ($embeds as $embed) {
         $serializedEmbeds[$embed->getRel()] = $context->accept($embed->getData());
     }
     $visitor->addData('_embedded', $serializedEmbeds);
 }
开发者ID:anthonyhowell,项目名称:Hateoas,代码行数:11,代码来源:JsonHalSerializer.php

示例12: getCollectionCategoryAction

 /**
  * @Route("/collection/category/{id}", methods={"GET"}, requirements={"id"="^[0-9].*$"})
  * @param CollectionCategory $collectionCategory
  * @return CollectionCategory
  */
 public function getCollectionCategoryAction(CollectionCategory $collectionCategory)
 {
     $serializer = $this->get("jms_serializer");
     $context = new SerializationContext();
     $context->enableMaxDepthChecks();
     $response = new Response($serializer->serialize($collectionCategory, 'json', $context));
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }
开发者ID:samisalami,项目名称:xenobladex-org,代码行数:14,代码来源:CollectionCategoryController.php

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

示例14: allCardLearningAction

 /**
  * @EXT\Route(
  *     "/card_learning/all/deck/{deck}",
  *     name="claroline_getall_card_learning"
  * )
  *
  * @param Deck $deck
  *
  * @return JsonResponse
  */
 public function allCardLearningAction(Deck $deck)
 {
     $this->assertCanOpen($deck);
     $user = $this->tokenStorage->getToken()->getUser();
     $cardLearnings = $this->manager->allCardLearning($deck, $user);
     $context = new SerializationContext();
     $context->setGroups('api_flashcard_card');
     return new JsonResponse(json_decode($this->serializer->serialize($cardLearnings, 'json', $context)));
 }
开发者ID:claroline,项目名称:distribution,代码行数:19,代码来源:CardLearningController.php

示例15: getUserAction

 /**
  * Информация о юзере
  *
  * @ApiDoc(
  *     section="User API",
  *     output={
  *          "class"="Vifeed\UserBundle\Entity\User",
  *          "groups"={"user"}
  *     },
  *     statusCodes={
  *         200="Returned when successful",
  *         403="Returned when the user is not authorized to use this method"
  *     }
  * )
  *
  * @Rest\Get("users/current")
  *
  * @return Response
  */
 public function getUserAction()
 {
     $user = $this->getUser();
     $context = new SerializationContext();
     $context->setGroups(array('user'));
     $view = new View($user);
     $view->setSerializationContext($context);
     return $this->handleView($view);
 }
开发者ID:bzis,项目名称:zomba,代码行数:28,代码来源:UserController.php


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