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


PHP JsonResponse::getEncodingOptions方法代码示例

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


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

示例5: 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

示例6: 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

示例7: testGetEncodingOptions

 public function testGetEncodingOptions()
 {
     $response = new JsonResponse();
     $this->assertEquals(JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT, $response->getEncodingOptions());
 }
开发者ID:sapwoo,项目名称:portfolio,代码行数:5,代码来源:JsonResponseTest.php

示例8: 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

示例9: strtolower

            $app->abort(403, 'Bad input');
        }
    }
    $extension = strtolower(preg_replace('/^[.]+/', '', $extension));
    $extension = preg_replace('/[.]+/', '.', $extension);
    if (!preg_match('/[A-Za-z0-9.]/', $extension)) {
        $app->abort(500, 'Invalid filename extension');
    }
    $authorized = password_verify($password, $app['password']);
    if (!$authorized) {
        $app->abort(403, "You aren't allowed to be here, fucko");
    }
    $file = $request->files->get('file');
    if (!$file instanceof UploadedFile || !$file->isValid()) {
        $app->abort(500, 'Either there was no file or the upload failed');
    }
    $app['db']->beginTransaction();
    $sth = $app['db']->prepare('INSERT INTO extensions (extension, mime_type) VALUES (?, ?)');
    $sth->bindValue(1, $extension);
    $sth->bindValue(2, $mimeType);
    $sth->execute();
    $file->move(__DIR__ . '/repository', 'tidus_laugh.' . $extension);
    $app['db']->commit();
    return $app->redirect('/manage', 303);
});
$app->get('/repository.json', function () use($app) {
    $all = $app['db']->fetchAll('SELECT * FROM extensions ORDER BY extension ASC');
    $response = new JsonResponse(['extensions' => $all]);
    $response->setEncodingOptions($response->getEncodingOptions() | JSON_PRETTY_PRINT);
    return $response;
});
开发者ID:emmausrs,项目名称:Tidus.moe,代码行数:31,代码来源:application.php

示例10: 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


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