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


PHP JsonResponse::setEncodingOptions方法代码示例

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


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

示例1: defaultAction

 /**
  * @Route("/graphql")
  *
  * @throws ConfigurationException
  *
  * @return JsonResponse
  */
 public function defaultAction()
 {
     if ($this->get('request_stack')->getCurrentRequest()->getMethod() == 'OPTIONS') {
         return $this->createEmptyResponse();
     }
     list($query, $variables) = $this->getPayload();
     $schemaClass = $this->getParameter('graphql.schema_class');
     if (!$schemaClass || !class_exists($schemaClass)) {
         return new JsonResponse([['message' => 'Schema class ' . $schemaClass . ' does not exist']], 200, $this->getParameter('graphql.response.headers'));
     }
     if (!$this->get('service_container')->initialized('graphql.schema')) {
         $schema = new $schemaClass();
         if ($schema instanceof ContainerAwareInterface) {
             $schema->setContainer($this->get('service_container'));
         }
         $this->get('service_container')->set('graphql.schema', $schema);
     }
     /** @var Processor $processor */
     $processor = $this->get('graphql.processor');
     $processor->processPayload($query, $variables);
     $response = new JsonResponse($processor->getResponseData(), 200, $this->getParameter('graphql.response.headers'));
     if ($this->getParameter('graphql.response.json_pretty')) {
         $response->setEncodingOptions($response->getEncodingOptions() | JSON_PRETTY_PRINT);
     }
     return $response;
 }
开发者ID:youshido,项目名称:graphql-bundle,代码行数:33,代码来源:GraphQLController.php

示例2: getHttpResponse

 public function getHttpResponse()
 {
     $result = $this->getResponseArray();
     $response = new JsonResponse($result);
     $response->setEncodingOptions($response->getEncodingOptions() | JSON_UNESCAPED_UNICODE);
     return $response;
 }
开发者ID:ragephp,项目名称:jsonrpc-server,代码行数:7,代码来源:JsonRpcResponse.php

示例3: renderAction

 /**
  * @param Request $request
  * @param EventIdentifier $eventIdentifier
  * @return JsonResponse
  */
 public function renderAction(Request $request, EventIdentifier $eventIdentifier)
 {
     if ($request->get('decimal')) {
         $decimal = $request->get('decimal');
     } else {
         $decimal = 0;
     }
     if ($request->get('limit')) {
         $limit = max($request->get('limit'), 2);
     } else {
         $limit = 2;
     }
     $conn = $this->container->get('database_connection');
     $sql = "SELECT value FROM `event` WHERE event_identifier_id=" . $eventIdentifier->getId() . " ORDER BY created desc limit " . $limit;
     $rows = $conn->query($sql)->fetchAll();
     $chart = new \StdClass();
     $datas = [];
     foreach ($rows as $row) {
         $datas[]['value'] = round($row['value'], $decimal);
     }
     $chart->item = $datas;
     $response = new JsonResponse($chart);
     $response->setEncodingOptions($response->getEncodingOptions() | JSON_PRETTY_PRINT);
     return $response;
 }
开发者ID:koalamon,项目名称:koalamonframeworkbundle,代码行数:30,代码来源:NumberChartController.php

示例4: createJsonReponse

 public function createJsonReponse($content)
 {
     $serializer = $this->get('jms_serializer');
     $json = $serializer->serialize($content, 'json');
     $response = new JsonResponse($json, 200);
     $response->setEncodingOptions(JSON_PRETTY_PRINT);
     return $response;
 }
开发者ID:Kafei59,项目名称:bound,代码行数:8,代码来源:AController.php

示例5: json

 /**
  * @param $data
  * @return JsonResponse
  */
 protected function json($data)
 {
     $response = new JsonResponse($data);
     if (empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
         $response->setEncodingOptions($response->getEncodingOptions() | JSON_PRETTY_PRINT);
     }
     return $response;
 }
开发者ID:sebastianhaeni,项目名称:wine-tasting,代码行数:12,代码来源:BaseController.php

