Last active
October 4, 2023 11:48
-
-
Save lpheller/79ec1539da6e18080932f5dc185240f3 to your computer and use it in GitHub Desktop.
Zero dependency quick check for missing keys within the .env.example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getEnvVariablesFrom($filepath){ | |
$envContent = file_get_contents($filepath); | |
$envVariables = array_filter( | |
explode("\n", $envContent), function($value){ | |
return str_contains($value, "=") | |
&& $value !== '' | |
&& !str_starts_with($value, "#"); | |
} | |
); | |
return array_map(function($item){ | |
return explode("=", $item)[0]; | |
}, $envVariables); | |
} | |
$envVariables = getEnvVariablesFrom('.env'); | |
$exapleVariables = getEnvVariablesFrom('.env.example'); | |
array_values(array_diff($envVariables, $exapleVariables)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment