Get a parent path the given levels above

@param string $pathname
@param int $depth Number of parents to rise
@return string
14939
protected function upLevels($pathname, $depth)
    {
        if ($depth < 0) {
            return null;
        }
        while ($depth--) {
            $pathname = dirname($pathname);
        }
        return $pathname;
    }
195157
protected function acceptFile($basename, $pathname, $depth)
    {
        if ($regex = $this->getOption('name_regex')) {
            if (!preg_match($regex, $basename)) {
                return false;
            }
        }

        if ($ignore = $this->getOption('ignore_files')) {
            if (in_array($basename, $ignore)) {
                return false;
            }
        }

        if ($minDepth = $this->getOption('min_depth')) {
            if ($depth < $minDepth) {
                return false;
            }
        }

        if ($callback = $this->getOption('accept_callback')) {
            if (!call_user_func($callback, $basename, $pathname, $depth)) {
                return false;
            }
        }

        if ($callback = $this->getOption('accept_file_callback')) {
            if (!call_user_func($callback, $basename, $pathname, $depth)) {
                return false;
            }
        }

        return true;
    }
1357894
public function getLevel()
    {
        if ($this->_level !== null) {
            return $this->_level;
        }

        if ($this->isRoot()) {
            $this->_level = -1;
            return $this->_level;
        }

        $parents = array($this);
        $node = $this;

        while ($parent = $node->getParent()){
            if (!$parent->isRoot()) {
                $parents[] = $parent;
            }
            $node = $parent;
        }

        $this->_level = count($parents);

        return $this->_level;
    }
1077913
static public function getRuntimePath($depth = 2)
    {
        $stack = debug_backtrace();
        $frame = $stack[count($stack) - $depth];
        return dirname($frame['file']);
    }
1040232
def prevparent(self, parent, depth):
        '''
        
        '''
        pdir = os.path.dirname(self.name)
        if depth > 1:  # can't jump to parent of root node!
            for c, d in parent.traverse():
                if c.name == self.name:
                    break
                if c.name.startswith(pdir):
                    parent.curline -= 1
        else:  # otherwise jus skip to previous directory
            pdir = self.name
            # - 1 otherwise hidden parent node throws count off & our
            # self.curline doesn't change!
            line = -1
            for c, d in parent.traverse():
                if c.name == self.name:
                    break
                if os.path.isdir(c.name) and c.name in parent.children[0:]:
                    parent.curline = line
                line += 1
        return pdir
782094
protected function acceptDir($basename, $pathname, $depth)
    {
        if ($regex = $this->getOption('dir_regex')) {
            if (!preg_match($regex, $basename)) {
                return false;
            }
        }

        if ($this->getOption('ignore_vcs') && in_array($basename, self::$vcs_dirs)) {
            return false;
        }

        if ($ignore = $this->getOption('ignore_dirs')) {
            if (in_array($basename, $ignore)) {
                return false;
            }
        }

        if ($max = $this->getOption('max_depth')) {
            if ($depth > $max) {
                return false;
            }
        }

        if ($callback = $this->getOption('accept_callback')) {
            if (!call_user_func($callback, $basename, $pathname, $depth)) {
                return false;
            }
        }

        if ($callback = $this->getOption('accept_dir_callback')) {
            if (!call_user_func($callback, $basename, $pathname, $depth)) {
                return false;
            }
        }

        return true;
    }
318148
private function findInitialWrongDepthGap()
    {
        // get nodes where difference to parents depth > 1
        $qb = $this->accountRepository->createQueryBuilder('c2')
            ->select('count(c2.id) as results')
            ->join('c2.parent', 'c1')
            ->where('(c2.depth - 1) <> c1.depth');
        $depthGapResult = $qb->getQuery()->getSingleScalarResult();

        return $depthGapResult;
    }
800079
function(depth) {
        if (depth >= this.depth || depth < 0)  {
            this.logger.log("illegal getAncestor depth: " + depth);
            return null;
        }

        var p = this.parent;
        
        while (p.depth > depth) {
            p = p.parent;
        }

        return p;
    }
941358
public function menuNodeHierarchy($depth = 10)
    {
        if ($depth == 0) {
            return $this;
        }

        return $this
            ->prototype('array')
                ->children()
                    ->scalarNode('route')->end()
                    ->arrayNode('routeParameters')
                        ->prototype('variable')
                        ->end()
                    ->end()
                    ->scalarNode('uri')->end()
                    ->scalarNode('label')->end()
                    ->booleanNode('display')->defaultTrue()->end()
                    ->booleanNode('displayChildren')->defaultTrue()->end()
                    ->integerNode('order')->end()
                    ->arrayNode('attributes')
                        ->prototype('variable')
                        ->end()
                    ->end()
                    ->arrayNode('linkAttributes')
                        ->prototype('variable')
                        ->end()
                    ->end()
                    ->arrayNode('childrenAttributes')
                        ->prototype('variable')
                        ->end()
                    ->end()
                    ->arrayNode('labelAttributes')
                        ->prototype('variable')
                        ->end()
                    ->end()
                    ->arrayNode('roles')
                        ->prototype('scalar')
                        ->end()
                    ->end()
                    ->arrayNode('extras')
                        ->prototype('scalar')
                        ->end()
                    ->end()
                    ->menuNode('children')->menuNodeHierarchy($depth - 1)
                ->end()
            ->end();
    }
1267378
public function getParents($depth = null)
    {
        /** @var \yii\db\ActiveQuery|MaterializedPathQueryTrait $query */
        $query = $this->owner->find();
        return $query->parentsOf($this->owner, $depth);
    }
