Skip to content

Commit

Permalink
adjusted to convert bools and floats
Browse files Browse the repository at this point in the history
  • Loading branch information
jamielsharief committed May 18, 2020
1 parent 3517540 commit 0533f6e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
18 changes: 10 additions & 8 deletions src/DotEnv.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ protected function parse(array $lines) : array
*/
protected function value($value)
{
if ($value === 'null') {
$value = null;
} elseif ($value === 'true') {
$value = true;
} elseif ($value === 'false') {
$value = false;
} else {
$value = str_replace('\n', "\n", $value);
if ($value === 'null' || $value === '') {
return null;
}
if ($value === 'true' || $value === 'false') {
return $value === 'true' ? true : false;
}
if (is_numeric($value)) {
return is_int($value) ? intval($value) : floatval($value);
}

$value = str_replace('\n', "\n", $value);

return is_string($value) ? trim($value) : $value;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ jumps over the lazy
fox'
BAD_ENV = omg
NUMBER=123
FLOAT=123.4
FLOAT=456.78
export SOMEVAR="result"
4 changes: 2 additions & 2 deletions tests/DotEnvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public function testLoadAndParsing()
$dotenv->load(__DIR__, '.env.test'); // TestApp

$results = $dotenv->getEnv();
$this->assertEquals('3a4e41e63f65b228e2927d6045c09577', md5(json_encode($results)));

$this->assertEquals('a8aa5046852048e0655d987528719c54', md5(json_encode($results)));
}

public function testLoadExecption()
Expand Down

0 comments on commit 0533f6e

Please sign in to comment.