Bluz\Http\CacheControl::setExpires PHP Method

setExpires() public method

Sets the Expires HTTP header with a DateTime instance
public setExpires ( DateTime | string $date ) : void
$date DateTime | string A \DateTime instance or date as string
return void
    public function setExpires($date)
    {
        if ($date instanceof \DateTime) {
            $date = clone $date;
        } else {
            $date = new \DateTime($date);
        }
        $date->setTimezone(new \DateTimeZone('UTC'));
        $this->response->setHeader('Expires', $date->format('D, d M Y H:i:s') . ' GMT');
    }

Usage Example

Example #1
0
 /**
  * Test Expires
  */
 public function testExpiresAsDate()
 {
     $date = new \DateTime('2012-12-12T12:12:12+00:00');
     $this->cacheControl->setExpires($date);
     $this->assertEquals('Wed, 12 Dec 2012 12:12:12 GMT', $this->cacheControl->getExpires());
     $this->assertEquals('Wed, 12 Dec 2012 12:12:12 GMT', $this->response->getHeader('Expires'));
 }