/** * @param ContextInterface $context */ private function convertContext(ContextInterface $context) { $newContext = []; foreach ($context->getAttributes() as $key => $value) { $newContext[$key] = $value; } if ($context instanceof GroupableContextInterface) { $newContext['groups'] = $context->getGroups(); } if ($context instanceof VersionableContextInterface) { $newContext['version'] = $context->getVersion(); } if ($context instanceof MaxDepthContextInterface) { $newContext['maxDepth'] = $context->getMaxDepth(); } return $newContext; }
/** * Fill a jms context. * * @param ContextInterface $context * @param JMSContext $newContext * * @return JMSContext */ private function fillContext(ContextInterface $context, JMSContext $newContext) { foreach ($context->getAttributes() as $key => $value) { $newContext->attributes->set($key, $value); } if ($context instanceof VersionableContextInterface && null !== $context->getVersion()) { $newContext->setVersion($context->getVersion()); } if ($context instanceof GroupableContextInterface) { $groups = $context->getGroups(); if (!empty($groups)) { $newContext->setGroups($context->getGroups()); } } if ($context instanceof MaxDepthContextInterface && null !== $context->getMaxDepth()) { $newContext->enableMaxDepthChecks(); } if ($context instanceof SerializeNullContextInterface && null !== $context->getSerializeNull()) { $newContext->setSerializeNull($context->getSerializeNull()); } return $newContext; }