8000 [Dotenv] Check required dotenvs by pizzaminded · Pull Request #32729 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Dotenv] Check required dotenvs #32729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Next Next commit
[Dotenv] added new method which checks if there are all envs defined …
…in $_ENV superglobal
  • Loading branch information
pizzaminded committed Jul 24, 2019
commit a9e75c0c2e819f15a0d3f99f73a2ff08f699b1c4
23 changes: 23 additions & 0 deletions src/Symfony/Component/Dotenv/Dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,29 @@ public function parse(string $data, string $path = '.env'): array
}
}

/**
* Checks if all required variables are populated.
*
* @param string[] $variables Array with variable names that should be set in $_ENV
*
* @throws \RuntimeException when some of declared variables are not defined
*/
public function checkRequired(array $variables)
{
$missingKeys = [];

foreach ($variables as $variable) {
if(!isset($_ENV[$variable])) {
$missingKeys[] = $variable;
}
}

if(count($missingKeys) > 0) {
throw new \RuntimeException(sprintf('Following environment variables are missing: %s', implode(',', $missingKeys)));
}

}

private function lexVarname()
{
// var name + optional export
Expand Down
0