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


PHP Response::setNotModified方法代码示例

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


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

示例1: testSetNotModified

 public function testSetNotModified()
 {
     $response = new Response();
     $modified = $response->setNotModified();
     $this->assertObjectHasAttribute('headers', $modified);
     $this->assertObjectHasAttribute('content', $modified);
     $this->assertObjectHasAttribute('version', $modified);
     $this->assertObjectHasAttribute('statusCode', $modified);
     $this->assertObjectHasAttribute('statusText', $modified);
     $this->assertObjectHasAttribute('charset', $modified);
     $this->assertEquals(304, $modified->getStatusCode());
 }
开发者ID:harmoniouscrab,项目名称:BSc_Project_Program,代码行数:12,代码来源:ResponseTest.php

示例2: viewMenu

 /**
  * Action rendering the tree menu for admin interface.
  * Note that parameters are not used at all since the request is entirely forwarded to the legacy kernel.
  *
  * @param int $nodeId
  * @param int $modified
  * @param int $expiry
  * @param string $perm
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function viewMenu($nodeId, $modified, $expiry, $perm)
 {
     $response = new Response();
     if ($this->getParameter('treemenu.http_cache')) {
         $request = $this->getRequest();
         $response->setMaxAge($this->getParameter('treemenu.ttl_cache'));
         // Aggressive cache : Always return a 304 response if "If-Modified-Since" request header is present.
         if ($request->headers->has('If-Modified-Since')) {
             $response->setNotModified();
             return $response;
         }
     }
     $result = $this->treeMenuKernel->run();
     if ($result->hasAttribute('lastModified')) {
         $response->setLastModified($result->getAttribute('lastModified'));
     }
     $response->setContent($result->getContent());
     return $response;
 }
开发者ID:CG77,项目名称:ezpublish-kernel,代码行数:30,代码来源:LegacyTreeMenuController.php

示例3: indexAction

 /**
  * Generates a JavaScript file with client-side localization constants.
  *
  * @param Request $request Incoming request.
  * @return Response Prepared JavaScript file with client side localization
  * constants.
  */
 public function indexAction(Request $request)
 {
     $locale = $request->attributes->get('locale');
     $item = $this->getCache()->getItem('translation/js/' . $locale);
     $content = $item->get(Invalidation::OLD);
     if ($item->isMiss()) {
         $item->lock();
         $messages = load_messages($locale);
         // Store JSON-encoded data to reduce count of json_encode calls.
         $content = sprintf('%s(%s);', 'Mibew.Localization.set', json_encode($messages));
         $item->set($content);
     }
     // Session is started automatically during application initialization
     // and PHP sets "Cache-Control" and "Expires" headers to forbid caching
     // and to keep the session private. In this script we actually does not
     // use session stuff, thus we can remove these headers to provide
     // caching. Notice that all headers are removed to clear "Set-Cookie"
     // header with session ID and may be some other unsafe headers that
     // must not be cached.
     header_remove();
     // The whole response body (JSON-encoded with a callback function) is
     // cached via cache backend, thus it's simpler to use Symfony's
     // Response class instead of JsonResponse.
     $response = new Response();
     $response->headers->set('Content-Type', 'text/javascript');
     // Set various cache headers
     $response->setPublic();
     $response->setMaxAge(120);
     if ($item->getCreation()) {
         // Creation field can be unavailable for some cache drivers.
         $response->setLastModified($item->getCreation());
     }
     $response->setETag(sha1($content));
     if ($response->isNotModified($request)) {
         $response->setNotModified();
         // We does not need to send content for the client. Just return 304
         // status code.
         return $response;
     }
     // Pass the whole response for the client.
     $response->setContent($content);
     return $response;
 }
开发者ID:aburakovskiy,项目名称:mibew,代码行数:50,代码来源:JsTranslationController.php

示例4: createStreamResponse

 /**
  * Generate the HTTP response
  * 200 : a full body containing the stream
  * 304 : Not modified.
  *
  * @param array $options
  * @param $format
  * @param string $source
  *
  * @return Response
  *
  * @throws \Exception
  */
 protected function createStreamResponse(array $options, $format, $source = self::DEFAULT_SOURCE)
 {
     $content = $this->getContent($options, $source);
     if ($this->mustForceRefresh() || $content->getLastModified() > $this->getModifiedSince()) {
         $response = new Response($this->getStringOutput($content, $format));
         $response->headers->set('Content-Type', 'application/xhtml+xml');
         if (!$this->container->getParameter('debril_rss_atom.private_feeds')) {
             $response->setPublic();
         }
         $response->setMaxAge(3600);
         $response->setLastModified($content->getLastModified());
     } else {
         $response = new Response();
         $response->setNotModified();
     }
     return $response;
 }
开发者ID:DrBallMD,项目名称:rss-atom-bundle,代码行数:30,代码来源:StreamController.php

示例5: setNotModified

 /**
  * Marks the response as not modified as per the Symfony
  */
 public function setNotModified()
 {
     parent::setNotModified();
     $this->setModel(null);
     return $this;
 }
开发者ID:sgulseth,项目名称:imbo,代码行数:9,代码来源:Response.php

示例6: function

$StatTracker->get("/resources/{resource_dir}/{resource}", function (Request $request, $resource) use($StatTracker) {
    switch ($resource) {
        case "style.css":
            $file = "./resources/css/style.less";
            $lastModified = filemtime($file);
            $css = new Symfony\Component\HttpFoundation\Response("", 200, array("Content-Type" => "text/css"));
            $css->setLastModified(new \DateTime("@" . filemtime($file)));
            if ($css->isNotModified($request)) {
                $css->setNotModified();
            } else {
                $parser = new Less_Parser(array("compress" => true));
                $parser->parseFile($file, $request->getBaseUrl());
                $css->setLastModified(new \DateTime("@" . filemtime($file)));
                $css->setContent($parser->getCss());
            }
            return $css;
            break;
        case "stat-tracker.js":
            $js = new Symfony\Component\HttpFoundation\Response();
            if ($js->isNotModified($request)) {
                $js->setNotModified();
            } else {
                $content = $StatTracker['twig']->render("stat-tracker.js.twig");
                $js->headers->set("Content-Type", "application/javascript");
                $js->setContent($content);
            }
            return $js;
            break;
    }
});
$StatTracker->run();
开发者ID:helifino,项目名称:StatTracker,代码行数:31,代码来源:index.php

示例7: setHeadersIfNotProcessed

 /**
  * setHeadersIfNotProcessed
  *
  * @param Response $response
  * @param Image $image
  *
  * @access protected
  * @return mixed
  */
 protected function setHeadersIfNotProcessed(Response $response, \DateTime $lastMod)
 {
     $response->setNotModified();
     $response->setLastModified($lastMod);
 }
开发者ID:rulemaker,项目名称:jitimage,代码行数:14,代码来源:GenericFileResponse.php


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