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