Go to the documentation of this file.00001 <?php
00002
00009 class oxFileCollector
00010 {
00016 protected $_sBaseDirectory;
00017
00023 protected $_aFiles;
00024
00030 public function setBaseDirectory( $sDir )
00031 {
00032 if ( !empty( $sDir ) )
00033 {
00034 $this->_sBaseDirectory = $sDir;
00035 }
00036 }
00037
00043 public function getFiles()
00044 {
00045 return $this->_aFiles;
00046 }
00047
00055 public function addFile( $sFile )
00056 {
00057 if ( empty( $sFile ) ) {
00058 throw new Exception( 'Parameter $sFile is empty!' );
00059 }
00060
00061 if ( empty( $this->_sBaseDirectory ) ) {
00062 throw new Exception( 'Base directory is not set, please use setter setBaseDirectory!' );
00063 }
00064
00065 if ( is_file( $this->_sBaseDirectory . $sFile ) ) {
00066
00067 $this->_aFiles[] = $sFile;
00068 return true;
00069 }
00070
00071 return false;
00072 }
00073
00074
00084 public function addDirectoryFiles( $sFolder, $aExtensions = array(), $blRecursive = false )
00085 {
00086 if ( empty( $sFolder ) ) {
00087 throw new Exception( 'Parameter $sFolder is empty!' );
00088 }
00089
00090 if ( empty( $this->_sBaseDirectory ) ) {
00091 throw new Exception( 'Base directory is not set, please use setter setBaseDirectory!' );
00092 }
00093
00094 $aCurrentList = array();
00095
00096 if (!is_dir( $this->_sBaseDirectory . $sFolder ) ) {
00097 return;
00098 }
00099
00100 $handle = opendir( $this->_sBaseDirectory . $sFolder );
00101
00102 while ( $sFile = readdir( $handle ) ){
00103
00104 if ( $sFile != "." && $sFile != "..") {
00105 if ( is_dir( $this->_sBaseDirectory . $sFolder . $sFile ) ) {
00106 if ( $blRecursive ) {
00107 $aResultList = $this->addDirectoryFiles( $sFolder . $sFile . '/', $aExtensions, $blRecursive );
00108
00109 if ( is_array( $aResultList ) ) {
00110 $aCurrentList = array_merge( $aCurrentList, $aResultList );
00111 }
00112 }
00113 }
00114 else
00115 {
00116 $sExt = substr( strrchr( $sFile, '.'), 1 );
00117
00118 if ( ( !empty( $aExtensions ) && is_array( $aExtensions ) && in_array( $sExt, $aExtensions ) ) ||
00119 ( empty( $aExtensions ) ) ) {
00120
00121 $this->addFile( $sFolder . $sFile );
00122 }
00123 }
00124 }
00125 }
00126 closedir( $handle );
00127 }
00128
00129 }