示例#1
0
 /**
  * Sends an expires header.
  * @param $mExpires The expires header to send. Can be one of the following:
  *                     • A DateInterval object
  *                     • A date interval spec in the form of Pxx (http://en.wikipedia.org/wiki/Iso8601#Durations) which will be added to today’s date
  *                     • A UNIX timestamp as an integer
  *                     • A string to be parsed into a date using strtotime
  *                     • A DateTime object
  *                     • A Cache object (which will be asked about the expiresTimestamp)
  *                     • `true` to expire in a year (the maxiumum permitted by RFC2616)
  *                     • `false` to mark as already expired (and to force re-evaluation)
  */
 public static function sendExpires($mTimestamp)
 {
     if (self::$EXPIRES_SENT) {
         return;
     }
     if ($mTimestamp instanceof Cache) {
         $mTimestamp = $mTimestamp->getStrategy()->expiresTimestamp($mTimestamp);
     }
     if ($mTimestamp === true) {
         $mTimestamp = 'P1Y';
     }
     if (is_string($mTimestamp) && substr($mTimestamp, 0, 1) === 'P') {
         $mTimestamp = new DateInterval($mTimestamp);
     }
     if (is_string($mTimestamp)) {
         $mTimestamp = strtotime($mTimestamp);
     }
     if ($mTimestamp === null) {
         return;
     }
     if ($mTimestamp instanceof DateInterval) {
         $oDate = new DateTime('now', new DateTimeZone('UTC'));
         $mTimestamp = $oDate->add($mTimestamp);
     } else {
         if ($mTimestamp instanceof DateTime) {
             $mTimestamp = clone $mTimestamp;
             $mTimestamp->setTimezone(new DateTimeZone('UTC'));
         } else {
             if (is_int($mTimestamp)) {
                 $mTimestamp = new DateTime("@{$mTimestamp}");
             }
         }
     }
     // Format for output
     if ($mTimestamp === false) {
         $mTimestamp = 0;
     } else {
         $mTimestamp = $mTimestamp->format(self::DATE_RFC2616);
     }
     header('Expires: ' . $mTimestamp);
     self::$EXPIRES_SENT = true;
 }