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


PHP Response::prepare方法代码示例

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


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

示例1: onEventResponse

 public function onEventResponse(Application $app, Response $response)
 {
     if (null === $response->getCharset()) {
         $response->setCharset($app->getParameter('charset'));
     }
     $response->prepare($app->getRequest());
 }
开发者ID:itlessons,项目名称:php-application,代码行数:7,代码来源:ResponseProvider.php

示例2: getResponse

 /**
  * Handle a request for a file
  *
  * @param Request $request HTTP request
  * @return Response
  */
 public function getResponse(Request $request)
 {
     $response = new Response();
     $response->prepare($request);
     $path = implode('/', $request->getUrlSegments());
     if (!preg_match('~serve-file/e(\\d+)/l(\\d+)/d([ia])/c([01])/([a-zA-Z0-9\\-_]+)/(.*)$~', $path, $m)) {
         return $response->setStatusCode(400)->setContent('Malformatted request URL');
     }
     list(, $expires, $last_updated, $disposition, $use_cookie, $mac, $path_from_dataroot) = $m;
     if ($expires && $expires < time()) {
         return $response->setStatusCode(403)->setContent('URL has expired');
     }
     $hmac_data = array('expires' => (int) $expires, 'last_updated' => (int) $last_updated, 'disposition' => $disposition, 'path' => $path_from_dataroot, 'use_cookie' => (int) $use_cookie);
     if ((bool) $use_cookie) {
         $hmac_data['cookie'] = $this->getCookieValue($request);
     }
     ksort($hmac_data);
     $hmac = $this->crypto->getHmac($hmac_data);
     if (!$hmac->matchesToken($mac)) {
         return $response->setStatusCode(403)->setContent('HMAC mistmatch');
     }
     $dataroot = $this->config->getDataPath();
     $filenameonfilestore = "{$dataroot}{$path_from_dataroot}";
     if (!is_readable($filenameonfilestore)) {
         return $response->setStatusCode(404)->setContent('File not found');
     }
     $actual_last_updated = filemtime($filenameonfilestore);
     if ($actual_last_updated != $last_updated) {
         return $response->setStatusCode(403)->setContent('URL has expired');
     }
     $if_none_match = $request->headers->get('if_none_match');
     if (!empty($if_none_match)) {
         // strip mod_deflate suffixes
         $request->headers->set('if_none_match', str_replace('-gzip', '', $if_none_match));
     }
     $etag = '"' . $actual_last_updated . '"';
     $response->setPublic()->setEtag($etag);
     if ($response->isNotModified($request)) {
         return $response;
     }
     $public = $use_cookie ? false : true;
     $content_disposition = $disposition == 'i' ? 'inline' : 'attachment';
     $headers = ['Content-Type' => (new MimeTypeDetector())->getType($filenameonfilestore)];
     $response = new BinaryFileResponse($filenameonfilestore, 200, $headers, $public, $content_disposition);
     $sendfile_type = $this->config->getVolatile('X-Sendfile-Type');
     if ($sendfile_type) {
         $request->headers->set('X-Sendfile-Type', $sendfile_type);
         $mapping = (string) $this->config->getVolatile('X-Accel-Mapping');
         $request->headers->set('X-Accel-Mapping', $mapping);
         $response->trustXSendfileTypeHeader();
     }
     $response->prepare($request);
     if (empty($expires)) {
         $expires = strtotime('+1 year');
     }
     $expires_dt = (new DateTime())->setTimestamp($expires);
     $response->setExpires($expires_dt);
     $response->setEtag($etag);
     return $response;
 }
开发者ID:elgg,项目名称:elgg,代码行数:66,代码来源:ServeFileHandler.php

示例3: prepare

 /**
  * Make response object with RFC 2616 compliant HTTP header
  *
  * @return \BEAR\Sunday\Web\ResponseInterface
  */
 public function prepare()
 {
     $this->response = new Response($this->view, $this->resource->code, (array) $this->resource->headers);
     // compliant with RFC 2616.
     $this->response->prepare();
     return $this;
 }
