本文整理汇总了PHP中JMS\Serializer\SerializationContext类的典型用法代码示例。如果您正苦于以下问题:PHP SerializationContext类的具体用法?PHP SerializationContext怎么用?PHP SerializationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SerializationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param Serializer $serializer
* @param SqsClient $sqsClient
*/
public function __construct(Serializer $serializer, SqsClient $sqsClient)
{
$this->serializer = $serializer;
$this->sqsClient = $sqsClient;
$this->serializationContext = new SerializationContext();
$this->serializationContext->setSerializeNull(true);
}
示例2: serializeEmbeddeds
/**
* {@inheritdoc}
*/
public function serializeEmbeddeds(array $embeddeds, XmlSerializationVisitor $visitor, SerializationContext $context)
{
foreach ($embeddeds as $embedded) {
if ($embedded->getData() instanceof \Traversable || is_array($embedded->getData())) {
foreach ($embedded->getData() as $data) {
$entryNode = $visitor->getDocument()->createElement('resource');
$visitor->getCurrentNode()->appendChild($entryNode);
$visitor->setCurrentNode($entryNode);
$visitor->getCurrentNode()->setAttribute('rel', $embedded->getRel());
if (null !== ($node = $context->accept($data))) {
$visitor->getCurrentNode()->appendChild($node);
}
$visitor->revertCurrentNode();
}
continue;
}
$entryNode = $visitor->getDocument()->createElement('resource');
$visitor->getCurrentNode()->appendChild($entryNode);
$visitor->setCurrentNode($entryNode);
$visitor->getCurrentNode()->setAttribute('rel', $embedded->getRel());
if (null !== ($node = $context->accept($embedded->getData()))) {
$visitor->getCurrentNode()->appendChild($node);
}
$visitor->revertCurrentNode();
}
}
示例3: 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;
}
示例4: serializeResponse
/**
* @param GetResponseForControllerResultEvent $event
*/
public function serializeResponse(GetResponseForControllerResultEvent $event)
{
if ($this->doSerialize) {
$data = $event->getControllerResult();
$apiResponse = new ApiResponse(200, $data);
$data = array_merge($apiResponse->toArray(), $this->data->all());
$data = array_filter($data);
if (!isset($data['data'])) {
$data['data'] = [];
}
$context = new SerializationContext();
$context->setSerializeNull(true);
if (method_exists($context, 'enableMaxDepthChecks')) {
$context->enableMaxDepthChecks();
}
if ($action = $this->getAction($event)) {
$context->setGroups($action->getSerializationGroups());
}
if ($fields = $event->getRequest()->query->get('fields')) {
$context->addExclusionStrategy(new FieldsListExclusionStrategy($fields));
}
$json = $this->serializer->serialize($data, 'json', $context);
$response = new Response($json, 200, ['Content-Type' => 'application/json']);
$event->setResponse($response);
$event->stopPropagation();
}
}
示例5: 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);
}
示例6: 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);
}
示例7: 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);
}
示例8: serializeObject
protected function serializeObject($object)
{
$serializer = SerializerBuilder::create()->build();
$serializationContext = new SerializationContext();
$serializationContext->setSerializeNull(true);
$objectJson = $serializer->serialize($object, 'json', $serializationContext);
return json_decode($objectJson);
}
示例9: __construct
/**
* @param SerializerInterface $serializer
*/
public function __construct(SerializerInterface $serializer = null)
{
$this->serializer = $serializer ?: SerializerBuilder::create()->build();
$this->serializationContext = new SerializationContext();
$this->serializationContext->setSerializeNull(true);
$this->deserializationContext = new DeserializationContext();
$this->deserializationContext->setSerializeNull(true);
}
示例10: jsonResponse
protected function jsonResponse($data)
{
$context = new SerializationContext();
$context->setSerializeNull(true);
$content = $this->serializer->serialize($data, 'json', $context);
$this->response->setContent($content);
return $this->response;
}
示例11: serializeEmbedded
/**
* {@inheritdoc}
*/
public function serializeEmbedded(array $embeds, JsonSerializationVisitor $visitor, SerializationContext $context)
{
$serializedEmbeds = array();
foreach ($embeds as $embed) {
$serializedEmbeds[$embed->getRel()] = $context->accept($embed->getData());
}
$visitor->addData('_embedded', $serializedEmbeds);
}
示例12: 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;
}
示例13: setData
/**
* {@inheritdoc}
*/
public function setData($data = array())
{
$this->originalData = $data;
$context = new SerializationContext();
$context->setSerializeNull(true);
$serializer = SerializerBuilder::create()->build();
$this->data = $serializer->serialize($data, 'json', $context);
return $this->update();
}
示例14: 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)));
}
示例15: 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);
}