117773
protected function getRelativePath($path1,$path2)
	{
		$segs1=explode(DIRECTORY_SEPARATOR,$path1);
		$segs2=explode(DIRECTORY_SEPARATOR,$path2);
		$n1=count($segs1);
		$n2=count($segs2);

		for($i=0;$i<$n1 && $i<$n2;++$i)
		{
			if($segs1[$i]!==$segs2[$i])
				break;
		}

		if($i===0)
			return "'".$path1."'";
		$up='';
		for($j=$i;$j<$n2-1;++$j)
			$up.='/..';
		for(;$i<$n1-1;++$i)
			$up.='/'.$segs1[$i];

		return 'dirname(__FILE__).\''.$up.'/'.basename($path1).'\'';
	}
519856
public function getDescendants($depth = null)
    {
        if(!$this->hasChildren())
        {
            return array();
        }

        if($this->descendants === null)
        {
            $qb = $this->getManager()->getConfiguration()->getBaseQueryBuilder();
            $alias = $this->getManager()->getConfiguration()->getQueryBuilderAlias();

            $qb->andWhere("$alias.".$this->getLeftFieldName()." > :lft1")
                ->setParameter('lft1', $this->getLeftValue())
                ->andWhere("$alias.".$this->getRightFieldName()." < :rgt1")
                ->setParameter('rgt1', $this->getRightValue())
                ->orderBy("$alias.".$this->getLeftFieldName(), "ASC");
            if($this->hasManyRoots())
            {
                $qb->andWhere("$alias.".$this->getRootFieldName()." = :root")
                    ->setParameter('root', $this->getRootValue());
            }

            // TODO: Add depth support or self join support?
			$q = $qb->getQuery();
			if ($this->getManager()->getConfiguration()->isQueryHintSet()){
				$q = $this->getManager()->addHintToQuery($q);
			}
            $results = $q->getResult();

            $this->descendants = array();
            foreach($results as $result)
            {
                $this->descendants[] = $this->getManager()->wrapNode($result);
            }
        }

        if($depth !== null)
        {
            // TODO: Don't rebuild filtered array everytime?
            return $this->getManager()->filterNodeDepth($this->descendants, $depth);
        }

        return $this->descendants;
    }
495357
public function findChildren(callable $callback, $depth = null, $level = null)
    {

        $level = $level ?: 0;

        foreach ($this->children as $child) {

            /** @var NodeInterface $child */
            if ($child->is($callback))
                yield $child;

            if ($depth === null || $level < $depth) {

                if ($child instanceof NodeInterface)
                    foreach ($child->findChildren($callback, $depth, $level + 1) as $subChild)
                        yield $subChild;
            }
        }
    }
130937
public function handleDirectory($basename, $pathname, $depth)
    {
        if ($basename !== self::TEMPLATES_DIR) {
            return;
        }
        $dir = trim(substr(dirname($pathname), strlen($this->base)), '/\\');
        $this->themes[] = "/" . $dir;
    }
84742
protected function traverseRecursively(string $path, int $depth = 0)
    {
        if ($depth > $this->maxDepth) {
            return;
        }

        /**
         * @throws \UnexpectedValueException
         */
        $iterator = new \FilesystemIterator(
            $path,
            \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS
            | ($this->skipSymLinks ? 0 : \FilesystemIterator::FOLLOW_SYMLINKS)
        );

        foreach ($iterator as $item) {
            $filename = $item->getFilename();

            $is_dir = $item->isDir();

            if ($is_dir == $this->dirs && $this->filter($item)) {
                if (!$this->requireUnique) {
                    if (!$this->itemValue) {
                        $this->append($item->getPathname());
                    }
                    else {
                        // Pathnames are key if itemValue and not requireUnique.
                        $this->offsetSet(
                            $item->getPathname(),
                            call_user_func_array($this->itemValue, [$item])
                        );
                    }
                }
                // Filenames are keys if requireUnique.
                elseif ($this->offsetExists($filename)) {
                    throw new FileNonUniqueException(
                        'Non-unique ' . (!$this->dirs ? 'filename' : 'dirname') . '[' . $filename
                        . '] found in paths [' . $this->offsetGet($filename) . ']'
                        . ' and [' . $item->getPathname() . '].'
                    );
                }
                else {
                    $this->offsetSet(
                        // Filenames are keys if requireUnique.
                        $filename,
                        !$this->itemValue ? $item->getPathname() : call_user_func_array($this->itemValue, [$item])
                    );
                }

                // If directory and not set to traverse matching dir.
                if ($is_dir && $this->dirs == 1) {
                    continue;
                }
            }
            elseif ($is_dir && !$this->traverseHidden && $filename{0} == '.') {
                continue;
            }

            if ($is_dir) {
                $pathname = $item->getPathname();
                if (!$this->skipUnreadable || is_readable($pathname)) {
                    $this->traverseRecursively($pathname, $depth + 1);
                }
            }
        }
    }
630164
public function isInsideVendor($basename, $pathname, $depth)
    {
        $base = basename($this->upLevels($pathname, $depth - 1));
        return $base === self::VENDOR_DIR;
    }
765174
public static function getTravelPath($from, $to)
    {
        $from = explode(DS, $from);
        $to = explode(DS, $to);

        $relPath = $to;

        foreach ($from as $depth => $dir) {
            // find first non-matching dir
            if ($dir === $to[$depth]) {
                // ignore this directory
                array_shift($relPath);
            } else {
                // get number of remaining dirs to $from
                $remaining = count($from) - ($depth - 1);
                if ($remaining > 1) {
                    // add traversals up to first matching dir
                    $padLength = (count($relPath) + $remaining - 1) * -1;
                    $relPath = array_pad($relPath, $padLength, '..');
                    break;
                } else {
                    $relPath[0] = './'.$relPath[0];
                }
            }
        }

        return implode('/', $relPath);
    }