예제 #1
0
 public function testRender()
 {
     $stylesheet = new Stylesheet();
     $stylesheet->addStyle3d(new Style3d("test-style", "test-model"))->setMood(new Mood());
     $domDocument = new \DOMDocument();
     $domElement = $stylesheet->render($domDocument);
     $domDocument->appendChild($domElement);
     $this->assertEquals("<?xml version=\"1.0\"?>\n<stylesheet><frame3dstyles><style3d id=\"test-style\" model=\"test-model\"/></frame3dstyles><mood/></stylesheet>\n", $domDocument->saveXML());
 }
예제 #2
0
 /**
  * Render the ManiaLink
  *
  * @param bool         $echo        (optional) If the XML text should be echoed and the Content-Type header should be set
  * @param \DOMDocument $domDocument (optional) DOMDocument for which the ManiaLink should be rendered
  * @return \DOMDocument
  */
 public function render($echo = false, $domDocument = null)
 {
     $isChild = (bool) $domDocument;
     if (!$isChild) {
         $domDocument = new \DOMDocument("1.0", "utf-8");
         $domDocument->xmlStandalone = true;
     }
     $maniaLink = $domDocument->createElement("manialink");
     if (!$isChild) {
         $domDocument->appendChild($maniaLink);
     }
     $maniaLink->setAttribute("version", "1");
     if ($this->maniaLinkId) {
         $maniaLink->setAttribute("id", $this->maniaLinkId);
     }
     if ($this->name) {
         $maniaLink->setAttribute("name", $this->name);
     }
     if ($this->background) {
         $maniaLink->setAttribute("background", $this->background);
     }
     if (!$this->navigable3d) {
         $maniaLink->setAttribute("navigable3d", "0");
     }
     if ($this->timeout) {
         $timeoutXml = $domDocument->createElement("timeout", $this->timeout);
         $maniaLink->appendChild($timeoutXml);
     }
     if ($this->dico) {
         $dicoXml = $this->dico->render($domDocument);
         $maniaLink->appendChild($dicoXml);
     }
     $scriptFeatures = array();
     foreach ($this->children as $child) {
         $childXml = $child->render($domDocument);
         $maniaLink->appendChild($childXml);
         if ($child instanceof ScriptFeatureable) {
             $scriptFeatures = array_merge($scriptFeatures, $child->getScriptFeatures());
         }
     }
     if ($this->stylesheet) {
         $stylesheetXml = $this->stylesheet->render($domDocument);
         $maniaLink->appendChild($stylesheetXml);
     }
     if ($scriptFeatures) {
         $this->createScript()->loadFeatures($scriptFeatures);
     }
     if ($this->script) {
         if ($this->script->needsRendering()) {
             $scriptXml = $this->script->render($domDocument);
             $maniaLink->appendChild($scriptXml);
         }
         $this->script->resetGenericScriptLabels();
     }
     if ($isChild) {
         return $maniaLink;
     }
     if ($echo) {
         header("Content-Type: application/xml; charset=utf-8;");
         echo $domDocument->saveXML();
     }
     return $domDocument;
 }