mirror of
https://github.com/flarum/framework.git
synced 2025-04-01 21:55:16 +08:00
Create ExtensionValidator.php
This commit is contained in:
parent
58f9c22375
commit
3702ffa998
51
src/Core/Listener/ExtensionValidator.php
Normal file
51
src/Core/Listener/ExtensionValidator.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Core\Listener;
|
||||
|
||||
use Flarum\Event\ExtensionWillBeEnabled;
|
||||
use Flarum\Event\ExtensionWillBeDisabled;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Flarum\Http\Exception\MethodNotAllowedException;
|
||||
|
||||
class ExtensionModificationValidator
|
||||
{
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(ExtensionWillBeEnabled::class, [$this, 'whenExtensionWillBeEnabled']);
|
||||
$events->listen(ExtensionWillBeDisabled::class, [$this, 'whenExtensionWillBeDisabled']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ExtensionWillBeEnabled $event
|
||||
*/
|
||||
public function whenExtensionWillBeEnabled(ExtensionWillBeEnabled $event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ExtensionWillBeDisabled $event
|
||||
* @throws MethodNotAllowedException
|
||||
*/
|
||||
public function whenExtensionWillBeDisabled(ExtensionWillBeDisabled $event)
|
||||
{
|
||||
if (in_array('flarum-locale', $event->extension->extra)) {
|
||||
$default_locale = $this->app->make('flarum.settings')->get('default_locale');
|
||||
$locale = array_get($event->extension->extra, 'flarum-locale.code');
|
||||
if ($locale === $default_locale) {
|
||||
throw new MethodNotAllowedException('You cannot remove all your language packs!');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user