1
0
mirror of https://github.com/flarum/core.git synced 2025-10-28 14:06:30 +01:00

Rename app to container (#2609)

* Rename `app` helper to `resolve`, deprecate old version
* Rename $this->app to $this->container in service providers

We no longer couple Flarum\Foundation\Application to the Laravel container; instead, we use the container separately. Changing our naming to reflect that will make things clearer.
This commit is contained in:
Alexander Skvortsov
2021-03-04 22:14:48 -05:00
committed by GitHub
parent 15cbe4daaa
commit c81f629b0b
29 changed files with 306 additions and 278 deletions

View File

@@ -25,7 +25,7 @@ class LocaleServiceProvider extends AbstractServiceProvider
public function boot(Dispatcher $events)
{
$events->listen(ClearingCache::class, function () {
$this->app->make('flarum.locales')->clearCache();
$this->container->make('flarum.locales')->clearCache();
});
}
@@ -34,9 +34,9 @@ class LocaleServiceProvider extends AbstractServiceProvider
*/
public function register()
{
$this->app->singleton(LocaleManager::class, function () {
$this->container->singleton(LocaleManager::class, function () {
$locales = new LocaleManager(
$this->app->make('translator'),
$this->container->make('translator'),
$this->getCacheDir()
);
@@ -45,14 +45,14 @@ class LocaleServiceProvider extends AbstractServiceProvider
return $locales;
});
$this->app->alias(LocaleManager::class, 'flarum.locales');
$this->container->alias(LocaleManager::class, 'flarum.locales');
$this->app->singleton('translator', function () {
$this->container->singleton('translator', function () {
$translator = new Translator(
$this->getDefaultLocale(),
null,
$this->getCacheDir(),
$this->app['flarum.debug']
$this->container['flarum.debug']
);
$translator->setFallbackLocales(['en']);
@@ -62,20 +62,20 @@ class LocaleServiceProvider extends AbstractServiceProvider
return $translator;
});
$this->app->alias('translator', Translator::class);
$this->app->alias('translator', TranslatorContract::class);
$this->app->alias('translator', TranslatorInterface::class);
$this->container->alias('translator', Translator::class);
$this->container->alias('translator', TranslatorContract::class);
$this->container->alias('translator', TranslatorInterface::class);
}
private function getDefaultLocale(): string
{
$repo = $this->app->make(SettingsRepositoryInterface::class);
$repo = $this->container->make(SettingsRepositoryInterface::class);
return $repo->get('default_locale', 'en');
}
private function getCacheDir(): string
{
return $this->app[Paths::class]->storage.'/locale';
return $this->container[Paths::class]->storage.'/locale';
}
}