[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/config/properties.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/file/file.class.php" ); 5 6 /** 7 * \ingroup File 8 * 9 * Extends the class Properties so that it can read the values 10 * from a file, which has the format 'name = value'. This class is not used 11 * anywhere anymore but has been left for compatibility reasons. 12 */ 13 class FileProperties extends Properties 14 { 15 16 var $_file; 17 var $_contents; 18 19 // regexps used to match the strings that are comments 20 var $_commentRegExps = Array( 1 => "/^\/\/\s*(.*)/i", 21 2 => "/^#\s*(.*)/i", 22 3 => "/^\/\*(.*)\*\//i" ); 23 24 /** 25 * Constructor of the class 26 * 27 * @param fileName Name of the file where data will be loaded from. 28 */ 29 function FileProperties( $fileName ) 30 { 31 $this->Properties(); 32 33 $this->_file = new File( $fileName ); 34 35 $this->_load(); 36 37 $this->_process(); 38 } 39 40 /** 41 * Loads the contents from the file, parses them and puts them 42 * into values 43 * 44 * @private 45 */ 46 function _load() 47 { 48 // open and load the contents of the file 49 $this->_file->open( "r" ); 50 51 $this->_contents = $this->_file->readFile(); 52 } 53 54 /** 55 * @private 56 */ 57 function _removeBlanks( $string, $where = 1 ) 58 { 59 if( $where == 1 ) { // remove from the beginning 60 $string = preg_replace( "/^( +)/", "", $string ); 61 } 62 if( $where == 2 ) { // remove from the end 63 $string = preg_replace( "/( +)$/", "", $string ); 64 } 65 66 return $string; 67 } 68 69 /** 70 * Returns true if the specified line is a comment or not 71 * 72 * @private 73 */ 74 function _isComment( $line ) 75 { 76 foreach( $this->_commentRegExps as $regexp ) { 77 if( preg_match( $regexp, $line )) 78 return true; 79 } 80 81 return false; 82 } 83 84 /** 85 * @private 86 */ 87 function _isNumber( $string ) 88 { 89 return is_numeric( $string ); 90 } 91 92 /** 93 * Parses the lines of the file. 94 * The following characters are considered to be comments, and can only 95 * appear in the beginning of the line: 96 * //, # 97 * 98 * The rest of the lines must either be empty or have the format 99 * key = value 100 * 101 * @private 102 */ 103 function _process() 104 { 105 foreach( $this->_contents as $line ) { 106 // remove blank spaces from the beginning, if any 107 $line = $this->_removeBlanks( $line ); 108 109 // if not empty, we deal with it 110 if( $line != "" ) { 111 // if line starts with any of the characters indicating 112 // coments, we ignore it 113 if( !$this->_isComment( $line )) { 114 // we have to split the line now 115 $parts = explode( "=", $line, 2 ); 116 // eliminate any trailing blank spaces 117 $parts[0] = trim( $parts[0] ); 118 $parts[1] = trim( $parts[1] ); 119 $parts[1] = $this->_removeBlanks( $parts[1] ); 120 121 // detect if it is a number or not 122 if( $this->_isNumber( $parts[1] )) { 123 $value = (int)$parts[1]; 124 $parts[1] = $value; 125 } 126 127 // special handling for the boolean types 128 if( $parts[1] == "true" ) 129 $parts[1] = true; 130 elseif ( $parts[1] == "false" ) 131 $parts[1] = false; 132 133 // and now we save the name and the value 134 $this->setValue( $parts[0], $parts[1] ); 135 } 136 } 137 } 138 } 139 } 140 ?>
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 |
![]() |