Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'ini-config-boolean' of https://github.com/akrabat/zf2 i…
Browse files Browse the repository at this point in the history
…nto hotfix/pr-459
  • Loading branch information
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Ini.php
Expand Up @@ -261,6 +261,11 @@ protected function _processKey($config, $key, $value)
throw new Exception\RuntimeException("Invalid key '$key'");
}
} else {
if(strtolower(trim($value)) === 'true') {
$value = '1';
} elseif(strtolower(trim($value)) === 'false') {
$value = '';
}
$config[$key] = $value;
}
return $config;
Expand Down
10 changes: 10 additions & 0 deletions test/IniTest.php
Expand Up @@ -47,6 +47,7 @@ public function setUp()
$this->_nonReadableConfig = __DIR__ . '/_files/nonreadable.ini';
$this->_iniFileNoSectionsConfig = __DIR__ . '/_files/nosections.ini';
$this->_iniFileInvalid = __DIR__ . '/_files/invalid.ini';
$this->_iniFileBooleans = __DIR__ . '/_files/booleans.ini';
}

public function testLoadSingleSection()
Expand Down Expand Up @@ -317,4 +318,13 @@ public function testPreservationOfIntegerKeys()

}

public function testBooleans()
{
$config = new Ini($this->_iniFileBooleans, 'all');
$this->assertEquals(true, (bool)$config->trueValue);
$this->assertEquals(false, (bool)$config->falseValue);
$this->assertEquals(true, (bool)$config->trueString);
$this->assertEquals(false, (bool)$config->falseString);
}

}
6 changes: 6 additions & 0 deletions test/_files/booleans.ini
@@ -0,0 +1,6 @@
[all]
trueValue = true
falseValue = false
trueString = "true"
falseString = "false"

0 comments on commit 0555415

Please sign in to comment.