Changeset 2076

Show
Ignore:
Timestamp:
02/18/2008 05:48:34 PM (11 months ago)
Author:
Shadowhand
Message:

Fixing #415, thanks stach.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/core/Config.php

    r2054 r2076  
    9191                Config::item($key); 
    9292 
    93                 // Convert dot-noted key string to an array 
    94                 $keys = explode('.', rtrim($key, '.')); 
     93                if (strpos($key, '{') !== FALSE) 
     94                { 
     95                        // The follow garbage is the biggest hack ever, and shows my total 
     96                        // lack of advanced regex skills. Hopefully Geert can replace this 
     97                        // with a "lookahead" or some kind of fancy-pants regex. :) -Woody 
     98 
     99                        // Final keys 
     100                        $keys = array(); 
     101 
     102                        // Break token and token buffer 
     103                        $break  = '.'; 
     104                        $buffer = ''; 
     105 
     106                        // Parse each letter of the string... ick 
     107                        for ($i = 0, $max = strlen($key); $i <= $max; $i++) 
     108                        { 
     109                                if ($i === $max AND ! empty($buffer)) 
     110                                { 
     111                                        if ($break === '}.' AND substr($buffer, -1) === '}') 
     112                                        { 
     113                                                // Remove the ending "unquote" 
     114                                                $buffer = substr($buffer, 0, -1); 
     115                                        } 
     116 
     117                                        // Add the final buffer 
     118                                        $keys[] = $buffer; 
     119                                        break; 
     120                                } 
     121 
     122                                // Current token 
     123                                $token = $key{$i}; 
     124 
     125                                if ($token === '{' AND $break === '.') 
     126                                { 
     127                                        // Change the break token to "unquote dot" 
     128                                        $break = '}.'; 
     129                                } 
     130                                elseif ($token === '.' AND $break === '.') 
     131                                { 
     132                                        // Add the key and reset the buffer 
     133                                        $keys[] = $buffer; 
     134                                        $buffer = ''; 
     135                                } 
     136                                elseif ($break === '}.' AND substr($key, $i, 2) === '}.') 
     137                                { 
     138                                        // Add the key and reset the buffer 
     139                                        $keys[] = $buffer; 
     140                                        $buffer = ''; 
     141 
     142                                        // Reset the break token 
     143                                        $break = '.'; 
     144 
     145                                        // Increase the buffer to skip the next "dot" 
     146                                        $i++; 
     147                                } 
     148                                else 
     149                                { 
     150                                        // Add the token to the buffer 
     151                                        $buffer = $buffer.$token; 
     152                                } 
     153                        } 
     154                } 
     155                else 
     156                { 
     157                        // Convert dot-noted key string to an array 
     158                        $keys = explode('.', rtrim($key, '.')); 
     159                } 
    95160 
    96161                // Used for recursion