mirror of
https://github.com/flarum/framework.git
synced 2024-11-29 21:11:55 +08:00
Use lifecycle interface for frontend extender (#2211)
This commit is contained in:
parent
7f27f1180b
commit
368a9836bd
|
@ -9,8 +9,6 @@
|
||||||
|
|
||||||
namespace Flarum\Admin;
|
namespace Flarum\Admin;
|
||||||
|
|
||||||
use Flarum\Extension\Event\Disabled;
|
|
||||||
use Flarum\Extension\Event\Enabled;
|
|
||||||
use Flarum\Foundation\AbstractServiceProvider;
|
use Flarum\Foundation\AbstractServiceProvider;
|
||||||
use Flarum\Foundation\ErrorHandling\Registry;
|
use Flarum\Foundation\ErrorHandling\Registry;
|
||||||
use Flarum\Foundation\ErrorHandling\Reporter;
|
use Flarum\Foundation\ErrorHandling\Reporter;
|
||||||
|
@ -118,7 +116,7 @@ class AdminServiceProvider extends AbstractServiceProvider
|
||||||
$events = $this->app->make('events');
|
$events = $this->app->make('events');
|
||||||
|
|
||||||
$events->listen(
|
$events->listen(
|
||||||
[Enabled::class, Disabled::class, ClearingCache::class],
|
ClearingCache::class,
|
||||||
function () {
|
function () {
|
||||||
$recompile = new RecompileFrontendAssets(
|
$recompile = new RecompileFrontendAssets(
|
||||||
$this->app->make('flarum.assets.admin'),
|
$this->app->make('flarum.assets.admin'),
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
|
|
||||||
namespace Flarum\Extend;
|
namespace Flarum\Extend;
|
||||||
|
|
||||||
use Flarum\Extension\Event\Disabled;
|
|
||||||
use Flarum\Extension\Event\Enabled;
|
|
||||||
use Flarum\Extension\Extension;
|
use Flarum\Extension\Extension;
|
||||||
use Flarum\Foundation\Event\ClearingCache;
|
use Flarum\Foundation\Event\ClearingCache;
|
||||||
use Flarum\Frontend\Assets;
|
use Flarum\Frontend\Assets;
|
||||||
|
@ -23,7 +21,7 @@ use Flarum\Locale\LocaleManager;
|
||||||
use Flarum\Settings\Event\Saved;
|
use Flarum\Settings\Event\Saved;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
|
|
||||||
class Frontend implements ExtenderInterface
|
class Frontend implements ExtenderInterface, LifecycleInterface
|
||||||
{
|
{
|
||||||
private $frontend;
|
private $frontend;
|
||||||
|
|
||||||
|
@ -115,13 +113,9 @@ class Frontend implements ExtenderInterface
|
||||||
$events = $container->make('events');
|
$events = $container->make('events');
|
||||||
|
|
||||||
$events->listen(
|
$events->listen(
|
||||||
[Enabled::class, Disabled::class, ClearingCache::class],
|
ClearingCache::class,
|
||||||
function () use ($container, $abstract) {
|
function () use ($container) {
|
||||||
$recompile = new RecompileFrontendAssets(
|
$this->recompile($container);
|
||||||
$container->make($abstract),
|
|
||||||
$container->make(LocaleManager::class)
|
|
||||||
);
|
|
||||||
$recompile->flush();
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -185,4 +179,27 @@ class Frontend implements ExtenderInterface
|
||||||
{
|
{
|
||||||
return $extension ? $extension->getId() : 'site-custom';
|
return $extension ? $extension->getId() : 'site-custom';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onEnable(Container $container, Extension $extension)
|
||||||
|
{
|
||||||
|
if (! empty($this->js) || ! empty($this->css)) {
|
||||||
|
$this->recompile($container);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onDisable(Container $container, Extension $extension)
|
||||||
|
{
|
||||||
|
if (! empty($this->js) || ! empty($this->css)) {
|
||||||
|
$this->recompile($container);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function recompile($container)
|
||||||
|
{
|
||||||
|
$recompile = new RecompileFrontendAssets(
|
||||||
|
$container->make('flarum.assets.'.$this->frontend),
|
||||||
|
$container->make(LocaleManager::class)
|
||||||
|
);
|
||||||
|
$recompile->flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
|
|
||||||
namespace Flarum\Forum;
|
namespace Flarum\Forum;
|
||||||
|
|
||||||
use Flarum\Extension\Event\Disabled;
|
|
||||||
use Flarum\Extension\Event\Enabled;
|
|
||||||
use Flarum\Formatter\Formatter;
|
use Flarum\Formatter\Formatter;
|
||||||
use Flarum\Foundation\AbstractServiceProvider;
|
use Flarum\Foundation\AbstractServiceProvider;
|
||||||
use Flarum\Foundation\ErrorHandling\Registry;
|
use Flarum\Foundation\ErrorHandling\Registry;
|
||||||
|
@ -134,7 +132,7 @@ class ForumServiceProvider extends AbstractServiceProvider
|
||||||
$events = $this->app->make('events');
|
$events = $this->app->make('events');
|
||||||
|
|
||||||
$events->listen(
|
$events->listen(
|
||||||
[Enabled::class, Disabled::class, ClearingCache::class],
|
ClearingCache::class,
|
||||||
function () {
|
function () {
|
||||||
$recompile = new RecompileFrontendAssets(
|
$recompile = new RecompileFrontendAssets(
|
||||||
$this->app->make('flarum.assets.forum'),
|
$this->app->make('flarum.assets.forum'),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user