本文整理汇总了PHP中JMS\Serializer\SerializationContext::setSerializeNull方法的典型用法代码示例。如果您正苦于以下问题:PHP SerializationContext::setSerializeNull方法的具体用法?PHP SerializationContext::setSerializeNull怎么用?PHP SerializationContext::setSerializeNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JMS\Serializer\SerializationContext
的用法示例。
在下文中一共展示了SerializationContext::setSerializeNull方法的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: __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);
}
示例3: 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();
}
}
示例4: 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);
}
示例5: 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);
}
示例6: 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;
}
示例7: 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();
}
示例8: createNewContext
/**
* Create a new serialization context
*
* @param array $groups [optional]
* @return SerializationContext
*/
protected function createNewContext(array $groups = null)
{
$context = new SerializationContext();
$context->setSerializeNull($this->serializeNull);
if (null !== $groups) {
$context->setGroups($groups);
}
return $context;
}
示例9: testToArrayUseProvidedSerializationContext
public function testToArrayUseProvidedSerializationContext()
{
$contextFactoryMock = $this->getMockForAbstractClass('JMS\\Serializer\\ContextFactory\\SerializationContextFactoryInterface');
$context = new SerializationContext();
$context->setSerializeNull(true);
$contextFactoryMock->expects($this->once())->method('createSerializationContext')->will($this->returnValue($context));
$this->serializer->setDefaultSerializationContextFactory($contextFactoryMock);
$result = $this->serializer->toArray(array('value' => null));
$this->assertEquals(array('value' => null), $result);
}
示例10: getmailAction
public function getmailAction()
{
try {
$jsonData = $this->getRequest()->getContent();
$data = $this->serializer->deserialize($jsonData, "Application\\API\\Canonicals\\Dto\\ThirdPartyEmailTransport", "json");
$emailRepo = $this->getServiceLocator()->get('EMailSvc');
$emails = $emailRepo->fetchMail($data->mailapikey);
$context = new SerializationContext();
$context->setSerializeNull(true);
$content = $this->serializer->serialize($emails, 'json', $context);
$this->response->setContent($content);
return $this->response;
} catch (\Exception $ex) {
error_log($ex->getMessage());
}
exit;
}
示例11: processForm
public function processForm(WebsiteOptions $options, array $parameters, $method = 'PUT')
{
$form = $this->formFactory->create(new WebsiteOptionsType(), $options, array('method' => $method));
$form->submit($parameters, 'PATCH' !== $method);
if ($form->isValid()) {
$options = $form->getData();
$this->om->persist($options);
$this->om->flush();
$serializationContext = new SerializationContext();
$serializationContext->setSerializeNull(true);
return json_decode($this->serializer->serialize($options, 'json', $serializationContext));
}
/*else {
return $this->getErrorMessages($form);
}*/
throw new \InvalidArgumentException();
}
示例12: testAbc
public function testAbc()
{
$client = new Entity\Client();
$location = new Entity\Location();
$orders = new Collections\ArrayCollection();
$orders->add(new Entity\Order('Order 001'));
$orders->add(new Entity\Order('Order 002'));
$orders->add(new Entity\Order('Order 003'));
$session = new Entity\Session('981be8ae41ba4a148f20a04508ab1ab');
$request = new Request\SaveOrder($session, $orders);
$context = new SerializationContext();
$context->setSerializeNull(true);
$serializer = SerializerBuilder::create()->build();
// serialize
$xml = $serializer->serialize($request, 'xml', $context);
//var_dump($xml);
// deserialize
$object = $serializer->deserialize($xml, Request\SaveOrder::class, 'xml');
var_dump($object);
}
示例13: cgetAction
public function cgetAction(Request $request)
{
$adminCode = $request->get('_sonata_admin');
if (!$adminCode) {
throw new \RuntimeException(sprintf('There is no `_sonata_admin` defined for the controller `%s` and the current route `%s`', get_class($this), $request->get('_route')));
}
$admin = $this->get('sonata.admin.pool')->getAdminByAdminCode($adminCode);
if (false === $admin->isGranted('LIST')) {
throw new AccessDeniedException();
}
/** @var MenuItemRepository $menuRepository */
$menuRepository = $this->get('doctrine.orm.entity_manager')->getRepository('GravityMenuBundle:MenuItem');
$menus = $menuRepository->findBy(['parent' => null], null, 20, 0);
$view = new View($menus);
$context = new SerializationContext();
$context->setSerializeNull(true);
$context->setGroups(['gravity_api_read']);
$view->setSerializationContext($context);
return $this->get('fos_rest.view_handler')->handle($view);
}
示例14: 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);
if (!empty($serializationGroups)) {
$context->setGroups($serializationGroups);
}
$view->setSerializationContext($context);
return $this->handle($view);
}
示例15: 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;
}