Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vlucas/phpdotenv
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.6.0
Choose a base ref
...
head repository: vlucas/phpdotenv
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.6.1
Choose a head ref
  • 3 commits
  • 5 files changed
  • 2 contributors

Commits on Mar 12, 2020

  1. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    124efcd View commit details
  2. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    82cccaa View commit details
  3. Updated boolean validation doc

    Closes #414
    
    Co-Authored-By: John Austin <johnmaustin78@users.noreply.github.com>
    GrahamCampbell and JohnMAustin78 committed Mar 12, 2020

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    8f7961f View commit details
Showing with 19 additions and 16 deletions.
  1. +1 −1 README.md
  2. +4 −0 composer.json
  3. +7 −15 src/Lines.php
  4. +6 −0 tests/Dotenv/DotenvTest.php
  5. +1 −0 tests/fixtures/env/empty.env
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -227,7 +227,7 @@ One or more environment variables failed assertions: FOO is not an integer

### Boolean Variables

You may need to ensure a variable is in the form of a boolean, accepting "On", "1", "Yes", "Off", "0" and "No". You may do the following:
You may need to ensure a variable is in the form of a boolean, accepting "true", "false", "On", "1", "Yes", "Off", "0" and "No". You may do the following:

```php
$dotenv->required('FOO')->isBoolean();
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -21,13 +21,17 @@
"symfony/polyfill-ctype": "^1.9"
},
"require-dev": {
"ext-filter": "*",
"phpunit/phpunit": "^4.8.35 || ^5.0 || ^6.0 || ^7.0"
},
"autoload": {
"psr-4": {
"Dotenv\\": "src/"
}
},
"suggest": {
"ext-filter": "Required to use the boolean validator."
},
"extra": {
"branch-alias": {
"dev-master": "3.6-dev"
22 changes: 7 additions & 15 deletions src/Lines.php
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ public static function process(array $lines)
foreach ($lines as $line) {
list($multiline, $line, $multilineBuffer) = self::multilineProcess($multiline, $line, $multilineBuffer);

if (!$multiline && !self::isComment($line) && self::isSetter($line)) {
if (!$multiline && !self::isCommentOrWhitespace($line)) {
$output[] = $line;
}
}
@@ -115,28 +115,20 @@ private static function getCharPairs($line)
}

/**
* Determine if the line in the file is a comment, e.g. begins with a #.
* Determine if the line in the file is a comment or whitespace.
*
* @param string $line
*
* @return bool
*/
private static function isComment($line)
private static function isCommentOrWhitespace($line)
{
if (trim($line) === '') {
return true;
}

$line = ltrim($line);

return isset($line[0]) && $line[0] === '#';
}

/**
* Determine if the given line looks like it's setting a variable.
*
* @param string $line
*
* @return bool
*/
private static function isSetter($line)
{
return strpos($line, '=') !== false;
}
}
6 changes: 6 additions & 0 deletions tests/Dotenv/DotenvTest.php
Original file line number Diff line number Diff line change
@@ -236,6 +236,12 @@ public function testMutlilineLoading()
$this->assertSame('https://vision.googleapis.com/v1/images:annotate?key=', getenv('TEST_EQS'));
}

public function testEmptyLoading()
{
$dotenv = Dotenv::create($this->fixturesFolder, 'empty.env');
$this->assertSame(['EMPTY_VAR' => null], $dotenv->load());
}

public function testGetEnvironmentVariablesList()
{
$dotenv = Dotenv::create($this->fixturesFolder);
1 change: 1 addition & 0 deletions tests/fixtures/env/empty.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EMPTY_VAR