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


PHP HttpFoundation\Response类代码示例

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


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

示例1: eventsListJSONAction

 public function eventsListJSONAction()
 {
     $repository = $this->getRepository();
     $request = $this->getRequest();
     $locationId = $request->query->get('locationId', $this->getConfigResolver('content.tree_root.location_id'));
     $location = $repository->getLocationService()->loadLocation($locationId);
     $contentTypeService = $repository->getContentTypeService();
     $contentType = $contentTypeService->loadContentType($location->getContentInfo()->contentTypeId);
     $params = array('start' => $request->query->get('start', false), 'end' => $request->query->get('end', false));
     switch ($contentType->identifier) {
         case 'agenda_folder':
             $jsonData = $this->getAgendaFolderContentRepository()->getJsonData($location, $params);
             break;
         case 'agenda':
             $jsonData = $this->getAgendaContentRepository()->getJsonData($location, $params);
             break;
         default:
             $jsonData = array();
     }
     $response = new Response();
     $response->headers->set('Content-Type', 'application/json');
     $response->headers->set('Access-Control-Allow-Origin', '*');
     $response->headers->set('Access-Control-Expose-Headers', 'Cache-Control,Content-Encoding');
     $response->setContent(json_encode($jsonData));
     return $response;
 }
开发者ID:Open-Wide,项目名称:OwPublishAgendaBundle,代码行数:26,代码来源:JsonController.php

示例2: assertForm

 /**
  * @param Response $response
  */
 protected function assertForm(Response $response)
 {
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertRegExp('/form/', $response->getContent());
     $this->assertNotRegExp('/<html/', $response->getContent());
     $this->assertNotRegExp('/_username/', $response->getContent());
 }
开发者ID:open-orchestra,项目名称:open-orchestra,代码行数:10,代码来源:AbstractFormTest.php

示例3: export

 /**
  * Export the workbook.
  *
  * @param null|string $filename
  *
  * @throws \Exception
  * @return mixed|void
  */
 public function export($filename = null)
 {
     $filename = $this->getFilename($filename);
     $output = $this->getExportable()->getDriver()->getOutputFromHtml($this->convertToHtml($this->getExportable()));
     $response = new Response($output, 200, ['Content-Type' => 'application/pdf', 'Content-Disposition' => 'attachment; filename="' . $filename . '.' . $this->getExtension() . '"']);
     return $response->send();
 }
开发者ID:ymnl007,项目名称:Clerk,代码行数:15,代码来源:Writer.php

示例4: injectScript

 /**
  * Injects the livereload script.
  *
  * @param Response $response A Response instance
  */
 protected function injectScript(Response $response)
 {
     if (function_exists('mb_stripos')) {
         $posrFunction = 'mb_strripos';
         $substrFunction = 'mb_substr';
     } else {
         $posrFunction = 'strripos';
         $substrFunction = 'substr';
     }
     $content = $response->getContent();
     $pos = $posrFunction($content, '</body>');
     if (false !== $pos) {
         $script = "livereload.js";
         if ($this->checkServerPresence) {
             // GET is required, as livereload apparently does not support HEAD requests ...
             $request = $this->httpClient->get($script);
             try {
                 $checkResponse = $this->httpClient->send($request);
                 if ($checkResponse->getStatusCode() !== 200) {
                     return;
                 }
             } catch (CurlException $e) {
                 // If error is connection failed, we assume the server is not running
                 if ($e->getCurlHandle()->getErrorNo() === 7) {
                     return;
                 }
                 throw $e;
             }
         }
         $content = $substrFunction($content, 0, $pos) . "\n" . '<script src="' . $this->httpClient->getBaseUrl() . $script . '"></script>' . "\n" . $substrFunction($content, $pos);
         $response->setContent($content);
     }
 }
开发者ID:bakie,项目名称:KunstmaanBundlesCMS,代码行数:38,代码来源:ScriptInjectorListener.php

示例5: createHttpResponse

 public function createHttpResponse()
 {
     $httpResponse = new HttpResponse();
     $httpResponse->setContent(json_encode($this));
     $httpResponse->headers->set('Content-Type', 'application/json');
     return $httpResponse;
 }
开发者ID:deft,项目名称:datatables-php,代码行数:7,代码来源:Response.php