开发者ID:rsky,项目名称:BEAR.Package,代码行数:12,代码来源:SymfonyResponse.php

示例4: handle

 function handle(Request $request, $type = HttpFoundation::MASTER_REQUEST, $catch = true)
 {
     $pathinfo = $request->getPathInfo();
     if (preg_match('{^/_pipe/(.+)$}', $pathinfo, $matches)) {
         $path = $matches[1];
         if (!$path or !($asset = $this->env->find($path, array('bundled' => true)))) {
             $this->log->error("pipe: Asset '{$path}' not found");
             return new Response('Not Found', 404);
         }
         $lastModified = new \DateTime();
         $lastModified->setTimestamp($asset->getLastModified());
         $response = new Response();
         $response->setPublic();
         $response->setLastModified($lastModified);
         if ($response->isNotModified($request)) {
             $this->log->info("pipe: 302 {$path}");
             return $response;
         }
         $start = microtime(true);
         $response->setContent($asset->getBody());
         $this->log->info(sprintf('pipe: Rendered "%s" in %d seconds', $path, microtime(true) - $start));
         $response->headers->set('Content-Type', $asset->getContentType());
         $response->prepare($request);
         return $response;
     }
     return $this->app->handle($request, $type, $catch);
 }
开发者ID:chh,项目名称:pipe,代码行数:27,代码来源:Middleware.php

示例5: itemsSaveAction

 /**
  * @Route("/items/save", name="items_save")
  * @method POST
  * @param Request $request
  * @return Response
  */
 public function itemsSaveAction(Request $request)
 {
     $result = '';
     $contentType = 'text/plain';
     $request = Request::createFromGlobals();
     $method = $request->getMethod();
     if ($method == 'POST') {
         $params = $request->getContent();
         if ($request->headers->get('content_type') == 'application/json') {
             $params = json_decode($params, true);
         }
         try {
             $result = $this->get($this->resource)->persist($params);
         } catch (\Exception $e) {
             echo $e->getMessage();
             exit;
             $result = $e->getMessage();
             $contentType = 'text/plain';
             $this->response_code = $e->getCode();
         }
     } else {
         $result = 'Method or action not implemented for the resource ' . $this->resource;
         $this->response_code = Response::HTTP_BAD_REQUEST;
     }
     $response = new Response('Content', $this->response_code, ['content-type' => $contentType]);
     $response->setContent($result);
     $response->setStatusCode($this->response_code);
     $response->prepare($request);
     //$response->send();
     return $response;
 }
开发者ID:radthoc,项目名称:sapis,代码行数:37,代码来源:ItemsController.php

示例6: handle

 function handle(HttpFoundation\Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     $path = ltrim($request->getPathInfo(), '/');
     $asset = $this->environment->find($path, array("bundled" => true));
     $debug = $request->query->get("debug", false);
     $cache = !$request->query->get("nocache", false);
     if (!$asset or $path == '') {
         return $this->renderNotFound($request);
     }
     if ($debug) {
         $this->environment->bundleProcessors->clear();
     }
     $lastModified = new \DateTime();
     $lastModified->setTimestamp($asset->getLastModified());
     $response = new HttpFoundation\Response();
     $response->setPublic();
     $response->setLastModified($lastModified);
     if ($cache and $response->isNotModified($request)) {
         return $response;
     }
     $response->setContent($asset->getBody());
     $response->headers->set('Content-Type', $asset->getContentType());
     $response->prepare($request);
     return $response;
 }
开发者ID:chh,项目名称:pipe,代码行数:25,代码来源:Server.php

