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


PHP Response::setExpires方法代码示例

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


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

示例1: cacheResponse

 /**
  * Cache the response 1 year (31536000 sec)
  */
 protected function cacheResponse(Response $response)
 {
     $response->setSharedMaxAge(31536000);
     $response->setMaxAge(31536000);
     $response->setExpires(new \DateTime('+1 year'));
     return $response;
 }
开发者ID:focuslife,项目名称:v0.1,代码行数:10,代码来源:AssetController.php

示例2: get

 public static function get($file = null)
 {
     $directory = env('DJEM_DEBUG', false) ? 'panel' : 'panel-compiled';
     if (empty($file)) {
         $file = 'index.html';
     }
     $public = realpath(__DIR__ . '/../../../' . $directory);
     $file = realpath($public . '/' . preg_replace('|[^-_0-9a-z/.]|i', '', $file));
     if (!is_file($file) || substr($file, 0, strlen($public)) !== $public) {
         abort(404);
     }
     // @codeCoverageIgnore
     $response = new Response(file_get_contents($file), 200, ['Content-type' => self::getContentType($file)]);
     $response->setSharedMaxAge(3600);
     $response->setMaxAge(3600);
     $response->setExpires(new \DateTime('+1 hour'));
     return $response;
 }
开发者ID:deadem,项目名称:djem,代码行数:18,代码来源:StaticFiles.php

示例3: setCacheHeaders

 /**
  * Set cache headers and 304 not modify if needed.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Illuminate\Http\Response $response
  */
 protected function setCacheHeaders($request, $response)
 {
     if (starts_with($request->getPathInfo(), ['/images'])) {
         $stat = stat(session()->pull('requestImagePath'));
     } else {
         if (($view = $response->getOriginalContent()) instanceof View) {
             $stat = stat($view->getPath());
         }
     }
     if (isset($stat)) {
         $response->setCache(['etag' => md5("{$stat['ino']}|{$stat['mtime']}|{$stat['size']}"), 'public' => true]);
         $response->setExpires(Carbon::now()->addDays(30));
         if (null !== ($etag = $request->headers->get('If-None-Match')) || null !== $request->headers->get('If-Modified-Since')) {
             $etags = explode('-', $etag, -1);
             $request->headers->set('If-None-Match', count($etags) ? $etags[0] . '"' : $etag);
             $response->isNotModified($request);
         }
     }
 }
开发者ID:BePsvPT,项目名称:CCU,代码行数:25,代码来源:SetCacheHeaders.php

示例4: getDisplayAttachment

 /**
  * Display an attachment file such as image
  *
  * @param Project    $project
  * @param Issue      $issue
  * @param Attachment $attachment
  * @param Request    $request
  *
  * @return Response
  */
 public function getDisplayAttachment(Project $project, Issue $issue, Attachment $attachment, Request $request)
 {
     $issue->setRelation('project', $project);
     $attachment->setRelation('issue', $issue);
     $path = config('tinyissue.uploads_dir') . '/' . $issue->project_id . '/' . $attachment->upload_token . '/' . $attachment->filename;
     $storage = \Storage::disk('local');
     $length = $storage->size($path);
     $time = $storage->lastModified($path);
     $type = $storage->getDriver()->getMimetype($path);
     $response = new Response();
     $response->setEtag(md5($time . $path));
     $response->setExpires(new \DateTime('@' . ($time + 60)));
     $response->setLastModified(new \DateTime('@' . $time));
     $response->setPublic();
     $response->setStatusCode(200);
     $response->header('Content-Type', $type);
     $response->header('Content-Length', $length);
     $response->header('Content-Disposition', 'inline; filename="' . $attachment->filename . '"');
     $response->header('Cache-Control', 'must-revalidate');
     if ($response->isNotModified($request)) {
         // Return empty response if not modified
         return $response;
     }
     // Return file if first request / modified
     $response->setContent($storage->get($path));
     return $response;
 }
开发者ID:oliverpool,项目名称:tinyissue,代码行数:37,代码来源:IssueController.php


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