示例6: action

 public function action(RouterInterface $router, RequestContext $context)
 {
     $request = Request::createFromGlobals();
     $bPath = $context->getPathInfo();
     try {
         $parameters = $router->match($bPath);
         var_dump($parameters);
         $_controller = $parameters["_controller"];
         $_controller = explode(":", $_controller);
         $class = $_controller[0];
         $action = strtolower($_controller[1]) . "Action";
         $class = new $class();
         ob_start();
         if (method_exists($class, $action)) {
             $class->{$action}($request, new JsonResponse());
             $response = new Response(ob_get_clean());
         } else {
             $response = new Response('Not Found', 404);
         }
     } catch (ResourceNotFoundException $e) {
         $response = new Response('Not Found', 404);
     } catch (Exception $e) {
         $response = new Response('An error occurred', 500);
     }
     $response->send();
 }
开发者ID:mbabenko21,项目名称:likedimion-server,代码行数:26,代码来源:RoutingBootstrap.php

示例7: simpleSearchAction

 public function simpleSearchAction($format)
 {
     $request = $this->container->get('request');
     $serializer = $this->container->get('jms_serializer');
     $searchedTerm = $request->get('term');
     $useSynonyms = $request->get('useSynonyms');
     // Grabbing the repartition filters service, the department filter and the UE filter
     $repFilters = $this->get('eveg_app.repFilters');
     $depFrFilter = $repFilters->getDepFrFilterSession();
     $ueFilter = $repFilters->getUeFilterSession();
     if (!$searchedTerm) {
         throw new \Exception('Empty variable \'term\'.');
     }
     if (!$useSynonyms) {
         $useSynonyms = true;
     }
     $searchedTerm = $searchedTerm . ' ';
     $searchedTerm = str_replace(' ', '%', $searchedTerm);
     $result = $this->getDoctrine()->getManager()->getRepository('evegAppBundle:SyntaxonCore')->findForSearchEngine($searchedTerm, $useSynonyms, $depFrFilter, $ueFilter);
     $serializedResult = $serializer->serialize($result, $format, SerializationContext::create()->setGroups(array('searchEngine')));
     $response = new Response();
     $response->setContent($serializedResult);
     if ($format == 'json') {
         $response->headers->set('Content-Type', 'application/json');
     } elseif ($format == 'xml') {
         $response->headers->set('Content-Type', 'application/xml');
     }
     return $response;
 }
开发者ID:steph-del,项目名称:eveg,代码行数:29,代码来源:SyntaxonSearchController.php

示例8: userLinksAction

 /**
  * Renders page header links with cache control
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function userLinksAction()
 {
     $response = new Response();
     $response->setSharedMaxAge(3600);
     $response->setVary('Cookie');
     return $this->render("BCPageLayoutOverrideTestBundle::page_header_links.html.twig", array(), $response);
 }
开发者ID:brookinsconsulting,项目名称:bcpagelayoutoverridetestbundle,代码行数:12,代码来源:BCPageLayoutOverrideTestController.php

示例9: clearCookie

 /**
  * Clear authorization Cookie
  *
  * @param string $authDomain
  */
 private function clearCookie(Request $request, Response $response, $authDomain)
 {
     if ($request->cookies->has($authDomain)) {
         $response->headers->clearCookie($authDomain);
         $response->send();
     }
 }
开发者ID:professor93,项目名称:mobicms,代码行数:12,代码来源:Logout.php

示例10: indexAction

 public function indexAction()
 {
     $response = new Response();
     $response->setMaxAge(60);
     $response->setStatusCode(Response::HTTP_OK);
     return $response;
 }
开发者ID:seclu,项目名称:playground,代码行数:7,代码来源:GameController.php

示例11: start

 /**
  * {@inheritdoc}
  */
 public function start(Request $request, AuthenticationException $authException = null)
 {
     $response = new Response();
     $response->headers->set('WWW-Authenticate', sprintf('Basic realm="%s"', $this->realmName));
     $response->setStatusCode(401);
     return $response;
 }
开发者ID:koumba,项目名称:monsiteweb.com,代码行数:10,代码来源:BasicAuthenticationEntryPoint.php

示例12: handle

 public function handle(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $wsseHeader = $request->headers->get(self::WSSE_HEADER, false);
     if (!$wsseHeader || 1 !== preg_match(self::WSSE_REGEX, $wsseHeader, $matches)) {
         $event->setResponse(new Response('', Response::HTTP_FORBIDDEN, array('WWW-Authenticate' => 'WSSE realm="webservice", profile="ApplicationToken"')));
         return;
     }
     $token = new WsseUserToken();
     $token->setUser($matches[1]);
     $token->digest = $matches[2];
     $token->nonce = $matches[3];
     $token->created = $matches[4];
     try {
         $authToken = $this->authenticationManager->authenticate($token);
         $this->securityContext->setToken($authToken);
         return;
     } catch (NonceExpiredException $failed) {
         $this->logger->debug("Nonce expired: " . $wsseHeader);
     } catch (AuthenticationException $failed) {
         $this->logger->debug("Authentication failed: " . $failed->getMessage());
     }
     $token = $this->securityContext->getToken();
     if ($token instanceof WsseUserToken) {
         $this->securityContext->setToken(null);
     }
     $response = new Response();
     $response->setStatusCode(Response::HTTP_UNAUTHORIZED);
     $event->setResponse($response);
 }
