protected function buildLink(Link $link) { $row = array('rel' => $link->getRel()); $type = $link->getType(); if (!empty($type)) { $row['type'] = $type; } $href = $link->getHref(); if (!empty($href)) { $row['href'] = $href; } $template = $link->getTemplate(); if (!empty($template)) { $row['template'] = $template; } $titles = $link->getTitles(); if (!empty($titles)) { $row['titles'] = $titles; } $properties = $link->getProperties(); if (!empty($properties)) { $row['properties'] = $properties; } return $row; }
protected function buildLink(XMLWriter $writer, Link $link) { $writer->startElement('Link'); $writer->writeAttribute('rel', $link->getRel()); $type = $link->getType(); if (!empty($type)) { $writer->writeAttribute('type', $type); } $href = $link->getHref(); $template = $link->getTemplate(); if (!empty($href)) { $writer->writeAttribute('href', $href); } else { if (!empty($template)) { $writer->writeAttribute('template', $template); } } $titles = $link->getTitles(); if (!empty($titles)) { foreach ($titles as $lang => $title) { if ($lang == 'default') { $writer->writeElement('Title', $title); } else { $writer->startElement('Title'); $writer->writeAttribute('xml:lang', $lang); $writer->text($title); $writer->endElement(); } } } $properties = $link->getProperties(); if (!empty($properties)) { foreach ($properties as $type => $value) { if ($value === null) { $writer->startElement('Property'); $writer->writeAttribute('type', $type); $writer->writeAttribute('xsi:nil', 'true'); $writer->endElement(); } else { $writer->startElement('Property'); $writer->writeAttribute('type', $type); $writer->text($value); $writer->endElement(); } } } $writer->endElement(); }