[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 /** 4 * \ingroup File 5 * 6 * given an array with strings and a folder on disk, this class will scan the folder and compare 7 * them with the ones in the array and return which ones from disk do NOT exist in the given array. 8 * In order to get the array with the elements that are new according to our first array, please 9 * use FileFinder::getNew() 10 * @see getNew 11 */ 12 class FileFinder 13 { 14 var $_folder; 15 var $_removed; 16 var $_new; 17 var $_recursive; 18 19 function FileFinder( $folder = '.' ) 20 { 21 $this->_folder = $folder; 22 $this->_removed = Array(); 23 $this->_new = Array(); 24 $this->_recursive = true; 25 } 26 27 /** 28 * given a file, generates a key for it so that it can be checked whether 29 * it really belongs to the $currentList array or not. This is useful in case of when we're 30 * for example looking for new template files and we'd like to know whether locale_en_UK.php 31 * is alreasdy in the list or not... This class can be extended to reimplement getKeyForFile 32 * so that $this->getKeyForFile( "locale_en_UK.php" ) returns "en_UK" and so forth. 33 * By default is returns the same name but if null is returned for a particular file, this 34 * file will be ignored. 35 * 36 * @param fileName tha name of the file 37 * @return the key for the given file. If null is returned, this file will be ignored. 38 */ 39 function getKeyForFile( $fileName ) 40 { 41 return( $fileName ); 42 } 43 44 /** 45 * uses Glob::glob() to find files that match the given format 46 * and compares the file names against the ones already available 47 * 48 * @param currentList 49 * @param fileName 50 */ 51 function find( $currentList, $fileName = '*' ) 52 { 53 lt_include( PLOG_CLASS_PATH.'class/misc/glob.class.php' ); 54 $files = Glob::myGlob( $this->_folder, $fileName ); 55 56 // create an empty array if we got something else other than an array so that 57 // we can avoid some ugly error messages! 58 if( !is_array($currentList)) 59 $currentList = Array(); 60 61 // loop through the files... 62 foreach( $files as $file ) { 63 // get the key for the given file 64 $key = $this->getKeyForFile( $file ); 65 if( $key != null && !in_array( $key, $currentList )) { 66 // the file is new! 67 $this->_new[] = $key; 68 } 69 } 70 71 // and now see which files are new and which ones have been removed, by comparing 72 // both arrays... 73 74 return true; 75 } 76 77 function findBinary( $binary, $searchFolders ) { 78 if( $searchFolders == null ) 79 $searchFolders = Array( $this->_folder ); 80 81 $found = false; 82 $i = 0; 83 while( !$found && $i < count($searchFolders)) { 84 // get the current folder 85 $currentFolder = $searchFolders[$i]; 86 // see if the file's there 87 $fullPath = $currentFolder.$binary; 88 if( File::isReadable( $fullPath )) 89 $found = true; 90 else 91 $i++; 92 } 93 94 if( $found ) 95 return $fullPath; 96 else 97 return ""; 98 } 99 100 /** 101 * returns all the new items that are not in the list that was passed as a parameter to the 102 * FileFinder::find() method 103 * 104 * @return An array with the new items 105 */ 106 function getNew() 107 { 108 return( $this->_new ); 109 } 110 } 111 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |