CFile::dirContents PHP Method

dirContents() private method

Gets directory contents (descendant files and folders).
private dirContents ( null | string $directory = null, boolean $recursive = False, null | string $filter = null ) : array
$directory null | string Initial directory to get descendants for
$recursive boolean If 'True' method would return all descendants recursively, otherwise just immediate descendants
$filter null | string Filter to be applied to all directory descendants. Could be a string, or an array of strings (perl regexp are supported, if started with '~'). See {@link filterPassed} method for further information on filters.
return array Array of descendants filepaths
    private function dirContents($directory = null, $recursive = False, $filter = null)
    {
        $descendants = array();
        if (!$directory) {
            $directory = $this->_realpath;
        }
        if ($filter !== null) {
            if (is_string($filter)) {
                $filter = array($filter);
            }
        }
        if ($contents = @scandir($directory . DIRECTORY_SEPARATOR)) {
            foreach ($contents as $key => $item) {
                $contents[$key] = $directory . DIRECTORY_SEPARATOR . $item;
                if (!in_array($item, array('.', '..'))) {
                    if ($this->filterPassed($contents[$key], $filter)) {
                        $descendants[] = $contents[$key];
                    }
                    if (is_dir($contents[$key]) && $recursive) {
                        $descendants = array_merge($descendants, $this->dirContents($contents[$key], $recursive, $filter));
                    }
                }
            }
        } else {
            throw new CFileException('Unable to get directory contents for "' . $directory . DIRECTORY_SEPARATOR . '"');
        }
        return $descendants;
    }