Skip to content

Instantly share code, notes, and snippets.

@lpheller
Last active October 4, 2023 11:48
Show Gist options
  • Save lpheller/79ec1539da6e18080932f5dc185240f3 to your computer and use it in GitHub Desktop.
Save lpheller/79ec1539da6e18080932f5dc185240f3 to your computer and use it in GitHub Desktop.
Zero dependency quick check for missing keys within the .env.example
<?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