本文整理汇总了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);
}
}
示例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());
}
示例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());
}
示例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;
}
示例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;
}
示例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'));
}
示例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());
//т.к. приемник - ифрейм, это эмуляция аякса(иначе поломается)
}
示例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;
}
示例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;
}
示例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'));
}
}
示例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);
}
示例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());
}
示例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;
}
示例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;
}
示例15: testJsonEncodeFlags
public function testJsonEncodeFlags()
{
$response = new JsonResponse('<>\'&"');
$this->assertEquals('"\\u003C\\u003E\\u0027\\u0026\\u0022"', $response->getContent());
}