Link access
The Net_WebFinger_Reaction object you get from Net_WebFinger::finger() lets you access the the user's links in three ways:
-
By one of the short name properties.
-
The
get()
method. -
Iterate with
foreach()
over the reaction object.
Short name properties
Often used link relations have a dedicated "short name" in Net_WebFinger to make accessing the link easy:
Short name | Link relation URL |
---|---|
contacts |
http://portablecontacts.net/spec/1.0
|
hcard |
http://microformats.org/profile/hcard
|
openid |
http://specs.openid.net/auth/2.0/provider
|
profile |
http://webfinger.net/rel/profile-page
|
xfn |
http://gmpg.org/xfn/11
|
You can use each short name as property on the reaction object like this:
<?php
require_once 'Net/WebFinger.php';
$wf = new Net_WebFinger();
$react = $wf->finger('user@example.org');
if ($react->openid !== null) {
echo 'OpenID provider found: ' . $react->openid . "\n";
}
?>
Net_WebFinger_Reaction::get()
Net_WebFinger_Reaction::get() can always be used to access any link, especially those that have no short name. Just pass the URL of the link relation.
It returns NULL
in case the link is not available,
and the string if its there.
<?php
require_once 'Net/WebFinger.php';
$wf = new Net_WebFinger();
$react = $wf->finger('user@example.org');
$openIdProvider = $react->get('http://specs.openid.net/auth/2.0/provider');
if ($openIdProvider !== null) {
echo 'OpenID provider found: ' . $openIdProvider . "\n";
}
?>
foreach()
You may use foreach()
on the
Net_WebFinger_Reaction
object to get all links.
This will give you a XML_XRD_Element_Link object for each single link.
<?php
require_once 'Net/WebFinger.php';
$wf = new Net_WebFinger();
$react = $wf->finger('user@example.org');
foreach ($react as $link) {
echo 'Link: ' . $link->rel . ' to ' . $link->href . "\n";
}
?>