Esempio n. 1
0
 /**
  * Sets a DataTree as child. Children are returned in same order as first insertion.
  * If composite already have a child with same name it will be overwritten
  *
  * @param DataTreeBase $dataTree
  * @param string $placeMark if you want tree to be assigned to other key
  *
  */
 public function setChildTree(DataTreeBase $dataTree)
 {
     $name = $dataTree->getName();
     $childrenMapIndex = $this->getIndexByName($name);
     if ($childrenMapIndex === false) {
         $treeIndex = $this->addChild($dataTree);
         $this->childrenMap[$name] = $treeIndex;
     } else {
         $this->setChild($dataTree, $childrenMapIndex);
     }
 }
Esempio n. 2
0
 /**
  * Sets $element as $pos child, overwrites existent if any
  *
  * @param DataTreeBase $element
  * @throws \InvalidArgumentException
  */
 protected function setChild(DataTreeBase $element, $pos)
 {
     if (!is_int($pos) || $pos < 0) {
         throw new \InvalidArgumentException('Pos have to be a positive integer');
     } elseif ($this->getValue()) {
         throw new \InvalidArgumentException('Cannot set a child if tree is a leaf one');
     } else {
         $element->setParent($this);
         $this->elements[$pos] = $element;
     }
 }