开发者ID:arghakroy,项目名称:Bangla-Radio,代码行数:30,代码来源:WsseListener.php

示例13: apiIntroAction

 function apiIntroAction()
 {
     $response = new Response();
     $response->setPublic();
     $response->setMaxAge($this->container->getParameter('cache_expiration'));
     return $this->render('AppBundle:Default:apiIntro.html.twig', array("pagetitle" => "API", "game_name" => $this->container->getParameter('game_name'), "publisher_name" => $this->container->getParameter('publisher_name')), $response);
 }
开发者ID:ScotSalmon,项目名称:thronesdb,代码行数:7,代码来源:DefaultController.php

示例14: chunk

 /**
  * Chunk the request into parts as
  * desired by the request range header.
  *
  * @param Response      $response
  * @param FileInterface $file
  */
 protected function chunk(Response $response, FileInterface $file)
 {
     $size = $chunkStart = $file->getSize();
     $end = $chunkEnd = $size;
     $response->headers->set('Content-length', $size);
     $response->headers->set('Content-Range', "bytes 0-{$end}/{$size}");
     if (!($range = array_get($_SERVER, 'HTTP_RANGE'))) {
         return;
     }
     list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
     if (strpos($range, ',') !== false) {
         $response->setStatusCode(416, 'Requested Range Not Satisfiable');
         $response->headers->set('Content-Range', "bytes 0-{$end}/{$size}");
     }
     if ($range == '-') {
         $chunkStart = $size - substr($range, 1);
     } else {
         $range = explode('-', $range);
         $chunkStart = $range[0];
         $chunkEnd = isset($range[1]) && is_numeric($range[1]) ? $range[1] : $size;
     }
     $chunkEnd = $chunkEnd > $end ? $end : $chunkEnd;
     if ($chunkStart > $chunkEnd || $chunkStart > $size || $chunkEnd >= $size) {
         $response->setStatusCode(416, 'Requested Range Not Satisfiable');
         $response->headers->set('Content-Range', "bytes 0-{$end}/{$size}");
     }
 }
开发者ID:ramcda,项目名称:files-module,代码行数:34,代码来源:FileStreamer.php

示例15: testFeed

 /**
  * Generates a test feed and simulates last-modified and etags.
  *
  * @param $use_last_modified
  *   Set TRUE to send a last modified header.
  * @param $use_etag
  *   Set TRUE to send an etag.
  * @param Request $request
  *   Information about the current HTTP request.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  *   A feed that forces cache validation.
  */
 public function testFeed($use_last_modified, $use_etag, Request $request)
 {
     $response = new Response();
     $last_modified = strtotime('Sun, 19 Nov 1978 05:00:00 GMT');
     $etag = Crypt::hashBase64($last_modified);
     $if_modified_since = strtotime($request->server->get('HTTP_IF_MODIFIED_SINCE'));
     $if_none_match = stripslashes($request->server->get('HTTP_IF_NONE_MATCH'));
     // Send appropriate response. We respond with a 304 not modified on either
     // etag or on last modified.
     if ($use_last_modified) {
         $response->headers->set('Last-Modified', gmdate(DateTimePlus::RFC7231, $last_modified));
     }
     if ($use_etag) {
         $response->headers->set('ETag', $etag);
     }
     // Return 304 not modified if either last modified or etag match.
     if ($last_modified == $if_modified_since || $etag == $if_none_match) {
         $response->setStatusCode(304);
         return $response;
     }
     // The following headers force validation of cache.
     $response->headers->set('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
     $response->headers->set('Cache-Control', 'must-revalidate');
     $response->headers->set('Content-Type', 'application/rss+xml; charset=utf-8');
     // Read actual feed from file.
     $file_name = drupal_get_path('module', 'aggregator_test') . '/aggregator_test_rss091.xml';
     $handle = fopen($file_name, 'r');
     $feed = fread($handle, filesize($file_name));
     fclose($handle);
     $response->setContent($feed);
     return $response;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:45,代码来源:AggregatorTestRssController.php


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