当前位置: 首页>>代码示例>>PHP>>正文


PHP JsonResponse::getContent方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\JsonResponse::getContent方法的典型用法代码示例。如果您正苦于以下问题:PHP JsonResponse::getContent方法的具体用法?PHP JsonResponse::getContent怎么用?PHP JsonResponse::getContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\JsonResponse的用法示例。


在下文中一共展示了JsonResponse::getContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: doKernelResponse

 protected function doKernelResponse(Request $request, Response $response)
 {
     if (!$response instanceof DataResponse) {
         return;
     }
     $routeName = $request->attributes->get('_route');
     $route = $this->routes->get($routeName);
     if (!$route) {
         return;
     }
     $acceptedFormat = $route->getOption(RouteOptions::ACCEPTED_FORMAT);
     if (!$acceptedFormat) {
         $response->setContent('');
         $response->setStatusCode(406);
     }
     if ($this->encoder->supportsEncoding($acceptedFormat) && $acceptedFormat === 'json') {
         $contentType = $request->getMimeType($acceptedFormat);
         $jsonResponse = new JsonResponse($response->getContent());
         $response->setContent($jsonResponse->getContent());
         $response->headers->set('Content-Type', $contentType);
     } elseif ($this->encoder->supportsEncoding($acceptedFormat)) {
         $contentType = $request->getMimeType($acceptedFormat);
         $content = $this->encoder->encode($response->getContent(), $acceptedFormat);
         $response->setContent($content);
         $response->headers->set('Content-Type', $contentType);
     }
 }
开发者ID:bcen,项目名称:silex-dispatcher,代码行数:27,代码来源:Serializer.php

示例2: JsonResponse

 /**
  * @param string $content
  * @param int $status
  * @param array $headers
  * @return Response
  */
 function response_json($content, $status = Response::HTTP_OK, array $headers = [])
 {
     // We have to do a little trick and do not allow WHMCS to sent all it's content.
     $response = new JsonResponse($content, $status, $headers);
     $response->sendHeaders();
     die($response->getContent());
 }
开发者ID:4ernovm,项目名称:whmcs-foundation,代码行数:13,代码来源:helper_functions.php

示例3: testConstructorWithSimpleTypes

 public function testConstructorWithSimpleTypes()
 {
     $response = new JsonResponse('foo');
     $this->assertSame('"foo"', $response->getContent());
     $response = new JsonResponse(0);
     $this->assertSame('0', $response->getContent());
     $response = new JsonResponse(0.1);
     $this->assertSame('0.1', $response->getContent());
     $response = new JsonResponse(true);
     $this->assertSame('true', $response->getContent());
 }
开发者ID:rouffj,项目名称:symfony,代码行数:11,代码来源:JsonResponseTest.php

示例4: getJsonResponse

 /**
  * @param Request $request
  * @param mixed   $data
  *
  * @return JsonResponse
  */
 protected function getJsonResponse(Request $request, $data = null)
 {
     $date = new \DateTime();
     $date->modify('+1 day');
     $response = new JsonResponse($data);
     $response->setExpires($date);
     $response->setETag(md5($response->getContent()));
     $response->setPublic();
     $response->isNotModified($request);
     $response->headers->set('X-Proudly-Crafted-By', "LesPolypodes.com");
     // It's nerdy, I know that.
     return $response;
 }
开发者ID:philippgerard,项目名称:GoogleDrive-based-DMS,代码行数:19,代码来源:ApiController.php

示例5: getListAction

 public function getListAction(Application $app)
 {
     $userList = $this->repository->findAll();
     $date = new \DateTime();
     $date->modify('+' . self::MAX_AGE . ' seconds');
     $response = new JsonResponse($userList, JsonResponse::HTTP_OK);
     $responseHash = sha1($response->getContent());
     $response->setMaxAge(self::MAX_AGE);
     $response->setSharedMaxAge(self::MAX_AGE);
     $response->setExpires($date);
     $response->setETag($responseHash);
     $response->isNotModified($app['request']);
     return $response;
 }
开发者ID:tecnom1k3,项目名称:insta-api,代码行数:14,代码来源:User.php

