deserialize() static public méthode

Parse an association as stored by serialize(). This is the inverse of serialize.
static public deserialize ( $class_name, string $assoc_s ) : Auth_OpenID_Association
$assoc_s string Association as serialized by serialize()
Résultat Auth_OpenID_Association $result instance of this class
Exemple #1
0
 function test_me()
 {
     $issued = time();
     $lifetime = 600;
     $assoc = new Auth_OpenID_Association('handle', 'secret', $issued, $lifetime, 'HMAC-SHA1');
     $s = $assoc->serialize();
     $assoc2 = Auth_OpenID_Association::deserialize('Auth_OpenID_Association', $s);
     if ($assoc2 === null) {
         $this->fail('deserialize returned null');
     } else {
         $this->assertTrue($assoc2->equal($assoc));
     }
 }
 /**
  * Retrieve all associations for a given server.
  *
  * The associations are returned as an associative array with the
  * association handle as the index and the association object as
  * the value.
  *
  * @param string $server_url  The server.
  * @return array  Associative array with associations.
  */
 private function getServerAssociations($server_url)
 {
     assert('is_string($server_url)');
     if (!array_key_exists($server_url, $this->associations)) {
         return array();
     }
     $ret = array();
     foreach ($this->associations[$server_url] as $handle => $association) {
         $association = Auth_OpenID_Association::deserialize('Auth_OpenID_Association', $association);
         if ($association === NULL) {
             continue;
         }
         if ($association->getExpiresIn() == 0) {
             continue;
         }
         $ret[$handle] = $association;
     }
     return $ret;
 }
Exemple #3
0
	function cleanupAssociations() { 
		$associations = get_option('openid_associations');

		foreach ($associations as $key => $assoc_s) {
			$assoc = Auth_OpenID_Association::deserialize('Auth_OpenID_Association', $assoc_s);

			if ( $assoc->getExpiresIn() == 0) {
				unset($associations[$key]);
			}
		}

		update_option('openid_associations', $associations);
	}
Exemple #4
0
 /**
  * Remove expired entries from the database. This is potentially
  * expensive, so only run when it is acceptable to take time.
  *
  * @access private
  */
 function _allAssocs()
 {
     $all_associations = array();
     $association_filenames = Auth_OpenID_FileStore::_listdir($this->association_dir);
     foreach ($association_filenames as $association_filename) {
         $association_file = fopen($association_filename, 'rb');
         if ($association_file !== false) {
             $assoc_s = fread($association_file, filesize($association_filename));
             fclose($association_file);
             // Remove expired or corrupted associations
             $association = Auth_OpenID_Association::deserialize('Auth_OpenID_Association', $assoc_s);
             if ($association === null) {
                 Auth_OpenID_FileStore::_removeIfPresent($association_filename);
             } else {
                 if ($association->getExpiresIn() == 0) {
                     $all_associations[] = array($association_filename, $association);
                 }
             }
         }
     }
     return $all_associations;
 }
 /**
  * Remove expired entries from the database. This is potentially
  * expensive, so only run when it is acceptable to take time.
  */
 function clean()
 {
     if (!$this->active) {
         trigger_error("FileStore no longer active", E_USER_ERROR);
         return null;
     }
     $nonces = Auth_OpenID_FileStore::_listdir($this->nonce_dir);
     $now = time();
     // Check all nonces for expiry
     foreach ($nonces as $nonce) {
         $filename = $this->nonce_dir . DIRECTORY_SEPARATOR . $nonce;
         $st = @stat($filename);
         if ($st !== false) {
             // Remove the nonce if it has expired
             $nonce_age = $now - $st[9];
             if ($nonce_age > $this->max_nonce_age) {
                 Auth_OpenID_FileStore::_removeIfPresent($filename);
             }
         }
     }
     $association_filenames = Auth_OpenID_FileStore::_listdir($this->association_dir);
     foreach ($association_filenames as $association_filename) {
         $association_file = fopen($association_filename, 'rb');
         if ($association_file !== false) {
             $assoc_s = fread($association_file, filesize($association_filename));
             fclose($association_file);
             // Remove expired or corrupted associations
             $association = Auth_OpenID_Association::deserialize('Auth_OpenID_Association', $assoc_s);
             if ($association === null) {
                 Auth_OpenID_FileStore::_removeIfPresent($association_filename);
             } else {
                 if ($association->getExpiresIn() == 0) {
                     Auth_OpenID_FileStore::_removeIfPresent($association_filename);
                 }
             }
         }
     }
 }
Exemple #6
0
 function _getKnownAssociation($server_url, $handle)
 {
     global $wgMemc;
     $k = $this->_associationKey($server_url, $handle);
     $v = $wgMemc->get($k);
     if ($v !== false && strlen($v) > 0) {
         # FIXME: why is this nl getting lost?
         $v .= "\n";
         $assoc = Auth_OpenID_Association::deserialize('Auth_OpenID_Association', $v);
         if ($assoc->getExpiresIn() > 0) {
             return $assoc;
         } else {
             return null;
         }
     }
 }