コード例 #1
0
 public function render(Node $node)
 {
     echo str_repeat('--', $node->getDepth()) . $node->getType() . "\n";
     foreach ($node->getChildren() as $child) {
         $this->render($child);
     }
 }
コード例 #2
0
 /**
  * Dumps a node or array.
  *
  * @param array|Node $node Node or array to dump
  *
  * @return string Dumped value
  */
 public function dump($node)
 {
     if ($node instanceof Node) {
         $r = $node->getType() . '(';
     } elseif (is_array($node)) {
         $r = 'array(';
     } else {
         throw new \InvalidArgumentException('Can only dump nodes and arrays.');
     }
     foreach ($node as $key => $value) {
         $r .= "\n" . '    ' . $key . ': ';
         if (null === $value) {
             $r .= 'null';
         } elseif (false === $value) {
             $r .= 'false';
         } elseif (true === $value) {
             $r .= 'true';
         } elseif (is_scalar($value)) {
             $r .= $value;
         } else {
             $r .= str_replace("\n", "\n" . '    ', $this->dump($value));
         }
     }
     return $r . "\n" . ')';
 }
コード例 #3
0
ファイル: index.php プロジェクト: recognant/guidesite
 function findParent(Node $node, $type = null)
 {
     if ($node->getType() == $type) {
         return $node;
     } else {
         findParent($node->getParent(), $type);
     }
 }
コード例 #4
0
 /**
  * @dataProvider provideNodes
  */
 public function testConstruct(array $attributes, Node $node)
 {
     $this->assertSame('Dummy', $node->getType());
     $this->assertSame(array('subNode1', 'subNode2'), $node->getSubNodeNames());
     $this->assertSame(10, $node->getLine());
     $this->assertSame('/** doc comment */', $node->getDocComment()->getText());
     $this->assertSame('value1', $node->subNode1);
     $this->assertSame('value2', $node->subNode2);
     $this->assertTrue(isset($node->subNode1));
     $this->assertTrue(isset($node->subNode2));
     $this->assertFalse(isset($node->subNode3));
     $this->assertSame($attributes, $node->getAttributes());
     return $node;
 }
コード例 #5
0
 /**
  * Dumps a node or array.
  *
  * @param array|Node $node Node or array to dump
  *
  * @return string Dumped value
  */
 public function dump($node)
 {
     if ($node instanceof Node) {
         $r = $node->getType() . '(';
         foreach ($node->getSubNodeNames() as $key) {
             $r .= "\n    " . $key . ': ';
             $value = $node->{$key};
             if (null === $value) {
                 $r .= 'null';
             } elseif (false === $value) {
                 $r .= 'false';
             } elseif (true === $value) {
                 $r .= 'true';
             } elseif (is_scalar($value)) {
                 $r .= $value;
             } else {
                 $r .= str_replace("\n", "\n    ", $this->dump($value));
             }
         }
         if ($this->dumpComments && ($comments = $node->getAttribute('comments'))) {
             $r .= "\n    comments: " . str_replace("\n", "\n    ", $this->dump($comments));
         }
     } elseif (is_array($node)) {
         $r = 'array(';
         foreach ($node as $key => $value) {
             $r .= "\n    " . $key . ': ';
             if (null === $value) {
                 $r .= 'null';
             } elseif (false === $value) {
                 $r .= 'false';
             } elseif (true === $value) {
                 $r .= 'true';
             } elseif (is_scalar($value)) {
                 $r .= $value;
             } else {
                 $r .= str_replace("\n", "\n    ", $this->dump($value));
             }
         }
     } elseif ($node instanceof Comment) {
         return $node->getReformattedText();
     } else {
         throw new \InvalidArgumentException('Can only dump nodes and arrays.');
     }
     return $r . "\n)";
 }