示例6: testFailedPostUserRegistrationAction

 public function testFailedPostUserRegistrationAction()
 {
     $this->configHandler->shouldReceive('getParameter')->with('allow_self_registration')->once()->andReturn(true);
     $bag = $this->getUserParameterBag();
     $this->request->request = $bag;
     $error = $this->mock('Symfony\\Component\\Validator\\ConstraintViolation');
     $error->shouldReceive('getPropertyPath')->once()->andReturn('username');
     $error->shouldReceive('getMessage')->once()->andReturn('message');
     $errorList = array($error);
     $this->validator->shouldReceive('validate')->once()->with(m::on(function (User $user) {
         return $user->getPlainPassword() === 'password' && $user->getUsername() === 'username' && $user->getFirstName() === 'firstname' && $user->getLastName() === 'lastname' && $user->getMail() === 'mail@mail.com';
     }))->andReturn($errorList);
     $response = new JsonResponse(array(array('property' => 'username', 'message' => 'message')), 422);
     $this->assertEquals($response->getContent(), $this->controller->postUserRegistrationAction('json')->getContent());
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\JsonResponse', $this->controller->postUserRegistrationAction('json'));
 }
开发者ID:ngydat,项目名称:CoreBundle,代码行数:16,代码来源:RegistrationControllerTest.php

示例7: uploadImage

 protected function uploadImage(Request $request, $user_type, $action)
 {
     $upl = $this->get('image_uploader');
     $upl->setPicDir($this->container->getParameter('picture_dir'));
     $r = ['ok' => false];
     try {
         $ret = $upl->upload($request, $user_type, $action);
         $r['ok'] = true;
         $r['id'] = $ret['id'];
         $r['src'] = $ret['uri'];
         unset($r['errors']);
     } catch (\Exception $e) {
         $r['errors'] = $e->getMessage();
     }
     $response = new JsonResponse($r);
     return new Response($response->getContent());
     //т.к. приемник - ифрейм, это эмуляция аякса(иначе поломается)
 }
开发者ID:nxnx,项目名称:donatservice,代码行数:18,代码来源:DefaultController.php

示例8: undeleteAction

 /**
  * Undeletes the entity
  *
  * @param int $objectId
  *
  * @return JsonResponse
  */
 public function undeleteAction($objectId)
 {
     $session = $this->factory->getSession();
     $formId = $this->request->query->get('formId');
     $fields = $session->get('mautic.form.' . $formId . '.fields.modified', array());
     $delete = $session->get('mautic.form.' . $formId . '.fields.deleted', array());
     //ajax only for form fields
     if (!$this->request->isXmlHttpRequest() || !$this->factory->getSecurity()->isGranted(array('form:forms:editown', 'form:forms:editother', 'form:forms:create'), 'MATCH_ONE')) {
         return $this->accessDenied();
     }
     $formField = array_key_exists($objectId, $fields) ? $fields[$objectId] : null;
     if ($this->request->getMethod() == 'POST' && $formField !== null) {
         //set custom params from event if applicable
         $customParams = !empty($formField['isCustom']) ? $formField['customParameters'] : array();
         //add the field to the delete list
         if (in_array($objectId, $delete)) {
             $key = array_search($objectId, $delete);
             unset($delete[$key]);
             $session->set('mautic.form.' . $formId . '.fields.deleted', $delete);
         }
         if (!empty($customParams)) {
             $template = $customParams['template'];
         } else {
             $template = 'MauticFormBundle:Field:' . $formField['type'] . '.html.php';
         }
         //prevent undefined errors
         $entity = new Field();
         $blank = $entity->convertToArray();
         $formField = array_merge($blank, $formField);
         $dataArray = array('mauticContent' => 'formField', 'success' => 1, 'target' => '#mauticform_' . $objectId, 'route' => false, 'fieldId' => $objectId, 'fieldHtml' => $this->renderView($template, array('inForm' => true, 'field' => $formField, 'id' => $objectId, 'deleted' => false, 'formId' => $formId)));
     } else {
         $dataArray = array('success' => 0);
     }
     $response = new JsonResponse($dataArray);
     $response->headers->set('Content-Length', strlen($response->getContent()));
     return $response;
 }
开发者ID:smotalima,项目名称:mautic,代码行数:44,代码来源:FieldController.php

