From 6a11f130c2dc51f45e923b97ba64802de34dbff4 Mon Sep 17 00:00:00 2001 From: Ethan Brace Date: Sun, 26 Apr 2020 06:07:27 -0400 Subject: [PATCH] use config helper instead of env in application code --- app/Console/Kernel.php | 4 ++-- app/Exceptions/Handler.php | 2 +- app/Http/Controllers/Auth/Login.php | 2 +- app/Http/Controllers/Install/Database.php | 4 +++- app/Http/ViewComposers/Notifications.php | 2 +- app/Http/ViewComposers/Suggestions.php | 6 +++--- app/Listeners/Update/V20/Version207.php | 2 +- app/Providers/App.php | 4 ++-- app/Traits/DateTime.php | 2 +- app/Utilities/Info.php | 2 +- app/Utilities/Installer.php | 6 +++--- config/app.php | 4 ++++ resources/views/partials/admin/head.blade.php | 2 +- resources/views/partials/auth/head.blade.php | 2 +- resources/views/partials/modules/head.blade.php | 2 +- resources/views/partials/portal/head.blade.php | 2 +- resources/views/partials/signed/head.blade.php | 2 +- resources/views/partials/wizard/head.blade.php | 2 +- 18 files changed, 29 insertions(+), 23 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 23f1ab7a0..6a4c03cbf 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -23,11 +23,11 @@ class Kernel extends ConsoleKernel protected function schedule(Schedule $schedule) { // Not installed yet - if (!env('APP_INSTALLED')) { + if (!config('app.installed')) { return; } - $schedule_time = env('APP_SCHEDULE_TIME', '09:00'); + $schedule_time = config('app.schedule_time'); $schedule->command('reminder:invoice')->dailyAt($schedule_time); $schedule->command('reminder:bill')->dailyAt($schedule_time); diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index e24768d9f..4092f98d8 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -54,7 +54,7 @@ class Handler extends ExceptionHandler */ public function render($request, Throwable $exception) { - if (env('APP_DEBUG') === false) { + if (config('app.debug') === false) { return $this->handleExceptions($request, $exception); } diff --git a/app/Http/Controllers/Auth/Login.php b/app/Http/Controllers/Auth/Login.php index dde57b182..d9a188986 100644 --- a/app/Http/Controllers/Auth/Login.php +++ b/app/Http/Controllers/Auth/Login.php @@ -115,7 +115,7 @@ class Login extends Controller auth()->logout(); // Session destroy is required if stored in database - if (env('SESSION_DRIVER') == 'database') { + if (config('session.driver') == 'database') { $request = app('Illuminate\Http\Request'); $request->session()->getHandler()->destroy($request->session()->getId()); } diff --git a/app/Http/Controllers/Install/Database.php b/app/Http/Controllers/Install/Database.php index fb15816fa..aa5ecff3a 100644 --- a/app/Http/Controllers/Install/Database.php +++ b/app/Http/Controllers/Install/Database.php @@ -27,8 +27,10 @@ class Database extends Controller */ public function store(Request $request) { + $connection = config('database.default','mysql'); + $host = $request['hostname']; - $port = env('DB_PORT', '3306'); + $port = config("database.connections.$connection.port", '3306'); $database = $request['database']; $username = $request['username']; $password = $request['password']; diff --git a/app/Http/ViewComposers/Notifications.php b/app/Http/ViewComposers/Notifications.php index da0d56f10..cb7b5ba80 100644 --- a/app/Http/ViewComposers/Notifications.php +++ b/app/Http/ViewComposers/Notifications.php @@ -19,7 +19,7 @@ class Notifications public function compose(View $view) { // No need to add suggestions in console - if (app()->runningInConsole() || !env('APP_INSTALLED') || !user()) { + if (app()->runningInConsole() || !config('app.installed') || !user()) { return; } diff --git a/app/Http/ViewComposers/Suggestions.php b/app/Http/ViewComposers/Suggestions.php index 25c568e34..ef60b0adf 100644 --- a/app/Http/ViewComposers/Suggestions.php +++ b/app/Http/ViewComposers/Suggestions.php @@ -20,7 +20,7 @@ class Suggestions public function compose(View $view) { // No need to add suggestions in console - if (app()->runningInConsole() || !env('APP_INSTALLED')) { + if (app()->runningInConsole() || !config('app.installed')) { return; } @@ -31,10 +31,10 @@ class Suggestions if ($path) { $suggestions = $this->getSuggestions($path); - + if ($suggestions) { $suggestion_modules = $suggestions->modules; - + foreach ($suggestion_modules as $key => $module) { $installed = Module::where('company_id', session('company_id'))->where('alias', $module->alias)->first(); diff --git a/app/Listeners/Update/V20/Version207.php b/app/Listeners/Update/V20/Version207.php index 178b008c3..97f4af5c7 100644 --- a/app/Listeners/Update/V20/Version207.php +++ b/app/Listeners/Update/V20/Version207.php @@ -26,7 +26,7 @@ class Version207 extends Listener // Update .env file Installer::updateEnv([ - 'MAIL_MAILER' => env('MAIL_DRIVER'), + 'MAIL_MAILER' => config('mail.default'), ]); } } diff --git a/app/Providers/App.php b/app/Providers/App.php index 990b6d9ae..e3a0d8f8e 100644 --- a/app/Providers/App.php +++ b/app/Providers/App.php @@ -31,11 +31,11 @@ class App extends Provider */ public function register() { - if (env('APP_INSTALLED') && env('APP_DEBUG')) { + if (config('app.installed') && config('app.debug')) { $this->app->register(\Barryvdh\Debugbar\ServiceProvider::class); } - if (env('APP_ENV') !== 'production') { + if (config('app.env') !== 'production') { $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class); } } diff --git a/app/Traits/DateTime.php b/app/Traits/DateTime.php index f3a81838d..5c4ec6ded 100644 --- a/app/Traits/DateTime.php +++ b/app/Traits/DateTime.php @@ -17,7 +17,7 @@ trait DateTime $default = 'd M Y'; // Make sure it's installed - if (!env('APP_INSTALLED') && (env('APP_ENV') !== 'testing')) { + if (!config('app.installed') && (config('app.env') !== 'testing')) { return $default; } diff --git a/app/Utilities/Info.php b/app/Utilities/Info.php index 157605abe..ccebe9d3c 100644 --- a/app/Utilities/Info.php +++ b/app/Utilities/Info.php @@ -33,7 +33,7 @@ class Info public static function mysqlVersion() { - if (env('DB_CONNECTION') === 'mysql') { + if (config('database.default') === 'mysql') { return DB::selectOne('select version() as mversion')->mversion; } diff --git a/app/Utilities/Installer.php b/app/Utilities/Installer.php index e671b3b60..cd44b82c6 100644 --- a/app/Utilities/Installer.php +++ b/app/Utilities/Installer.php @@ -183,8 +183,8 @@ class Installer 'database' => $database, 'username' => $username, 'password' => $password, - 'driver' => env('DB_CONNECTION', 'mysql'), - 'charset' => env('DB_CHARSET', 'utf8mb4'), + 'driver' => $connection = config('database.default', 'mysql'), + 'charset' => config("database.connections.$connection.charset", 'utf8mb4'), ]); try { @@ -213,7 +213,7 @@ class Installer 'DB_PREFIX' => $prefix, ]); - $con = env('DB_CONNECTION', 'mysql'); + $con = config('database.default', 'mysql'); // Change current connection $db = Config::get('database.connections.' . $con); diff --git a/config/app.php b/config/app.php index 58edec322..d8831bcbb 100644 --- a/config/app.php +++ b/config/app.php @@ -14,6 +14,10 @@ return [ 'name' => env('APP_NAME', 'Akaunting'), + 'installed' => env('APP_INSTALLED', false), + + 'schedule_time' => env('APP_SCHEDULE_TIME', '9:00'), + /* |-------------------------------------------------------------------------- | Application Environment diff --git a/resources/views/partials/admin/head.blade.php b/resources/views/partials/admin/head.blade.php index 223ff0781..391d2811b 100644 --- a/resources/views/partials/admin/head.blade.php +++ b/resources/views/partials/admin/head.blade.php @@ -33,7 +33,7 @@ @stack('js') diff --git a/resources/views/partials/auth/head.blade.php b/resources/views/partials/auth/head.blade.php index 573476d90..35aa6f139 100644 --- a/resources/views/partials/auth/head.blade.php +++ b/resources/views/partials/auth/head.blade.php @@ -28,7 +28,7 @@ @stack('js') diff --git a/resources/views/partials/modules/head.blade.php b/resources/views/partials/modules/head.blade.php index 8a2b3b2b0..ec22e4ee5 100644 --- a/resources/views/partials/modules/head.blade.php +++ b/resources/views/partials/modules/head.blade.php @@ -31,7 +31,7 @@ @stack('js') diff --git a/resources/views/partials/portal/head.blade.php b/resources/views/partials/portal/head.blade.php index d6d121250..5e0fac33d 100644 --- a/resources/views/partials/portal/head.blade.php +++ b/resources/views/partials/portal/head.blade.php @@ -30,7 +30,7 @@ @stack('js') diff --git a/resources/views/partials/signed/head.blade.php b/resources/views/partials/signed/head.blade.php index d6d121250..5e0fac33d 100644 --- a/resources/views/partials/signed/head.blade.php +++ b/resources/views/partials/signed/head.blade.php @@ -30,7 +30,7 @@ @stack('js') diff --git a/resources/views/partials/wizard/head.blade.php b/resources/views/partials/wizard/head.blade.php index 4e9272c4b..c73198260 100644 --- a/resources/views/partials/wizard/head.blade.php +++ b/resources/views/partials/wizard/head.blade.php @@ -30,7 +30,7 @@ @stack('js')