/**
* 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;
}
}
}