mirror of
https://github.com/flarum/core.git
synced 2025-08-15 12:54:47 +02:00
fixed container bindings use of container (#2807)
This commit is contained in:
@@ -12,6 +12,7 @@ namespace Flarum\Locale;
|
||||
use Flarum\Foundation\AbstractServiceProvider;
|
||||
use Flarum\Foundation\Paths;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Contracts\Translation\Translator as TranslatorContract;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
@@ -22,25 +23,25 @@ class LocaleServiceProvider extends AbstractServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->container->singleton(LocaleManager::class, function () {
|
||||
$this->container->singleton(LocaleManager::class, function (Container $container) {
|
||||
$locales = new LocaleManager(
|
||||
$this->container->make('translator'),
|
||||
$this->getCacheDir()
|
||||
$container->make('translator'),
|
||||
$this->getCacheDir($container)
|
||||
);
|
||||
|
||||
$locales->addLocale($this->getDefaultLocale(), 'Default');
|
||||
$locales->addLocale($this->getDefaultLocale($container), 'Default');
|
||||
|
||||
return $locales;
|
||||
});
|
||||
|
||||
$this->container->alias(LocaleManager::class, 'flarum.locales');
|
||||
|
||||
$this->container->singleton('translator', function () {
|
||||
$this->container->singleton('translator', function (Container $container) {
|
||||
$translator = new Translator(
|
||||
$this->getDefaultLocale(),
|
||||
$this->getDefaultLocale($container),
|
||||
null,
|
||||
$this->getCacheDir(),
|
||||
$this->container['flarum.debug']
|
||||
$this->getCacheDir($container),
|
||||
$container['flarum.debug']
|
||||
);
|
||||
|
||||
$translator->setFallbackLocales(['en']);
|
||||
@@ -56,15 +57,15 @@ class LocaleServiceProvider extends AbstractServiceProvider
|
||||
$this->container->alias('translator', TranslatorInterface::class);
|
||||
}
|
||||
|
||||
private function getDefaultLocale(): string
|
||||
private function getDefaultLocale(Container $container): string
|
||||
{
|
||||
$repo = $this->container->make(SettingsRepositoryInterface::class);
|
||||
$repo = $container->make(SettingsRepositoryInterface::class);
|
||||
|
||||
return $repo->get('default_locale', 'en');
|
||||
}
|
||||
|
||||
private function getCacheDir(): string
|
||||
private function getCacheDir(Container $container): string
|
||||
{
|
||||
return $this->container[Paths::class]->storage.'/locale';
|
||||
return $container[Paths::class]->storage.'/locale';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user