コード例 #6
0
 /**
  * Dumps a node or array.
  *
  * @param array|Node $node Node or array to dump
  *
  * @return string Dumped value
  */
 public function dump($node)
 {
     if ($node instanceof Node) {
         $r = "\n{\n \"title\"" . ":" . " \"" . $node->getType() . "\"," . "\n" . " \"value\": {\n";
         foreach ($node->getSubNodeNames() as $key) {
             $value = $node->{$key};
             if (null === $value) {
                 $r .= "    \"" . $key . "\"" . ":" . "null,";
             } elseif (false === $value) {
                 $r .= "    \"" . $key . "\"" . ":" . "false," . "";
             } elseif (true === $value) {
                 $r .= 'true';
             } elseif (is_scalar($value)) {
                 $r .= "    \"{$key}\"" . ":" . "\"{$value}\"" . ",";
             } else {
                 $r .= " \n\"{$key}\": " . str_replace("\n", "\n   ", $this->dump($value)) . ",";
             }
         }
         $r = rtrim($r, ",");
         $r .= "\n  }\n}";
     } elseif (is_array($node)) {
         $r = " [";
         foreach ($node as $key => $value) {
             if (null === $value) {
                 $r .= 'null';
             } elseif (false === $value) {
                 $r .= 'false';
             } elseif (true === $value) {
                 $r .= 'true';
             } elseif (is_scalar($value)) {
                 $r .= "\n\"" . $value . "\"\n";
             } else {
                 $r .= str_replace("\n", "\n   ", $this->dump($value)) . ",";
             }
         }
         $r = rtrim($r, ",");
         $r .= "\n ]";
     } else {
         throw new \InvalidArgumentException('Can only dump nodes and arrays.');
     }
     return $r . "\n";
 }
コード例 #7
0
ファイル: migration.php プロジェクト: adamfranco/harmoni
 /**
  * Create a new node and its children
  * 
  * @param object Hierarchy $newHierarchy
  * @param object Node $oldNode
  * @param optional object Id $parentId 
  * @return void
  * @access protected
  * @since 4/17/08
  */
 protected function addNode(Hierarchy $newHierarchy, Node $oldNode, Id $parentId = null)
 {
     // If it has already been created, get it and try to set its parent
     try {
         $newNode = $newHierarchy->getNode($oldNode->getId());
         if (!is_null($parentId)) {
             try {
                 $newNode->addParent($parentId);
             } catch (Exception $e) {
                 // Do nothing if the child already exists
                 if ($e->getMessage() != "A child with the given id already exists!") {
                     throw $e;
                 }
             }
         }
     } catch (UnknownIdException $e) {
         if (is_null($parentId)) {
             $newNode = $newHierarchy->createRootNode($oldNode->getId(), $oldNode->getType(), $oldNode->getDisplayName(), $oldNode->getDescription());
         } else {
             $newNode = $newHierarchy->createNode($oldNode->getId(), $parentId, $oldNode->getType(), $oldNode->getDisplayName(), $oldNode->getDescription());
         }
         $this->nodeStatus->updateStatistics();
     }
     $oldChildren = $oldNode->getChildren();
     while ($oldChildren->hasNext()) {
         $oldChild = $oldChildren->next();
         $this->addNode($newHierarchy, $oldChild, $newNode->getId());
     }
 }
コード例 #8
0
ファイル: Service.php プロジェクト: rickselby/nbt
 /**
  * Write the given tag to the stream.
  *
  * @param resource $fPtr Stream pointer
  * @param Node     $node Tag to write
  *
  * @return bool
  */
 private function writeTag($fPtr, Node $node)
 {
     return $this->dataHandler->putTAGByte($fPtr, $node->getType()) && $this->dataHandler->putTAGString($fPtr, $node->getName()) && $this->writeType($fPtr, $node->getType(), $node);
 }
コード例 #9
0
ファイル: class.History.php プロジェクト: Goodgulf/nodemesh
    public static function Log(Node $user, $action, Node $node1, $summary)
    {
        $type1      = $node1->getType();
        $pk1        = $node1->pk;
        $context1   = $node1->context;

        // Escape the summary
        self::_EscapeString($summary);

        $date = date('Y-m-d G:i:s');

        $sql = "INSERT INTO node_history (user_pk, user_context, pk1, type1, context1, action, date, summary)
                VALUES ($user->pk, $user->context, $pk1, '$type1', $context1, '$action', '$date', '$summary')
                ";

        $dbc    = new DatabaseConnection();
        $rows   = $dbc->query($sql);

        return true;
    }