Symfony\Component\HttpFoundation\Response::setLastModified PHP Method

setLastModified() public method

Passing null as value will remove the header.
public setLastModified ( DateTime $date = null ) : Response
$date DateTime A \DateTime instance or null to remove the header
return Response
    public function setLastModified(\DateTime $date = null)
    {
        if (null === $date) {
            $this->headers->remove('Last-Modified');
        } else {
            $date = clone $date;
            $date->setTimezone(new \DateTimeZone('UTC'));
            $this->headers->set('Last-Modified', $date->format('D, d M Y H:i:s').' GMT');
        }

        return $this;
    }

Usage Example

Example #1
0
 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);
 }
All Usage Examples Of Symfony\Component\HttpFoundation\Response::setLastModified