mirror of
https://github.com/flarum/framework.git
synced 2025-01-20 03:52:46 +08:00
Early returns
This commit is contained in:
parent
b58380e224
commit
4b00f7996b
|
@ -42,12 +42,15 @@ class DefaultLanguagePackGuard
|
|||
*/
|
||||
public function whenExtensionWillBeDisabled(Disabling $event)
|
||||
{
|
||||
if (in_array('flarum-locale', $event->extension->extra)) {
|
||||
$defaultLocale = $this->settings->get('default_locale');
|
||||
$locale = array_get($event->extension->extra, 'flarum-locale.code');
|
||||
if ($locale === $defaultLocale) {
|
||||
throw new ForbiddenException('You cannot disable the default language pack!');
|
||||
}
|
||||
if (! in_array('flarum-locale', $event->extension->extra)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$defaultLocale = $this->settings->get('default_locale');
|
||||
$locale = array_get($event->extension->extra, 'flarum-locale.code');
|
||||
|
||||
if ($locale === $defaultLocale) {
|
||||
throw new ForbiddenException('You cannot disable the default language pack!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,39 +69,41 @@ class ValidateCustomLess
|
|||
*/
|
||||
public function whenSettingsSaving(Saving $event)
|
||||
{
|
||||
if (isset($event->settings['custom_less'])) {
|
||||
// We haven't saved the settings yet, but we want to trial a full
|
||||
// recompile of the CSS to see if this custom LESS will break
|
||||
// anything. In order to do that, we will temporarily override the
|
||||
// settings repository with the new settings so that the recompile
|
||||
// is effective. We will also use a dummy filesystem so that nothing
|
||||
// is actually written yet.
|
||||
|
||||
$settings = $this->container->make(SettingsRepositoryInterface::class);
|
||||
|
||||
$this->container->extend(
|
||||
SettingsRepositoryInterface::class,
|
||||
function ($settings) use ($event) {
|
||||
return new OverrideSettingsRepository($settings, $event->settings);
|
||||
}
|
||||
);
|
||||
|
||||
$assetsDir = $this->assets->getAssetsDir();
|
||||
$this->assets->setAssetsDir(new FilesystemAdapter(new Filesystem(new NullAdapter)));
|
||||
|
||||
try {
|
||||
$this->assets->makeCss()->commit();
|
||||
|
||||
foreach ($this->locales->getLocales() as $locale => $name) {
|
||||
$this->assets->makeLocaleCss($locale)->commit();
|
||||
}
|
||||
} catch (Less_Exception_Parser $e) {
|
||||
throw new ValidationException(['custom_less' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
$this->assets->setAssetsDir($assetsDir);
|
||||
$this->container->instance(SettingsRepositoryInterface::class, $settings);
|
||||
if (! isset($event->settings['custom_less'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We haven't saved the settings yet, but we want to trial a full
|
||||
// recompile of the CSS to see if this custom LESS will break
|
||||
// anything. In order to do that, we will temporarily override the
|
||||
// settings repository with the new settings so that the recompile
|
||||
// is effective. We will also use a dummy filesystem so that nothing
|
||||
// is actually written yet.
|
||||
|
||||
$settings = $this->container->make(SettingsRepositoryInterface::class);
|
||||
|
||||
$this->container->extend(
|
||||
SettingsRepositoryInterface::class,
|
||||
function ($settings) use ($event) {
|
||||
return new OverrideSettingsRepository($settings, $event->settings);
|
||||
}
|
||||
);
|
||||
|
||||
$assetsDir = $this->assets->getAssetsDir();
|
||||
$this->assets->setAssetsDir(new FilesystemAdapter(new Filesystem(new NullAdapter)));
|
||||
|
||||
try {
|
||||
$this->assets->makeCss()->commit();
|
||||
|
||||
foreach ($this->locales->getLocales() as $locale => $name) {
|
||||
$this->assets->makeLocaleCss($locale)->commit();
|
||||
}
|
||||
} catch (Less_Exception_Parser $e) {
|
||||
throw new ValidationException(['custom_less' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
$this->assets->setAssetsDir($assetsDir);
|
||||
$this->container->instance(SettingsRepositoryInterface::class, $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,12 +111,14 @@ class ValidateCustomLess
|
|||
*/
|
||||
public function whenSettingsSaved(Saved $event)
|
||||
{
|
||||
if (isset($event->settings['custom_less'])) {
|
||||
$this->assets->makeCss()->flush();
|
||||
if (! isset($event->settings['custom_less'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->locales->getLocales() as $locale => $name) {
|
||||
$this->assets->makeLocaleCss($locale)->flush();
|
||||
}
|
||||
$this->assets->makeCss()->flush();
|
||||
|
||||
foreach ($this->locales->getLocales() as $locale => $name) {
|
||||
$this->assets->makeLocaleCss($locale)->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user