Skip to content

Commit

Permalink
Keys in the first level can now contain dots
Browse files Browse the repository at this point in the history
  • Loading branch information
Magnus Eriksson committed Jul 13, 2015
1 parent 37c7dfa commit c00c939
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public function get($key = null, $default = null)
return $default;
}

// If we have a direct match, return it.
// This makes it possible to have keys containing dots
if (array_key_exists($key, $this->conf)) {
return $this->conf[$key];
}

$conf =& $this->conf;

foreach(explode('.', $key) as $segment) {
Expand Down
4 changes: 4 additions & 0 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public function testGet()

$result = $this->config->get('level1.level2');
$this->assertArrayHasKey('level3', $result, "Test return partial nested");


$result = $this->config->get('dotlevel1.dotlevel2');
$this->assertEquals("dotvalue2", $result, "Test return key containing dots. Key with dots has priority.");
}


Expand Down
6 changes: 6 additions & 0 deletions tests/test_assets/config1.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@
'level3' => 'level3_value',
],
],

'dotlevel1' => [
'dotlevel2' => 'dotvalue1',
],

'dotlevel1.dotlevel2' => 'dotvalue2'
];

0 comments on commit c00c939

Please sign in to comment.