diff --git a/application/core/FML/ManiaLink.php b/application/core/FML/ManiaLink.php index 80ab9881..777176d1 100644 --- a/application/core/FML/ManiaLink.php +++ b/application/core/FML/ManiaLink.php @@ -2,8 +2,6 @@ namespace FML; -require_once __DIR__ . '/autoload.php'; - use FML\Types\Container; use FML\Types\Renderable; use FML\Script\Script; @@ -129,8 +127,10 @@ class ManiaLink implements Container { * If the xml should be echoed and the content-type header should be set * @return \DOMDocument */ - public function render($echo = false) { - $domDocument = new \DOMDocument('1.0', $this->encoding); + public function render($echo = false, $domDocument = null) { + if (!$domDocument) { + $domDocument = new \DOMDocument('1.0', $this->encoding); + } $manialink = $domDocument->createElement($this->tagName); $domDocument->appendChild($manialink); if ($this->id) { diff --git a/application/core/FML/ManiaLinks.php b/application/core/FML/ManiaLinks.php new file mode 100644 index 00000000..60bb8d7c --- /dev/null +++ b/application/core/FML/ManiaLinks.php @@ -0,0 +1,72 @@ +encoding = $encoding; + return $this; + } + + /** + * Add a child manialink + * + * @param ManiaLink $child + * @return \FML\ManiaLinks + */ + public function add(ManiaLink $child) { + array_push($this->children, $child); + return $this; + } + + /** + * Remove all child manialinks + * + * @return \FML\ManiaLinks + */ + public function removeChildren() { + $this->children = array(); + return $this; + } + + /** + * Render the xml document + * + * @param bool $echo + * If the xml should be echoed and the content-type header should be set + * @return \DOMDocument + */ + public function render($echo = false) { + $domDocument = new \DOMDocument('1.0', $this->encoding); + $manialink = $domDocument->createElement($this->tagName); + $domDocument->appendChild($manialink); + foreach ($this->children as $child) { + $child->render(false, $domDocument); + } + if ($echo) { + header('Content-Type: application/xml'); + echo $domDocument->saveXML(); + } + return $domDocument; + } +} + +?>