/** * @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; }
public function getHttpResponse() { $result = $this->getResponseArray(); $response = new JsonResponse($result); $response->setEncodingOptions($response->getEncodingOptions() | JSON_UNESCAPED_UNICODE); return $response; }
/** * @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; }
/** * @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; }
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; }
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; }
public function testGetEncodingOptions() { $response = new JsonResponse(); $this->assertEquals(JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT, $response->getEncodingOptions()); }
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; }
$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; });
/** * 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; }