示例7: getResponse

 /**
  * Handle a request for a file
  *
  * @param Request $request HTTP request
  * @return Response
  */
 public function getResponse($request)
 {
     $response = new Response();
     $response->prepare($request);
     $path = implode('/', $request->getUrlSegments());
     if (!preg_match('~download-file/g(\\d+)$~', $path, $m)) {
         return $response->setStatusCode(400)->setContent('Malformatted request URL');
     }
     $this->application->start();
     $guid = (int) $m[1];
     $file = get_entity($guid);
     if (!$file instanceof ElggFile) {
         return $response->setStatusCode(404)->setContent("File with guid {$guid} does not exist");
     }
     $filenameonfilestore = $file->getFilenameOnFilestore();
     if (!is_readable($filenameonfilestore)) {
         return $response->setStatusCode(404)->setContent('File not found');
     }
     $last_updated = filemtime($filenameonfilestore);
     $etag = '"' . $last_updated . '"';
     $response->setPublic()->setEtag($etag);
     if ($response->isNotModified($request)) {
         return $response;
     }
     $response = new BinaryFileResponse($filenameonfilestore, 200, array(), false, 'attachment');
     $response->prepare($request);
     $expires = strtotime('+1 year');
     $expires_dt = (new DateTime())->setTimestamp($expires);
     $response->setExpires($expires_dt);
     $response->setEtag($etag);
     return $response;
 }
开发者ID:nirajkaushal,项目名称:Elgg,代码行数:38,代码来源:DownloadFileHandler.php

示例8: indexAction

 public function indexAction(Request $request, $key)
 {
     $userManager = $this->container->get('ilioscore.user.manager');
     $user = $userManager->findUserBy(array('icsFeedKey' => $key));
     if (!$user) {
         throw new NotFoundHttpException();
     }
     $calendar = new ICS\Calendar('Ilios Calendar for ' . $user->getFirstAndLastName());
     $calendar->setPublishedTTL('P1H');
     $from = new \DateTime('-6 months');
     $to = new \DateTime('+6 months');
     $events = $userManager->findEventsForUser($user->getId(), $from, $to);
     foreach ($events as $event) {
         $vEvent = new ICS\Event();
         $vEvent->setDtStart($event->startDate)->setDtEnd($event->endDate)->setSummary($event->name)->setDescription($this->getDescriptionForEvent($event))->setCategories([$event->eventClass])->setLocation($event->location);
         $calendar->addComponent($vEvent);
     }
     $response = new Response();
     $response->setContent($calendar->render());
     $response->setCharset('utf-8');
     $response->headers->set('Content-Type', 'text/calendar');
     $response->headers->set('Content-Disposition', 'attachment; filename="' . $key . '.ics"');
     $response->prepare($request);
     $response->send();
 }
开发者ID:Okami-,项目名称:ilios,代码行数:25,代码来源:IcsController.php

示例9: run

 /**
  * Create a response if none is found, and prepare it.
  */
 public function run()
 {
     try {
         (yield null);
     } catch (\Exception $exception) {
         if (!$this->master() || $this->app['debug']) {
             throw $exception;
         } elseif ($exception instanceof HttpException) {
             $this->response($exception->getMessage() ?: Response::$statusTexts[$exception->getStatusCode()], $exception->getStatusCode(), $exception->getHeaders());
         } else {
             $this->response($exception->getMessage(), 500);
         }
     } finally {
         if (!$this->response()) {
             $result = $this->last();
             if (is_array($result)) {
                 $response = new JsonResponse($result);
             } elseif (is_int($result) && array_key_exists($result, Response::$statusTexts)) {
                 $response = new Response(null, $result);
             } else {
                 $response = new Response($result);
             }
             $response->prepare($this->request());
             $this->response($response);
         }
     }
 }
开发者ID:gigablah,项目名称:durian,代码行数:30,代码来源:ResponseMiddleware.php

示例10: meOptionsAction

 public function meOptionsAction(Request $request)
 {
     $response = new Response('Go Ahead!', Response::HTTP_OK);
     $response->setCharset('UTF-8');
     $response->prepare($request);
     $response->send();
     return;
 }
开发者ID:Avazanga1,项目名称:OAuth-Server-Demo,代码行数:8,代码来源:SecurityController.php

