Inject settings repository in event listener

`$this->app` was not defined here anyway.

Refs #1032.
This commit is contained in:
Franz Liedke 2017-07-03 10:15:09 +02:00
parent 1215a1ef9b
commit fddd134fa0
No known key found for this signature in database
GPG Key ID: 9A0231A879B055F4

View File

@ -13,10 +13,21 @@ namespace Flarum\Extension;
use Flarum\Extension\Event\Disabling;
use Flarum\Http\Exception\ForbiddenException;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Events\Dispatcher;
class DefaultLanguagePackGuard
{
/**
* @var SettingsRepositoryInterface
*/
protected $settings;
public function __construct(SettingsRepositoryInterface $settings)
{
$this->settings = $settings;
}
/**
* @param Dispatcher $events
*/
@ -32,9 +43,9 @@ class DefaultLanguagePackGuard
public function whenExtensionWillBeDisabled(Disabling $event)
{
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');
if ($locale === $default_locale) {
if ($locale === $defaultLocale) {
throw new ForbiddenException('You cannot disable the default language pack!');
}
}