Google\Spreadsheet\Util::getLinkHref PHP Method

getLinkHref() public static method

Extracts the href for a specific rel from an xml object.
public static getLinkHref ( SimpleXMLElement $xml, string $rel ) : string
$xml SimpleXMLElement
$rel string the value of the rel attribute whose href you want
return 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 . '"');
    }

Usage Example

 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);
 }
All Usage Examples Of Google\Spreadsheet\Util::getLinkHref