示例11: prepare

 public function prepare(Request $request)
 {
     if ('xml' === $request->getRequestFormat()) {
         $this->requestFormat = 'xml';
         $this->headers->set('Content-Type', 'application/hal+xml');
     }
     return parent::prepare($request);
 }
开发者ID:jsor,项目名称:stack-hal,代码行数:8,代码来源:HalResponse.php

示例12: exportJsonFileAction

 /**
  * Export a Json file containing NodeType datas and fields.
  *
  * @param Symfony\Component\HttpFoundation\Request $request
  * @param int                                      $nodeTypeId
  *
  * @return Symfony\Component\HttpFoundation\Response
  */
 public function exportJsonFileAction(Request $request, $nodeTypeId)
 {
     $this->validateAccessForRole('ROLE_ACCESS_NODETYPES');
     $nodeType = $this->getService('em')->find('RZ\\Roadiz\\Core\\Entities\\NodeType', (int) $nodeTypeId);
     $response = new Response(NodeTypeJsonSerializer::serialize($nodeType), Response::HTTP_OK, []);
     $response->headers->set('Content-Disposition', $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $nodeType->getName() . '.rzt'));
     // Rezo-Zero Type
     $response->prepare($request);
     return $response;
 }
开发者ID:bryanbanda,项目名称:roadiz,代码行数:18,代码来源:NodeTypesUtilsController.php

示例13: getResponse

 /**
  * Write the response (header and response body).
  *
  * @param OutgoingResponse &$outGoingResponse Headers and streams to output.
  * @param Request &$request The original Symfony Request
  */
 public function getResponse()
 {
     $outGoingResponse = $this->response;
     $request = $this->request;
     $headers = $outGoingResponse->getHeaders();
     $status_code = isset($headers[ODataConstants::HTTPRESPONSE_HEADER_STATUS]) ? $headers[ODataConstants::HTTPRESPONSE_HEADER_STATUS] : 200;
     unset($headers[ODataConstants::HTTPRESPONSE_HEADER_STATUS]);
     $response = new Response(trim($outGoingResponse->getStream()), $status_code, array_filter($headers));
     $response->prepare($request->getRequest());
     return $response;
 }
开发者ID:vivait,项目名称:podata-symfony2,代码行数:17,代码来源:Symfony2OperationContext.php

示例14: exportAction

 /**
  * Export a Group in a Json file (.rzt).
  *
  * @param Symfony\Component\HttpFoundation\Request $request
  * @param int                                      $groupId
  *
  * @return Symfony\Component\HttpFoundation\Response
  */
 public function exportAction(Request $request, $groupId)
 {
     $this->validateAccessForRole('ROLE_ACCESS_GROUPS');
     $existingGroup = $this->getService('em')->find('RZ\\Roadiz\\Core\\Entities\\Group', (int) $groupId);
     $group = GroupCollectionJsonSerializer::serialize([$existingGroup]);
     $response = new Response($group, Response::HTTP_OK, []);
     $response->headers->set('Content-Disposition', $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'group-' . $existingGroup->getName() . '-' . date("YmdHis") . '.rzt'));
     // Rezo-Zero Type
     $response->prepare($request);
     return $response;
 }
开发者ID:bryanbanda,项目名称:roadiz,代码行数:19,代码来源:GroupsUtilsController.php

示例15: adaptResponse

 /**
  * @param InternalResponse $iResponse
  * @return Response
  */
 public function adaptResponse(InternalResponse $iResponse)
 {
     $response = new Response($iResponse->getContent(), $iResponse->getStatusCode(), $iResponse->getHeaders());
     if ($this->request) {
         $response->prepare($this->request);
     }
     if ($response->getStatusCode() !== 200) {
         $response->setContent(Response::$statusTexts[$response->getStatusCode()]);
         return $response;
     }
     return $response;
 }
开发者ID:kankje,项目名称:xi-filelib,代码行数:16,代码来源:SymfonyRendererAdapter.php


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