Changeset 827
- Timestamp:
- 03/21/08 00:19:16 (10 months ago)
- Files:
-
- trunk/lib/jelix/installer/jInstallerBase.class.php (modified) (1 diff)
- trunk/lib/jelix/installer/jInstallerBase.class.php (modified) (1 diff)
- trunk/lib/jelix/installer/jInstallerBase.class.php (modified) (1 diff)
- trunk/lib/jelix/utils/jIniFileModifier.class.php (modified) (8 diffs)
- trunk/lib/jelix/utils/jIniFileModifier.class.php (modified) (8 diffs)
- trunk/lib/jelix/utils/jIniFileModifier.class.php (modified) (8 diffs)
- trunk/testapp/modules/jelix_tests/tests/utils.jinifilemodifier.html_cli.php (modified) (4 diffs)
- trunk/testapp/modules/jelix_tests/tests/utils.jinifilemodifier.html_cli.php (modified) (4 diffs)
- trunk/testapp/modules/jelix_tests/tests/utils.jinifilemodifier.html_cli.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/jelix/installer/jInstallerBase.class.php
r824 r827 60 60 /** 61 61 * @param string $filename relative path to the var/config directory 62 * 62 * @return jIniFileModifier 63 63 */ 64 64 function getConfig($filename) { 65 throw new Exception("copyDirectoryContent not implemented");65 return new jIniFileModifier(JELIX_APP_CONFIG_PATH.$filename); 66 66 } 67 67 68 68 /** 69 69 * @param string $path relative path to the install directory 70 * @param string $target 'www' for the www path70 * @param string $target 71 71 */ 72 72 function copyDirectoryContent($path, $target) { 73 73 throw new Exception("copyDirectoryContent not implemented"); 74 /*$currentTarget = $target; 75 $dir = new DirectoryIterator($this->basePath.$path); 76 foreach ($dir as $dirContent) { 77 if ($dirContent->isFile()) { 78 copy($dirContent->getPathName(),$currentTarget.'/'.); 79 } else { 80 // recursive directory deletion 81 if (!$dirContent->isDot() && $dirContent->isDir()) { 82 $this->copyDirectoryContent($dirContent->getPathName()); 83 } 84 } 85 } 74 86 } 75 87 } trunk/lib/jelix/installer/jInstallerBase.class.php
r824 r827 60 60 /** 61 61 * @param string $filename relative path to the var/config directory 62 * 62 * @return jIniFileModifier 63 63 */ 64 64 function getConfig($filename) { 65 throw new Exception("copyDirectoryContent not implemented");65 return new jIniFileModifier(JELIX_APP_CONFIG_PATH.$filename); 66 66 } 67 67 68 68 /** 69 69 * @param string $path relative path to the install directory 70 * @param string $target 'www' for the www path70 * @param string $target 71 71 */ 72 72 function copyDirectoryContent($path, $target) { 73 73 throw new Exception("copyDirectoryContent not implemented"); 74 /*$currentTarget = $target; 75 $dir = new DirectoryIterator($this->basePath.$path); 76 foreach ($dir as $dirContent) { 77 if ($dirContent->isFile()) { 78 copy($dirContent->getPathName(),$currentTarget.'/'.); 79 } else { 80 // recursive directory deletion 81 if (!$dirContent->isDot() && $dirContent->isDir()) { 82 $this->copyDirectoryContent($dirContent->getPathName()); 83 } 84 } 85 } 74 86 } 75 87 } trunk/lib/jelix/installer/jInstallerBase.class.php
r824 r827 60 60 /** 61 61 * @param string $filename relative path to the var/config directory 62 * 62 * @return jIniFileModifier 63 63 */ 64 64 function getConfig($filename) { 65 throw new Exception("copyDirectoryContent not implemented");65 return new jIniFileModifier(JELIX_APP_CONFIG_PATH.$filename); 66 66 } 67 67 68 68 /** 69 69 * @param string $path relative path to the install directory 70 * @param string $target 'www' for the www path70 * @param string $target 71 71 */ 72 72 function copyDirectoryContent($path, $target) { 73 73 throw new Exception("copyDirectoryContent not implemented"); 74 /*$currentTarget = $target; 75 $dir = new DirectoryIterator($this->basePath.$path); 76 foreach ($dir as $dirContent) { 77 if ($dirContent->isFile()) { 78 copy($dirContent->getPathName(),$currentTarget.'/'.); 79 } else { 80 // recursive directory deletion 81 if (!$dirContent->isDot() && $dirContent->isDir()) { 82 $this->copyDirectoryContent($dirContent->getPathName()); 83 } 84 } 85 } 74 86 } 75 87 } trunk/lib/jelix/utils/jIniFileModifier.class.php
r824 r827 28 28 protected $filename = ''; 29 29 30 /** 31 * load the given ini file 32 * @param string $filename the file to load 33 */ 30 34 function __construct($filename) { 31 35 if(!file_exists($filename)) … … 35 39 } 36 40 37 41 /** 42 * parsed the lines of the ini file 43 */ 38 44 protected function parse($lines) { 39 45 $this->content = array(0=>array()); … … 52 58 } else if(preg_match('/^\s*([a-z0-9_.-]+)(\[([a-z0-9_.-]*)\])?\s*=\s*(")?([^"]*)(")?(\s*)/i', $line, $m)) { 53 59 list($all, $name, $foundkey, $key, $firstquote, $value ,$secondquote,$lastspace) = $m; 60 54 61 if($foundkey !='') 55 62 $currentValue = array(self::TK_ARR_VALUE, $name, $value, $key); … … 79 86 } 80 87 88 /** 89 * modify an option in the ini file. If the option doesn't exist, 90 * it is created. 91 * @param string $name the name of the option to modify 92 * @param string $value the new value 93 * @param string $section the section where to set the item. 0 is the global section 94 * @param string $key for option which is an item of array, the key in the array 95 */ 81 96 public function setValue($name, $value, $section=0, $key=null) { 82 97 $foundValue=false; 83 98 if(isset($this->content[$section])) { 99 $deleteMode = false; 84 100 foreach ($this->content[$section] as $k =>$item) { 101 if($deleteMode) { 102 if( $item[0] == self::TK_ARR_VALUE && $item[1] == $name ) 103 $this->content[$section][$k] = array(self::TK_WS,''); 104 continue; 105 } 85 106 if( ($item[0] != self::TK_VALUE && $item[0] != self::TK_ARR_VALUE) 86 107 || $item[1] != $name) … … 90 111 continue; 91 112 } 92 $item[2] = $value; 93 $this->content[$section][$k]=$item; 113 if($key !== null) { 114 $this->content[$section][$k]=array(self::TK_ARR_VALUE,$name,$value, $key); 115 } else { 116 $this->content[$section][$k]=array(self::TK_VALUE,$name,$value); 117 if($item[0] == self::TK_ARR_VALUE) { 118 $deleteMode = true; 119 $foundValue = true; 120 continue; 121 } 122 } 94 123 $foundValue=true; 95 124 break; 96 125 } 126 }else{ 127 $this->content[$section] = array(array(self::TK_SECTION, '['.$section.']')); 97 128 } 98 129 if(!$foundValue) { … … 105 136 } 106 137 107 public function getValue($name) { 108 throw Exception('Not implemented'); 109 } 110 138 /** 139 * return the value of an option in the ini file. If the option doesn't exist, 140 * it returns null. 141 * @param string $name the name of the option to retrieve 142 * @param string $section the section where the option is. 0 is the global section 143 * @param string $key for option which is an item of array, the key in the array 144 * @return mixed the value 145 */ 146 public function getValue($name, $section=0, $key=null) { 147 if(!isset($this->content[$section])) { 148 return null; 149 } 150 foreach ($this->content[$section] as $k =>$item) { 151 if( ($item[0] != self::TK_VALUE && $item[0] != self::TK_ARR_VALUE) 152 || $item[1] != $name) 153 continue; 154 if($item[0] == self::TK_ARR_VALUE && $key !== null){ 155 if($item[3] != $key) 156 continue; 157 } 158 159 if (preg_match('/^-?[0-9]$/', $item[2])) { 160 return intval($item[2]); 161 } 162 else if (preg_match('/^-?[0-9\.]$/', $item[2])) { 163 return floatval($item[2]); 164 } 165 else if (strtolower($item[2]) === 'true' || strtolower($item[2]) === 'on') { 166 return true; 167 } 168 else if (strtolower($item[2]) === 'false' || strtolower($item[2]) === 'off') { 169 return false; 170 } 171 return $item[2]; 172 } 173 return null; 174 } 175 176 /** 177 * save the ini file 178 */ 111 179 public function save() { 112 180 file_put_contents($this->filename, $this->generateIni()); 113 181 } 114 182 183 /** 184 * save the content in an new ini file 185 * @param string $filename the name of the file 186 */ 115 187 public function saveAs($filename) { 116 188 file_put_contents($filename, $this->generateIni()); … … 123 195 switch($item[0]) { 124 196 case self::TK_SECTION: 125 if($item[1] != 0)197 if($item[1] != '0') 126 198 $content.=$item[1]."\n"; 127 199 break; … … 141 213 return $content; 142 214 } 143 215 144 216 protected function getIniValue($value) { 145 217 if ($value === '' || is_numeric($value) || preg_match("/^[\w]*$/", $value) || strpos("\n",$value) === false ) { 146 $value = $item[2];218 return $value; 147 219 }else if($value === false) { 148 220 $value="0"; trunk/lib/jelix/utils/jIniFileModifier.class.php
r824 r827 28 28 protected $filename = ''; 29 29 30 /** 31 * load the given ini file 32 * @param string $filename the file to load 33 */ 30 34 function __construct($filename) { 31 35 if(!file_exists($filename)) … … 35 39 } 36 40 37 41 /** 42 * parsed the lines of the ini file 43 */ 38 44 protected function parse($lines) { 39 45 $this->content = array(0=>array()); … … 52 58 } else if(preg_match('/^\s*([a-z0-9_.-]+)(\[([a-z0-9_.-]*)\])?\s*=\s*(")?([^"]*)(")?(\s*)/i', $line, $m)) { 53 59 list($all, $name, $foundkey, $key, $firstquote, $value ,$secondquote,$lastspace) = $m; 60 54 61 if($foundkey !='') 55 62 $currentValue = array(self::TK_ARR_VALUE, $name, $value, $key); … … 79 86 } 80 87 88 /** 89 * modify an option in the ini file. If the option doesn't exist, 90 * it is created. 91 * @param string $name the name of the option to modify 92 * @param string $value the new value 93 * @param string $section the section where to set the item. 0 is the global section 94 * @param string $key for option which is an item of array, the key in the array 95 */ 81 96 public function setValue($name, $value, $section=0, $key=null) { 82 97 $foundValue=false; 83 98 if(isset($this->content[$section])) { 99 $deleteMode = false; 84 100 foreach ($this->content[$section] as $k =>$item) { 101 if($deleteMode) { 102 if( $item[0] == self::TK_ARR_VALUE && $item[1] == $name ) 103 $this->content[$section][$k] = array(self::TK_WS,''); 104 continue; 105 } 85 106 if( ($item[0] != self::TK_VALUE && $item[0] != self::TK_ARR_VALUE) 86 107 || $item[1] != $name) … … 90 111 continue; 91 112 } 92 $item[2] = $value; 93 $this->content[$section][$k]=$item; 113 if($key !== null) { 114 $this->content[$section][$k]=array(self::TK_ARR_VALUE,$name,$value, $key); 115 } else { 116 $this->content[$section][$k]=array(self::TK_VALUE,$name,$value); 117 if($item[0] == self::TK_ARR_VALUE) { 118 $deleteMode = true; 119 $foundValue = true; 120 continue; 121 } 122 } 94 123 $foundValue=true; 95 124 break; 96 125 } 126 }else{ 127 $this->content[$section] = array(array(self::TK_SECTION, '['.$section.']')); 97 128 } 98 129 if(!$foundValue) { … … 105 136 } 106 137 107 public function getValue($name) { 108 throw Exception('Not implemented'); 109 } 110 138 /** 139 * return the value of an option in the ini file. If the option doesn't exist, 140 * it returns null. 141 * @param string $name the name of the option to retrieve 142 * @param string $section the section where the option is. 0 is the global section 143 * @param string $key for option which is an item of array, the key in the array 144 * @return mixed the value 145 */ 146 public function getValue($name, $section=0, $key=null) { 147 if(!isset($this->content[$section])) { 148 return null; 149 } 150 foreach ($this->content[$section] as $k =>$item) { 151 if( ($item[0] != self::TK_VALUE && $item[0] != self::TK_ARR_VALUE) 152 || $item[1] != $name) 153 continue; 154 if($item[0] == self::TK_ARR_VALUE && $key !== null){ 155 if($item[3] != $key) 156 continue; 157 } 158 159 if (preg_match('/^-?[0-9]$/', $item[2])) { 160 return intval($item[2]); 161 } 162 else if (preg_match('/^-?[0-9\.]$/', $item[2])) { 163 return floatval($item[2]); 164 } 165 else if (strtolower($item[2]) === 'true' || strtolower($item[2]) === 'on') { 166 return true; 167 } 168 else if (strtolower($item[2]) === 'false' || strtolower($item[2]) === 'off') { 169 return false; 170 } 171 return $item[2]; 172 } 173 return null; 174 } 175 176 /** 177 * save the ini file 178 */ 111 179 public function save() { 112 180 file_put_contents($this->filename, $this->generateIni()); 113 181 } 114 182 183 /** 184 * save the content in an new ini file 185 * @param string $filename the name of the file 186 */ 115 187 public function saveAs($filename) { 116 188 file_put_contents($filename, $this->generateIni()); … … 123 195 switch($item[0]) { 124 196 case self::TK_SECTION: 125 if($item[1] != 0)197 if($item[1] != '0') 126 198 $content.=$item[1]."\n"; 127 199 break; … … 141 213 return $content; 142 214 } 143 215 144 216 protected function getIniValue($value) { 145 217 if ($value === '' || is_numeric($value) || preg_match("/^[\w]*$/", $value) || strpos("\n",$value) === false ) { 146 $value = $item[2];218 return $value; 147 219 }else if($value === false) { 148 220 $value="0"; trunk/lib/jelix/utils/jIniFileModifier.class.php
r824 r827 28 28 protected $filename = ''; 29 29 30 /** 31 * load the given ini file 32 * @param string $filename the file to load 33 */ 30 34 function __construct($filename) { 31 35 if(!file_exists($filename)) … … 35 39 } 36 40 37 41 /** 42 * parsed the lines of the ini file 43 */ 38 44 protected function parse($lines) { 39 45 $this->content = array(0=>array()); … … 52 58 } else if(preg_match('/^\s*([a-z0-9_.-]+)(\[([a-z0-9_.-]*)\])?\s*=\s*(")?([^"]*)(")?(\s*)/i', $line, $m)) { 53 59 list($all, $name, $foundkey, $key, $firstquote, $value ,$secondquote,$lastspace) = $m; 60 54 61 if($foundkey !='') 55 62 $currentValue = array(self::TK_ARR_VALUE, $name, $value, $key); … … 79 86 } 80 87 88 /** 89 * modify an option in the ini file. If the option doesn't exist, 90 * it is created. 91 * @param string $name the name of the option to modify 92 * @param string $value the new value 93 * @param string $section the section where to set the item. 0 is the global section 94 * @param string $key for option which is an item of array, the key in the array 95 */ 81 96 public function setValue($name, $value, $section=0, $key=null) { 82 97 $foundValue=false; 83 98 if(isset($this->content[$section])) { 99 $deleteMode = false; 84 100 foreach ($this->content[$section] as $k =>$item) { 101 if($deleteMode) { 102 if( $item[0] == self::TK_ARR_VALUE && $item[1] == $name ) 103 $this->content[$section][$k] = array(self::TK_WS,''); 104 continue; 105 } 85 106 if( ($item[0] != self::TK_VALUE && $item[0] != self::TK_ARR_VALUE) 86 107 || $item[1] != $name) … … 90 111 continue; 91 112 } 92 $item[2] = $value; 93 $this->content[$section][$k]=$item; 113 if($key !== null) { 114 $this->content[$section][$k]=array(self::TK_ARR_VALUE,$name,$value, $key); 115 } else { 116 $this->content[$section][$k]=array(self::TK_VALUE,$name,$value); 117 if($item[0] == self::TK_ARR_VALUE) { 118 $deleteMode = true; 119 $foundValue = true; 120 continue; 121 } 122 } 94 123 $foundValue=true; 95 124 break; 96 125 } 126 }else{ 127 $this->content[$section] = array(array(self::TK_SECTION, '['.$section.']')); 97 128 } 98 129 if(!$foundValue) { … … 105 136 } 106 137 107 public function getValue($name) { 108 throw Exception('Not implemented'); 109 } 110 138 /** 139 * return the value of an option in the ini file. If the option doesn't exist, 140 * it returns null. 141 * @param string $name the name of the option to retrieve 142 * @param string $section the section where the option is. 0 is the global section 143 * @param string $key for option which is an item of array, the key in the array 144 * @return mixed the value 145 */ 146 public function getValue($name, $section=0, $key=null) { 147 if(!isset($this->content[$section])) { 148 return null; 149 } 150 foreach ($this->content[$section] as $k =>$item) { 151 if( ($item[0] != self::TK_VALUE && $item[0] != self::TK_ARR_VALUE) 152 || $item[1] != $name) 153 continue; 154 if($item[0] == self::TK_ARR_VALUE && $key !== null){ 155 if($item[3] != $key) 156 continue; 157 } 158 159 if (preg_match('/^-?[0-9]$/', $item[2])) { 160 return intval($item[2]); 161 } 162 else if (preg_match('/^-?[0-9\.]$/', $item[2])) { 163 return floatval($item[2]); 164 } 165 else if (strtolower($item[2]) === 'true' || strtolower($item[2]) === 'on') { 166 return true; 167 } 168 else if (strtolower($item[2]) === 'false' || strtolower($item[2]) === 'off') { 169 return false; 170 } 171 return $item[2]; 172 } 173 return null; 174 } 175 176 /** 177 * save the ini file 178 */ 111 179 public function save() { 112 180 file_put_contents($this->filename, $this->generateIni()); 113 181 } 114 182 183 /** 184 * save the content in an new ini file 185 * @param string $filename the name of the file 186 */ 115 187 public function saveAs($filename) { 116 188 file_put_contents($filename, $this->generateIni()); … … 123 195 switch($item[0]) { 124 196 case self::TK_SECTION: 125 if($item[1] != 0)197 if($item[1] != '0') 126 198 $content.=$item[1]."\n"; 127 199 break; … … 141 213 return $content; 142 214 } 143 215 144 216 protected function getIniValue($value) { 145 217 if ($value === '' || is_numeric($value) || preg_match("/^[\w]*$/", $value) || strpos("\n",$value) === false ) { 146 $value = $item[2];218 return $value; 147 219 }else if($value === false) { 148 220 $value="0"; trunk/testapp/modules/jelix_tests/tests/utils.jinifilemodifier.html_cli.php
r824 r827 18 18 function testParse($content) { 19 19 $this->parse(explode("\n", $content)); 20 } 21 function getContent() { 20 22 return $this->content; 21 23 } 24 25 function generate(){ return $this->generateIni(); } 22 26 23 27 } 24 28 25 29 26 class UTjIniFileModifier extends UnitTestCase {30 class UTjIniFileModifier extends jUnitTestCase { 27 31 28 32 public function testParseFile(){ … … 34 38 ), 35 39 ); 36 $this->assertEqual($parser->testParse($content), $expected); 40 $parser->testParse($content); 41 $this->assertEqual($parser->getContent(), $expected); 37 42 38 43 $content =' … … 51 56 ); 52 57 53 $this->assertEqual($parser->testParse($content), $expected); 58 $parser->testParse($content); 59 $this->assertEqual($parser->getContent(), $expected); 54 60 55 61 $content =' … … 76 82 ); 77 83 78 $this->assertEqual($parser->testParse($content), $expected); 79 } 80 84 $parser->testParse($content); 85 $this->assertEqual($parser->getContent(), $expected); 86 87 $content =' 88 ; a comment 89 90 foo=bar 91 92 [aSection] 93 truc=machin 94 95 [othersection] 96 truc=machin2 97 98 '; 99 $expected=array( 100 0 => array( 101 array(jIniFileModifier::TK_WS, ""), 102 array(jIniFileModifier::TK_COMMENT, " ; a comment"), 103 array(jIniFileModifier::TK_WS, " "), 104 array(jIniFileModifier::TK_VALUE, 'foo','bar'), 105 array(jIniFileModifier::TK_WS, ""), 106 ), 107 'aSection'=>array( 108 array(jIniFileModifier::TK_SECTION, "[aSection]"), 109 array(jIniFileModifier::TK_VALUE, 'truc','machin'), 110 array(jIniFileModifier::TK_WS, ""), 111 ), 112 'othersection'=>array( 113 array(jIniFileModifier::TK_SECTION, "[othersection]"), 114 array(jIniFileModifier::TK_VALUE, 'truc','machin2'), 115 array(jIniFileModifier::TK_WS, ""), 116 array(jIniFileModifier::TK_WS, ""), 117 ), 118 ); 119 120 $parser->testParse($content); 121 $this->assertEqual($parser->getContent(), $expected); 122 123 124 $content =' 125 foo[]=bar 126 example=1 127 foo[]=machine 128 '; 129 $expected=array( 130 0 => array( 131 array(jIniFileModifier::TK_WS, ""), 132 array(jIniFileModifier::TK_ARR_VALUE, 'foo','bar',''), 133 array(jIniFileModifier::TK_VALUE, 'example','1'), 134 array(jIniFileModifier::TK_ARR_VALUE, 'foo','machine',''), 135 array(jIniFileModifier::TK_WS, ""), 136 ), 137 ); 138 139 $parser->testParse($content); 140 $this->assertEqual($parser->getContent(), $expected); 141 } 142 143 function testSetValue() { 144 $parser = new testIniFileModifier(''); 145 $content = ' 146 ; a comment 147 148 foo=bar 149 150 [aSection] 151 truc=machin 152 153 [othersection] 154 truc=machin2 155 156 '; 157 $expected=array( 158 0 => array( 159 array(jIniFileModifier::TK_WS, ""), 160 array(jIniFileModifier::TK_COMMENT, " ; a comment"), 161 array(jIniFileModifier::TK_WS, " "), 162 array(jIniFileModifier::TK_VALUE, 'foo','bar'), 163 array(jIniFileModifier::TK_WS, ""), 164 ), 165 'aSection'=>array( 166 array(jIniFileModifier::TK_SECTION, "[aSection]"), 167 array(jIniFileModifier::TK_VALUE, 'truc','machin'), 168 array(jIniFileModifier::TK_WS, ""), 169 ), 170 'othersection'=>array( 171 array(jIniFileModifier::TK_SECTION, "[othersection]"), 172 array(jIniFileModifier::TK_VALUE, 'truc','machin2'), 173 array(jIniFileModifier::TK_WS, ""), 174 array(jIniFileModifier::TK_WS, ""), 175 ), 176 ); 177 178 $parser->testParse($content); 179 $this->assertEqual($parser->getContent(), $expected); 180 181 $parser->setValue('foo','hello'); 182 $expected=array( 183 0 => array( 184 array(jIniFileModifier::TK_WS, ""), 185 array(jIniFileModifier::TK_COMMENT, " ; a comment"), 186 array(jIniFileModifier::TK_WS, " "), 187 array(jIniFileModifier::TK_VALUE, 'foo','hello'), 188 array(jIniFileModifier::TK_WS, ""), 189 ), 190 'aSection'=>array( 191 array(jIniFileModifier::TK_SECTION, "[aSection]"), 192 array(jIniFileModifier::TK_VALUE, 'truc','machin'), 193 array(jIniFileModifier::TK_WS, ""), 194 ), 195 'othersection'=>array( 196 array(jIniFileModifier::TK_SECTION, "[othersection]"), 197 array(jIniFileModifier::TK_VALUE, 'truc','machin2'), 198 array(jIniFileModifier::TK_WS, ""), 199 array(jIniFileModifier::TK_WS, ""), 200 ), 201 ); 202 $this->assertEqual($parser->getContent(), $expected); 203 204 $parser->setValue('truc','bidule', 'aSection'); 205 $expected=array( 206 0 => array( 207 array(jIniFileModifier::TK_WS, ""), 208 array(jIniFileModifier::TK_COMMENT, " ; a comment"), 209 array(jIniFileModifier::TK_WS, " "), 210 array(jIniFileModifier::TK_VALUE, 'foo','hello'), 211 array(jIniFileModifier::TK_WS, ""), 212 ), 213 'aSection'=>array( 214 array(jIniFileModifier::TK_SECTION, "[aSection]"), 215 array(jIniFileModifier::TK_VALUE, 'truc','bidule'), 216 array(jIniFileModifier::TK_WS, ""), 217 ), 218 'othersection'=>array( 219 array(jIniFileModifier::TK_SECTION, "[othersection]"), 220 array(jIniFileModifier::TK_VALUE, 'truc','machin2'), 221 array(jIniFileModifier::TK_WS, ""), 222 array(jIniFileModifier::TK_WS, ""), 223 ), 224 ); 225 $this->assertEqual($parser->getContent(), $expected); 226 227 $parser->setValue('truc','bidule2', 'othersection'); 228 $expected=array( 229 0 => array( 230 array(jIniFileModifier::TK_WS, ""), 231 array(jIniFileModifier::TK_COMMENT, " ; a comment"), 232 array(jIniFileModifier::TK_WS, " "), 233 array(jIniFileModifier::TK_VALUE, 'foo','hello'), 234 array(jIniFileModifier::TK_WS, ""), 235 ), 236 'aSection'=>array( 237 array(jIniFileModifier::TK_SECTION, "[aSection]"), 238 array(jIniFileModifier::TK_VALUE, 'truc','bidule'), 239 array(jIniFileModifier::TK_WS, ""), 240 ), 241 'othersection'=>array( 242 array(jIniFileModifier::TK_SECTION, "[othersection]"), 243 array(jIniFileModifier::TK_VALUE, 'truc','bidule2'), 244 array(jIniFileModifier::TK_WS, ""), 245 array(jIniFileModifier::TK_WS, ""), 246 ), 247 ); 248 $this->assertEqual($parser->getContent(), $expected); 249 250 $parser->setValue('name','toto', 'othersection'); 251 $expected=array( 252 0 => array( 253 array(jIniFileModifier::TK_WS, ""), 254 array(jIniFileModifier::TK_COMMENT, " ; a comment"), 255 array(jIniFileModifier::TK_WS, " "), 256 array(jIniFileModifier::TK_VALUE, 'foo','hello'), 257 array(jIniFileModifier::TK_WS, ""), 258 ), 259 'aSection'=>array( 260 array(jIniFileModifier::TK_SECTION, "[aSection]"), 261 array(jIniFileModifier::TK_VALUE, 'truc','bidule'), 262 array(jIniFileModifier::TK_WS, ""), 263 ), 264 'othersection'=>array( 265 array(jIniFileModifier::TK_SECTION, "[othersection]"), 266 array(jIniFileModifier::TK_VALUE, 'truc','bidule2'), 267 array(jIniFileModifier::TK_WS, ""), 268 array(jIniFileModifier::TK_WS, ""), 269 array(jIniFileModifier::TK_VALUE, 'name','toto'), 270 ), 271 ); 272 $this->assertEqual($parser->getContent(), $expected); 273 274 $parser->setValue('name','toto', 'othersection',''); 275 $expected=array( 276 0 => array( 277 array(jIniFileModifier::TK_WS, ""), 278 array(jIniFileModifier::TK_COMMENT, " ; a comment"), 279 array(jIniFileModifier::TK_WS, " "), 280 array(jIniFileModifier::TK_VALUE, 'foo','hello'), 281 array(jIniFileModifier::TK_WS, ""), 282 ), 283 'aSection'=>array( 284 array(jIniFileModifier::TK_SECTION, "[aSection]"), 285 array(jIniFileModifier::TK_VALUE, 'truc','bidule'), 286 array(jIniFileModifier::TK_WS, ""), 287 ), 288 'othersection'=>array( 289 array(jIniFileModifier::TK_SECTION, "[othersection]"), 290 array(jIniFileModifier::TK_VALUE, 'truc','bidule2'), 291 array(jIniFileModifier::TK_WS, ""), 292 array(jIniFileModifier::TK_WS, ""), 293 array(jIniFileModifier::TK_ARR_VALUE, 'name','toto',''), 294 ), 295 ); 296 $this->assertEqual($parser->getContent(), $expected); 297 //$this->dump($parser->getContent()); 298 $parser->setValue('theme','blue', 'aSection','0'); 299 $expected=array( 300 0 => array( 301 array(jIniFileModifier::TK_WS, ""), 302 array(jIniFileModifier::TK_COMMENT, " ; a comment"), 303 array(jIniFileModifier::TK_WS, " "), 304 array(jIniFileModifier::TK_VALUE, 'foo','hello'), 305 array(jIniFileModifier::TK_WS, ""), 306 ), 307 'aSection'=>array( 308 array(jIniFileModifier::TK_SECTION, "[aSection]"), 309 array(jIniFileModifier::TK_VALUE, 'truc','bidule'), 310 array(jIniFileModifier::TK_WS, ""), 311 array(jIniFileModifier::TK_ARR_VALUE, 'theme','blue','0'), 312 ), 313 'othersection'=>array( 314 array(jIniFileModifier::TK_SECTION, "[othersection]"), 315 array(jIniFileModifier::TK_VALUE, 'truc','bidule2'), 316 array(jIniFileModifier::TK_WS, ""), 317 array(jIniFileModifier::TK_WS, ""), 318 array(jIniFileModifier::TK_ARR_VALUE, 'name','toto',''), 319 ), 320 ); 321 $this->assertEqual($parser->getContent(), $expected); 322 323 324 $content =' 325 foo[]=bar 326 example=1 327 foo[]=machine 328 '; 329 $expected=array( 330 0 => array( 331 array(jIniFileModifier::TK_WS, ""), 332 array(jIniFileModifier::TK_ARR_VALUE, 'foo','bar',''), 333 array(jIniFileModifier::TK_VALUE, 'example','1'), 334 array(jIniFileModifier::TK_ARR_VALUE, 'foo','machine',''), 335 array(jIniFileModifier::TK_WS, ""), 336 ), 337 ); 338 339 $parser->testParse($content); 340 $this->assertEqual($parser->getContent(), $expected); 341 342 $parser->setValue('theme','blue', 'aSection','0'); 343 $expected=array( 344 0 => array( 345 array(jIniFileModifier::TK_WS, ""), 346 array(jIniFileModifier::TK_ARR_VALUE, 'foo','bar',''), 347 array(jIniFileModifier::TK_VALUE, 'example','1'), 348 array(jIniFileModifier::TK_ARR_VALUE, 'foo','machine',''), 349 array(jIniFileModifier::TK_WS, ""), 350 ), 351 'aSection'=>array( 352 array(jIniFileModifier::TK_SECTION, "[aSection]"), 353 array(jIniFileModifier::TK_ARR_VALUE, 'theme','blue','0'), 354 ), 355 ); 356 $this->assertEqual($parser->getContent(), $expected); 357 358 $parser->setValue('foo','button'); 359 $expected=array( 360 0 => array( 361 array(jIniFileModifier::TK_WS, ""), 362 array(jIniFileModifier::TK_VALUE, 'foo','button'), 363 array(jIniFileModifier::TK_VALUE, 'example','1'), 364 array(jIniFileModifier::TK_WS,''), 365 array(jIniFileModifier::TK_WS, ""), 366 ), 367 'aSection'=>array( 368 array(jIniFileModifier::TK_SECTION, "[aSection]"), 369 array(jIniFileModifier::TK_ARR_VALUE, 'theme','blue','0'), 370 ), 371 ); 372 $this->assertEqual($parser->getContent(), $expected); 373 } 374 375 376 function testGetValue() { 377 $parser = new testIniFileModifier(''); 378 $content = ' 379 ; a comment 380 381 foo=bar 382 anumber=98 383 afloatnumber= 5.098 384 [aSection] 385 truc= true 386 laurent=toto 387 isvalid = on 388 389 [othersection] 390 truc=machin2 391 392 '; 393 $parser->testParse($content); 394 $this->assertEqual($parser->getValue('foo'), 'bar' ); 395 $this->assertEqual($parser->getValue('anumber'), 98 ); 396 $this->assertEqual($parser->getValue('afloatnumber'), 5.098 ); 397 $this->assertEqual($parser->getValue('truc','aSection'), true ); 398 $this->assertEqual($parser->getValue('laurent','aSection'), 'toto' ); 399 $this->assertEqual($parser->getValue('isvalid','aSection'), true ); 400 } 401