示例9: deleteAction

 /**
  * Deletes the entity
  *
  * @param         $objectId
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function deleteAction($leadId, $objectId)
 {
     $lead = $this->checkLeadAccess($leadId, 'view');
     if ($lead instanceof Response) {
         return $lead;
     }
     $model = $this->factory->getModel('lead.note');
     $note = $model->getEntity($objectId);
     if ($note === null || !$this->factory->getSecurity()->hasEntityAccess('lead:leads:editown', 'lead:leads:editother', $lead->getOwner()) || $model->isLocked($note) || $this->request->getMethod() != 'POST') {
         return $this->accessDenied();
     }
     $model->deleteEntity($note);
     $response = new JsonResponse(array('deleteId' => $objectId, 'mauticContent' => 'leadNote', 'downNoteCount' => 1));
     $response->headers->set('Content-Length', strlen($response->getContent()));
     return $response;
 }
开发者ID:Jandersolutions,项目名称:mautic,代码行数:23,代码来源:NoteController.php

示例10: editAction

 public function editAction($objectId)
 {
     $session = $this->factory->getSession();
     $type = $this->request->get('type', $session->get('ddi.lead_actions.task.form.type', ''));
     $session->set('ddi.lead_actions.task.form.type', $type);
     $model = $this->factory->getModel('plugin.customCrm.task');
     $task = $model->getEntity($objectId);
     $action = $this->generateUrl('mautic_task_action', array('objectAction' => 'edit', 'objectId' => $objectId));
     $form = $model->createForm($task, $this->get('form.factory'), $action);
     $valid = false;
     $closeModal = false;
     if ($this->request->getMethod() == 'POST') {
         if (!($cancelled = $this->isFormCancelled($form))) {
             if ($valid = $this->isFormValid($form)) {
                 $closeModal = true;
                 // Save task
                 $em = $this->getDoctrine()->getManager();
                 $em->flush();
             }
         } else {
             $closeModal = true;
         }
     }
     if ($closeModal) {
         $passthroughVars = array('closeModal' => 1, 'mauticContent' => 'task');
         if ($valid && !$cancelled) {
             $passthroughVars['upTaskCount'] = 0;
             $passthroughVars['html'] = $this->renderView('CustomCrmBundle:Task:task.html.php', array('task' => $task));
             $passthroughVars['taskId'] = $task->getId();
         }
         if ($type) {
             $response = new JsonResponse($passthroughVars);
             $response->headers->set('Content-Length', strlen($response->getContent()));
             return $response;
         } else {
             $page = $this->factory->getSession()->get('mautic.task.page', 1);
             $returnUrl = $this->generateUrl('ddi_lead_actions_task_index', array('page' => $page));
             return $this->postActionRedirect(array('returnUrl' => $returnUrl, 'viewParameters' => array('page' => $page), 'contentTemplate' => 'CustomCrmBundle:Task:index', 'passthroughVars' => $passthroughVars));
         }
     } else {
         return $this->delegateView(array('viewParameters' => array('form' => $form->createView()), 'contentTemplate' => 'CustomCrmBundle:Task:form.html.php'));
     }
 }
开发者ID:joelmartins,项目名称:Mautic_CRM,代码行数:43,代码来源:TaskController.php

示例11: deleteAction

 public function deleteAction($objectId)
 {
     $page = $this->factory->getSession()->get('customcrm.opportunity.page', 1);
     $returnUrl = $this->generateUrl('mautic_customcrm_opportunity_index', array('page' => $page));
     $postActionVars = array('returnUrl' => $returnUrl, 'viewParameters' => array('page' => $page), 'contentTemplate' => 'CustomCrmBundle:Opportunity:index', 'passthroughVars' => array('activeLink' => '#mautic_customcrm_opportunity_index', 'mauticContent' => 'opportunity'));
     if ($this->request->getMethod() == 'POST') {
         /** @var \MauticPlugin\CustomCrmBundle\Model\OpportunityModel $model */
         $model = $this->factory->getModel('plugin.customCrm.opportunity');
         $entity = $model->getEntity($objectId);
         if ($entity === null) {
             $this->addFlash('mautic.customcrm.opportunity.error.notfound', array('%id%' => $objectId), 'error');
         }
         $model->deleteEntity($entity);
         $this->addFlash('mautic.core.notice.deleted', array('%name%' => 'Opportunity #' . $objectId), 'notice');
     }
     //else don't do anything
     if ($this->request->get('qf', false)) {
         $passthroughVars = array('closeModal' => 1, 'mauticContent' => 'opportunity', 'upOpportunityCount' => -1);
         $passthroughVars['opportunityId'] = $objectId;
         $passthroughVars['deleted'] = 1;
         $passthroughVars['flashes'] = $this->getFlashContent();
         $response = new JsonResponse($passthroughVars);
         $response->headers->set('Content-Length', strlen($response->getContent()));
         return $response;
     }
     return $this->postActionRedirect($postActionVars);
 }
