/** * error 404 page. useful when: page not found, content not found. * * @return string */ public function indexAction() { $response = new \Symfony\Component\HttpFoundation\Response(); $response->setStatusCode(404); $response->setcontent($this->Theme->render('errors/templates/e404/index')); return $response; }
protected function restResult($obj, $status = 200) { $response = new \Symfony\Component\HttpFoundation\Response(); $classParser = $this->container->get("rest.internal_class_parser"); $content = $classParser->serializeObject($obj); $response->setContent($content["result"]); $response->headers->add(array("content-type" => $content["type"])); $response->setStatusCode($status); return $response; }
private function downloadResponse($service) { $result = $service->execute(); $csvFile = $result['file']; $filename = $result['filename']; $response = new \Symfony\Component\HttpFoundation\Response(); $response->setStatusCode(200); $response->setContent(file_get_contents($csvFile)); $response->headers->set('Content-Type', 'application/stream'); $response->headers->set('Content-length', filesize($csvFile)); $response->headers->set('Content-Disposition', sprintf('attachment;filename="%s"', $filename)); $response->send(); return $response; }
public function onKernelResponse(FilterResponseEvent $event) { if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) { // don't do anything if it's not the master request return; } if (false === strpos($event->getRequest()->getRequestUri(), 'login')) { if ($event->getRequest()->isXmlHttpRequest() && $event->getResponse()->getStatusCode() == "302") { $event->getResponse()->setStatusCode(401); $response = new \Symfony\Component\HttpFoundation\Response(); $response->setStatusCode(401); $event->setResponse($response); } } }
public function replaceAction(Request $request) { $dataPath = rtrim($this->container->getParameter('fferriere_spreadsheets_replacement.data_path'), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $form = $this->createFormBuilder()->add('file', 'file', array('label' => 'Fichier :'))->add('submit', 'submit', array('label' => 'Valider'))->getForm(); $form->handleRequest($request); if ($form->isValid()) { if (!is_dir($dataPath)) { mkdir($dataPath, 0770, true); } $newFileName = date('Y-m-d-His') . '.csv'; $form['file']->getData()->move($dataPath, $newFileName); $filepath = $dataPath . $newFileName; $replacer = $this->container->get('fferriere_spreadsheets_replacement.replacer'); if (!$replacer instanceof \Fferriere\SpreadsheetsReplacement\Replacer\CsvReplacer) { throw new Exception('$replacer is not an instance of Fferriere\\SpreadsheetsReplacement\\Replacer\\CsvReplacer'); } $sheet = $replacer->getSheet(); if ($sheet instanceof \Fferriere\SpreadsheetsReplacement\Sheet\CsvSheet) { $sheet->setReadFilePath($filepath); } $hydrator = $this->container->get('fferriere_spreadsheets_replacement.hydrator'); if (!$hydrator instanceof \Fferriere\SpreadsheetsReplacement\Hydrator\HydratorInterface) { throw new Exception('$hydrator is not an instance of Fferriere\\SpreadsheetsReplacement\\Hydrator\\HydratorInterface'); } $params = (include $this->container->getParameter('fferriere_spreadsheets_replacement.replacement_pattern_path')); $columns = $hydrator->hydrate($params); $sheet->addColumns($columns); $newFilepath = $replacer->replaceFile(); $filename = basename($newFilepath); $response = new \Symfony\Component\HttpFoundation\Response(); $response->setStatusCode(200); $response->headers->set('Content-Type', 'text/csv'); $response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"'); $response->headers->set('Content-Length', filesize($newFilepath)); $response->setContent(file_get_contents($newFilepath)); return $response; } return $this->render('FferriereSpreadsheetsReplacementBundle:Default:replace.html.twig', array('form' => $form->createView())); }
<?php require_once 'bootstrap.php'; $Request = \Symfony\Component\HttpFoundation\Request::createFromGlobals(); $App->setRequest($Request); $routes = (require_once DIR_PROJECT . '/config/route.php'); $Router = new TelegramBot\Utils\Router($routes, $App); $Response = new \Symfony\Component\HttpFoundation\Response(); try { $Route = $Router->findAction($Request); $Response->setContent($Router->resolve()); } catch (\TelegramBot\Exception\ExceptionNotFound $e) { $Response->setStatusCode(404); } catch (\Exception $e) { $Response->setStatusCode(500); } $Response->send();
<?php $SERVER = $app['request']->server->all(); $username = isset($SERVER['PHP_AUTH_USER']) ? $SERVER['PHP_AUTH_USER'] : false; $password = isset($SERVER['PHP_AUTH_PW']) ? $SERVER['PHP_AUTH_PW'] : false; if ($username == 'mink-user' && $password == 'mink-password') { echo 'is authenticated'; } else { $resp = new \Symfony\Component\HttpFoundation\Response(); $resp->setStatusCode(401); $resp->headers->set('WWW-Authenticate', 'Basic realm="Mink Testing Area"'); echo 'is not authenticated'; }
/** * */ function getHttpResponse() { $output = ['jsonrpc' => $this->jsonrpcVersion, 'id' => isset($this->jsonRequest['id']) ? $this->jsonRequest['id'] : -9999]; if (!is_null($this->result)) { $this->http_status = 200; $output['result'] = $this->result; } else { if (!is_null($this->error)) { $output['error'] = $this->error; } } $httpResponse = new \Symfony\Component\HttpFoundation\Response(); if ($this->http_status === 0) { echo 'WTF'; } $httpResponse->setStatusCode($this->http_status); $res = json_encode($output); if ($res === false) { $httpResponse->setContent([" content was not jason-able "]); } else { $httpResponse->setContent($res); } return $httpResponse; }
/** * export all local author to csv * @param Request $request [] * @author Nash Lesigon <*****@*****.**> * @return Response */ public function exportToCsvAction(Request $request) { $exportToCsvService = $this->get("buggl_mail.export_local_author_to_csv"); $result = $exportToCsvService->execute(); $csvFile = $result['file']; $filename = $result['filename']; $response = new \Symfony\Component\HttpFoundation\Response(); $response->setStatusCode(200); $response->setContent(file_get_contents($csvFile)); $response->headers->set('Content-Type', 'application/stream'); $response->headers->set('Content-length', filesize($csvFile)); $response->headers->set('Content-Disposition', sprintf('attachment;filename="%s"', $filename)); $response->send(); return $response; }
return new \Models\ActionModel($app['pdo']); }; $app['lateness'] = function () use($app) { return new \Services\LatenessService($app['userModel'], $app['actionModel'], $app['monolog']); }; $app->post('/', function (Request $request) use($app) { $app['monolog']->addDebug(sprintf('Command from user : %s', $request->get('text'))); $commandArgs = explode(' ', $request->get('text')); $method = $commandArgs[0]; if (method_exists($app['lateness'], $method)) { $text = $app['lateness']->{$method}($commandArgs); } else { $text = $app['lateness']->help(); } $content = array("text" => $text, "mrkdwn" => true); $response = new \Symfony\Component\HttpFoundation\Response(); $response->headers->set('Content-Type', 'application/json'); $response->setStatusCode(200); $response->setContent(json_encode($content)); return $response; }); $app->run(); #878787 /* $attachments = new \stdClass; $attachments->text = "Partly cloudy today and tomorrow"; $content = array( "text" => $app['request']->get('user_name'), "attachments" => [$attachments] ); */