コード例 #1
0
ファイル: DOMBuilder.php プロジェクト: jvlonden/html
 /**
  * @param Element $element
  * @return \DOMElement
  */
 protected function createElement(Element $element)
 {
     $dom = $this->doc->createElement($element->getName(), $element->getValue());
     foreach ($element->getAttributes() as $attribute) {
         $dom->setAttribute($attribute->getName(), $attribute->getValue());
     }
     foreach ($element->getChildren() as $child) {
         $child = $this->createElement($child);
         $dom->appendChild($child);
     }
     return $this->doc->appendChild($dom);
 }
コード例 #2
0
ファイル: Element.php プロジェクト: jvlonden/html
 /**
  * @return $this|Element
  */
 public function getRoot()
 {
     if ($this->parent = null) {
         return $this;
     } else {
         return $this->parent->getRoot();
     }
 }
コード例 #3
0
ファイル: ElementBuilder.php プロジェクト: jvlonden/html
 protected function parseElement($tag, array $description = array())
 {
     $text = null;
     $children = array();
     $attributes = array();
     foreach ($description as $key => $value) {
         $type = $this->determineType($key, $value);
         switch ($type) {
             case self::ELEMENT:
                 $children[] = $this->parseElement($key, $value);
                 break;
             case self::ATTRIBUTE:
                 $attributes = array_merge($attributes, $this->parseAttributes($value));
                 break;
             case self::TEXT:
                 $text = $value;
                 break;
         }
     }
     $element = new Element($tag, $text);
     $element->addAttributes($attributes);
     $element->appendChildren($children);
     return $element;
 }