Assembla home | Assembla project page
 

Changeset 118

Show
Ignore:
Timestamp:
03/04/08 02:30:14 (9 months ago)
Author:
Seldaek
Message:

* Set: Fixes setIni() calls by parsing ini values as parse_ini_file() would have parsed them.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Phergie/Plugin/Set.php

    r117 r118  
    3030        // Replace var/value 
    3131        if (preg_match('#^\s*('.str_replace('.', '\\.', $var).'\s*=\s*)(.*)$#im', $contents, $m)) { 
    32                 $contents = str_replace($m[2], $this->makeValue($value, $m[2], $append), $contents); 
    33                 $this->setIni($var, trim($this->makeValue($value, $m[2], $append), '" ')); 
     32                $contents = str_replace($m[2], $this->makeIniValue($value, $m[2], $append), $contents); 
     33                $this->setIni($var, $this->parseIniValue($this->makeIniValue($value, $m[2], $append))); 
    3434                // Insert it if not set 
    3535        } else { 
    36                 $contents .= "\r\n".$var.' = '.$this->makeValue($value); 
    37                 $this->setIni($var, trim($value, '" ')); 
     36                $contents .= "\r\n".$var.' = '.$this->makeIniValue($value); 
     37                $this->setIni($var, $this->parseIniValue($value)); 
    3838        } 
    3939        // Save ini file 
     
    4444         * Builds a ini value 
    4545         */ 
    46     protected function makeValue($new, $old = "", $append = false) 
     46    protected function makeIniValue($new, $old = "", $append = false) 
    4747    { 
    4848        $new = trim($new, '" '); 
     
    6565                } 
    6666    } 
     67 
     68    protected function parseIniValue($value) 
     69    { 
     70        $value = trim($value, '" '); 
     71                switch (strtolower($value)) { 
     72                        case 'true': 
     73                        case 'on': 
     74                        case '1': 
     75                                return '1'; 
     76                        case 'false': 
     77                        case 'off': 
     78                        case '0': 
     79                        case '': 
     80                                return ''; 
     81                        default: 
     82                                return $value; 
     83                } 
     84    } 
    6785}