本文整理汇总了PHP中Node::getType方法的典型用法代码示例。如果您正苦于以下问题:PHP Node::getType方法的具体用法?PHP Node::getType怎么用?PHP Node::getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Node
的用法示例。
在下文中一共展示了Node::getType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
public function render(Node $node)
{
echo str_repeat('--', $node->getDepth()) . $node->getType() . "\n";
foreach ($node->getChildren() as $child) {
$this->render($child);
}
}
示例2: dump
/**
* 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: findParent
function findParent(Node $node, $type = null)
{
if ($node->getType() == $type) {
return $node;
} else {
findParent($node->getParent(), $type);
}
}
示例4: testConstruct
/**
* @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: dump
/**
* 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: dump
/**
* 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: addNode
/**
* 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: writeTag
/**
* 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: Log
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;
}