本文整理汇总了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());
}
示例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;
}
示例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;
}
示例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;
}
示例5: setNotModified
/**
* Marks the response as not modified as per the Symfony
*/
public function setNotModified()
{
parent::setNotModified();
$this->setModel(null);
return $this;
}
示例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();
示例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);
}