本文整理汇总了PHP中Symfony\Component\HttpFoundation\Response::setLastModified方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setLastModified方法的具体用法?PHP Response::setLastModified怎么用?PHP Response::setLastModified使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Response
的用法示例。
在下文中一共展示了Response::setLastModified方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: update
/**
* {@inheritdoc}
*/
public function update(Response $response)
{
// if we have no embedded Response, do nothing
if (0 === $this->embeddedResponses) {
return;
}
// Remove validation related headers in order to avoid browsers using
// their own cache, because some of the response content comes from
// at least one embedded response (which likely has a different caching strategy).
if ($response->isValidateable()) {
$response->setEtag(null);
$response->setLastModified(null);
$this->cacheable = false;
}
if (!$this->cacheable) {
$response->headers->set('Cache-Control', 'no-cache, must-revalidate');
return;
}
$this->ttls[] = $response->getTtl();
$this->maxAges[] = $response->getMaxAge();
if (null !== ($maxAge = min($this->maxAges))) {
$response->setSharedMaxAge($maxAge);
$response->headers->set('Age', $maxAge - min($this->ttls));
}
$response->setMaxAge(0);
}
示例3: onKernelController
public function onKernelController(FilterControllerEvent $event)
{
$controller = $event->getController();
$request = $event->getRequest();
$annotation = $this->findAnnotation($controller);
if (!$annotation) {
return;
}
$lastTouched = $annotation->calculateLastModified($this->metaQueryFactory);
if (!$lastTouched) {
return;
}
$this->lastTouchedResults[$request] = $lastTouched;
/*
* Für kernel.debug = 1 senden wir niemals
* 304-Responses, anstatt den Kernel auszuführen:
*
* Das Ergebnis hängt auch von vielen Dingen außerhalb
* wfd_meta ab (z. B. template-Code), die wir hier nicht
* berücksichtigen können.
*/
if ($this->debug) {
return;
}
$response = new Response();
$response->setLastModified($lastTouched);
if ($response->isNotModified($request)) {
$event->setController(function () use($response) {
return $response;
});
}
}
示例4: analyze
public function analyze(Request $request = null)
{
$request = $request ?: $this->request;
$response = null;
$key = $request->getPathInfo();
if ($this['http.cache']->contains($key)) {
$value = $this['http.cache']->fetch($key);
$content = $value['content'];
$modified = \DateTime::createFromFormat('Y-m-d H:i:s', $value['modified']);
$statusCode = Response::HTTP_OK;
$ifModified = $this->request->headers->get('if-modified-since', null);
if (null !== $ifModified) {
$ifModified = \DateTime::createFromFormat('D, d M Y H:i:s T', $ifModified);
if ($modified->getTimestamp() === $ifModified->getTimestamp()) {
$content = null;
$statusCode = Response::HTTP_NOT_MODIFIED;
}
}
$response = new Response($content, $statusCode);
$response->setLastModified($modified);
}
if (null === $response) {
$this->forceHydrate();
$response = parent::analyze($request);
}
return $response;
}
示例5: filter
/**
*
*
* @param Event $event An Event instance
*/
public function filter(Event $event, Response $response)
{
if (!$configuration = $event->get('request')->attributes->get('_cache')) {
return $response;
}
if (!$response->isSuccessful()) {
return $response;
}
if (null !== $configuration->getSMaxAge()) {
$response->setSharedMaxAge($configuration->getSMaxAge());
}
if (null !== $configuration->getMaxAge()) {
$response->setMaxAge($configuration->getMaxAge());
}
if (null !== $configuration->getExpires()) {
$date = \DateTime::create(\DateTime::createFromFormat('U', $configuration->getExpires(), new \DateTimeZone('UTC')));
$response->setLastModified($date);
}
return $response;
}
示例6: getResponse
private function getResponse(Request $request, $name, array $files, $content_type)
{
if (!isset($files[$name])) {
return new Response('Not Found', 404, array('Content-Type' => 'text/plain'));
}
$file = $files[$name];
$response = new Response();
$response->setPublic();
$response->setMaxAge(self::EXPIRED_TIME);
$response->setSharedMaxAge(self::EXPIRED_TIME);
$response->headers->set('Content-Type', $content_type);
// set a custom Cache-Control directive
$response->headers->addCacheControlDirective('must-revalidate', true);
$date = new \DateTime();
$date->setTimestamp(strtotime($this->container->getParameter('sf.version')));
$response->setETag($date->getTimestamp());
$response->setLastModified($date);
if ($response->isNotModified($request)) {
return $response;
}
if (!file_exists($file)) {
throw new \Exception(sprintf("file `%s`, `%s` not exists", $name, $file));
}
$response->setContent(file_get_contents($file));
return $response;
}
示例7: resultatAction
public function resultatAction(Request $request, AbstractTerritoire $territoire)
{
$response = new Response();
$response->setLastModified($this->get('repository.cache_info')->getLastModified($territoire));
$response->setPublic();
if ($response->isNotModified($request)) {
return $response;
}
$allEcheances = $this->get('repository.echeance')->getAll();
$form = $this->createForm(new EcheanceChoiceType($allEcheances), array(), array('method' => 'GET'));
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid() && ($data = $form->getData())) {
$reference = $data['comparaison'] ? $data['comparaison']->getNom() : null;
$echeances = $data['echeances'];
if (!in_array($reference, $echeances->toArray(), true)) {
$reference = null;
}
} else {
$echeances = array_filter($allEcheances, function ($element) {
return $element->getType() !== Echeance::MUNICIPALES;
});
$reference = null;
$form->get('echeances')->setData(new ArrayCollection($echeances));
}
$results = $this->getResults($territoire, $echeances);
return $this->render('resultat.html.twig', array('form' => $form->createView(), 'resultats' => $results, 'territoire' => $territoire->getNom(), 'reference' => $reference), $response);
}
示例8: handle
/**
* Handle request to convert it to a Response object.
*/
public function handle()
{
try {
if (!$this->request->query->has('image')) {
throw new FileNotFoundException("No valid image path found in URI", 1);
}
$nativePath = $this->configuration->getImagesPath() . '/' . $this->request->query->get('image');
$this->nativeImage = new File($nativePath);
$this->parseQuality();
if ($this->configuration->hasCaching()) {
$cache = new FileCache($this->request, $this->nativeImage, $this->configuration->getCachePath(), $this->logger, $this->quality, $this->configuration->getTtl(), $this->configuration->getGcProbability(), $this->configuration->getUseFileChecksum());
$cache->setDispatcher($this->dispatcher);
/** @var Response response */
$this->response = $cache->getResponse(function (InterventionRequest $interventionRequest) {
return $interventionRequest->processImage();
}, $this);
} else {
$this->processImage();
$this->response = new Response((string) $this->image->encode(null, $this->quality), Response::HTTP_OK, ['Content-Type' => $this->image->mime(), 'Content-Disposition' => 'filename="' . $this->nativeImage->getFilename() . '"', 'X-Generator-First-Render' => true]);
$this->response->setLastModified(new \DateTime('now'));
}
} catch (FileNotFoundException $e) {
$this->response = $this->getNotFoundResponse($e->getMessage());
} catch (\RuntimeException $e) {
$this->response = $this->getBadRequestResponse($e->getMessage());
}
}
示例9: show
public function show()
{
$assetic = $this->getServices()->get($this->getServices()->getProperty('asseticServiceName', 'assetic'));
$response = new Response();
$response->setExpires(new \DateTime());
if (empty($this->asset) || strpos($this->asset, '/') === false) {
$response->setStatusCode(400);
return $response;
}
list(, $formulaName, ) = explode('/', $this->asset);
// asset not found
if (empty($formulaName) || !$assetic->getAssetManager()->has($formulaName)) {
$response->setStatusCode(404);
return $response;
}
$formula = $assetic->getAssetManager()->getFormula($formulaName);
if ($formula[0] instanceof AssetInterface) {
$asset = $formula[0];
} else {
$asset = $assetic->getFactory()->createAsset($formula[0], $formula[1], $formula[2]);
}
if (null !== ($lastModified = $asset->getLastModified())) {
$date = new \DateTime();
$date->setTimestamp($lastModified);
$response->setLastModified($date);
}
$formula['last_modified'] = $lastModified;
$response->setETag(md5($asset->getContent()));
$this->defineContentType($response);
if ($response->isNotModified($this->getContext()->getRequest())) {
return $response;
}
$response->setContent($this->cacheAsset($asset)->dump());
return $response;
}
示例10: viewAction
/**
* View a single content page
*
* This Controller action is being routed to from either our custom ContentRouter,
* or the ExceptionController.
* @see Opifer\SiteBundle\Router\ContentRouter
*
* @param Request $request
* @param ContentInterface $content
* @param int $statusCode
*
* @return Response
*
* @throws \Exception
*/
public function viewAction(Request $request, ContentInterface $content, $statusCode = 200)
{
$version = $request->query->get('_version');
$debug = $this->getParameter('kernel.debug');
$contentDate = $content->getUpdatedAt();
$templateDate = $content->getTemplate()->getUpdatedAt();
$date = $contentDate > $templateDate ? $contentDate : $templateDate;
$response = new Response();
$response->setLastModified($date);
$response->setPublic();
if (null === $version && false == $debug && $response->isNotModified($request)) {
// return the 304 Response immediately
return $response;
}
$version = $request->query->get('_version');
/** @var Environment $environment */
$environment = $this->get('opifer.content.block_environment');
$environment->setObject($content);
$response->setStatusCode($statusCode);
if (null !== $version && $this->isGranted('ROLE_ADMIN')) {
$environment->setDraft(true);
}
$environment->load();
return $this->render($environment->getView(), $environment->getViewParameters(), $response);
}
示例11: onKernelController
/**
* Handles HTTP validation headers.
*/
public function onKernelController(FilterControllerEvent $event)
{
$request = $event->getRequest();
if (!($configuration = $request->attributes->get('_cache'))) {
return;
}
$response = new Response();
$lastModifiedDate = '';
if ($configuration->getLastModified()) {
$lastModifiedDate = $this->getExpressionLanguage()->evaluate($configuration->getLastModified(), $request->attributes->all());
$response->setLastModified($lastModifiedDate);
}
$etag = '';
if ($configuration->getETag()) {
$etag = hash('sha256', $this->getExpressionLanguage()->evaluate($configuration->getETag(), $request->attributes->all()));
$response->setETag($etag);
}
if ($response->isNotModified($request)) {
$event->setController(function () use($response) {
return $response;
});
} else {
if ($etag) {
$this->etags[$request] = $etag;
}
if ($lastModifiedDate) {
$this->lastModifiedDates[$request] = $lastModifiedDate;
}
}
}
示例12: 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;
}
示例13: generate
/**
* Generate a Response object
*
* @param mixed $date a single namespace, an array of namespaces, or a \DateTime object
* @param Response $response
* @return Response
*/
public function generate($date = 'global', Response $response = null)
{
if (!$response) {
$response = new Response();
}
if ($this->maxAge) {
$response->setMaxAge($this->maxAge);
}
if ($this->sharedMaxAge) {
$response->setSharedMaxAge($this->sharedMaxAge);
}
if ($date instanceof \DateTime) {
$response->setLastModified($date);
} else {
$response->setLastModified($this->manager->getLastUpdate($date));
}
return $response;
}
示例14: setLastModified
public function setLastModified($timestamp = 0, $max_age = 0)
{
$time = new \DateTime('@' . $timestamp);
$etag = md5($this->builder->getTheme()->getDir() . $this->builder->getStyle() . '|' . $timestamp . '|' . $max_age);
$this->response->headers->addCacheControlDirective('must-revalidate', true);
$this->response->setLastModified($time);
$this->response->setEtag($etag);
$this->response->setMaxAge($max_age);
}
示例15: hasCachedResponse
public function hasCachedResponse(Request $request, DateTime $lastWriteTime)
{
$response = new Response();
$response->setLastModified($lastWriteTime);
if ($response->isNotModified($request)) {
return $response;
}
return false;
}