From ea7d31e15e792c36890a5993ba1f99ad057410d1 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com> Date: Wed, 23 Sep 2020 00:21:45 -0400 Subject: [PATCH] Revert "Use lifecycle interface for frontend extender (#2211)" (#2301) This reverts commit 368a9836bd0f58e2dcb7879fe9c89e42974da97e. --- .../core/src/Admin/AdminServiceProvider.php | 4 +- framework/core/src/Extend/Frontend.php | 37 +++++-------------- .../core/src/Forum/ForumServiceProvider.php | 4 +- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/framework/core/src/Admin/AdminServiceProvider.php b/framework/core/src/Admin/AdminServiceProvider.php index 65be464cc..103bd35df 100644 --- a/framework/core/src/Admin/AdminServiceProvider.php +++ b/framework/core/src/Admin/AdminServiceProvider.php @@ -9,6 +9,8 @@ namespace Flarum\Admin; +use Flarum\Extension\Event\Disabled; +use Flarum\Extension\Event\Enabled; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\ErrorHandling\Registry; use Flarum\Foundation\ErrorHandling\Reporter; @@ -116,7 +118,7 @@ class AdminServiceProvider extends AbstractServiceProvider $events = $this->app->make('events'); $events->listen( - ClearingCache::class, + [Enabled::class, Disabled::class, ClearingCache::class], function () { $recompile = new RecompileFrontendAssets( $this->app->make('flarum.assets.admin'), diff --git a/framework/core/src/Extend/Frontend.php b/framework/core/src/Extend/Frontend.php index 224080823..3fd5e8554 100644 --- a/framework/core/src/Extend/Frontend.php +++ b/framework/core/src/Extend/Frontend.php @@ -9,6 +9,8 @@ namespace Flarum\Extend; +use Flarum\Extension\Event\Disabled; +use Flarum\Extension\Event\Enabled; use Flarum\Extension\Extension; use Flarum\Foundation\Event\ClearingCache; use Flarum\Frontend\Assets; @@ -21,7 +23,7 @@ use Flarum\Locale\LocaleManager; use Flarum\Settings\Event\Saved; use Illuminate\Contracts\Container\Container; -class Frontend implements ExtenderInterface, LifecycleInterface +class Frontend implements ExtenderInterface { private $frontend; @@ -113,9 +115,13 @@ class Frontend implements ExtenderInterface, LifecycleInterface $events = $container->make('events'); $events->listen( - ClearingCache::class, - function () use ($container) { - $this->recompile($container); + [Enabled::class, Disabled::class, ClearingCache::class], + function () use ($container, $abstract) { + $recompile = new RecompileFrontendAssets( + $container->make($abstract), + $container->make(LocaleManager::class) + ); + $recompile->flush(); } ); @@ -179,27 +185,4 @@ class Frontend implements ExtenderInterface, LifecycleInterface { 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(); - } } diff --git a/framework/core/src/Forum/ForumServiceProvider.php b/framework/core/src/Forum/ForumServiceProvider.php index d333b7505..1903783d6 100644 --- a/framework/core/src/Forum/ForumServiceProvider.php +++ b/framework/core/src/Forum/ForumServiceProvider.php @@ -9,6 +9,8 @@ namespace Flarum\Forum; +use Flarum\Extension\Event\Disabled; +use Flarum\Extension\Event\Enabled; use Flarum\Formatter\Formatter; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\ErrorHandling\Registry; @@ -132,7 +134,7 @@ class ForumServiceProvider extends AbstractServiceProvider $events = $this->app->make('events'); $events->listen( - ClearingCache::class, + [Enabled::class, Disabled::class, ClearingCache::class], function () { $recompile = new RecompileFrontendAssets( $this->app->make('flarum.assets.forum'),