Auth_OpenID_Association::getExpiresIn PHP Method

getExpiresIn() public method

This returns the number of seconds this association is still valid for, or 0 if the association is no longer valid.
public getExpiresIn ( $now = null ) : integer
return integer $seconds The number of seconds this association is still valid for, or 0 if the association is no longer valid.
    function getExpiresIn($now = null)
    {
        if ($now == null) {
            $now = time();
        }
        return max(0, $this->issued + $this->lifetime - $now);
    }

Usage Example

Example #1
0
 /**
  * Get an association
  * 
  * @param string $server_url The identity server endpoint
  * @param string $handle     The association handle
  * @return Auth_OpenID_Association
  */
 public function getAssociation($server_url, $handle = null)
 {
     $assocs = $this->getAssociations($server_url, $handle);
     if (!$assocs || count($assocs) == 0) {
         return null;
     } else {
         $associations = array();
         foreach ($assocs as $object) {
             $assoc = new Auth_OpenID_Association($object->handle, base64_decode($object->secret), $object->issued, $object->lifetime, $object->assoc_type);
             if ($assoc->getExpiresIn() == 0) {
                 $this->removeAssociation($server_url, $assoc->handle);
             } else {
                 $associations[] = array($assoc->issued, $assoc);
             }
         }
         if ($associations) {
             $issued = array();
             $assocs = array();
             foreach ($associations as $key => $assoc) {
                 $issued[$key] = $assoc[0];
                 $assocs[$key] = $assoc[1];
             }
             array_multisort($issued, SORT_DESC, $assocs, SORT_DESC, $associations);
             // return the most recently issued one.
             list($issued, $assoc) = $associations[0];
             return $assoc;
         } else {
             return null;
         }
     }
 }
All Usage Examples Of Auth_OpenID_Association::getExpiresIn