Skip to content

Commit fc663d5

Browse files
authored
Merge pull request #91 from rodrigopedra/master
[Laravel 7] fix dotenv 4 checks
2 parents 14cb57c + 2c8379d commit fc663d5

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/Checks/ExampleEnvironmentVariablesAreSet.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public function name(array $config): string
2929
*/
3030
public function check(array $config): bool
3131
{
32+
if (method_exists(Dotenv::class, 'createImmutable')) {
33+
return $this->checkForDotEnvV4();
34+
}
35+
3236
if (interface_exists(\Dotenv\Environment\FactoryInterface::class)) {
3337
$examples = Dotenv::create(base_path(), '.env.example');
3438
$actual = Dotenv::create(base_path(), '.env');
@@ -46,6 +50,23 @@ public function check(array $config): bool
4650
return $this->envVariables->isEmpty();
4751
}
4852

53+
/**
54+
* Perform the verification of this check for DotEnv v4.
55+
*
56+
* @return bool
57+
*/
58+
private function checkForDotEnvV4(): bool
59+
{
60+
$examples = Dotenv::createImmutable(base_path(), '.env.example');
61+
$actual = Dotenv::createImmutable(base_path(), '.env');
62+
63+
$this->envVariables = Collection::make($examples->safeLoad())
64+
->diffKeys($actual->safeLoad())
65+
->keys();
66+
67+
return $this->envVariables->isEmpty();
68+
}
69+
4970
/**
5071
* The error message to display in case the check does not pass.
5172
*

src/Checks/ExampleEnvironmentVariablesAreUpToDate.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public function name(array $config): string
2929
*/
3030
public function check(array $config): bool
3131
{
32+
if (method_exists(Dotenv::class, 'createImmutable')) {
33+
return $this->checkForDotEnvV4();
34+
}
35+
3236
if (interface_exists(\Dotenv\Environment\FactoryInterface::class)) {
3337
$examples = Dotenv::create(base_path(), '.env.example');
3438
$actual = Dotenv::create(base_path(), '.env');
@@ -46,6 +50,23 @@ public function check(array $config): bool
4650
return $this->envVariables->isEmpty();
4751
}
4852

53+
/**
54+
* Perform the verification of this check for DotEnv v4.
55+
*
56+
* @return bool
57+
*/
58+
private function checkForDotEnvV4(): bool
59+
{
60+
$examples = Dotenv::createImmutable(base_path(), '.env.example');
61+
$actual = Dotenv::createImmutable(base_path(), '.env');
62+
63+
$this->envVariables = Collection::make($actual->safeLoad())
64+
->diffKeys($examples->safeLoad())
65+
->keys();
66+
67+
return $this->envVariables->isEmpty();
68+
}
69+
4970
/**
5071
* The error message to display in case the check does not pass.
5172
*

0 commit comments

Comments
 (0)