/**
  * Recursively inserts a path of nodes
  * 
  * @param Node $curr_node
  * @param string $path a slash delimited path of node names
  * @param array $array optional data array added to last node in the path
  */
 public function insertByPath(&$curr_node, $path = '', $array = null)
 {
     if (is_string($path)) {
         $p = explode('/', $path);
         $n = array_shift($p);
         if ($curr_node instanceof Node) {
             $curr_name = $curr_node->getName();
         }
         if ($curr_name === $n) {
             if (isset($p[0])) {
                 $n = $p[0];
             }
             if ($next_node = $curr_node->getNode($n)) {
                 $next_node = $next_node;
             } else {
                 $next_node = $curr_node;
             }
         } else {
             $new_node = self::build($n);
             $new_node->setData($array);
             $curr_node->insert($new_node);
             $next_node = $new_node;
         }
         if ($n !== '') {
             $remaining_path = implode('/', $p);
             while (count($p) > 0) {
                 return $this->insertByPath($next_node, $remaining_path, $array);
             }
         }
     }
 }
示例#2
0
文件: gc_017.php 项目: badlamer/hhvm
    public $children;
    public $parent;
    function __construct($name)
    {
        $this->name = $name;
        $this->children = array();
        $this->parent = null;
    }
    function insert($node)
    {
        $node->parent = $this;
        $this->children[] = $node;
    }
    function __destruct()
    {
        var_dump($this->name);
        unset($this->name);
        unset($this->children);
        unset($this->parent);
    }
}
$a = new Node('A');
$b = new Node('B');
$c = new Node('C');
$a->insert($b);
$a->insert($c);
unset($a);
unset($b);
unset($c);
var_dump(gc_collect_cycles());
echo "ok\n";
示例#3
0
 public function insert(PSNode $node)
 {
     /* Sobrescrita para Tipagem Correta */
     parent::insert($node);
     /* Verificação de Alturas */
     $left = $this->getLeft();
     $right = $this->getRight();
     /* Configuração de Alturas */
     $lheight = 0;
     $rheight = 0;
     /* Altura da Subárvore Esquerda */
     if ($left !== NULL) {
         $lheight = $left->getHeight();
     }
     /* Altura da Subárvore Direita */
     if ($right !== NULL) {
         $rheight = $right->getHeight();
     }
     /* Altura Local */
     $height = $lheight < $rheight ? $rheight : $lheight;
     $this->setHeight($height + 1);
     return $this;
 }
$node->insert('foo');
echo var_dump($node);
$node->insert('bar');
echo var_dump($node);
echo var_dump($node->getMember(2));
$node->delete(1);
echo var_dump($node);
$node->insert(new Node());
echo var_dump($node);
//NOTE: properties created dynamically are public by default
#$node->{3} = null;
#echo var_dump($node);
foreach ($node as $i => $property) {
    echo var_dump($property);
}
$node3 = new Node();
$node3->insert('dog');
$node->{3}->insert($node3);
#$node->setMember(3, 'baz'); // replaces the previously inserted node
$node->insert(new Node());
$node->setMember(2, 'baz');
$next_node = new Node();
$next_node->insert('bin');
echo var_dump($next_node);
$node->insert($next_node);
echo var_dump($node);
?>
</pre>
<?php 
$html = $node->emitHTML();
echo $html;