source/Application/Model/FileCollector.php
public function addDirectoryFiles($sFolder, $aExtensions = [], $blRecursive = false)
    {
        if (empty($sFolder)) {
            throw new Exception('Parameter $sFolder is empty!');
        }

        if (empty($this->_sBaseDirectory)) {
            throw new Exception('Base directory is not set, please use setter setBaseDirectory!');
        }

        $aCurrentList = [];

        if (!is_dir($this->_sBaseDirectory . $sFolder)) {
            return;
        }

        $handle = opendir($this->_sBaseDirectory . $sFolder);

        while ($sFile = readdir($handle)) {
            if ($sFile != "." && $sFile != "..") {
                if (is_dir($this->_sBaseDirectory . $sFolder . $sFile)) {
                    if ($blRecursive) {
                        $aResultList = $this->addDirectoryFiles($sFolder . $sFile . '/', $aExtensions, $blRecursive);

                        if (is_array($aResultList)) {
                            $aCurrentList = array_merge($aCurrentList, $aResultList);
                        }
                    }
                } else {
                    $sExt = substr(strrchr($sFile, '.'), 1);

                    if ((!empty($aExtensions) && is_array($aExtensions) && in_array($sExt, $aExtensions)) ||
                        (empty($aExtensions))
                    ) {
                        $this->addFile($sFolder . $sFile);
                    }
                }
            }
        }
        closedir($handle);
    }
public function addDirectoryFiles($sFolder, $aExtensions = [], $blRecursive = false)
    {
        if (empty($sFolder)) {
            throw new Exception('Parameter $sFolder is empty!');
        }

        if (empty($this->_sBaseDirectory)) {
            throw new Exception('Base directory is not set, please use setter setBaseDirectory!');
        }

        $aCurrentList = [];

        if (!is_dir($this->_sBaseDirectory . $sFolder)) {
            return;
        }

        $handle = opendir($this->_sBaseDirectory . $sFolder);

        while ($sFile = readdir($handle)) {
            if ($sFile != "." && $sFile != "..") {
                if (is_dir($this->_sBaseDirectory . $sFolder . $sFile)) {
                    if ($blRecursive) {
                        $aResultList = $this->addDirectoryFiles($sFolder . $sFile . '/', $aExtensions, $blRecursive);

                        if (is_array($aResultList)) {
                            $aCurrentList = array_merge($aCurrentList, $aResultList);
                        }
                    }
                } else {
                    $sExt = substr(strrchr($sFile, '.'), 1);

                    if ((!empty($aExtensions) && is_array($aExtensions) && in_array($sExt, $aExtensions)) ||
                        (empty($aExtensions))
                    ) {
                        $this->addFile($sFolder . $sFile);
                    }
                }
            }
        }
        closedir($handle);
    }
public function addDirectoryFiles ( $ sFolder , $ aExtensions = [ ] , $ blRecursive = false ) { if ( empty ( $ sFolder ) ) { throw new Exception ( 'Parameter $sFolder is empty!' ) ; } if ( empty ( $ this -> _sBaseDirectory ) ) { throw new Exception ( 'Base directory is not set, please use setter setBaseDirectory!' ) ; } $ aCurrentList = [ ] ; if ( ! is_dir ( $ this -> _sBaseDirectory . $ sFolder ) ) { return ; } $ handle = opendir ( $ this -> _sBaseDirectory . $ sFolder ) ; while ( $ sFile = readdir ( $ handle ) ) { if ( $ sFile != "." && $ sFile != ".." ) { if ( is_dir ( $ this -> _sBaseDirectory . $ sFolder . $ sFile ) ) { if ( $ blRecursive ) { $ aResultList = $ this -> addDirectoryFiles ( $ sFolder . $ sFile . '/' , $ aExtensions , $ blRecursive ) ; if ( is_array ( $ aResultList ) ) { $ aCurrentList = array_merge ( $ aCurrentList , $ aResultList ) ; } } } else { $ sExt = substr ( strrchr ( $ sFile , '.' ) , 1 ) ; if ( ( ! empty ( $ aExtensions ) && is_array ( $ aExtensions ) && in_array ( $ sExt , $ aExtensions ) ) || ( empty ( $ aExtensions ) ) ) { $ this -> addFile ( $ sFolder . $ sFile ) ; } } } } closedir ( $ handle ) ; }
browse all folders and sub-folders after files which have given extensions

@param string  $sFolder     which is explored
@param array   $aExtensions list of extensions to scan - if empty all files are taken
@param boolean $blRecursive should directories be checked in recursive manner

@throws exception
@return null
browse all folders and sub - folders after files which have given extensions