示例6: renderAction

 public function renderAction(Request $request, EventIdentifier $eventIdentifier)
 {
     if ($request->get('interval')) {
         $intervalType = $request->get('interval');
     } else {
         $intervalType = 'd';
     }
     if ($request->get('decimal')) {
         $decimal = $request->get('decimal');
     } else {
         $decimal = 0;
     }
     if ($request->get('labelInterval')) {
         $labelInterval = $request->get('labelInterval');
     } else {
         $labelInterval = 1;
     }
     switch ($intervalType) {
         case 'd':
             $groupDateForm = "%Y%m%d";
             $selectDateForm = "%d.%m.%Y";
             $interval = 'P1M';
             break;
         case 'h':
             $groupDateForm = "%Y%m%d%H";
             $selectDateForm = "%h %p";
             $interval = 'P1D';
             break;
         default:
             return new JsonResponse(['status' => 'error', 'message' => 'IntervalType ' . $intervalType . ' does not exists.'], 404);
     }
     $startDate = new \DateTime('now');
     $startDate->sub(new \DateInterval($interval));
     $conn = $this->container->get('database_connection');
     $sql = "SELECT AVG(value) as avgValue, DATE_FORMAT(created, '" . $selectDateForm . "') as timespan FROM `event` WHERE event_identifier_id=" . $eventIdentifier->getId() . " and created > '" . $startDate->format('Y-m-d H:i:s') . "' GROUP BY DATE_FORMAT(created, '" . $groupDateForm . "')";
     $rows = $conn->query($sql)->fetchAll();
     $chart = new \StdClass();
     $chart->x_axis = ['labels' => []];
     $datas = [];
     $i = 0;
     foreach ($rows as $row) {
         if ($i % $labelInterval == 0) {
             $chart->x_axis['labels'][] = strtolower($row['timespan']);
         } else {
             $chart->x_axis['labels'][] = '';
         }
         $i++;
         $datas[] = round($row['avgValue'], $decimal);
     }
     $chart->series = [['data' => $datas]];
     $response = new JsonResponse($chart);
     $response->setEncodingOptions($response->getEncodingOptions() | JSON_PRETTY_PRINT);
     return $response;
 }
开发者ID:koalamon,项目名称:koalamonframeworkbundle,代码行数:54,代码来源:LineChartController.php

示例7: search

 /**
  * @param Request $request
  * @return JsonResponse
  */
 public function search(Request $request)
 {
     $keyword = $request->get('keyword');
     $searchManager = $this->get('app.service.search_manager');
     $searchManager->setSearchEngine($this->get('app.service.search_engine.kilobaitas.search'));
     $searchManager->setSearchEngine($this->get('app.service.search_engine.skytech.search'));
     $searchManager->setSearchEngine($this->get('app.service.search_engine.one_a.search'));
     $data = $searchManager->search($keyword);
     $response = new JsonResponse($data);
     $response->setEncodingOptions(JSON_PRETTY_PRINT);
     return $response;
 }
开发者ID:uikolas,项目名称:LT-eshops-search,代码行数:16,代码来源:DefaultController.php

示例8: getAction

 /**
  * Display one member identified by id in Json format.
  * 
  * @example
  * {
  *   "member": {
  *       "id": 1,
  *       "name": "Bland",
  *       "firstName": "\u00a0Angie",
  *       "phone": "0611111111"
  *     }
  * }
  * 
  * @Route("/api/members/{id}", requirements={"id" = "\d+"})
  */
 public function getAction($id)
 {
     $response = new JsonResponse();
     $response->setCharset('UTF-8');
     $response->setEncodingOptions(JSON_PRETTY_PRINT);
     try {
         $this->initialize();
         $member = $this->memberRepository->findById($id);
         if ($member == null) {
             $response->setData('Aucun adhérent ne correspond à votre demande');
             $response->setStatusCode(JsonResponse::HTTP_NOT_FOUND);
         } else {
             $response->setData($this->memberFormatter->format($member));
         }
     } catch (\Exception $e) {
         $response->setStatusCode(JsonResponse::HTTP_INTERNAL_SERVER_ERROR);
     }
     return $response;
 }
开发者ID:spiteau,项目名称:MemberRepository,代码行数:34,代码来源:MemberController.php

示例9: json

 /**
  * Convert some data into a JSON response.
  *
  * @param mixed   $data    The response data
  * @param integer $status  The response status code
  * @param array   $headers An array of response headers
  * @return JsonResponse
  * @see JsonResponse
  */
 public function json($data = [], $status = 200, array $headers = [])
 {
     $request = $this['request_stack']->getMasterRequest();
     if ($request->query->has('fields') && !($status >= 400 && $status < 500)) {
         $fields = $this['rest.fields'];
         $fields->addParameter('id');
         $data = $this['rest.filter']->filter($data);
     }
     $flags = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT;
     if ($request->query->get('pretty', true)) {
         $flags |= JSON_PRETTY_PRINT;
     }
     $response = new JsonResponse();
     $response->headers->replace($headers);
     $response->setStatusCode($status);
     $response->setEncodingOptions($flags);
     $response->setData($data);
     if ($request->query->has('callback')) {
         $response->setCallback($request->query->get('callback'));
     }
     return $response;
 }
