mirror of
https://github.com/leonelquinteros/php-toml.git
synced 2025-01-17 12:28:16 +01:00
Throw exception on key overwrite
This commit is contained in:
parent
0eb93e8d87
commit
2f1c034a78
@ -17,8 +17,6 @@ Supports commit: f68d014bfd4a84a64fb5f6a7c1a83a4162415d4b
|
||||
TODO
|
||||
----
|
||||
|
||||
- Throw exception on extra chars after keygroup definition
|
||||
- Throw exception on key or keygroup overwriting
|
||||
- Write better tests.
|
||||
- Support Unicode and \b chars.
|
||||
|
||||
|
16
src/toml.php
16
src/toml.php
@ -96,13 +96,19 @@ class Toml
|
||||
|
||||
$keygroup = substr($line, 1, -1);
|
||||
$aKeygroup = explode('.', $keygroup);
|
||||
$last = count($aKeygroup) - 1;
|
||||
|
||||
foreach($aKeygroup as $keygroup)
|
||||
foreach($aKeygroup as $i => $keygroup)
|
||||
{
|
||||
if( !isset($pointer[$keygroup]) )
|
||||
{
|
||||
$pointer[$keygroup] = array();
|
||||
}
|
||||
elseif($i == $last)
|
||||
{
|
||||
// Overwrite key
|
||||
throw new Exception('Key overwrite previous keys: ' . $line);
|
||||
}
|
||||
|
||||
// Move pointer forward
|
||||
$pointer = & $pointer[$keygroup];
|
||||
@ -112,9 +118,15 @@ class Toml
|
||||
elseif(strpos($line, '='))
|
||||
{
|
||||
$kv = explode('=', $line, 2);
|
||||
|
||||
if(!isset($pointer[ trim($kv[0]) ]))
|
||||
{
|
||||
$pointer[ trim($kv[0]) ] = self::parseValue( $kv[1] );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception('Key overwrite previous keys: ' . $line);
|
||||
}
|
||||
}
|
||||
elseif($line[0] == '[' && substr($line, -1) != ']')
|
||||
{
|
||||
throw new Exception('Key groups have to be on a line by themselves: ' . $line);
|
||||
|
Loading…
x
Reference in New Issue
Block a user