Back to AtomParser class

Method bestLinkForUri

private \SimpleXMLElement
bestLinkForUri
(array $links)
If there is more than one <link> in the feed entry, find the most appropriate one and return it.
Parameters
  • array $links Array of <link> elements from the feed entry.
Returns
  • \SimpleXMLElement
Class: AtomParser
Project: Joomla

Method bestLinkForUri - Source code

/**
 * If there is more than one <link> in the feed entry, find the most appropriate one and return it.
 *
 * @param   array  $links  Array of <link> elements from the feed entry.
 *
 * @return  \SimpleXMLElement
 */
private function bestLinkForUri(array $links)
{
    $linkPrefs = array('', 'self', 'alternate');
    foreach ($linkPrefs as $pref) {
        foreach ($links as $link) {
            $rel = (string) $link['rel'];
            if ($rel === $pref) {
                return $link;
            }
        }
    }
    return array_shift($links);
}