Exemplo n.º 1
0
 private static function internalFindComponentTag(XmlElement $markup, $componentTagId, Component $component)
 {
     if ($markup instanceof ComponentTag && $markup->getComponentTagId() == $componentTagId) {
         return $markup;
     } else {
         if ($markup instanceof MarkupElement && $markup->hasChildren() && (!$markup instanceof ComponentTag || $component->getId() == $markup->getComponentTagId())) {
             $componentTag = null;
             foreach ($markup->getChildren() as $element) {
                 if ($element instanceof MarkupElement) {
                     $componentTag = self::internalFindComponentTag($element, $componentTagId, $component);
                     if ($componentTag != null) {
                         return $componentTag;
                     }
                 }
             }
         }
         return null;
     }
 }
Exemplo n.º 2
0
 private function parseTemplate(XmlElement $composition)
 {
     $templateName = $composition->getAttribute("template");
     $title = $composition->getAttribute("title");
     $description = $composition->getAttribute("description");
     $tplXml = $this->getTemplateLocation($templateName);
     if (!file_exists($tplXml)) {
         throw new TemplateNotExistsException($templateName);
     }
     $replaces = array();
     foreach ($composition->getChildren() as $define) {
         $key = "<insert name=\"{$define->getAttribute("name")}\"/>";
         $replaces[$key] = $define->asXmlChildren();
     }
     $tplNode = $this->xmlFactory->fromFile($tplXml)->getRootElement();
     $result = $tplNode->asXml();
     $result = StringUtil::replaceWith($result, "<template>", "<view>");
     $result = StringUtil::replaceWith($result, "</template>", "</view>");
     $inserts = $tplNode->getNbDescendants("insert");
     for ($i = 0; $i < $inserts; $i++) {
         $result = StringUtil::replaceAssoc($result, $replaces);
     }
     $root = $this->xmlFactory->fromString($result)->getRootElement();
     if (!is_null($title)) {
         $root->addAttribute("title", $title);
     }
     if (!is_null($description)) {
         $root->addAttribute("description", $description);
     }
     return $root;
 }