Beans_Lessc::findBlocks PHP Method

findBlocks() protected method

attempt to find blocks matched by path and args
protected findBlocks ( $searchIn, $path, $orderedArgs, $keywordArgs, $seen = [] )
    protected function findBlocks($searchIn, $path, $orderedArgs, $keywordArgs, $seen = array())
    {
        if ($searchIn == null) {
            return null;
        }
        if (isset($seen[$searchIn->id])) {
            return null;
        }
        $seen[$searchIn->id] = true;
        $name = $path[0];
        if (isset($searchIn->children[$name])) {
            $blocks = $searchIn->children[$name];
            if (count($path) == 1) {
                $matches = $this->patternMatchAll($blocks, $orderedArgs, $keywordArgs, $seen);
                if (!empty($matches)) {
                    // This will return all blocks that match in the closest
                    // scope that has any matching block, like lessjs
                    return $matches;
                }
            } else {
                $matches = array();
                foreach ($blocks as $subBlock) {
                    $subMatches = $this->findBlocks($subBlock, array_slice($path, 1), $orderedArgs, $keywordArgs, $seen);
                    if (!is_null($subMatches)) {
                        foreach ($subMatches as $sm) {
                            $matches[] = $sm;
                        }
                    }
                }
                return count($matches) > 0 ? $matches : null;
            }
        }
        if ($searchIn->parent === $searchIn) {
            return null;
        }
        return $this->findBlocks($searchIn->parent, $path, $orderedArgs, $keywordArgs, $seen);
    }