SimpleSAML_Utilities::parseDuration PHP Method

parseDuration() public static method

Deprecation: This method will be removed in SSP 2.0. Please use \SimpleSAML\Utils\Time::parseDuration() instead.
public static parseDuration ( $duration, $timestamp = null )
    public static function parseDuration($duration, $timestamp = null)
    {
        return SimpleSAML\Utils\Time::parseDuration($duration, $timestamp);
    }

Usage Example

Example #1
0
 /**
  * Determine how long a given element can be cached.
  *
  * This function looks for the 'cacheDuration' and 'validUntil' attributes to determine
  * how long a given XML-element is valid. It returns this as na unix timestamp.
  *
  * If both the 'cacheDuration' and 'validUntil' attributes are present, the shorter of them
  * will be returned.
  *
  * @param DOMElement $element  The element we should determine the expiry time of.
  * @return int  The unix timestamp for when the element should expire. Will be NULL if no
  *              limit is set for the element.
  */
 private static function getExpireTime(DOMElement $element)
 {
     if ($element->hasAttribute('cacheDuration')) {
         $cacheDuration = $element->getAttribute('cacheDuration');
         $cacheDuration = SimpleSAML_Utilities::parseDuration($cacheDuration, time());
     } else {
         $cacheDuration = NULL;
     }
     if ($element->hasAttribute('validUntil')) {
         $validUntil = $element->getAttribute('validUntil');
         $validUntil = SimpleSAML_Utilities::parseSAML2Time($validUntil);
     } else {
         $validUntil = NULL;
     }
     if ($cacheDuration !== NULL && $validUntil !== NULL) {
         /* Both are given. Return the shortest. */
         if ($cacheDuration < $validUntil) {
             return $cacheDuration;
         } else {
             return $validUntil;
         }
     } elseif ($cacheDuration !== NULL) {
         return $cacheDuration;
     } elseif ($validUntil !== NULL) {
         return $validUntil;
     } else {
         return NULL;
     }
 }
All Usage Examples Of SimpleSAML_Utilities::parseDuration