本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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)));
}
示例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;
}
示例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;
}
示例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);
}
示例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]);
}
示例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)));
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}