remove usage of getenv from codebase (#1861)

This commit is contained in:
Kevin Papst
2020-08-02 01:02:04 +02:00
committed by GitHub
parent 6f8c0e3cb6
commit 476e6ca150
14 changed files with 122 additions and 123 deletions

View File

@@ -21,7 +21,7 @@ class DoctrineCompilerPass implements CompilerPassInterface
/**
* @var string[]
*/
protected $allowedEngines = [
private $allowedEngines = [
'mysql',
'sqlite'
];
@@ -33,20 +33,32 @@ class DoctrineCompilerPass implements CompilerPassInterface
protected function findEngine()
{
$engine = null;
$databaseUrl = null;
if (null === $engine) {
$dbConfig = explode('://', getenv('DATABASE_URL'));
$engine = $dbConfig['0'] ?: null;
if (null === $databaseUrl && isset($_ENV['DATABASE_URL'])) {
$databaseUrl = $_ENV['DATABASE_URL'];
}
if (null === $databaseUrl && isset($_SERVER['DATABASE_URL'])) {
$databaseUrl = $_SERVER['DATABASE_URL'];
}
if (null === $databaseUrl && (false !== $envDbUrl = getenv('DATABASE_URL'))) {
$databaseUrl = $envDbUrl;
}
if (null !== $databaseUrl) {
$urlParts = explode('://', $databaseUrl);
$engine = $urlParts[0] ?: null;
}
if (null === $engine) {
$engine = getenv('DATABASE_ENGINE');
}
if (false === $engine) {
if (empty($engine)) {
throw new \Exception(
'Could not detect database engine. Please set the environment config DATABASE_ENGINE ' .
'to one of: "' . implode(', ', $this->allowedEngines) . '" in your .env file, e.g. DATABASE_ENGINE=sqlite'
'Could not detect database engine, make sure DATABASE_URL is available from $_SERVER or $_ENV. Check your .env file.'
);
}