本文整理汇总了PHP中JMS\Serializer\SerializationContext::enableMaxDepthChecks方法的典型用法代码示例。如果您正苦于以下问题:PHP SerializationContext::enableMaxDepthChecks方法的具体用法?PHP SerializationContext::enableMaxDepthChecks怎么用?PHP SerializationContext::enableMaxDepthChecks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JMS\Serializer\SerializationContext
的用法示例。
在下文中一共展示了SerializationContext::enableMaxDepthChecks方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Render the view into a string and return for output
*
* @param mixed $input
* @return string
* @throws \Exception
*/
public function render($input = null)
{
$context = new SerializationContext();
$context->setSerializeNull(true);
$context->enableMaxDepthChecks();
FrontController::getInstance()->getResponse()->headers->set('Content-Type', 'application/json');
return $this->serializer->serialize($input, $this->format, $context);
}
示例2: getMonsterAction
/**
* @Route("/monster/{id}", methods={"GET"}, requirements={"id"="^[0-9].*$"})
* @param Monster $monster
* @return Monster
*/
public function getMonsterAction(Monster $monster)
{
$serializer = $this->get("jms_serializer");
$context = new SerializationContext();
$context->enableMaxDepthChecks();
$response = new Response($serializer->serialize($monster, 'json', $context));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
示例3: getCollectionCategoryAction
/**
* @Route("/collection/category/{id}", methods={"GET"}, requirements={"id"="^[0-9].*$"})
* @param CollectionCategory $collectionCategory
* @return CollectionCategory
*/
public function getCollectionCategoryAction(CollectionCategory $collectionCategory)
{
$serializer = $this->get("jms_serializer");
$context = new SerializationContext();
$context->enableMaxDepthChecks();
$response = new Response($serializer->serialize($collectionCategory, 'json', $context));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
示例4: buildMultiObjectResponse
/**
* @param PaginationInterface $pagination
* @param Request $request
* @param Router $router
* @param array $serializationGroups
*
* @return mixed
*/
public function buildMultiObjectResponse(PaginationInterface $pagination, Request $request, Router $router, array $serializationGroups = array())
{
if (empty($pagination->getItems())) {
return $this->handle(View::create(null, Response::HTTP_NO_CONTENT));
}
$paginationData = $pagination->getPaginationData();
$link = $this->buildPaginationLink($paginationData, $request, $router);
$headers = [];
if (!empty($link)) {
$headers['Link'] = $link;
}
if (isset($paginationData['totalCount'])) {
$headers['X-Total-Count'] = $paginationData['totalCount'];
}
$view = View::create($pagination->getItems(), Response::HTTP_OK, $headers);
$context = new SerializationContext();
$context->setSerializeNull(true);
$context->enableMaxDepthChecks();
if (!empty($serializationGroups)) {
$context->setGroups($serializationGroups);
}
$view->setSerializationContext($context);
return $this->handle($view);
}
示例5: createSerializationContext
/**
* Create serialization context with settings taken from the controller's annotation
*
* @param MappingInterface $mapping
* @return SerializationContext
*/
protected function createSerializationContext(MappingInterface $mapping)
{
$context = new SerializationContext();
if ($mapping->getAnnotation()->getSerializerEnableMaxDepthChecks()) {
$context->enableMaxDepthChecks();
}
if ($mapping->getAnnotation()->getSerializerGroups()) {
$context->setGroups($mapping->getAnnotation()->getSerializerGroups());
}
if ($mapping->getAnnotation()->getSerializerSerializeNull()) {
$context->setSerializeNull(true);
}
return $context;
}
示例6: formatItem
/**
* Serializes an object.
*
* Implements FormatterInterface::formatItem($item)
*
* @param mixed $item
*
* @return array
*/
public function formatItem($item, $format = 'json')
{
$formatted = null;
switch ($format) {
case 'json':
// serialize properties with null values
$context = new SerializationContext();
$context->setSerializeNull(true);
$context->enableMaxDepthChecks(true);
$formatted = $this->getSerializer()->serialize($item, 'json', $context);
break;
case 'jsonp':
$callback = $this->getRequest()->query->get('jsonp.callback', 'JSONP.callback');
// validate against XSS
$validator = new \JsonpCallbackValidator();
if (!$validator->validate($callback)) {
throw new BadRequestHttpException('Invalid JSONP callback value');
}
$context = new SerializationContext();
$context->setSerializeNull(true);
$json = $this->getSerializer()->serialize($item, 'json');
$formatted = sprintf('/**/%s(%s)', $callback, $json);
break;
default:
// any other format is not supported
throw new \InvalidArgumentException(sprintf('Format not supported: %s', $format));
}
return $formatted;
}