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


PHP SerializationContext::setGroups方法代码示例

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


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

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

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

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

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

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

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

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

示例8: create

 public static function create($data = null, $statusCode = null, array $headers = array(), array $groups = array())
 {
     $view = parent::create($data, $statusCode, $headers);
     if ($groups) {
         $context = new SerializationContext();
         $context->setGroups($groups);
         $view->setSerializationContext($context);
     }
     return $view;
 }
开发者ID:jmclean,项目名称:InfiniteApiSupportBundle,代码行数:10,代码来源:View.php

示例9: getCitiesByCountryAction

 /**
  * Список городов по стране
  *
  * @param Country $country
  *
  * @Rest\Get("/countries/{id}/cities", requirements={"id"="\d+"})
  * @ParamConverter("country", class="VifeedGeoBundle:Country")
  * @ApiDoc(
  *     section="Geo API",
  *     resource=true,
  *     requirements={
  *       {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="id страны"}
  *     },
  *     output={
  *          "class"="Vifeed\GeoBundle\Entity\City",
  *          "groups"={"default"}
  *     },
  *     statusCodes={
  *         200="Returned when successful",
  *         403="Returned when the user is not authorized to use this method",
  *         404="Returned when country not found"
  *     }
  * )
  *
  * @return Response
  */
 public function getCitiesByCountryAction(Country $country)
 {
     /** @var City[] $data */
     $data = $this->getDoctrine()->getRepository('VifeedGeoBundle:City')->findBy(['country' => $country]);
     $context = new SerializationContext();
     $context->setGroups(['default']);
     $view = new View($data);
     $view->setSerializationContext($context);
     return $this->handleView($view);
 }
开发者ID:bzis,项目名称:zomba,代码行数:36,代码来源:CityController.php

示例10: SerializationContext

 function it_should_thow_exception_on_invalid_serialization_group()
 {
     $subject = ['data' => ['username' => 'drymek'], 'statusCode' => Codes::HTTP_OK, 'serializationGroups' => ['user_profile'], 'headers' => ['cache-control' => ['no-cache'], 'date' => ["@string@.isDateTime()"]]];
     $arguments = [$subject];
     $view = View::create($subject['data'], $subject['statusCode'], []);
     $context = new SerializationContext();
     $context->setGroups(['other']);
     $view->setSerializationContext($context);
     $this->shouldThrow(new FailureException('Expected serialization group to be user_profile, but they are not'))->during('positiveMatch', ['', $view, $arguments]);
 }
开发者ID:codifico,项目名称:phpspec-rest-view-extension,代码行数:10,代码来源:RestViewMatcherSpec.php

示例11: createSessionAction

 /**
  * @EXT\Route(
  *     "/session/create/deck/{deck}",
  *     name="claroline_create_session"
  * )
  *
  * @param Deck $deck
  *
  * @return JsonResponse
  */
 public function createSessionAction(Deck $deck)
 {
     $this->assertCanOpen($deck);
     $user = $this->tokenStorage->getToken()->getUser();
     $session = new Session();
     $session->setDeck($deck);
     $session->setUser($user);
     $session = $this->manager->save($session);
     $context = new SerializationContext();
     $context->setGroups('api_flashcard_session');
     return new JsonResponse(json_decode($this->serializer->serialize($session, 'json', $context)));
 }
开发者ID:claroline,项目名称:distribution,代码行数:22,代码来源:SessionController.php

示例12: postCustomersAction

 /**
  */
 public function postCustomersAction()
 {
     try {
         $customer = $this->customerService->createCustomer($this->request);
     } catch (FormValidationException $e) {
         return View::create($e->getForm(), 400);
     }
     $view = View::create($customer, 201)->setHeader('Location', $this->router->generate('get_customer', ['id' => $customer->getId()], true));
     $context = new SerializationContext();
     $context->setGroups(array('customer_list'));
     $view->setSerializationContext($context);
     return $view;
 }
开发者ID:mkrusteva,项目名称:test,代码行数:15,代码来源:CustomersController.php

示例13: postAccountsAction

 /**
  * Create new account
  */
 public function postAccountsAction()
 {
     try {
         $account = $this->accountService->createAccount($this->request);
     } catch (FormValidationException $e) {
         return View::create($e->getForm(), 400);
     }
     $view = View::create($account, 201)->setHeader('Location', $this->router->generate('get_account', ['id' => $account->getId()], true));
     $context = new SerializationContext();
     $context->setGroups(array('account_list'));
     $view->setSerializationContext($context);
     return $view;
 }
开发者ID:mkrusteva,项目名称:test,代码行数:16,代码来源:AccountsController.php

示例14: serializerAction

 public function serializerAction()
 {
     $article = new Article();
     $article->setPath('/foo');
     $article->setTitle('Example use of the default handlers');
     $article->setBody("Read up on JMSSerializerBundle to see how what other handlers exist ");
     $view = new View();
     $view->setData($article);
     $context = new SerializationContext();
     $context->setVersion('2.1');
     $context->setGroups(array('data'));
     $view->setSerializationContext($context);
     return $this->viewHandler->handle($view);
 }
开发者ID:nashidgit,项目名称:LiipHelloBundle,代码行数:14,代码来源:HelloController.php

示例15: getUserAction

 /**
  * @ApiDoc
  *
  * @param integer $objectId            
  * @throws NotFoundHttpException
  */
 public function getUserAction($userId = 0)
 {
     /* @var $model \App\ModuleObjectsBundle\Model\MapObjectModel */
     $model = $this->container->get('app_module_user.model.user');
     $data = $model->findOneById($userId);
     if (null === $data) {
         throw new NotFoundHttpException();
     }
     $view = new View();
     $view->setData($data);
     $context = new SerializationContext();
     $context->setGroups(array('.all', 'user.get'));
     $view->setSerializationContext($context);
     return $this->viewHandler->handle($view);
 }
开发者ID:amin1984,项目名称:Behat,代码行数:21,代码来源:UsersController.php


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