Call service for Tree
@param integer $node Node to call
@return array Node Data
14294
public function serviceTree($node = null)
	{
		$node = ($node === null) ? -1 : $node;
		$json = $this->service('tree', $node);
		return $json;
	}
879514
private function getCallingInfo(Node $node)
    {
        return coroutine(function () use ($node) {
            $fqn = null;
            $callingNode = null;
            if ($node instanceof Node\DelimitedList\ArgumentExpressionList) {
                // Cursor is already inside a (
                $argumentExpressionList = $node;
                if ($node->parent instanceof Node\Expression\ObjectCreationExpression) {
                    // Constructing something
                    $callingNode = $node->parent->classTypeDesignator;
                    if (!$callingNode instanceof Node\QualifiedName) {
                        // We only support constructing from a QualifiedName
                        return null;
                    }
                    $fqn = $this->definitionResolver->resolveReferenceNodeToFqn($callingNode);
                    $fqn = "{$fqn}->__construct()";
                } else {
                    $callingNode = $node->parent->getFirstChildNode(
                        Node\Expression\MemberAccessExpression::class,
                        Node\Expression\ScopedPropertyAccessExpression::class,
                        Node\QualifiedName::class
                    );
                }
            } elseif ($node instanceof Node\Expression\CallExpression) {
                $argumentExpressionList = $node->getFirstChildNode(Node\DelimitedList\ArgumentExpressionList::class);
                $callingNode = $node->getFirstChildNode(
                    Node\Expression\MemberAccessExpression::class,
                    Node\Expression\ScopedPropertyAccessExpression::class,
                    Node\QualifiedName::class
                );
            } elseif ($node instanceof Node\Expression\ObjectCreationExpression) {
                $argumentExpressionList = $node->getFirstChildNode(Node\DelimitedList\ArgumentExpressionList::class);
                $callingNode = $node->classTypeDesignator;
                if (!$callingNode instanceof Node\QualifiedName) {
                    // We only support constructing from a QualifiedName
                    return null;
                }
                // Manually build the __construct fqn
                $fqn = $this->definitionResolver->resolveReferenceNodeToFqn($callingNode);
                $fqn = "{$fqn}->__construct()";
            }

            if (!$callingNode) {
                return null;
            }

            // Now find the definition of the call
            $fqn = $fqn ?: DefinitionResolver::getDefinedFqn($callingNode);
            while (true) {
                if ($fqn) {
                    $def = $this->index->getDefinition($fqn);
                } else {
                    $def = $this->definitionResolver->resolveReferenceNodeToDefinition($callingNode);
                }
                if ($def !== null || $this->index->isComplete()) {
                    break;
                }
                yield waitForEvent($this->index, 'definition-added');
            }

            if (!$def) {
                return null;
            }

            return [$def, $argumentExpressionList];
        });
    }
934381
protected function processNodeResult(Node $node)
    {
        $ret = false;
        $name = $node->getName();
        if (isset($this->nodeResults[$name])) {
            foreach ($this->nodeResults[$name] as $resultInfo) {
                /* @var $resultInfo NodeActionCommand */
                if ($resultInfo->appliesTo($node)) {
                    if ($resultInfo->isActionHangup()) {
                        $this->logDebug("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'];
                        }
                        $this->logDebug("Jumping from $name to $nodeName");
                        $ret = $nodeName;
                        break;
                    } elseif ($resultInfo->isActionExecute()) {
                        $this->logDebug("Executing callback after $name");
                        $data = $resultInfo->getActionData();
                        $callback = $data['callback'];
                        $callback($node);
                    }
                }
            }
        }
        return $ret;
    }
739564
public static function get_ancestors( \DOMNode $node ) {
		$result = [];

		while ( ( $node = $node->parentNode ) && ( $node instanceof \DOMElement ) ) { // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
			$result[] = $node;
		}

		return $result;
	}
76910
protected function getIdsForTree($tree)
    {
        $ids = [];

        foreach ($tree as $key => $item) {
            $ids[] = $item['id'];

            /** @noinspection SlowArrayOperationsInLoopInspection */
            $ids = array_merge($ids, $this->getIdsForTree($tree[$key]['__children']));
        }

        return $ids;
    }
676688
private function getNodeIndex( $node )
	{
		for( $i=0; $i<$this->count(); $i++ )
			if( $this->nodes[$i] == $node )
				return $i;
		return NULL;
	}
