_onlyFiles = false; $this->_onlyDirs = false; } /** * Sets only files mode. * * @param bool $only_files true if only files should be added to output. */ function setOnlyFiles($only_files) { $this->_onlyFiles = $only_files; } /** * Gets only files mode. * * @return bool true if only files should be added to output. */ function getOnlyFiles() { return $this->_onlyFiles; } /** * Sets only dirs mode. * * @param bool $only_dirs true if only dirs should be added to output. */ function setOnlyDirs($only_dirs) { $this->_onlyDirs = $only_dirs; } /** * Gets only dirs mode. * * @return bool true if only dirs should be added to output. */ function getOnlyDirs() { return $this->_onlyDirs; } /** * Sets the max level to include in tree parse. * * @param int $level max level to include in tree parse. */ function setMaxLevel($level) { $this->_maxLevel = $level; } /** * Sets is the result is to be built in to an array or not. * The result is returned by getFileArray when the tree list completes. * Note: The default value of this state is false. * * @param boolean $state True if the result is to be built in to an array or not. */ function setMakeArray($state) { $this->_makeArray = $state; if ($this->_makeArray) $this->_array = array(); } /** * Returns the tree as an array of MCE_File instances. This method * will not return anything if the setMakeArray isn't set to true. * * @return Array Array of MCE_File instances. */ function &getFileArray() { return $this->_array; } /** * Handles a file instance while looping an tree of directories. * * @param MCE_File $file File object reference * @param int $level Current level of tree parse * @return int State of what to do next can be CONTINUE, ABORT or ABORTFOLDER. */ function handle($file, $level) { $add = true; if (is_array($this->_array) && $this->_onlyDirs && $file->isFile()) $add = false; if (is_array($this->_array) && $this->_onlyFiles && $file->isDir()) $add = false; if ($add) $this->_array[] = $file; if ($this->_maxLevel && $level >= $this->_maxLevel) return $this->ABORT_FOLDER; return $this->CONTINUE; } /**#@-*/ } class Moxiecode_ConfigFilteredFileTreeHandler extends Moxiecode_BasicFileTreeHandler { var $_config; /** * Handles a file instance while looping an tree of directories. * * @param MCE_File $file File object reference * @param int $level Current level of tree parse * @return int State of what to do next can be CONTINUE, ABORT or ABORTFOLDER. */ function handle($file, $level) { if ($file->isDirectory() || !is_array($this->_config)) { if ($level == 0) return parent::handle($file, $level); else $parentFile = $file->getParentFile(); $this->_config = $parentFile->getConfig(); } $filter = new Moxiecode_BasicFileFilter(); $filter->setIncludeFilePattern($this->_config['filesystem.include_file_pattern']); $filter->setExcludeFilePattern($this->_config['filesystem.exclude_file_pattern']); $filter->setIncludeDirectoryPattern($this->_config['filesystem.include_directory_pattern']); $filter->setExcludeDirectoryPattern($this->_config['filesystem.exclude_directory_pattern']); $filter->setOnlyDirs($this->_onlyDirs); if (!$filter->accept($file)) return $this->ABORT_FOLDER; return parent::handle($file, $level); } } ?>