Returns the Last-Modified HTTP header as a DateTime instance.
public getLastModified ( ) : DateTime | null | ||
return | DateTime | null | A DateTime instance or null if the header does not exist |
/** * @return \DateTime */ protected function getLastModified() { if ($this->response === null) { return null; } return $this->response->getLastModified(); }
/** * @param Response $response * * @return string */ public function hash(Response $response) { $suffix = ''; // add cookies to ETag if ($this->request_stack->getMasterRequest()) { $suffix = self::ETAG_SEPARATOR . http_build_query($this->request_stack->getMasterRequest()->cookies->all()); } return hash($this->algorithm, $response->getLastModified()->format(\DateTime::ISO8601) . $suffix); }
protected function logResponse(Response $response, Request $request) { if ($response->getStatusCode() >= 500) { $color = LogLevel::ERROR; } elseif ($response->getStatusCode() >= 400) { $color = LogLevel::WARNING; } elseif ($response->getStatusCode() >= 300) { $color = LogLevel::NOTICE; } elseif ($response->getStatusCode() >= 200) { $color = LogLevel::INFO; } else { $color = LogLevel::INFO; } $msg = 'Response {response_status_code} for "{request_method} {request_uri}"'; $context = array('request_method' => $request->getMethod(), 'request_uri' => $request->getRequestUri(), 'response_status_code' => $response->getStatusCode(), 'response_charset' => $response->getCharset(), 'response_date' => $response->getDate(), 'response_etag' => $response->getEtag(), 'response_expires' => $response->getExpires(), 'response_last_modified' => $response->getLastModified(), 'response_max_age' => $response->getMaxAge(), 'response_protocol_version' => $response->getProtocolVersion(), 'response_ttl' => $response->getTtl(), 'response_vary' => $response->getVary()); $this->logger->log($color, $msg, $context); }
public function testSetLastModified() { $response = new Response(); $response->setLastModified(new \DateTime()); $this->assertNotNull($response->getLastModified()); $response->setLastModified(null); $this->assertNull($response->getLastModified()); }
/** * @param Response $response * @param Request $request * * @return array */ protected function createContext(Response $response, Request $request) { $context = array('response_status_code' => $response->getStatusCode(), 'response_charset' => $response->getCharset(), 'response_date' => $response->getDate(), 'response_etag' => $response->getEtag(), 'response_expires' => $response->getExpires(), 'response_last_modified' => $response->getLastModified(), 'response_max_age' => $response->getMaxAge(), 'response_protocol_version' => $response->getProtocolVersion(), 'response_ttl' => $response->getTtl(), 'response_vary' => $response->getVary(), 'request_method' => $request->getMethod(), 'request_uri' => $request->getRequestUri(), 'request_route' => $request->attributes->get('_route'), 'response_time' => $this->getTime($request), 'response_memory' => $this->getMemory()); return $context; }