The XML_XRD object offers three ways to access links:
Use foreach
to iterate over the object and get all links
get() to fetch a single link with certain properties
getAll() to fetch all links that have certain properties
The returned links are objects of type XML_XRD_Element_Link which has several properties, e.g. rel, href, type and template .
Get all links
<?php
require_once 'XML/XRD.php';
$xrd = new XML_XRD();
$xrd->loadFile('http://example.org/.well-known/host-meta');
foreach ($xrd as $link) {
echo $link->rel . ': ' . $link->href . "\n";
}
?>
Get link by relation
<?php
require_once 'XML/XRD.php';
$xrd = new XML_XRD();
$xrd->loadFile('http://example.org/.well-known/host-meta');
$idpLink = $xrd->get('lrdd');
echo $idpLink->rel . ': ' . $idpLink->href . "\n";
?>
Get link by relation + optional type
If no link with the given type
is found, the first link with the correct
relation
and an empty
type
will be returned
<?php
require_once 'XML/XRD.php';
$xrd = new XML_XRD();
$xrd->loadFile('http://example.org/.well-known/host-meta');
$link = $xrd->get('lrdd', 'application/xrd+xml');
echo $link->rel . ': ' . $link->href . "\n";
?>
Get link by relation + type
The relation
and the type
both need to match exact:
<?php
require_once 'XML/XRD.php';
$xrd = new XML_XRD();
$xrd->loadFile('http://example.org/.well-known/host-meta');
$link = $xrd->get('lrdd', 'application/xrd+xml', false);
echo $link->rel . ': ' . $link->href . "\n";
?>
Get all links by relation
<?php
require_once 'XML/XRD.php';
$xrd = new XML_XRD();
$xrd->loadFile('http://example.org/.well-known/host-meta');
foreach ($xrd->getAll('lrdd') as $link) {
echo $link->rel . ': ' . $link->href . "\n";
}
?>
Accessing all link attributes
<?php
$link = $xrd->get('http://specs.openid.net/auth/2.0/provider');
$title = $link->getTitle('de');
$url = $link->href;
$urlTemplate = $link->template;
$mimetype = $link->type;
?>
Additional link properties
Works just like properties in the XRD document.
<?php
$link = $xrd->get('http://specs.openid.net/auth/2.0/provider');
$prop = $link['foo'];
?>