886999
public function processNodes(DOMNode $node)
    {
        // get all link nodes
        $allLinkNodes = $this->xp->query('.//a', $node);
        $allLinkNodesSortedByLength = [];
        foreach ($allLinkNodes as $linkNode) {
            $allLinkNodesSortedByLength[] = [
                'href' => $linkNode->getAttribute('href'),
                'node' => $linkNode,
            ];
        }

        // sort by link-length
        usort(
            $allLinkNodesSortedByLength,
            function ($a, $b) {
                $lengthA = strlen($a['href']);
                $lengthB = strlen($b['href']);
                if ($lengthA == $lengthB) {
                    return 0;
                }

                return ($lengthA < $lengthB) ? 1 : -1;
            }
        );

        // set best matching link node to active, all ancestors to open
        $requestedUri = $this->requestedUri;
        while (DIRECTORY_SEPARATOR !== $requestedUri) {
            foreach ($allLinkNodesSortedByLength as $currentLinkNode) {
                if ($currentLinkNode['href'] === $requestedUri) {
                    $currentLinkNode['node']->setAttribute('class', trim($currentLinkNode['node']->getAttribute('class').' '.self::CLASS_ACTIVE));

                    // set nearest li ancestor to active
                    $ancestorListNode = $this->xp->query('./ancestor::li', $currentLinkNode['node'])->item(
                        $this->xp->query('./ancestor::li', $currentLinkNode['node'])->length - 1
                    );
                    $ancestorListNode->setAttribute('class', trim($ancestorListNode->getAttribute('class').' '.self::CLASS_ACTIVE));

                    // set all other li ancestors to open and all links inside them to open
                    $remainingAncestorListNodes = $this->xp->query('ancestor::li', $ancestorListNode);
                    foreach ($remainingAncestorListNodes as $remainingAncestorListNode) {
                        $remainingAncestorListNode->setAttribute('class', trim($remainingAncestorListNode->getAttribute('class').' '.self::CLASS_OPEN));
                        $descendantAnchorNode = $this->xp->query('descendant::a', $remainingAncestorListNode)->item(0);
                        $descendantAnchorNode->setAttribute('class', trim($descendantAnchorNode->getAttribute('class').' '.self::CLASS_OPEN));
                    }

                    return;
                }
            }
            $requestedUri = dirname($requestedUri);
        }

        return false;
    }
658154
public function logListAction(ResourceNode $node)
    {
        $resource = $this->resourceManager->getResourceFromNode($node);
        $collection = new ResourceCollection([$node]);
        $this->checkAccess('ADMINISTRATE', $collection);

        return [
            'workspace' => $node->getWorkspace(),
            '_resource' => $resource,
            'actions' => $this->eventManager->getEventsForApiFilter(LogGenericEvent::DISPLAYED_WORKSPACE),
        ];
    }
87233
private function processNode(array $node): array
    {
        $config = [];
        foreach ($node as $name => $value) {
            if (\preg_match('/^num__([0-9]+)$/', $name, $matches)) {
                $name = $matches[1];
            }
            if (\count($nameEx = \explode('.', $name)) > 1) {
                $name = \array_shift($nameEx);
                $mergeBase = isset($config[$name]) ? $config[$name] : [];
                $mergeWith = $this->processNode([\implode('.', $nameEx) => $value]);
                $config[$name] = \array_merge_recursive($mergeBase, $mergeWith);
            } elseif (\is_array($value)) {
                $config[$name] = $this->processNode($value);
            } else {
                $config[$name] = $this->castValue((string)$value);
            }
        }
        return $config;
    }
1237845
public function toArray(\Closure $prepare = null, array &$tree = null)
    {
        if (null === $prepare) {
            $prepare = function(NodeInterface $node) {
                return (string) $node;
            };
        }
        if (null === $tree) {
            $tree = array($this->getNodeId() => array('node' => $prepare($this), 'children' => array()));
        }

        foreach ($this->getChildNodes() as $node) {
            $tree[$this->getNodeId()]['children'][$node->getNodeId()] = array('node' => $prepare($node), 'children' => array());
            $node->toArray($prepare, $tree[$this->getNodeId()]['children']);
        }

        return $tree;
    }
