mirror of
https://github.com/flarum/core.git
synced 2025-06-25 12:14:13 +02:00
Inject settings repository in event listener
`$this->app` was not defined here anyway. Refs #1032.
This commit is contained in:
@ -13,10 +13,21 @@ namespace Flarum\Extension;
|
|||||||
|
|
||||||
use Flarum\Extension\Event\Disabling;
|
use Flarum\Extension\Event\Disabling;
|
||||||
use Flarum\Http\Exception\ForbiddenException;
|
use Flarum\Http\Exception\ForbiddenException;
|
||||||
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
|
||||||
class DefaultLanguagePackGuard
|
class DefaultLanguagePackGuard
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var SettingsRepositoryInterface
|
||||||
|
*/
|
||||||
|
protected $settings;
|
||||||
|
|
||||||
|
public function __construct(SettingsRepositoryInterface $settings)
|
||||||
|
{
|
||||||
|
$this->settings = $settings;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Dispatcher $events
|
* @param Dispatcher $events
|
||||||
*/
|
*/
|
||||||
@ -32,9 +43,9 @@ class DefaultLanguagePackGuard
|
|||||||
public function whenExtensionWillBeDisabled(Disabling $event)
|
public function whenExtensionWillBeDisabled(Disabling $event)
|
||||||
{
|
{
|
||||||
if (in_array('flarum-locale', $event->extension->extra)) {
|
if (in_array('flarum-locale', $event->extension->extra)) {
|
||||||
$default_locale = $this->app->make('flarum.settings')->get('default_locale');
|
$defaultLocale = $this->settings->get('default_locale');
|
||||||
$locale = array_get($event->extension->extra, 'flarum-locale.code');
|
$locale = array_get($event->extension->extra, 'flarum-locale.code');
|
||||||
if ($locale === $default_locale) {
|
if ($locale === $defaultLocale) {
|
||||||
throw new ForbiddenException('You cannot disable the default language pack!');
|
throw new ForbiddenException('You cannot disable the default language pack!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user