protected function doCopyTest($treeFrom, $treeTo) { ezcTree::copy($treeFrom, $treeTo); self::assertSame(35, $treeFrom->getChildCountRecursive('Hominoidea')); self::assertSame(35, $treeTo->getChildCountRecursive('Hominoidea')); $pathFrom = $treeFrom->fetchPath('H**o Superior'); $pathTo = $treeTo->fetchPath('H**o Superior'); self::assertEquals(5, $pathFrom->size); self::assertEquals(5, $pathTo->size); self::assertSame(array_keys($pathFrom->nodes), array_keys($pathTo->nodes)); $node = $treeFrom->fetchNodeById('Müller\'s Bornean Gibbon'); self::assertSame("Müller's Bornean Gibbon", $node->data); $node = $treeTo->fetchNodeById('Müller\'s Bornean Gibbon'); self::assertSame("Müller's Bornean Gibbon", $node->data); }
<?php require_once 'tutorial_autoload.php'; $store = new ezcTreeXmlInternalDataStore(); $tree = new ezcTreeXml('files/example1.xml', $store); $memTree = ezcTreeMemory::create(new ezcTreeMemoryDataStore()); ezcTree::copy($tree, $memTree); echo $memTree->getChildCountRecursive('Elements'), "\n";
/** * Copies the tree in $from to the empty tree in $to. * * This method copies all the nodes, including associated data from the * used data store, from the tree $from to the tree $to. Because this * function uses internally setRootNode() the target tree will be cleared * out automatically. The method will not check whether the $from and $to * trees share the same database table or data store, so make sure they are * different to prevent unexpected behavior. * * @param ezcTree $from * @param ezcTree $to */ public static function copy(ezcTree $from, ezcTree $to) { $fromRootNode = $from->getRootNode(); $to->setRootNode(new ezcTreeNode($to, $fromRootNode->id, $fromRootNode->data)); $toRootNode = $to->getRootNode(); self::copyChildren($from, $to, $fromRootNode, $toRootNode); }
/** * Returns true if the property $name is set, otherwise false. * * @param string $name * @return bool * @ignore */ public function __isset($name) { switch ($name) { case 'prefix': return isset($this->properties[$name]); default: return parent::__isset($name); } }