983412
public function processNode(Node $node, Scope $scope): array
    {
        if (0 === \count($node->params)) {
            return [];
        }

        $params = \array_filter($node->params, static function (Node\Param $node): bool {
            if (!$node->default instanceof Node\Expr\ConstFetch) {
                return false;
            }

            return 'null' === $node->default->name->toLowerString();
        });

        if (0 === \count($params)) {
            return [];
        }

        return \array_map(static function (Node\Param $node): string {
            /** @var Node\Expr\Variable $variable */
            $variable = $node->var;

            /** @var string $parameterName */
            $parameterName = $variable->name;

            return \sprintf(
                'Closure has parameter $%s with null as default value.',
                $parameterName
            );
        }, $params);
    }
10121
protected function getSubtree($node, $depth = 0)
    {
        // Check if this node is limited due to child count
        $numChildren = $this->getNumChildren($node);
        $limited = $this->isNodeLimited($node, $numChildren);

        // Build root rode
        $expanded = $this->isExpanded($node);
        $opened = $this->isTreeOpened($node);
        $count = ($limited && $numChildren > $this->getMaxChildNodes()) ? 0 : $numChildren;
        $output = [
            'node' => $node,
            'marked' => $this->isMarked($node),
            'expanded' => $expanded,
            'opened' => $opened,
            'depth' => $depth,
            'count' => $count, // Count of DB children
            'limited' => $limited, // Flag whether 'items' has been limited
            'children' => [], // Children to return in this request
        ];

        // Don't iterate children if past limit
        // or not expanded (requires subsequent request to get)
        if ($limited || !$expanded) {
            return $output;
        }

        // Get children
        $children = $this->getChildren($node);
        foreach ($children as $child) {
            // Recurse
            if ($this->isMarked($child)) {
                $output['children'][] = $this->getSubtree($child, $depth + 1);
            }
        }
        return $output;
    }
470207
public function leaveNode(Node $node)
    {
        if ($node instanceof Use_) {
            // Store a reference to every "use" statement, because we'll need
            // them in a bit.
            foreach ($node->uses as $use) {
                $alias = $use->alias ?: \end($use->name->parts);
                $this->aliases[\strtolower($alias)] = $use->name;
            }

            return NodeTraverser::REMOVE_NODE;
        } elseif ($node instanceof GroupUse) {
            // Expand every "use" statement in the group into a full, standalone
            // "use" and store 'em with the others.
            foreach ($node->uses as $use) {
                $alias = $use->alias ?: \end($use->name->parts);
                $this->aliases[\strtolower($alias)] = Name::concat($node->prefix, $use->name, [
                    'startLine' => $node->prefix->getAttribute('startLine'),
                    'endLine'   => $use->name->getAttribute('endLine'),
                ]);
            }

            return NodeTraverser::REMOVE_NODE;
        } elseif ($node instanceof Namespace_) {
            // Start fresh, since we're done with this namespace.
            $this->lastNamespace = $node->name;
            $this->lastAliases   = $this->aliases;
            $this->aliases       = [];
        } else {
            foreach ($node as $name => $subNode) {
                if ($subNode instanceof Name) {
                    // Implicitly thunk all aliases.
                    if ($replacement = $this->findAlias($subNode)) {
                        $node->$name = $replacement;
                    }
                }
            }

            return $node;
        }
    }
1166634
public function getLanguagesForNode(NodeInterface $node)
    {
        $languages = [];
        foreach ($node->getProperties() as $property) {
            /* @var PropertyInterface $property */
            preg_match('/^' . $this->languageNamespace . ':([a-zA-Z_]*?)-changer/', $property->getName(), $matches);

            if ($matches) {
                $languages[$matches[1]] = $matches[1];
            }
        }

        return array_values($languages);
    }
927665
protected function findNodeIndex(Node $node)
    {

        foreach ($this->data as $i=>$added) {
            if ($added->getId() == $node->getId()) {
                return $i;
            }
        }

        // Not found? try it by spl_object_hash
        $nodeHash = spl_object_hash($node);

        foreach ($this->data as $i=>$added) {
            if (spl_object_hash($added) == $nodeHash) {
                return $i;
            }
        }

        return null;

    }
848074
protected function getChildren(DataObject $node)
    {
        $method = $this->getChildrenMethod();
        return $node->$method() ?: ArrayList::create();
    }
385877
public function leaveNode(Node $node)
    {
        if ($node instanceof Stmt\GroupUse) {
            $nodes = [];
            foreach ($node->uses as $use) {
                $name = Name::concat($node->prefix, $use->name);
                $nodes[] = new Stmt\Use_([new Stmt\UseUse($name)]);
            }
            return $nodes;
        }
    }