From a9dd8eb9e7b9abc8583d5a7c847fc05df6059694 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 27 Apr 2018 06:26:37 +0200 Subject: [PATCH] Fix #1382 --- bootstrap/app.php | 15 +++++++++++++++ config/app.php | 12 ++++++------ config/cache.php | 2 +- config/database.php | 20 ++++++++++---------- config/logging.php | 10 +++++----- config/mail.php | 4 ++-- config/queue.php | 4 ++-- 7 files changed, 41 insertions(+), 26 deletions(-) diff --git a/bootstrap/app.php b/bootstrap/app.php index f1d4085827..1eb38a8791 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -36,6 +36,21 @@ declare(strict_types=1); bcscale(12); +/** + * @param string $key + * @param null $default + * + * @return mixed|null + */ +function envNonEmpty(string $key, $default = null) +{ + $result = env($key, $default); + if (is_string($result) && $result === '') { + $result = $default; + } + return $result; +} + $app = new Illuminate\Foundation\Application( realpath(__DIR__ . '/../') diff --git a/config/app.php b/config/app.php index 6a4a8ae47a..953ed046ee 100644 --- a/config/app.php +++ b/config/app.php @@ -23,17 +23,17 @@ declare(strict_types=1); return [ - 'name' => env('APP_NAME', 'Firefly III'), - 'env' => env('APP_ENV', 'production'), + 'name' => envNonEmpty('APP_NAME', 'Firefly III'), + 'env' => envNonEmpty('APP_ENV', 'production'), 'debug' => env('APP_DEBUG', false), - 'url' => env('APP_URL', 'http://localhost'), - 'timezone' => env('TZ', 'UTC'), + 'url' => envNonEmpty('APP_URL', 'http://localhost'), + 'timezone' => envNonEmpty('TZ', 'UTC'), 'locale' => 'en_US', 'fallback_locale' => 'en_US', 'key' => env('APP_KEY'), 'cipher' => 'AES-256-CBC', - 'log' => env('APP_LOG', 'errorlog'), - 'log_level' => env('APP_LOG_LEVEL', 'info'), + 'log' => envNonEmpty('APP_LOG', 'errorlog'), + 'log_level' => envNonEmpty('APP_LOG_LEVEL', 'info'), 'providers' => [ /* diff --git a/config/cache.php b/config/cache.php index d8ac011596..414ea33ea6 100644 --- a/config/cache.php +++ b/config/cache.php @@ -37,7 +37,7 @@ return [ | */ - 'default' => env('CACHE_DRIVER', 'file'), + 'default' => envNonEmpty('CACHE_DRIVER', 'file'), /* |-------------------------------------------------------------------------- diff --git a/config/database.php b/config/database.php index 4f7fd754f6..50c1e8ede9 100644 --- a/config/database.php +++ b/config/database.php @@ -38,19 +38,19 @@ if (!($databaseUrl === false)) { return [ - 'default' => env('DB_CONNECTION', 'mysql'), + 'default' => envNonEmpty('DB_CONNECTION', 'mysql'), 'connections' => [ 'sqlite' => [ 'driver' => 'sqlite', - 'database' => env('DB_DATABASE', storage_path('database/database.sqlite')), + 'database' => envNonEmpty('DB_DATABASE', storage_path('database/database.sqlite')), 'prefix' => '', ], 'mysql' => [ 'driver' => 'mysql', - 'host' => env('DB_HOST', '127.0.0.1'), - 'port' => env('DB_PORT', '3306'), - 'database' => env('DB_DATABASE', 'forge'), - 'username' => env('DB_USERNAME', 'forge'), + 'host' => envNonEmpty('DB_HOST', '127.0.0.1'), + 'port' => envNonEmpty('DB_PORT', '3306'), + 'database' => envNonEmpty('DB_DATABASE', 'forge'), + 'username' => envNonEmpty('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8mb4', @@ -61,10 +61,10 @@ return [ ], 'pgsql' => [ 'driver' => 'pgsql', - 'host' => env('DB_HOST', $host), - 'port' => env('DB_PORT', '5432'), - 'database' => env('DB_DATABASE', $database), - 'username' => env('DB_USERNAME', $username), + 'host' => envNonEmpty('DB_HOST', $host), + 'port' => envNonEmpty('DB_PORT', '5432'), + 'database' => envNonEmpty('DB_DATABASE', $database), + 'username' => envNonEmpty('DB_USERNAME', $username), 'password' => env('DB_PASSWORD', $password), 'charset' => 'utf8', 'prefix' => '', diff --git a/config/logging.php b/config/logging.php index 78f0ab48dd..3e1dcfd1f3 100644 --- a/config/logging.php +++ b/config/logging.php @@ -34,7 +34,7 @@ return [ | */ - 'default' => env('LOG_CHANNEL', 'daily'), + 'default' => envNonEmpty('LOG_CHANNEL', 'daily'), /* |-------------------------------------------------------------------------- @@ -65,13 +65,13 @@ return [ 'daily' => [ 'driver' => 'daily', 'path' => storage_path('logs/ff3-' . PHP_SAPI . '.log'), - 'level' => env('APP_LOG_LEVEL', 'info'), + 'level' => envNonEmpty('APP_LOG_LEVEL', 'info'), 'days' => 7, ], 'dailytest' => [ 'driver' => 'daily', 'path' => storage_path('logs/test-ff3-' . PHP_SAPI . '.log'), - 'level' => env('APP_LOG_LEVEL', 'info'), + 'level' => envNonEmpty('APP_LOG_LEVEL', 'info'), 'days' => 7, ], @@ -85,12 +85,12 @@ return [ 'syslog' => [ 'driver' => 'syslog', - 'level' => env('APP_LOG_LEVEL', 'info'), + 'level' => envNonEmpty('APP_LOG_LEVEL', 'info'), ], 'errorlog' => [ 'driver' => 'errorlog', - 'level' => env('APP_LOG_LEVEL', 'info'), + 'level' => envNonEmpty('APP_LOG_LEVEL', 'info'), ], ], diff --git a/config/mail.php b/config/mail.php index fb87f15799..5a782feed8 100644 --- a/config/mail.php +++ b/config/mail.php @@ -38,7 +38,7 @@ return [ | */ - 'driver' => env('MAIL_DRIVER', 'log'), + 'driver' => envNonEmpty('MAIL_DRIVER', 'log'), /* |-------------------------------------------------------------------------- @@ -76,7 +76,7 @@ return [ | used globally for all e-mails that are sent by your application. | */ - 'from' => ['address' => env('MAIL_FROM', 'changeme@example.com'), 'name' => 'Firefly III Mailer'], + 'from' => ['address' => envNonEmpty('MAIL_FROM', 'changeme@example.com'), 'name' => 'Firefly III Mailer'], /* diff --git a/config/queue.php b/config/queue.php index a3d2a3e528..eddc6dae49 100644 --- a/config/queue.php +++ b/config/queue.php @@ -37,7 +37,7 @@ return [ | */ - 'default' => env('QUEUE_DRIVER', 'sync'), + 'default' => envNonEmpty('QUEUE_DRIVER', 'sync'), /* |-------------------------------------------------------------------------- @@ -100,7 +100,7 @@ return [ */ 'failed' => [ - 'database' => env('DB_CONNECTION', 'mysql'), + 'database' => envNonEmpty('DB_CONNECTION', 'mysql'), 'table' => 'failed_jobs', ],