Changeset 827

Show
Ignore:
Timestamp:
03/21/08 00:19:16 (10 months ago)
Author:
laurentj
Message:

finished class jIniFileModifier

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix/installer/jInstallerBase.class.php

    r824 r827  
    6060    /** 
    6161     * @param string $filename relative path to the var/config directory 
    62      * 
     62     * @return jIniFileModifier 
    6363     */ 
    6464    function getConfig($filename) { 
    65         throw new Exception("copyDirectoryContent not implemented"); 
     65        return new jIniFileModifier(JELIX_APP_CONFIG_PATH.$filename); 
    6666    } 
    6767 
    6868    /** 
    6969     * @param string $path relative path to the install directory 
    70      * @param string $target 'www' for the www path 
     70     * @param string $target  
    7171     */ 
    7272    function copyDirectoryContent($path, $target) { 
    7373        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        } 
    7486    } 
    7587} 
  • trunk/lib/jelix/installer/jInstallerBase.class.php

    r824 r827  
    6060    /** 
    6161     * @param string $filename relative path to the var/config directory 
    62      * 
     62     * @return jIniFileModifier 
    6363     */ 
    6464    function getConfig($filename) { 
    65         throw new Exception("copyDirectoryContent not implemented"); 
     65        return new jIniFileModifier(JELIX_APP_CONFIG_PATH.$filename); 
    6666    } 
    6767 
    6868    /** 
    6969     * @param string $path relative path to the install directory 
    70      * @param string $target 'www' for the www path 
     70     * @param string $target  
    7171     */ 
    7272    function copyDirectoryContent($path, $target) { 
    7373        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        } 
    7486    } 
    7587} 
  • trunk/lib/jelix/installer/jInstallerBase.class.php

    r824 r827  
    6060    /** 
    6161     * @param string $filename relative path to the var/config directory 
    62      * 
     62     * @return jIniFileModifier 
    6363     */ 
    6464    function getConfig($filename) { 
    65         throw new Exception("copyDirectoryContent not implemented"); 
     65        return new jIniFileModifier(JELIX_APP_CONFIG_PATH.$filename); 
    6666    } 
    6767 
    6868    /** 
    6969     * @param string $path relative path to the install directory 
    70      * @param string $target 'www' for the www path 
     70     * @param string $target  
    7171     */ 
    7272    function copyDirectoryContent($path, $target) { 
    7373        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        } 
    7486    } 
    7587} 
  • trunk/lib/jelix/utils/jIniFileModifier.class.php

    r824 r827  
    2828    protected $filename = ''; 
    2929 
     30    /** 
     31     * load the given ini file 
     32     * @param string $filename the file to load 
     33     */ 
    3034    function __construct($filename) { 
    3135        if(!file_exists($filename)) 
     
    3539    } 
    3640 
    37  
     41    /** 
     42     * parsed the lines of the ini file 
     43     */ 
    3844    protected function parse($lines) { 
    3945        $this->content = array(0=>array()); 
     
    5258            } else if(preg_match('/^\s*([a-z0-9_.-]+)(\[([a-z0-9_.-]*)\])?\s*=\s*(")?([^"]*)(")?(\s*)/i', $line, $m)) { 
    5359                list($all, $name, $foundkey, $key, $firstquote, $value ,$secondquote,$lastspace) = $m; 
     60 
    5461                if($foundkey !='')  
    5562                    $currentValue = array(self::TK_ARR_VALUE, $name, $value, $key); 
     
    7986    } 
    8087 
     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     */ 
    8196    public function setValue($name, $value, $section=0, $key=null) { 
    8297        $foundValue=false; 
    8398        if(isset($this->content[$section])) { 
     99            $deleteMode = false; 
    84100            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                } 
    85106                if( ($item[0] != self::TK_VALUE && $item[0] != self::TK_ARR_VALUE) 
    86107                    || $item[1] != $name) 
     
    90111                        continue; 
    91112                } 
    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                } 
    94123                $foundValue=true; 
    95124                break; 
    96125            } 
     126        }else{ 
     127            $this->content[$section] = array(array(self::TK_SECTION, '['.$section.']')); 
    97128        } 
    98129        if(!$foundValue) { 
     
    105136    } 
    106137 
    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     */ 
    111179    public function save() { 
    112180        file_put_contents($this->filename, $this->generateIni()); 
    113181    } 
    114182 
     183    /** 
     184     * save the content in an new ini file 
     185     * @param string $filename the name of the file 
     186     */ 
    115187    public function saveAs($filename) { 
    116188        file_put_contents($filename, $this->generateIni()); 
     
    123195                switch($item[0]) { 
    124196                  case self::TK_SECTION: 
    125                     if($item[1] != 0
     197                    if($item[1] != '0'
    126198                        $content.=$item[1]."\n"; 
    127199                    break; 
     
    141213        return $content; 
    142214    } 
    143      
     215 
    144216    protected function getIniValue($value) { 
    145217        if ($value === '' || is_numeric($value) || preg_match("/^[\w]*$/", $value) || strpos("\n",$value) === false ) { 
    146             $value = $item[2]
     218            return $value
    147219        }else if($value === false) { 
    148220            $value="0"; 
  • trunk/lib/jelix/utils/jIniFileModifier.class.php

    r824 r827  
    2828    protected $filename = ''; 
    2929 
     30    /** 
     31     * load the given ini file 
     32     * @param string $filename the file to load 
     33     */ 
    3034    function __construct($filename) { 
    3135        if(!file_exists($filename)) 
     
    3539    } 
    3640 
    37  
     41    /** 
     42     * parsed the lines of the ini file 
     43     */ 
    3844    protected function parse($lines) { 
    3945        $this->content = array(0=>array()); 
     
    5258            } else if(preg_match('/^\s*([a-z0-9_.-]+)(\[([a-z0-9_.-]*)\])?\s*=\s*(")?([^"]*)(")?(\s*)/i', $line, $m)) { 
    5359                list($all, $name, $foundkey, $key, $firstquote, $value ,$secondquote,$lastspace) = $m; 
     60 
    5461                if($foundkey !='')  
    5562                    $currentValue = array(self::TK_ARR_VALUE, $name, $value, $key); 
     
    7986    } 
    8087 
     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     */ 
    8196    public function setValue($name, $value, $section=0, $key=null) { 
    8297        $foundValue=false; 
    8398        if(isset($this->content[$section])) { 
     99            $deleteMode = false; 
    84100            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                } 
    85106                if( ($item[0] != self::TK_VALUE && $item[0] != self::TK_ARR_VALUE) 
    86107                    || $item[1] != $name) 
     
    90111                        continue; 
    91112                } 
    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                } 
    94123                $foundValue=true; 
    95124                break; 
    96125            } 
     126        }else{ 
     127            $this->content[$section] = array(array(self::TK_SECTION, '['.$section.']')); 
    97128        } 
    98129        if(!$foundValue) { 
     
    105136    } 
    106137 
    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     */ 
    111179    public function save() { 
    112180        file_put_contents($this->filename, $this->generateIni()); 
    113181    } 
    114182 
     183    /** 
     184     * save the content in an new ini file 
     185     * @param string $filename the name of the file 
     186     */ 
    115187    public function saveAs($filename) { 
    116188        file_put_contents($filename, $this->generateIni()); 
     
    123195                switch($item[0]) { 
    124196                  case self::TK_SECTION: 
    125                     if($item[1] != 0
     197                    if($item[1] != '0'
    126198                        $content.=$item[1]."\n"; 
    127199                    break; 
     
    141213        return $content; 
    142214    } 
    143      
     215 
    144216    protected function getIniValue($value) { 
    145217        if ($value === '' || is_numeric($value) || preg_match("/^[\w]*$/", $value) || strpos("\n",$value) === false ) { 
    146             $value = $item[2]
     218            return $value
    147219        }else if($value === false) { 
    148220            $value="0"; 
  • trunk/lib/jelix/utils/jIniFileModifier.class.php

    r824 r827  
    2828    protected $filename = ''; 
    2929 
     30    /** 
     31     * load the given ini file 
     32     * @param string $filename the file to load 
     33     */ 
    3034    function __construct($filename) { 
    3135        if(!file_exists($filename)) 
     
    3539    } 
    3640 
    37  
     41    /** 
     42     * parsed the lines of the ini file 
     43     */ 
    3844    protected function parse($lines) { 
    3945        $this->content = array(0=>array()); 
     
    5258            } else if(preg_match('/^\s*([a-z0-9_.-]+)(\[([a-z0-9_.-]*)\])?\s*=\s*(")?([^"]*)(")?(\s*)/i', $line, $m)) { 
    5359                list($all, $name, $foundkey, $key, $firstquote, $value ,$secondquote,$lastspace) = $m; 
     60 
    5461                if($foundkey !='')  
    5562                    $currentValue = array(self::TK_ARR_VALUE, $name, $value, $key); 
     
    7986    } 
    8087 
     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     */ 
    8196    public function setValue($name, $value, $section=0, $key=null) { 
    8297        $foundValue=false; 
    8398        if(isset($this->content[$section])) { 
     99            $deleteMode = false; 
    84100            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                } 
    85106                if( ($item[0] != self::TK_VALUE && $item[0] != self::TK_ARR_VALUE) 
    86107                    || $item[1] != $name) 
     
    90111                        continue; 
    91112                } 
    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                } 
    94123                $foundValue=true; 
    95124                break; 
    96125            } 
     126        }else{ 
     127            $this->content[$section] = array(array(self::TK_SECTION, '['.$section.']')); 
    97128        } 
    98129        if(!$foundValue) { 
     
    105136    } 
    106137 
    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     */ 
    111179    public function save() { 
    112180        file_put_contents($this->filename, $this->generateIni()); 
    113181    } 
    114182 
     183    /** 
     184     * save the content in an new ini file 
     185     * @param string $filename the name of the file 
     186     */ 
    115187    public function saveAs($filename) { 
    116188        file_put_contents($filename, $this->generateIni()); 
     
    123195                switch($item[0]) { 
    124196                  case self::TK_SECTION: 
    125                     if($item[1] != 0
     197                    if($item[1] != '0'
    126198                        $content.=$item[1]."\n"; 
    127199                    break; 
     
    141213        return $content; 
    142214    } 
    143      
     215 
    144216    protected function getIniValue($value) { 
    145217        if ($value === '' || is_numeric($value) || preg_match("/^[\w]*$/", $value) || strpos("\n",$value) === false ) { 
    146             $value = $item[2]
     218            return $value
    147219        }else if($value === false) { 
    148220            $value="0"; 
  • trunk/testapp/modules/jelix_tests/tests/utils.jinifilemodifier.html_cli.php

    r824 r827  
    1818    function testParse($content) { 
    1919       $this->parse(explode("\n", $content)); 
     20    } 
     21    function getContent() { 
    2022       return $this->content; 
    2123    } 
     24     
     25    function generate(){ return $this->generateIni(); } 
    2226 
    2327} 
    2428 
    2529 
    26 class UTjIniFileModifier extends UnitTestCase { 
     30class UTjIniFileModifier extends jUnitTestCase { 
    2731 
    2832    public function testParseFile(){ 
     
    3438                 ), 
    3539        ); 
    36         $this->assertEqual($parser->testParse($content), $expected); 
     40        $parser->testParse($content); 
     41        $this->assertEqual($parser->getContent(), $expected); 
    3742 
    3843        $content =' 
     
    5156        ); 
    5257 
    53         $this->assertEqual($parser->testParse($content), $expected); 
     58        $parser->testParse($content); 
     59        $this->assertEqual($parser->getContent(), $expected); 
    5460 
    5561        $content =' 
     
    7682        ); 
    7783 
    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   
     90foo=bar 
     91 
     92[aSection] 
     93truc=machin 
     94 
     95[othersection] 
     96truc=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 =' 
     125foo[]=bar 
     126example=1 
     127foo[]=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   
     148foo=bar 
     149 
     150[aSection] 
     151truc=machin 
     152 
     153[othersection] 
     154truc=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 =' 
     325foo[]=bar 
     326example=1 
     327foo[]=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   
     381foo=bar 
     382anumber=98 
     383afloatnumber=   5.098   
     384[aSection] 
     385truc= true 
     386laurent=toto 
     387isvalid = on 
     388 
     389[othersection] 
     390truc=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