开发者ID:mehulsbhatt,项目名称:RestServiceProvider,代码行数:31,代码来源:RestTrait.php

示例10: getConfigAction

 public function getConfigAction(Request $request)
 {
     if ($request->get('integration_key') != DefaultController::INTEGRATION_KEY) {
         return new JsonResponse('You are not allowed to call this action.');
     }
     $collections = $this->getDoctrine()->getRepository('LeanKoalaIntegrationMissingRequestBundle:Collection')->findBy([], ['name' => 'ASC']);
     $systemCollections = array();
     foreach ($collections as $collection) {
         foreach ($collection->getSystems() as $system) {
             if (!array_key_exists($system->getId(), $systemCollections)) {
                 $systemCollections[$system->getId()]['system'] = $system;
             }
             $systemCollections[$system->getId()]['options'][] = $collection;
         }
     }
     $result = [];
     foreach ($systemCollections as $collection) {
         $result[] = $collection;
     }
     $response = new JsonResponse($result);
     $response->setEncodingOptions($response->getEncodingOptions() | JSON_PRETTY_PRINT);
     return $response;
 }
开发者ID:koalamon,项目名称:leankoalaplatform,代码行数:23,代码来源:RestController.php

示例11: exportAction

 /**
  * Exports the widgets of current user into a json file
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function exportAction()
 {
     /** @var \Mautic\DashboardBundle\Model\DashboardModel $model */
     $model = $this->factory->getModel('dashboard');
     $widgetsPaginator = $model->getWidgets();
     $usersName = $this->factory->getUser()->getName();
     $dateTime = new \DateTime();
     $dateStamp = $dateTime->format('Y-m-d H:i:s');
     $name = $this->request->get('name', 'dashboard-of-' . str_replace(' ', '-', $usersName) . '-' . $dateStamp);
     $description = $this->get('translator')->trans('mautic.dashboard.generated_by', array('%name%' => $usersName, '%date%' => $dateStamp));
     $dashboard = array('name' => $name, 'description' => $description, 'widgets' => array());
     foreach ($widgetsPaginator as $widget) {
         $dashboard['widgets'][] = array('name' => $widget->getName(), 'width' => $widget->getWidth(), 'height' => $widget->getHeight(), 'ordering' => $widget->getOrdering(), 'type' => $widget->getType(), 'params' => $widget->getParams(), 'template' => $widget->getTemplate());
     }
     // Make the filename safe
     $filename = InputHelper::alphanum($name, false, '_') . '.json';
     if ($this->request->get('save', false)) {
         // Save to the user's folder
         $dir = $this->factory->getSystemPath('dashboard.user');
         file_put_contents($dir . '/' . $filename, json_encode($dashboard));
         return $this->redirect($this->get('router')->generate('mautic_dashboard_action', array('objectAction' => 'import')));
     }
     $response = new JsonResponse($dashboard);
     $response->setEncodingOptions($response->getEncodingOptions() | JSON_PRETTY_PRINT);
     $response->headers->set('Content-Length', strlen($response->getContent()));
     $response->headers->set('Content-Type', 'application/force-download');
     $response->headers->set('Content-Type', 'application/octet-stream');
     $response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
     $response->headers->set('Expires', 0);
     $response->headers->set('Cache-Control', 'must-revalidate');
     $response->headers->set('Pragma', 'public');
     return $response;
 }
开发者ID:HomeRefill,项目名称:mautic,代码行数:38,代码来源:DashboardController.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: returnJson

 protected function returnJson($resource)
 {
     $response = new JsonResponse($resource);
     $response->setEncodingOptions(JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     return $response;
 }
开发者ID:forestadmin,项目名称:forest-symfony,代码行数:6,代码来源:LianaController.php

示例14: send

 /**
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function send()
 {
     $jsonResponse = new JsonResponse($this->response->toArray(), Response::HTTP_OK, ['X-Zed-Host' => 1]);
     if ($this->repeatIsActive) {
         $jsonResponse->setEncodingOptions(JSON_PRETTY_PRINT);
     }
     return $jsonResponse;
 }
开发者ID:spryker,项目名称:Application,代码行数:11,代码来源:TransferServer.php

示例15: restGetSystemsForProjectAction

 public function restGetSystemsForProjectAction(Request $request)
 {
     $this->assertApiKey($request->get('api_key'));
     $response = new JsonResponse($this->getActiveSystemsForProject($this->getProject()));
     $response->setEncodingOptions($response->getEncodingOptions() | JSON_PRETTY_PRINT);
     return $response;
 }
开发者ID:koalamon,项目名称:koalamonframeworkbundle,代码行数:7,代码来源:SystemAwareIntegrationController.php


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