From dccbefeafa9408d12ac9e30e4b0b924c59b79478 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 21 Apr 2018 18:57:15 +0200 Subject: [PATCH] Get rid of some Application methods These are not necessary to be available so broadly. In fact, they seem to make it too easy to use them, which has lead to some sub- optimal architecture decisions. Their equivalents have been moved to the classes where used. --- .../src/Database/DatabaseServiceProvider.php | 6 ++-- framework/core/src/Foundation/Application.php | 28 ++----------------- .../core/src/Locale/LocaleServiceProvider.php | 7 +++-- 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/framework/core/src/Database/DatabaseServiceProvider.php b/framework/core/src/Database/DatabaseServiceProvider.php index 8d3c08262..302305266 100644 --- a/framework/core/src/Database/DatabaseServiceProvider.php +++ b/framework/core/src/Database/DatabaseServiceProvider.php @@ -50,9 +50,7 @@ class DatabaseServiceProvider extends AbstractServiceProvider */ public function boot() { - if ($this->app->isInstalled()) { - AbstractModel::setConnectionResolver($this->app->make('Illuminate\Database\ConnectionResolverInterface')); - AbstractModel::setEventDispatcher($this->app->make('events')); - } + AbstractModel::setConnectionResolver($this->app->make('Illuminate\Database\ConnectionResolverInterface')); + AbstractModel::setEventDispatcher($this->app->make('events')); } } diff --git a/framework/core/src/Foundation/Application.php b/framework/core/src/Foundation/Application.php index 61c8fd798..10c194520 100644 --- a/framework/core/src/Foundation/Application.php +++ b/framework/core/src/Foundation/Application.php @@ -11,7 +11,6 @@ namespace Flarum\Foundation; -use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Container\Container; use Illuminate\Contracts\Foundation\Application as ApplicationContract; use Illuminate\Events\EventServiceProvider; @@ -114,27 +113,6 @@ class Application extends Container implements ApplicationContract } } - /** - * Determine if Flarum has been installed. - * - * @return bool - */ - public function isInstalled(): bool - { - return $this->bound('flarum.config'); - } - - public function isUpToDate(): bool - { - $settings = $this->make(SettingsRepositoryInterface::class); - - try { - $version = $settings->get('version'); - } finally { - return isset($version) && $version === $this->version(); - } - } - /** * @param string $key * @param mixed $default @@ -142,7 +120,7 @@ class Application extends Container implements ApplicationContract */ public function config($key, $default = null) { - return $this->isInstalled() ? array_get($this->make('flarum.config'), $key, $default) : $default; + return array_get($this->make('flarum.config'), $key, $default); } /** @@ -152,7 +130,7 @@ class Application extends Container implements ApplicationContract */ public function inDebugMode() { - return ! $this->isInstalled() || $this->config('debug'); + return $this->config('debug', true); } /** @@ -163,7 +141,7 @@ class Application extends Container implements ApplicationContract */ public function url($path = null) { - $config = $this->isInstalled() ? $this->make('flarum.config') : []; + $config = $this->make('flarum.config'); $url = array_get($config, 'url', array_get($_SERVER, 'REQUEST_URI')); if (is_array($url)) { diff --git a/framework/core/src/Locale/LocaleServiceProvider.php b/framework/core/src/Locale/LocaleServiceProvider.php index 74ab5331d..b9cf94b68 100644 --- a/framework/core/src/Locale/LocaleServiceProvider.php +++ b/framework/core/src/Locale/LocaleServiceProvider.php @@ -13,6 +13,7 @@ namespace Flarum\Locale; use Flarum\Event\ConfigureLocales; use Flarum\Foundation\AbstractServiceProvider; +use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Translation\Translator as TranslatorContract; use Symfony\Component\Translation\MessageSelector; @@ -54,8 +55,8 @@ class LocaleServiceProvider extends AbstractServiceProvider private function getDefaultLocale(): string { - return $this->app->isInstalled() && $this->app->isUpToDate() - ? $this->app->make('flarum.settings')->get('default_locale', 'en') - : 'en'; + $repo = $this->app->make(SettingsRepositoryInterface::class); + + return $repo->get('default_locale', 'en'); } }