コード例 #1
0
 /**
  * test klonowania
  */
 public function testClone()
 {
     $el = new HtmlElement('meta');
     $el2 = clone $el;
     $el3 = $el;
     $this->assertNotSame($el->getElement(), $el2->getElement());
     $this->assertSame($el->getElement(), $el3->getElement());
     $el->destroy($el);
     $el2->destroy($el2);
 }
コード例 #2
0
 /**
  * wstaw element obecny element do innego elementu
  * 
  * @param HtmlElement $element
  * @param int $where
  * 
  * @throws \RuntimeException
  */
 public function insertTo(HtmlElement $element, $where = self::CHILD_APPEND)
 {
     if ($this->element === $element->getElement()) {
         throw new \RuntimeException('You can not insert the Element into a self.');
     }
     switch ($where) {
         case self::CHILD_APPEND:
             $element->getElement()->appendChild($this->element);
             break;
         case self::CHILD_PREPEND:
             $element->getElement()->insertBefore($this->element, $element->getElement()->childNodes->item(0));
             break;
     }
 }
コード例 #3
0
 /**
  * @param string $name
  *
  * @throws \InvalidArgumentException
  */
 public function renameRoot($name)
 {
     if (!is_string($name)) {
         throw new \InvalidArgumentException('name is not string');
     }
     $newnode = new HtmlElement($name);
     foreach ($this->root->getElement()->attributes as $attrNode) {
         $newnode->getElement()->setAttribute($attrNode->name, $attrNode->value);
     }
     $this->root->destroy($this->root);
     $this->root = $newnode;
 }