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