本文整理匯總了PHP中JMS\Serializer\SerializationContext::setVersion方法的典型用法代碼示例。如果您正苦於以下問題:PHP SerializationContext::setVersion方法的具體用法?PHP SerializationContext::setVersion怎麽用?PHP SerializationContext::setVersion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類JMS\Serializer\SerializationContext
的用法示例。
在下文中一共展示了SerializationContext::setVersion方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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);
}
示例2: getSerializationContext
/**
* Gets or creates a JMS\Serializer\SerializationContext and initializes it with
* the view exclusion strategies, groups & versions if a new context is created
*
* @param View $view
*
* @return SerializationContext
*/
public function getSerializationContext(View $view)
{
$context = $view->getSerializationContext();
if (null === $context) {
$context = new SerializationContext();
$groups = $this->container->getParameter('fos_rest.serializer.exclusion_strategy.groups');
if ($groups) {
$context->setGroups($groups);
}
$version = $this->container->getParameter('fos_rest.serializer.exclusion_strategy.version');
if ($version) {
$context->setVersion($version);
}
}
return $context;
}