Jarves\Storage\ViewStorage::getBranch PHP Метод

getBranch() публичный Метод

{@inheritDoc}
public getBranch ( $pk = null, Condition $condition = null, $depth = 1, $scope = null, $options = null )
$condition Jarves\Configuration\Condition
    public function getBranch($pk = null, Condition $condition = null, $depth = 1, $scope = null, $options = null)
    {
        $result = null;
        $path = $pk['path'];
        if ($depth === null) {
            $depth = 1;
        }
        if ($path) {
            $path = '@' . trim($path, '/@');
            $path = str_replace(':', '/', $path);
        }
        $c = 0;
        $offset = $options['offset'];
        $limit = $options['limit'];
        $result = array();
        if (!$path) {
            $result = array();
            $bundles = array_keys($this->jarves->getBundles());
            foreach ($bundles as $bundleName) {
                $directory = $this->jarves->resolvePath('@' . $bundleName, 'Resources/views', true);
                if (!$this->localFilesystem->has($directory)) {
                    continue;
                }
                $file = $this->localFilesystem->getFile($directory);
                if (!$file) {
                    $result[] = $directory;
                    continue;
                }
                $file = $file->toArray();
                $file['name'] = $bundleName;
                $file['path'] = $bundleName;
                if ($offset && $offset > $c) {
                    continue;
                }
                if ($limit && $limit < $c) {
                    continue;
                }
                if ($condition && $condition->hasRules() && !$this->conditionOperator->satisfy($condition, $file)) {
                    $result[] = $directory;
                    continue;
                }
                $c++;
                if ($depth > 0) {
                    $children = self::getBranch(array('path' => $bundleName), $condition, $depth - 1);
                    $file['_childrenCount'] = count($children);
                    if ($depth > 1 && $file['type'] == 'dir') {
                        $file['_children'] = $children;
                    }
                }
            }
        } else {
            if (!($bundleName = $this->jarves->getBundleFromPath($path))) {
                return [];
            }
            $directory = $this->jarves->resolvePath($path, 'Resources/views', true) . '/';
            if (!$this->localFilesystem->has($directory)) {
                return [];
            }
            $files = $this->localFilesystem->getFiles($directory);
            foreach ($files as $file) {
                $item = $file->toArray();
                if ($condition && $condition->hasRules() && !$this->conditionOperator->satisfy($condition, $item, 'jarves/file')) {
                    continue;
                }
                $c++;
                if ($offset && $offset >= $c) {
                    continue;
                }
                if ($limit && $limit < $c) {
                    continue;
                }
                $item = array('name' => $this->buildPath($path . '/' . Tools::getRelativePath($item['path'], $directory)), 'path' => $this->buildPath($path . '/' . Tools::getRelativePath($item['path'], $directory)));
                if ($file->isDir()) {
                    $children = self::getBranch(array('path' => $item['path']), $condition, $depth - 1);
                    foreach ($children as $child) {
                        //                        $child['name'] = $item['name'] . '/' . $child['name'];
                        $result[] = $child;
                    }
                }
                if ($file->isFile()) {
                    $result[] = $item;
                }
            }
        }
        return $result;
    }