本文整理汇总了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;
}
示例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());
}
示例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();
}
示例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);
}
}
示例5: createHttpResponse
public function createHttpResponse()
{
$httpResponse = new HttpResponse();
$httpResponse->setContent(json_encode($this));
$httpResponse->headers->set('Content-Type', 'application/json');
return $httpResponse;
}
示例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();
}
示例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;
}
示例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();
}
}
示例10: indexAction
public function indexAction()
{
$response = new Response();
$response->setMaxAge(60);
$response->setStatusCode(Response::HTTP_OK);
return $response;
}
示例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;
}
示例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);
}
示例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);
}
示例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}");
}
}
示例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;
}