本文整理汇总了PHP中Node类的典型用法代码示例。如果您正苦于以下问题:PHP Node类的具体用法?PHP Node怎么用?PHP Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: push
public function push($value)
{
$newHead = new Node($value);
$newHead->setNext($this->linkedList);
$this->linkedList = $newHead;
$this->size++;
}
开发者ID:SamyGhannad,项目名称:CtCI-6th-Edition,代码行数:7,代码来源:SizedStack.php
示例2: processNodeResult
/**
* Process the result of the given node. Returns false if no other nodes
* should be run, or a string with the next node name.
*
* @param Node $node Node that was run
*
* @return string
*/
protected function processNodeResult(Node $node)
{
$result = null;
$name = $node->getName();
if (isset($this->nodeResults[$name])) {
foreach ($this->nodeResults[$name] as $resultInfo) {
if ($resultInfo->appliesTo($node)) {
if ($resultInfo->isActionHangup()) {
// hanging up after $name
$this->client->hangup();
} elseif ($resultInfo->isActionJumpTo()) {
$data = $resultInfo->getActionData();
if (isset($data['nodeEval'])) {
$callback = $data['nodeEval'];
$nodeName = $callback($node);
} else {
$nodeName = $data['nodeName'];
}
// jumping from $name to $nodeName
$result = $nodeName;
} elseif ($resultInfo->isActionExecute()) {
// executing callback after $name
$data = $resultInfo->getActionData();
$callback = $data['callback'];
$callback($node);
}
}
}
}
return $result;
}
开发者ID:excelwebzone,项目名称:pastum,代码行数:39,代码来源:NodeController.php
示例3: testGetIntersectingNode
public function testGetIntersectingNode()
{
$a1 = new Node("one");
$a2 = new Node("two");
$a3 = new Node("three");
$a4 = new Node("four");
$a5 = new Node("five");
$a1->setNext($a2);
$a2->setNext($a3);
$a3->setNext($a4);
$a4->setNext($a5);
$b1 = new Node("un");
$b2 = new Node("deux");
$b3 = new Node("trois");
$b1->setNext($b2);
$b2->setNext($b3);
$this->assertNull(LinkedListIntersectionCheckerNoHashMap::getIntersectingNode($a1, $b1));
$c1 = new Node("uno");
$c2 = new Node("dos");
$c3 = new Node("tres");
$c1->setNext($c2);
$c2->setNext($c3);
$a5->setNext($c1);
$b3->setNext($c1);
$this->assertSame($c1, LinkedListIntersectionCheckerNoHashMap::getIntersectingNode($a1, $b1));
// disconnect the first 4 nodes of the linked list.
// now it begins @ $a5
$a4->setNext(null);
$this->assertSame($c1, LinkedListIntersectionCheckerNoHashMap::getIntersectingNode($a5, $b1));
}
开发者ID:SamyGhannad,项目名称:CtCI-6th-Edition,代码行数:30,代码来源:LinkedListIntersectionCheckerNoHashMapTest.php
示例4: _getBindingString
/**
* Helper Function for function buildXmlResult($vartable). Generates
* an xml string for a single variable an their corresponding value.
*
* @param String $varname The variables name
* @param Node $varvalue The value of the variable
* @return String The xml string
*/
protected function _getBindingString($varname, $varvalue)
{
$binding = '<binding name="' . $varname . '">';
$value = '<unbound/>';
if ($varvalue instanceof BlankNode) {
$value = '<bnode>' . $varvalue->getLabel() . '</bnode>';
} else {
if ($varvalue instanceof Resource) {
$value = '<uri>' . $varvalue->getUri() . '</uri>';
} else {
if ($varvalue instanceof Literal) {
$label = htmlspecialchars($varvalue->getLabel());
$value = '<literal>' . $label . '</literal>';
if ($varvalue->getDatatype() != null) {
$value = '<literal datatype="' . $varvalue->getDatatype() . '">' . $label . '</literal>';
}
if ($varvalue->getLanguage() != null) {
$value = '<literal xml:lang="' . $varvalue->getLanguage() . '">' . $label . '</literal>';
}
}
}
}
$binding = $binding . $value . '</binding>';
return $binding;
}
开发者ID:p4535992,项目名称:programate,代码行数:33,代码来源:XML.php
示例5: getLabelsFor
/**
* Возвращает список меток для документа.
*/
protected function getLabelsFor(Node $node)
{
if (!$node->id) {
return array();
}
return array_unique((array) $node->getDB()->getResultsKV('id', 'name', "SELECT `id`, `name` FROM `node` " . "WHERE `class` = 'label' AND `deleted` = 0 AND `id` " . "IN (SELECT `tid` FROM `node__rel` WHERE `nid` = ? AND `key` = ?)", array($node->id, $this->value . '*')));
}
开发者ID:umonkey,项目名称:molinos-cms,代码行数:10,代码来源:control.labels.php
示例6: __construct
/**
* Constructor.
*
* @param Node $parent (optional) parent node
*/
public function __construct($parent = null)
{
$this->parent = $parent;
if (null !== $parent) {
$this->level = 1 + $parent->getLevel();
}
}
开发者ID:mneudert,项目名称:junit-scribe,代码行数:12,代码来源:Node.php
示例7: getCommentsAction
/**
* Get editorial comments
*
* @ApiDoc(
* statusCodes={
* 200="Returned when success",
* }
* )
*
* @Route("/articles/{number}/{language}/editorial_comments/order/{order}.{_format}", defaults={"_format"="json", "order"="chrono"}, options={"expose"=true}, name="newscoop_gimme_articles_get_editorial_comments")
* @Method("GET")
* @View(serializerGroups={"list"})
*/
public function getCommentsAction(Request $request, $number, $language, $order)
{
$em = $this->container->get('em');
$editorialComments = $em->getRepository('Newscoop\\ArticlesBundle\\Entity\\EditorialComment')->getAllByArticleNumber($number)->getResult();
if ($order == 'nested' && $editorialComments) {
$root = new \Node(0, 0, '');
$reSortedComments = array();
foreach ($editorialComments as $comment) {
$reSortedComments[$comment->getId()] = $comment;
}
ksort($reSortedComments);
foreach ($reSortedComments as $comment) {
if ($comment->getParent() instanceof EditorialComment) {
$node = new \Node($comment->getId(), $comment->getParent()->getId(), $comment);
} else {
$node = new \Node($comment->getId(), 0, $comment);
}
$root->insertNode($node);
}
$editorialComments = $root->flatten(false);
}
$paginator = $this->get('newscoop.paginator.paginator_service');
$paginator->setUsedRouteParams(array('number' => $number, 'language' => $language));
$editorialComments = $paginator->paginate($editorialComments);
return $editorialComments;
}
开发者ID:sourcefabric,项目名称:newscoop,代码行数:39,代码来源:EditorialCommentsApiController.php
示例8: render
public function render(Node $node)
{
echo str_repeat('--', $node->getDepth()) . $node->getType() . "\n";
foreach ($node->getChildren() as $child) {
$this->render($child);
}
}
开发者ID:heybigname,项目名称:html-to-markdown,代码行数:7,代码来源:TextRenderer.php
示例9: interpret
public function interpret(Node &$node){
$name = $node->getAttribute('#');
$childs = $node->getChilds();
if($name != ''){
$ret = '<'.$name;
}else{
$ret = '<Node noname="true"';
}
foreach ($node->attrs as $k => $v){
if(!in_array($k[0], array('#', '>', '@'))){
$ret .= ' '.$k.'="'.$v.'"';
}
}
for($i=0; $i<$node->atidx; ++$i){
$ret .= ' attr'.$i.'="'.$node->attrs['@'.$i].'"';
}
$ret .='>';
foreach ($childs as $child){
$ret .= $this->interpret($child);
}
if($name != ''){
$ret .= '</'.$name.'>';
}else{
$ret .= '</Node>';
}
return $ret;
}
开发者ID:ray58750034,项目名称:shorp,代码行数:32,代码来源:XMLInterpreter.php
示例10: On_PostAction_iterator_fetch
function On_PostAction_iterator_fetch($a_data)
{
// Find iterator in template
$doc = new Template_Document($a_data->post['iterator_template']);
function search_func($node, $args)
{
if ($node instanceof Template_TagNode) {
return $node->getAttribute("name") == $args;
} else {
return false;
}
}
$itrs = $doc->getElementsByFunc(search_func, $a_data->post['iterator_name']);
$iterator = $itrs[0];
// Generate id
$id = Time("U") . substr((string) microtime(), 2, 6);
// Build iterator template
$node = new Node(-$id);
$node->Build($iterator);
// Pack JSON data
$data = array();
$data['id'] = $id;
$data['content'] = Editor::$m_data['module_data'][-$id];
print json_encode($data);
}
开发者ID:transformersprimeabcxyz,项目名称:cms-intel-fake,代码行数:25,代码来源:cms_iterator.plugin.php
示例11: testGetIntersectingNode
public function testGetIntersectingNode()
{
$a1 = new Node("one");
$a2 = new Node("two");
$a3 = new Node("three");
$a4 = new Node("four");
$a5 = new Node("five");
$a1->setNext($a2);
$a2->setNext($a3);
$a3->setNext($a4);
$a4->setNext($a5);
$b1 = new Node("un");
$b2 = new Node("deux");
$b3 = new Node("trois");
$b1->setNext($b2);
$b2->setNext($b3);
$this->assertNull(LinkedListIntersectionChecker::getIntersectingNode($a1, $b1));
$c1 = new Node("uno");
$c2 = new Node("dos");
$c3 = new Node("tres");
$c1->setNext($c2);
$c2->setNext($c3);
$a5->setNext($c1);
$b3->setNext($c1);
$this->assertSame($c1, LinkedListIntersectionChecker::getIntersectingNode($a1, $b1));
}
开发者ID:SamyGhannad,项目名称:CtCI-6th-Edition,代码行数:26,代码来源:LinkedListIntersectionCheckerTest.php
示例12: createTextElement
function createTextElement($text)
{
$node = new Node();
$node->setType(TEXTELEMENT);
$node->setValue($text);
return $node;
}
开发者ID:digideskio,项目名称:oscmax2,代码行数:7,代码来源:xmldocument.php
示例13: attachChild
/**
* Attach a child node
*
* @param \Zend\Server\Reflection\Node $node
* @return void
*/
public function attachChild(Node $node)
{
$this->children[] = $node;
if ($node->getParent() !== $this) {
$node->setParent($this);
}
}
开发者ID:razvansividra,项目名称:pnlzf2-1,代码行数:13,代码来源:Node.php
示例14: get_categories_and_products
function get_categories_and_products($parent_id)
{
$href_string = "javascript:set_return('productcatalog')";
$nodes = array();
if ($parent_id == '' or empty($parent_id)) {
$query = "select id, name , 'category' type from product_categories where (parent_id is null or parent_id='') and deleted=0";
$query .= " union select id, name , 'product' type from product_templates where (category_id is null or category_id='') and deleted=0";
} else {
$query = "select id, name , 'category' type from product_categories where parent_id ='{$parent_id}' and deleted=0";
$query .= " union select id, name , 'product' type from product_templates where category_id ='{$parent_id}' and deleted=0";
}
$result = $GLOBALS['db']->query($query);
// fetchByAssoc has been changed in version 7 and it does encoding of the string data.
// for the treeview we do not encoding as it messes up the display of the folder labels,
// hence we pass false as an additional parameter
while (($row = $GLOBALS['db']->fetchByAssoc($result, false)) != null) {
$node = new Node($row['id'], $row['name']);
$node->set_property("href", $href_string);
$node->set_property("type", $row['type']);
if ($row['type'] == 'product') {
$node->expanded = false;
$node->dynamic_load = false;
} else {
$node->expanded = false;
$node->dynamic_load = true;
}
$nodes[] = $node;
}
return $nodes;
}
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:30,代码来源:TreeData.php
示例15: interpret
public function interpret(Node $node){
$text = $node->getAttribute('@0');
$ret = '<h1>'.$text.'</h1>';
return $ret;
}
开发者ID:ray58750034,项目名称:shorp,代码行数:7,代码来源:TitleInterpreter.php
示例16: insertByPath
/**
* 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);
}
}
}
}
开发者ID:mikecurtis1,项目名称:Patterns-and-Data-Structures,代码行数:38,代码来源:nodepath.php
示例17: run
/**
* @param Node $start
* @param Node $goal
* @return Node[]
*/
public function run(Node $start, Node $goal)
{
$path = array();
$this->clear();
$start->setG(0);
$start->setH($this->calculateEstimatedCost($start, $goal));
$this->getOpenList()->add($start);
while (!$this->getOpenList()->isEmpty()) {
$currentNode = $this->getOpenList()->extractBest();
$this->getClosedList()->add($currentNode);
if ($currentNode->getID() === $goal->getID()) {
$path = $this->generatePathFromStartNodeTo($currentNode);
break;
}
$successors = $this->computeAdjacentNodes($currentNode, $goal);
foreach ($successors as $successor) {
if ($this->getOpenList()->contains($successor)) {
$successorInOpenList = $this->getOpenList()->get($successor);
if ($successor->getG() >= $successorInOpenList->getG()) {
continue;
}
}
if ($this->getClosedList()->contains($successor)) {
$successorInClosedList = $this->getClosedList()->get($successor);
if ($successor->getG() >= $successorInClosedList->getG()) {
continue;
}
}
$successor->setParent($currentNode);
$this->getClosedList()->remove($successor);
$this->getOpenList()->add($successor);
}
}
return $path;
}
开发者ID:AlexKex,项目名称:php-a-star,代码行数:40,代码来源:Algorithm.php
示例18: isNodeOnMap
function isNodeOnMap(Node $node)
{
$position = $node->getPosition();
$nodes = $this->getNodesAtPosition($position);
$index = $this->nodeIndex($node, $nodes);
return $index === false ? false : true;
}
开发者ID:kolesar-andras,项目名称:opencellid-osm-api,代码行数:7,代码来源:Map.php
示例19: 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" . ')';
}
开发者ID:Ingothq,项目名称:multiarmedbandit,代码行数:32,代码来源:NodeDumper.php
示例20: traverseNode
protected function traverseNode(Node $node)
{
foreach ($node->getSubNodeNames() as $name) {
$subNode =& $node->{$name};
if (is_array($subNode)) {
$subNode = $this->traverseArray($subNode);
} elseif ($subNode instanceof Node) {
$traverseChildren = true;
foreach ($this->visitors as $visitor) {
$return = $visitor->enterNode($subNode);
if (self::DONT_TRAVERSE_CHILDREN === $return) {
$traverseChildren = false;
} else {
if (null !== $return) {
$subNode = $return;
}
}
}
if ($traverseChildren) {
$subNode = $this->traverseNode($subNode);
}
foreach ($this->visitors as $visitor) {
if (null !== ($return = $visitor->leaveNode($subNode))) {
if (is_array($return)) {
throw new \LogicException('leaveNode() may only return an array ' . 'if the parent structure is an array');
}
$subNode = $return;
}
}
}
}
return $node;
}
开发者ID:nikic,项目名称:php-parser,代码行数:33,代码来源:NodeTraverser.php
注:本文中的Node类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论