public static getLinkHref ( SimpleXMLElement $xml, string $rel ) : string | ||
$xml | SimpleXMLElement | |
$rel | string | the value of the rel attribute whose href you want |
Résultat | string |
public static function getLinkHref(\SimpleXMLElement $xml, $rel)
{
foreach ($xml->link as $link) {
$attributes = $link->attributes();
if ($attributes['rel']->__toString() === $rel) {
return $attributes['href']->__toString();
}
}
throw new Exception('No link found with rel "' . $rel . '"');
}
public function testGetLinkHref() { $xml = new SimpleXMLElement(file_get_contents(__DIR__ . '/xml/worksheet.xml')); $expected = 'https://spreadsheets.google.com/feeds/worksheets/tA3TdJ0RIVEem3xQZhG2Ceg/private/full/od8'; $actual = Util::getLinkHref($xml, 'self'); $this->assertEquals($expected, $actual); }