开发者ID:joelmartins,项目名称:Mautic_CRM,代码行数:27,代码来源:OpportunityController.php

示例12: testSetEncodingOptions

 public function testSetEncodingOptions()
 {
     $response = new JsonResponse();
     $response->setData(array(array(1, 2, 3)));
     $this->assertEquals('[[1,2,3]]', $response->getContent());
     $response->setEncodingOptions(JSON_FORCE_OBJECT);
     $this->assertEquals('{"0":{"0":1,"1":2,"2":3}}', $response->getContent());
 }
开发者ID:sapwoo,项目名称:portfolio,代码行数:8,代码来源:JsonResponseTest.php

示例13: undeleteAction

 /**
  * Undeletes the entity
  *
  * @param         $objectId
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function undeleteAction($objectId)
 {
     $campaignId = $this->request->query->get('campaignId');
     $session = $this->factory->getSession();
     $modifiedEvents = $session->get('mautic.campaign.' . $campaignId . '.events.modified', array());
     $deletedEvents = $session->get('mautic.campaign.' . $campaignId . '.events.deleted', array());
     //ajax only for form fields
     if (!$this->request->isXmlHttpRequest() || !$this->factory->getSecurity()->isGranted(array('campaign:campaigns:edit', 'campaign:campaigns:create'), 'MATCH_ONE')) {
         return $this->accessDenied();
     }
     $event = array_key_exists($objectId, $modifiedEvents) ? $modifiedEvents[$objectId] : null;
     if ($this->request->getMethod() == 'POST' && $event !== null) {
         $events = $this->factory->getModel('campaign')->getEvents();
         $event['settings'] = $events[$event['eventType']][$event['type']];
         //add the field to the delete list
         if (in_array($objectId, $deletedEvents)) {
             $key = array_search($objectId, $deletedEvents);
             unset($deletedEvents[$key]);
             $session->set('mautic.campaign.' . $campaignId . '.events.deleted', $deletedEvents);
         }
         $template = empty($event['settings']['template']) ? 'MauticCampaignBundle:Event:generic.html.php' : $event['settings']['template'];
         //prevent undefined errors
         $entity = new Event();
         $blank = $entity->convertToArray();
         $event = array_merge($blank, $event);
         $dataArray = array('mauticContent' => 'campaignEvent', 'success' => 1, 'route' => false, 'eventId' => $objectId, 'eventHtml' => $this->renderView($template, array('event' => $event, 'id' => $objectId, 'campaignId' => $campaignId)));
     } else {
         $dataArray = array('success' => 0);
     }
     $response = new JsonResponse($dataArray);
     $response->headers->set('Content-Length', strlen($response->getContent()));
     return $response;
 }
开发者ID:kasobus,项目名称:EDENS-Mautic,代码行数:40,代码来源:EventController.php

示例14: postProcessing

 /**
  * Some post processing on the generated result. Replacing some variables.
  *
  * @param JsonResponse $response
  * @return JsonResponse
  */
 private function postProcessing(JsonResponse $response)
 {
     $apiUrl = $this->getServiceContainer()->getPreferenceLoader()->getSystemPreferences()->getApiUrl();
     $response->setContent(str_replace('%apiurl%', $apiUrl, $response->getContent()));
     return $response;
 }
开发者ID:keeko,项目名称:api-app,代码行数:12,代码来源:ApiApplication.php

示例15: testJsonEncodeFlags

 public function testJsonEncodeFlags()
 {
     $response = new JsonResponse('<>\'&"');
     $this->assertEquals('"\\u003C\\u003E\\u0027\\u0026\\u0022"', $response->getContent());
 }
开发者ID:Werelds,项目名称:FrameworkBenchmarks,代码行数:5,代码来源:JsonResponseTest.php


注:本文中的Symfony\Component\HttpFoundation\JsonResponse::getContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。