mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 23:23:52 +08:00
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.
This commit is contained in:
parent
fe07d4064b
commit
dccbefeafa
|
@ -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'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user