本文整理匯總了PHP中Symfony\Component\HttpFoundation\Response::getDate方法的典型用法代碼示例。如果您正苦於以下問題:PHP Response::getDate方法的具體用法?PHP Response::getDate怎麽用?PHP Response::getDate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\HttpFoundation\Response
的用法示例。
在下文中一共展示了Response::getDate方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getDate
/**
* {@inheritdoc}
*/
public function getDate()
{
$date = $this->headers->getDate('Date', null);
if ($date === null) {
$this->setDate(new \DateTime('now'));
}
return parent::getDate();
}
示例2: testGetDate
public function testGetDate()
{
$response = new Response('', 200, array('Date' => $this->createDateTimeOneHourAgo()->format(DATE_RFC2822)));
$this->assertEquals(0, $this->createDateTimeOneHourAgo()->diff($response->getDate())->format('%s'), '->getDate() returns the Date header if present');
$response = new Response();
$date = $response->getDate();
$this->assertLessThan(1, $date->diff(new \DateTime(), true)->format('%s'), '->getDate() returns the current Date if no Date header present');
$response = new Response('', 200, array('Date' => $this->createDateTimeOneHourAgo()->format(DATE_RFC2822)));
$now = $this->createDateTimeNow();
$response->headers->set('Date', $now->format(DATE_RFC2822));
$this->assertEquals(0, $now->diff($response->getDate())->format('%s'), '->getDate() returns the date when the header has been modified');
}
示例3: logResponse
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);
}
示例4: testGetTtl
public function testGetTtl()
{
$response = new Response();
$this->assertNull($response->getTtl(), '->getTtl() returns null when no Expires or Cache-Control headers are present');
$response = new Response();
$response->headers->set('Expires', $this->createDateTimeOneHourLater()->format(DATE_RFC2822));
$this->assertLessThan(1, 3600 - $response->getTtl(), '->getTtl() uses the Expires header when no max-age is present');
$response = new Response();
$response->headers->set('Expires', $this->createDateTimeOneHourAgo()->format(DATE_RFC2822));
$this->assertLessThan(0, $response->getTtl(), '->getTtl() returns negative values when Expires is in past');
$response = new Response();
$response->headers->set('Expires', $response->getDate()->format(DATE_RFC2822));
$response->headers->set('Age', 0);
$this->assertSame(0, $response->getTtl(), '->getTtl() correctly handles zero');
$response = new Response();
$response->headers->set('Cache-Control', 'max-age=60');
$this->assertLessThan(1, 60 - $response->getTtl(), '->getTtl() uses Cache-Control max-age when present');
}
示例5: assertResponseEquals
protected function assertResponseEquals(Response $expected, Response $actual)
{
$expected->setDate($actual->getDate());
$this->assertEquals($expected, $actual);
}
示例6: setLifetime
/**
* Set max-age, s-maxage and expires headers.
*
* Set $lifetime as < 0 for not set max-age
* Need set Cache-Control public/private before set lifetime
*
* @param Response $response
* @param int $lifetime
*
* @return ResponseConfigurator
*/
protected function setLifetime(Response $response, $lifetime)
{
if ($lifetime >= 0) {
$date = clone $response->getDate();
$response->setMaxAge($lifetime)->setExpires($date->modify(sprintf('now +%s seconds', $lifetime)));
if (!$response->headers->hasCacheControlDirective('private')) {
$response->setSharedMaxAge($lifetime);
}
}
return $this;
}
示例7: createContext
/**
* @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;
}